T09 · Insecure Skill Coding Practices
- Location
scripts/create_weekly_report.py:132- Finding
Shell Command Injection Through the Report Title
- Content
View full analysis
Vulnerability Details
File Location:
scripts/create_weekly_report.py:132-139
Vulnerability Type: Shell command injection in generated operator instructions
Risk Level: MediumVulnerable Code
python print(f""" # 1. 创建文档 wecom_mcp call doc create_doc '{{"doc_type": 3, "doc_name": "{title}"}}' # 2. 记录返回的 docid,然后编辑内容 wecom_mcp call doc edit_doc_content '{{"docid": "返回的DOCID", "content": "{content[:100]}...", "content_type": 1}}' """)Technical Analysis
The
titlevalue can be supplied through the--titlecommand-line argument and is interpolated directly into a shell command enclosed in single quotes. The implementation performs neither JSON serialization nor shell escaping.An attacker can include a single quote in the title to terminate the quoted JSON argument and append arbitrary shell syntax. Although the application only prints the command rather than executing it, the output is explicitly presented as a command for the operator to execute. This creates a command-injection path based on operator interaction.
The same unsafe command-construction pattern also appears in
scripts/publish_to_wecom.py, including title and document-ID interpolation.Attack Path
- An attacker provides or recommends a crafted report title containing a single quote and shell operators.
- The operator invokes the script with that title using
--auto-publish. - The script embeds the title into a displayed
wecom_mcpshell command without escaping it. - The operator copies and executes the generated command as instructed.
- The injected shell command executes with the operator's privileges.
Impact Assessment
Successful exploitation permits arbitrary command execution in the security context of the operator who follows the generated instructions. The attacker could access or modify files available to that user, invoke local tools, obtain credentials exposed to the process enviro ...[truncated 246 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not construct or display executable shell commands using string interpolation.
- Invoke the intended tool through a structured API or
subprocess.run()with an argument list andshell=False. - Build request payloads with
json.dumps()rather than manually constructing JSON. - If displaying a shell command is unavoidable, apply
shlex.quote()to the entire serialized JSON argument. - Validate report titles against an appropriate length limit and character policy as defense in depth.
- Apply the same protections to
titleanddocidinterpolation inscripts/publish_to_wecom.py.
