T09 · Insecure Skill Coding Practices
- Location
scripts/suggestions.sh:33- Finding
Arbitrary Python Code Execution Through Unsafely Interpolated Keyword
- Content
View full analysis
/dev/null || echo "$KEYWORD")" \ --connect-timeout 10 \ ``` ### Technical Analysis The user-controlled `KEYWORD` variable is directly interpolated into Python source code supplied to `python3 -c`: ```python import urllib.parse; print(urllib.parse.quote('$KEYWORD')) ``` Although the shell expansion occurs within a double-quoted shell argument, the expanded keyword becomes part of the Python program itself. An attacker can include a single quote and Python statement delimiters in the keyword to terminate the intended string, close the surrounding function calls, and append arbitrary Python statements. For example, a keyword shaped like the following can escape the intended Python string and invoke an operating-system command: ```text ')); __import__("os").system("id"); # ``` The constructed Python source would be equivalent to: ```python import urllib.parse; print(urllib.parse.quote('')); __import__("os").system("id"); #')) ``` This is valid Python and executes the injected operating-system command before `curl` sends the resulting request. URL encoding therefore does not protect the script because the injection occurs before the keyword is encoded. ### Attack Path 1. An attacker supplies a crafted keyword to `scripts/suggestions.sh`, directly or through an Agent request that causes the script to be invoked. 2. The script assigns the untrusted first argument to `KEYWORD`. 3. Lines 33–35 insert `KEYWORD` directly into the source passed to `python3 -c`. 4. The crafted keyword terminates the intended Python string and appends attacker-controlled Python statements. 5. Python evaluates the injected statements loca ...[truncated 1082 chars]- Remediation
View remediation
