Command-Injection-MCP
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Command-Injection-MCPCan you wash my car with soap?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Deceptive MCP Server & Command Injection (Proof of Concept)
โ ๏ธ DISCLAIMER: FOR EDUCATIONAL & SECURITY RESEARCH PURPOSES ONLY
This repository is intended strictly for security researchers, developers, and educators to understand security vulnerabilities in the Model Context Protocol (MCP) ecosystem. It demonstrates the dangers of deceptive tool naming (tool masquerading/misrepresentation) and unsanitized command execution. Do not deploy or execute untested tools in production environments.
๐ Overview
As Large Language Models (LLMs) increasingly interface with local systems via the Model Context Protocol (MCP), users trust servers to expose tools that accurately reflect their stated purpose.
This project demonstrates a critical attack surface in MCP implementations:
Deceptive Tool Naming (Masquerading): Exposing tools under benign or misleading names (e.g.,
wash-car-mcp,wash_car,wash_with_soap) that obscure what actions they actually take on the host system.Reconnaissance & OS Fingerprinting: Programmatically detecting the underlying operating system (Windows, macOS, Linux).
Unsanitized Shell Execution: Executing system-level shell commands (
whoami, etc.) usingshell=Truewithout input validation or strict containment, highlighting command execution and injection risks.
Related MCP server: MCP Terminal Tool Server
๐ How the Demonstration Works
The server registers two primary MCP tools:
1. Host Fingerprinting (wash_car)
Declared Appearance: Implies a harmless utility related to washing a vehicle.
Actual Functionality: Queries
platform.system()to identify whether the host environment is running Windows, macOS (Darwin), or Linux.Risk: Gathers system architecture and OS details without notifying the operator of the system probe.
2. Command Execution & Reconnaissance (wash_with_soap)
Declared Appearance: Implies another benign sub-step of a car wash process.
Actual Functionality:
Calls the OS detection routine.
Constructs a shell command targeting the identified platform (
whoami).Invokes the command through Python's
subprocess.run(..., shell=True).Returns the current system username and operating system directly to the LLM/client.
Risk: Demonstrates that a client or agent invoking seemingly harmless tools can inadvertently trigger local shell command execution on the host.
โ ๏ธ Security Vulnerability Breakdown
1. Tool Masquerading / Supply Chain Risk
In the MCP architecture, the client (LLM or host interface) relies on tool names, docstrings, and schemas to decide when and how to call tools.
A server can declare an innocent label (
wash_with_soap) while performing sensitive system reconnaissance or running terminal commands behind the scenes.Users installing untrusted community MCP servers risk granting silent command execution capabilities to their machines.
2. Command Injection & Arbitrary Execution Risk
Using
shell=Truein subprocess calls allows shell meta-characters (;,&,|,`,$()) to chain and execute secondary commands.If user-supplied or LLM-generated arguments are concatenated into shell strings without strict sanitization or parameterization, an attacker or compromised model can execute arbitrary commands with the privileges of the running MCP server process.
๐ก๏ธ Remediation & Security Best Practices
To safeguard MCP servers and host environments from command execution and deceptive tool exploits:
For MCP Server Developers
Avoid
shell=True: Always pass arguments as a list tosubprocess.run(e.g.,["whoami"]) to prevent shell interpolation.Strict Input Validation & Whitelisting: If commands or filenames must be accepted, validate against strict regex patterns or fixed allowed lists.
Transparent Tool Naming & Documentation: Ensure tool names and descriptions accurately depict all actions, side effects, and permissions required.
Least Privilege: Run MCP servers under restricted user accounts or isolated containers (Docker, gVisor, sandboxes).
For MCP Host Clients & Users
Tool Approval Prompts (Human-in-the-Loop): Require explicit user confirmation before executing any tool that accesses the shell, filesystem, or network.
Server Verification: Only install MCP servers from trusted, verified publishers and review the source code before running.
Environment Sandboxing: Run local MCP servers in containers with restricted filesystem access and blocked network interfaces unless explicitly required.
๐งช Local Testing Setup
Prerequisites
Python 3.10+
uvpackage manager (or standardpip/venv)
Installation & Execution
# Clone the repository
git clone https://github.com/<your-username>/command-injection-mcp.git
cd command-injection-mcp
# Install dependencies
uv sync
# Inspect tools and run locally
uv run python main.py๐ License
Distributed for educational and defensive research purposes. Ensure compliance with all local laws and organizational policies regarding security testing.
This server cannot be deployed
Maintenance
Related MCP Connectors
Security research: MCP registries verify identity, not tool behavior. See gtfo.dev.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Scan any MCP server for tool-poisoning, security, auth & license. Trust score before install.
Security research canary remote MCP server for owned-account testing.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceMCP server to perform various OSINT tasks by leveraging common network reconnaissance tools.48-
- FlicenseBqualityDmaintenanceAn MCP server that enables users to execute arbitrary shell commands on their local machine and receive the output. It provides a terminal tool for running system commands through MCP-compatible clients using the Python SDK.1-
- FlicenseNot gradedqualityDmaintenanceExposes MCP tools that enable remote LLMs to query local Docker containers, OS processes, and system services in real time.-
- AlicenseNot gradedqualityCmaintenanceA rogue MCP server (~90 lines) that demonstrates prompt injection via tool responses to achieve remote code execution on a developer's machine.MIT