T09 · Insecure Skill Coding Practices
- Location
scripts/mcp-desktop-control.py:87- Finding
Unrestricted Shell Command Execution Through the MCP Tool
- Content
View full analysis
Vulnerability Details
File Location:
scripts/mcp-desktop-control.py:87-90
Vulnerability Type: OS command injection / unrestricted command execution
Risk Level: HighVulnerable Code
python elif tool == 'shell': cmd = args.get('command', '') timeout = args.get('timeout', 30) result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout)Technical Analysis
The
shellMCP tool accepts an arbitrary caller-controlledcommandand passes it directly tosubprocess.runwithshell=True. The command is therefore interpreted by the operating-system shell, including command separators, pipelines, redirections, variable expansion, and command substitutions.The implementation has no command allowlist, argument validation, path restrictions, authorization boundary, sandbox, or confirmation mechanism. The declared MCP input schema does not mitigate this issue because it only specifies that the command is a string; it does not constrain its contents.
Although shell automation is documented as a feature, this implementation grants substantially broader access than the documented file-management operations require. Any process or agent context capable of calling this MCP server can execute commands with the privileges and environment of the server process.
Attack Path
- An attacker directly submits a crafted MCP
tools/callrequest, or attacker-controlled content causes an agent to generate such a request. - The request selects the
shelltool and places arbitrary shell syntax in thecommandargument. handle_requestretrieves the string without validation.subprocess.run(..., shell=True)passes the string to the system shell.- The shell interprets all included commands and metacharacters with the MCP server's user privileges.
- The attacker can use the resulting execution capability to access files, change system state, invoke instal ...[truncated 741 chars]
- An attacker directly submits a crafted MCP
- Remediation
View remediation
Remediation Suggestions
- Remove the generic
shelltool and replace it with narrowly scoped operations such asmove_file,copy_file,create_directory, andlist_directory. - Invoke programs using fixed executable names and argument arrays with
shell=False. - Validate all paths through canonicalization and enforce an allowlisted working directory.
- Reject shell metacharacters and unsupported arguments if legacy shell functionality must temporarily remain.
- Require explicit user confirmation before destructive, executable, network, credential-related, or persistence-related operations.
- Run the server in a sandbox with minimal filesystem, network, and process permissions.
- Apply strict timeout and output-size bounds, and validate the timeout against a safe minimum and maximum.
- Record security-relevant command requests in an audit log without storing secrets.
- Remove the generic
