T09 · Insecure Skill Coding Practices
- Location
scripts/monitor-and-execute.sh:204- Finding
Arbitrary Python Code Execution in Budget Validation
- Content
View full analysis
$budget_limit" | python3 -c "import sys; print(eval(sys.stdin.read()))") )); then log "WARN" "订单金额 ${total_amount} 超过预算上限 ${budget_limit},暂停并通知财务" notify_feishu "⚠️ 采购预算超限" "规则 ${rule_id}\n订单金额: ¥${total_amount}\n预算上限: ¥${budget_limit}\n请财务审批后手动执行" return 1 fi ``` ### Technical Analysis The script builds a Python expression from `total_amount` and `budget_limit`, then processes it with unrestricted Python `eval()`. The `budget_limit` value comes from the `purchase_rules` database table and is not validated as a numeric value before reaching this sink. An attacker who can alter a purchase rule, exploit the separate SQL injection path, or otherwise influence `budget_per_order` can supply Python syntax instead of a number. Because `eval()` has access to Python built-ins, the expression can invoke functions such as `__import__()` and execute operating-system commands. This operation is unnecessary for numeric comparison and exceeds the minimum privileges needed for budget validation. ### Attack Path 1. The attacker gains the ability to create or modify `budget_per_order`, directly or through an application/database vulnerability. 2. The attacker stores a value containing a valid Python expression with side effects. 3. The affected rule is triggered by monitor mode or invoked through `execute --rule-id`. 4. `execute_purchase` passes the malicious budget value into the string evaluated by Python. 5. The injected Python executes with the operating-system identity and environment of the purchase process. 6. The attacker can read inherited secrets, alter files, invoke local programs, or manipulate subseq ...[truncated 610 chars]- Remediation
View remediation
limit else 1) PY ``` The surrounding shell logic should be adjusted to handle the explicit result without evaluating generated code. ]]>
