T09 · Insecure Skill Coding Practices
- Location
rock-solid-watchdog.sh:285- Finding
Arbitrary Python Code Execution Through Environment-Variable Interpolation
- Content
View full analysis
/dev/null || { ``` ### Technical Analysis The script interpolates shell-controlled values directly into the source text supplied to `python3 -c`. In particular, `LLAMA_HOST`, `LLAMA_PORT`, `PI_CONFIG_FILE`, and the temporary filename are inserted into Python string literals or expressions without Python-safe encoding. An attacker who can influence the watchdog's environment can provide a value containing quote characters and additional Python statements. When `ensure_pi_port_alignment` detects a missing or misaligned Pi configuration, the generated source is parsed and executed by Python. Shell quoting around the overall `python3 -c` argument does not protect the resulting Python program from Python syntax injection. `LLAMA_PORT` is especially dangerous because it is inserted as an unquoted Python expression: ```python cfg['llm']['port'] = $llama_port ``` The values are also used earlier in generated JSON, so strict type and content validation is necessary independently of the injection fix. ### Attack Path 1. The attacker obtains a way to control environment variables used to launch the watchdog, such as a service configuration, wrapper script, shell profile, or invocation command. 2. The attacker assigns malicious Python syntax to `LLAMA_HOST`, `LLAMA_PORT`, or another interpolate ...[truncated 950 chars]- Remediation
View remediation
