Command Injection Vulnerability in MCP File Reader
@Eliran79
Command Injection Vulnerability in MCP File Reader について
A deliberately vulnerable MCP server demonstrating command injection flaws. This Python implementation shows how lack of input sanitization in file paths leads to critical security vulnerabilities allowing attackers to execute arbitrary commands. For educational purposes only - d
設定
ツール
ツールは検出されませんでした
ツールは README から自動的に抽出されます。メンテナーは ## Tools という見出しの下に記載することで、このタブに反映できます。
概要
What is Command Injection Vulnerability in MCP File Reader?
A deliberately vulnerable Python MCP server that demonstrates a critical command injection flaw in its read_file tool, intended for educational security testing.
How to use Command Injection Vulnerability in MCP File Reader?
Install Python 3.12+, MCP library 1.6.0, clone the repository, run mcp install main.py, configure Claude Desktop as shown in the README, then start with mcp dev main.py. Use the MCP Inspector to send malicious file_name values to the read_file tool.
Key features of Command Injection Vulnerability in MCP File Reader
- Uses
shell=Truein subprocess calls - Interpolates user input directly into a shell command
- Performs only superficial path validation
- Demonstrates command injection payloads like
; whoami - Includes a proper fix using
shlex.quote()or list arguments
Use cases of Command Injection Vulnerability in MCP File Reader
- Security researchers learning about command injection in MCP servers
- Educators demonstrating the dangers of
shell=Truewith user input - Practicing exploitation techniques in a safe, local environment
FAQ from Command Injection Vulnerability in MCP File Reader
What is the vulnerability in this server?
The read_file function runs cat {file_name} with shell=True, allowing an attacker to append arbitrary shell commands after a semicolon in the file name.
How can I fix the vulnerability?
Replace the unsafe call with a list argument (subprocess.check_output(['cat', file_name])) or use shlex.quote(file_name) if shell=True is necessary. Also validate that the resolved path stays within the allowed directory.
What dependencies are required?
Python 3.12 or higher and the MCP library version 1.6.0.
Can this server be used in production?
No, this implementation is for educational purposes only and must never be used on production systems or with sensitive data.
How do I connect to the server from an MCP client?
Configure Claude Desktop by editing ~/.config/claude-desktop/claude_desktop_config.json with the appropriate command and arguments as shown in the README.
よくある質問
What is the vulnerability in this server?
The `read_file` function runs `cat {file_name}` with `shell=True`, allowing an attacker to append arbitrary shell commands after a semicolon in the file name.
How can I fix the vulnerability?
Replace the unsafe call with a list argument (`subprocess.check_output(['cat', file_name])`) or use `shlex.quote(file_name)` if `shell=True` is necessary. Also validate that the resolved path stays within the allowed directory.
What dependencies are required?
Python 3.12 or higher and the MCP library version 1.6.0.
Can this server be used in production?
No, this implementation is for educational purposes only and must never be used on production systems or with sensitive data.
How do I connect to the server from an MCP client?
Configure Claude Desktop by editing `~/.config/claude-desktop/claude_desktop_config.json` with the appropriate command and arguments as shown in the README.
基本情報
「開発者ツール」の他のコンテンツ
mcp-excalidraw
yctimlinMCP server and Claude Code skill for Excalidraw — programmatic canvas toolkit to create, edit, and export diagrams via AI agents with real-time canvas sync.
Serena
oraiosA powerful MCP toolkit for coding, providing semantic retrieval and editing capabilities - the IDE for your agent
JetBrains MCP Proxy Server
JetBrainsA model context protocol server to work with JetBrains IDEs: IntelliJ, PyCharm, WebStorm, etc. Also, works with Android Studio
extentos
Asger mølgaardExtentos is a multi-vendor development platform for adding smart-glasses capabilities to existing iOS and Android apps. The simplest analogy is Stripe for smart glasses:
Vibgrate MCP
VibgrateQuery your team's drift, vulnerability, and migration data from any AI assistant. Vibgrate MCP connects Cursor, Claude, ChatGPT, Windsurf, or VS Code to Vibgrate Cloud: 51 tools for DriftScores, CVEs and EOL runtimes, up
コメント