T09 · Insecure Skill Coding Practices
- Location
scripts/scrape.sh:5- Finding
Arbitrary Python Code Execution Through Unsanitized CLI Arguments
- Content
View full analysis
[output_file]" echo "Platforms: baidu zhihu weibo csdn" echo "" echo "Note: taobao/douyin/1688/xiaohongshu require login cookies." echo "Use the Python API with cookie injection for these platforms." exit 1 fi python3 -c " from scrapling import StealthyFetcher, Fetcher import json import sys platform = '$PLATFORM' keyword = '$KEYWORD' output = '$OUTPUT' ``` ### Technical Analysis The script embeds three user-controlled shell arguments directly into a Python program passed to `python3 -c`. Shell quoting does not make these values safe inside the resulting Python source code. An argument containing a single quote can terminate the surrounding Python string literal and inject additional Python statements. Because Python exposes operating-system functionality through modules such as `os` and `subprocess`, successful injection results in arbitrary command execution. All three arguments are potentially affected: - `PLATFORM` - `KEYWORD` - `OUTPUT` No validation, escaping, or parameterized data transfer separates these values from executable Python source. ### Attack Path 1. An attacker supplies a crafted CLI argument containing a closing quote and Python statements. 2. The shell expands the argument while constructing the `python3 -c` string. 3. The injected content becomes part of the Python source code. 4. Python parses and executes the injected statement with the privileges of the user running the Skill. For example, a malicious keyword could follow this structure: ```bash ./scripts/scrape.sh baidu "';__import__('os').system('id');#" ``` The exact quoting requir ...[truncated 764 chars]- Remediation
View remediation
