T09 · Insecure Skill Coding Practices
- Location
record-usage.sh:28- Finding
Arbitrary Python Code Execution Through Usage Recording
- Content
View full analysis
/dev/null || echo "{\"$SKILL_NAME\":\"$TIMESTAMP\"}" > "$LATEST_FILE" ``` ### Technical Analysis `SKILL_NAME` is accepted from the first command-line argument and interpolated directly into a Python program passed to `python3 -c`. Shell quoting does not protect the generated Python source. A skill name containing a single quote and additional Python statements can terminate the intended string literal and introduce arbitrary statements. For example, a name shaped like the following can produce syntactically valid injected Python: ```text x'] = ''; __import__('os').system('COMMAND'); data['y ``` The generated statement becomes equivalent to: ```python data['x'] = '' __import__('os').system('COMMAND') data['y'] = 'TIMESTAMP' ``` The vulnerable branch is reached when `latest-usage.json` already exists. That file is normally created by the same script, so this condition is expected during ordinary repeated use. ### Attack Path 1. Ensure `latest-usage.json` exists, such as by invoking `record-usage.sh` once with an ordinary skill name. 2. Invoke `record-usage.sh` with a crafted skill-name argument containing a single quote and injected Python statements. 3. The script places the argument directly inside the `python3 -c` source. 4. Python parses and executes the injected statements. 5. Any command launched by the injected Python runs with the account privileges of the user executing the lifecycle script. ### Impact Assessment Successful exploitation provides arbitrary local code execution as the invoking user. The attacker can read or alter fil ...[truncated 255 chars]- Remediation
View remediation
