Vulnerable MCP File Reader Server

Vulnerable MCP File Reader Server

vulnerable-file-reader-server•byeliran79

A deliberately vulnerable Python MCP server that exposes a read_file tool intended to read files from a safe directory but permits shell command injection.

License: Not specified•Runtime: Awaiting documentation review•Category: file systems-docs

WHAT IT DOES

  • •Exposes an MCP tool named read_file that reads files by building a cat shell command from the supplied file name.
  • •Interpolates user input into the shell command with shell=True and only superficial path validation, enabling arbitrary command execution.

BEST FOR

  • •Educational demonstrations of command injection in MCP servers and how to fix it.

ABOUT VULNERABLE-FILE-READER-SERVER

Vulnerable MCP File Reader Server is cataloged as an MCP server attributed to eliran79. A deliberately vulnerable Python MCP server that exposes a read_file tool intended to read files from a safe directory but permits shell command injection. It is categorized under file systems-docs. See the capability inspector for recorded interfaces and their independent review status; consult upstream documentation for the current interface.

HOW TO INSTALL

Installation configuration is not reviewed. No executable setup is offered for this entry; inspect the source repository before proceeding.

LICENSE

Catalog license label: Not specified. Check the source repository's current license and terms before using, modifying or distributing this software.

能力检查器

能力定义尚未审核。未核验的采集内容不会作为可信接口展示。

Tools (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

Resources (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

Prompts (0)

暂无可展示的已审核记录。这不表示上游不支持此能力。

NEWSLETTER - COMING LATER

Newsletter subscriptions are not open yet

Email delivery is not connected. This page does not collect email addresses or create subscriptions.

Browse the registry for current listings instead.

Community Reviews

Coming later

Reviews for Vulnerable MCP File Reader Server are not available yet

Review publishing and storage are not connected. This page does not collect or publish ratings or comments, including after sign-in.

FREQUENTLY ASKED QUESTIONS

How is the command injection exploited?

By appending shell commands to the file_name value, such as /tmp/safe/test.txt; whoami, which the server executes due to shell=True.

What is the recommended fix?

Avoid shell=True with user input by passing an argument list, quoting input with shlex.quote if needed, and performing proper path validation.

上游原版 README

在 GitHub 查看同一版本原文

README.md · d9a293be24bd · 采集于 2026-11-13 12:25:12 UTC

保留上游原文,不做 AI 改写。为安全起见过滤脚本、表单和不安全链接。

当前显示最后一次成功采集的文档快照,请以来源页面为准。

Command Injection Vulnerability in MCP File Reader

This repository demonstrates a critical command injection vulnerability in a Python MCP (Model Context Protocol) server implementation. The vulnerability allows attackers to execute arbitrary shell commands on the host system by manipulating the file path parameter.

The Vulnerability

The vulnerability exists in the read_file function which is intended to read files from a "safe" directory but contains a dangerous implementation flaw:

command = f"cat {file_name}"
result = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)

This code is vulnerable because:

  1. It uses shell=True which invokes a shell to execute the command
  2. It directly interpolates user input (file_name) into the command string without proper sanitization
  3. It performs only superficial validation on the input path

A simple semantic difference between using quotes around the filename ('file_name') and not using quotes (file_name) exposes the entire system to command execution.

Installation

Prerequisites

  • Python 3.12 or higher
  • MCP library version 1.6.0

Setup

  1. Clone this repository:

    git clone https://github.com/Eliran79/Vulnerable-file-reader-server.git
    cd Vulnerable-file-reader-server
    
  2. Install the MCP server:

    mcp install main.py
    
  3. Configure Claude Desktop to use your MCP server by editing ~/.config/claude-desktop/claude_desktop_config.json:

    {
      "mcpServers": {
        "file-reader": {
          "command": "/ABSOLUTE/PATH/TO/uv",
          "args": [
            "--directory",
            "/data/git/file_reader_server",
            "/usr/bin/uv",
            "run,--with,mcp,mcp,run,main.py"
          ]
        }
      }
    }
    

    Be sure to replace /ABSOLUTE/PATH/TO/uv with the actual path to your uv executable and adjust the directory path if needed.

  4. Start the MCP server in development mode:

    mcp dev main.py
    

Demonstration

  1. In a separate terminal, install and run the MCP inspector:

    pip install mcp-inspector
    mcp-inspector
    
  2. Connect to the server in the MCP Inspector GUI:

    • Set Transport Type to "STDIO"
    • Set Command to: run --with mcp run main.py
    • Click "Restart"
  3. Exploit the vulnerability:

    • Go to the "Tools" tab
    • Find the "read_file" tool
    • In the "file_name" field, enter:
      /tmp/safe/test.txt; whoami
      
    • Click "Run Tool"
  4. You should see the contents of test.txt followed by your username, demonstrating successful command execution.

Additional Exploitation Examples

Here are more command injection payloads to try:

/tmp/safe/test.txt; id
/tmp/safe/test.txt; ls -la /etc
/tmp/safe/test.txt; cat /etc/passwd
/tmp/safe/test.txt; echo $(hostname)
/tmp/safe/test.txt; find / -name "*.conf" 2>/dev/null | head -5

Proper Fix

To fix this vulnerability, never use shell=True with user-provided input. Instead:

# SECURE: Use a list of arguments instead of shell=True
result = subprocess.check_output(['cat', file_name], shell=False)

# OR, if shell=True is necessary, properly quote the argument:
import shlex
result = subprocess.check_output(f"cat {shlex.quote(file_name)}", shell=True)

# AND perform proper path validation:
import os
safe_dir_resolved = os.path.abspath(SAFE_DIRECTORY)
requested_path_resolved = os.path.abspath(file_name)
if not requested_path_resolved.startswith(safe_dir_resolved):
    return f"Error: Access denied. Path traversal attempt detected."

Warning

⚠️ FOR EDUCATIONAL PURPOSES ONLY: This implementation contains deliberate security vulnerabilities. Never use this code in a production environment or on any system that contains sensitive information.

Install configuration

Are you the maintainer?

Claim this server with your GitHub account to request manual ownership verification.

README Embed Badge
Markdown

Link to the catalog listing for Vulnerable MCP File Reader Server from your README. This badge does not certify ownership, compatibility or security.

[![MCP catalog listing](https://img.shields.io/badge/MCP-awesome--mcp-orange?style=flat-square)](https://awesome-mcp.com/servers/vulnerable-file-reader-server)

REPOSITORY STATS

GitHub StarsUnavailable
ForksUnavailable

Public repository statistics could not be verified. Check the configured source address; unavailable counts are not zero.

下载与拉取统计

来源、范围和时段分别列出;不相加,不代表安装人数、活跃用户或安全审核。

尚无已审核的包 / 镜像标识,暂不展示下载统计。

Related file systems-docs MCP Servers

Alternative and complementary servers in the same category

View all in file systems-docs →

A Model Context Protocol server for global law with read-only tools to find and read provisions by date, trace the law behind each word, search text and changes, and check cases or briefs against law in force.

Repository stats unavailable
Files & Documentation
LoreKeeper MCP server
lorekeeper-rpg-lorekeeper-com•lore-keeper

Hosted MCP server for tabletop RPG worlds that organizes messy notes and documents into a private store and lets MCP apps search lore, read documents, find characters, and optionally generate character or world pictures.

Repository stats unavailable
Files & Documentation

An MCP server that gives AI assistants scoped file system operations inside a project directory, with read-only reference projects plus git and GitHub tools.

Repository stats unavailable
Files & Documentation