T09 · Insecure Skill Coding Practices
- Location
batch_whisper.py:34- Finding
Shell Command Injection Through Attacker-Controlled Video Paths
- Content
View full analysis
Vulnerability Details
File Location:
batch_whisper.py, lines 34–37
Vulnerability Type: OS command injection
Risk Level: HighVulnerable Code
python def extract_audio(video_path, temp_dir): """提取音频到临时文件""" audio_path = os.path.join(temp_dir, f"{Path(video_path).stem}.wav") cmd = f'ffmpeg -y -i "{video_path}" -vn -acodec pcm_s16le -ar 16000 -ac 1 "{audio_path}" 2>/dev/null' os.system(cmd) return audio_path if os.path.exists(audio_path) else NoneTechnical Analysis
The application constructs an FFmpeg command by directly interpolating
video_pathand the derivedaudio_pathinto a command string passed toos.system(). The shell therefore parses both paths as command-line syntax rather than treating them exclusively as literal arguments.Wrapping a path in double quotes is not sufficient shell escaping. Shell constructs such as command substitution, backticks, embedded quotes, and other metacharacters can still alter the command's behavior. Because
video_pathoriginates from the user-controlled--inputargument or from filenames discovered in a user-selected directory, an attacker can influence the command string.The output path is also derived from
Path(video_path).stem, so hostile filename content may propagate into both interpolated paths.Attack Path
- An attacker creates or supplies a video file whose filename contains shell syntax.
- The victim invokes the Skill with that file, a matching wildcard, or the directory containing it.
- The file-discovery logic includes the attacker-controlled path in the processing list.
extract_audio()embeds the path in the FFmpeg command string.os.system()invokes a shell to parse the resulting command.- The injected shell expression executes with the privileges of the account running the Skill.
Exploitation requires the attacker to control or influence a processed filename or input path. ...[truncated 692 chars]
- Remediation
View remediation
Remediation Suggestions
Replace the shell command string and
os.system()withsubprocess.run()using an explicit argument list:python import subprocess def extract_audio(video_path, temp_dir): audio_path = os.path.join(temp_dir, f"{Path(video_path).stem}.wav") try: subprocess.run( [ "ffmpeg", "-y", "-i", video_path, "-vn", "-acodec", "pcm_s16le", "-ar", "16000", "-ac", "1", audio_path, ], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True, ) except subprocess.CalledProcessError: return None return audio_path if os.path.isfile(audio_path) else NoneAdditional hardening measures:
- Never use
shell=Truefor this operation. - Resolve FFmpeg through a trusted, documented executable path where appropriate.
- Validate that each input is a regular file before processing it.
- Consider rejecting unexpected file types after inspecting actual media content rather than relying only on extensions.
- Generate temporary output names independently of untrusted filenames, such as with
tempfile. - Check the FFmpeg exit status and report extraction failures without exposing sensitive command details.
- Never use
