T09 · Insecure Skill Coding Practices
Error
- Location
- examples/trust-check.sh:15
- Finding
- Arbitrary Python Code Execution Through AUID Interpolation<![CDATA[ ## Vulnerability Details **File Location**: `examples/trust-check.sh`, line 15 **Vulnerability Type**: Python source-code injection **Risk Level**: High ### Vulnerable Code ```bash # URL-encode the JSON input INPUT=$(python3 -c "import urllib.parse, json; print(urllib.parse.quote(json.dumps({'json':{'auid':'$AUID'}})))") ``` ### Technical Analysis The script embeds the user-controlled `AUID` argument directly inside Python source passed to `python3 -c`. Shell quoting does not make the resulting Python string safe. An AUID containing Python quote delimiters and additional Python expressions can terminate the intended string and insert new statements. This differs from ordinary malformed input: the value is interpreted as executable Python syntax before it is serialized as JSON or sent to the AXIS API. The injected code runs locally with all permissions of the user invoking the script. ### Attack Path 1. An attacker supplies or publishes a crafted value represented as an AXIS AUID. 2. A victim invokes `trust-check.sh` with that value. 3. The shell expands `$AUID` into the source-code string supplied to `python3 -c`. 4. Crafted quote and statement delimiters escape the intended Python string. 5. Python evaluates the inserted statements locally. 6. The injected code can access files, environment variables, network resources, and commands available to the victim account. ### Impact Assessment Successful exploitation provides arbitrary local code execution with the invoking user's privileges. The resulting scope can include: - Reading files and credentials accessible to the user. - Modifying or deleting user-owned data. - Making arbitrary outbound network requests. - Running local commands or installing user-level persistence. - Compromising authentication material present in the process environment or filesystem. The code does not itself elevate privileges, so exploitation is constrained to the permissions already held by the caller. ]]>
- Remediation
- <![CDATA[ ## Remediation Suggestions Pass the AUID as data rather than embedding it in Python source: ```bash INPUT=$(python3 -c ' import json import sys import urllib.parse print(urllib.parse.quote(json.dumps({"json": {"auid": sys.argv[1]}}))) ' "$AUID") ``` Additionally: 1. Validate the AUID against the documented format and enforce a reasonable maximum length. 2. Prefer the Python example, which already passes the AUID through normal Python variables. 3. Add regression tests containing quotes, backslashes, newlines, semicolons, and Unicode characters. 4. Never interpolate untrusted data into `python3 -c`, `eval`, shell source, SQL, or another executable language. ]]>
