T09 · Insecure Skill Coding Practices
- Location
scripts/portfolio.sh:106- Finding
Remote API Data Is Interpolated Directly into Executable Python Source
- Content
View full analysis
= 100000000: print(f'{flow/100000000:.2f}亿') elif abs(flow) >= 10000: print(f'{flow/10000:.2f}万') else: print(f'{flow:.0f}') " 2>/dev/null) ``` ### Technical Analysis The `flow` shell variable is derived from the `f62` field returned by the remote authenticated market-data API. It is subsequently inserted into the source text passed to `python3 -c`. Shell quoting does not make this safe because the substitution occurs while Bash constructs the Python program. If the API returns a value containing a single quote followed by Python syntax, the value can terminate the argument to `float()` and introduce arbitrary Python statements. Although the endpoint normally returns numeric market data, the code does not validate that `flow` is numeric before constructing executable source. Exploitation would therefore be possible if the API service, its response-generation pipeline, DNS resolution, trusted infrastructure, or another upstream data source were compromised. ### Attack Path 1. An attacker gains control over, or causes malicious content to be returned by, the quote API used by `get_stock_quote`. 2. The attacker places a Python payload in the returned `f62` field. 3. `get_stock_quote` emits that field as the fifth pipe-delimited value. 4. `portfolio.sh` assigns it to `flow`. 5. The value is substituted into the `python3 -c` source at line 107. 6. The injected Python executes with the same OS account and permissions as the Skill process. ### Impact Assessment Successful exploitation permits arbitrary Python execution and, through modules such as `os` or `subprocess`, arbitrary command execution. The attacker could read files available to the Skill account, modify pro ...[truncated 257 chars]- Remediation
View remediation
= Decimal("100000000"): print(f"{value / Decimal('100000000'):.2f}e8") elif abs(value) >= Decimal("10000"): print(f"{value / Decimal('10000'):.2f}e4") else: print(f"{value:.0f}") ') ``` Apply the same rule to all shell variables: treat configuration and network responses as data, never as fragments of shell or Python source. ]]>
