T09 · Insecure Skill Coding Practices
- Location
SKILL.md:37- Finding
Arbitrary Python Code Execution Through Unsafe File-Path Interpolation
- Content
View full analysis
' out = '<输出路径>.txt' # 尝试从文件名解析录音开始时间 m = re.search(r'(\d{8})_(\d{6})', wav) ``` ### Technical Analysis The documented workflow directs the agent to replace the audio and output placeholders inside Python source passed to `python3 -c`. The resulting values are therefore interpreted as part of the program rather than supplied as data through command-line arguments or another safe input channel. If an attacker controls the audio filename or path, a single quote in that path can terminate the `wav` string literal. Additional Python statements can then be inserted before the remainder of the generated source is neutralized. Shell metacharacters could create an additional injection boundary depending on how the agent performs placeholder substitution and invokes the command. No escaping, validation, canonicalization, or argument-based invocation is prescribed. Merely quoting the outer shell command with double quotes does not protect the embedded Python single-quoted literals. ### Attack Path 1. An attacker provides or causes the agent to process an audio file whose filename contains a single quote followed by Python statements. 2. The agent substitutes the attacker-controlled path directly into `wav = ''`. 3. The injected single quote terminates the intended Python string. 4. The following filename content becomes executable Python syntax when the generated command is passed to `python3 -c`. 5. The injected code executes with the operating-system privileges and environment of the agent process. 6. The code can read local ...[truncated 1151 chars]- Remediation
View remediation
