T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:292- Finding
Arbitrary Python Code Execution Through a Crafted Dataset Filename
- Content
View full analysis
/dev/null || echo "parse-error") ``` ### Technical Analysis The user-controlled `--file` value is interpolated directly into Python source code enclosed by `open('$file')`. Shell quotation does not make this value safe for the Python parser. A filename containing a single quote, closing parentheses, semicolons, and additional Python statements can terminate the intended expression and inject arbitrary Python code. The preceding `[[ -f "$file" ]]` check does not prevent exploitation. An attacker who can create files in the working directory can create both the crafted filename required to pass that check and any secondary file referenced by the injected Python expression. The script already uses a safe argument-based approach in the subsequent heredoc invocation: ```bash python3 - "$file" "$fmt" << 'PYEOF' ``` The same design should be applied to the initial count operation. ### Attack Path 1. An attacker creates a JSON file and an additional file whose name contains Python syntax. 2. The attacker invokes: ```bash bash scripts/script.sh validate --file "" ``` 3. The shell expands `$file` into the `python3 -c` source string. 4. The crafted quote and Python syntax escape the intended `open()` call. 5. Python executes the injected statements with the privileges of the user running the Skill. For example, the injected statements could invoke `os.system()`, read accessible files, modify the user's files, or launch another executable. ### Impact Assessment Successful exploitation provides arbitrary code execution under the current user's account. The attacker can access any files, environment variables, tokens, SSH mate ...[truncated 226 chars]- Remediation
View remediation
/dev/null || echo "parse-error" ) ``` Alternatively, combine the counting and format validation operations into the existing argument-based Python heredoc. Never construct executable Python source using direct interpolation of user-controlled values. ]]>
