T09 · Insecure Skill Coding Practices
- Location
scripts/zapper.sh:20- Finding
Python Code Injection Through an Attacker-Controlled Configuration Path
- Content
View full analysis
/dev/null || echo "") ``` ### Technical Analysis `CONFIG_FILE` is derived from the `HOME` environment variable and interpolated directly into the source code supplied to `python3 -c`. Shell quoting protects the value from direct shell expansion, but it does not make the resulting text safe as a Python string literal. If `HOME` contains a single quote followed by valid Python syntax, the generated path can terminate the argument to `open()` and introduce additional Python statements. The attacker must also arrange for the shell's `[[ -f "$CONFIG_FILE" ]]` check to succeed, but this is possible when the attacker controls the relevant filesystem hierarchy. The vulnerable function is reached by the `portfolio`, `tokens`, `apps`, `nfts`, `tx`, and `claimables` commands. ### Attack Path 1. An attacker gains control over the `HOME` environment variable supplied to the script, such as through an unsafe service wrapper, automation job, or delegated execution environment. 2. The attacker assigns a path containing a single quote and injected Python syntax to `HOME`. 3. The attacker creates the corresponding filesystem path and `config.json` entry so that the `-f` check succeeds. 4. A command that invokes `load_api_key` is executed. 5. The crafted path is embedded into the `python3 -c` source string. 6. Python parses and executes the injected statements with the privileges of the user running the skill. ### Impact Assessment Successful exploitation permits arbitrary local code execution with the operating-sy ...[truncated 351 chars]- Remediation
View remediation
/dev/null`. ]]>
