test

test

test

Category
访问服务器

README

Insecure MCP Demo

Overview

This project demonstrates a vulnerable MCP server and multiple clients, including a proof-of-concept attack client and also a good client. It is designed for educational purposes to showcase potential security vulnerabilities in MCP server.

Project Structure

  • vuln-mcp.py: Vulnerable MCP server exposing insecure tools.
  • good-mcp-client.py: Regular good client for normal interactions (insert/query records).
  • attack-mcp-client.py: Automated attack client that demonstrates exploitation of server vulnerabilities.
  • requirements.txt: Python dependencies for the project.

Features & Vulnerabilities

Exposed Server Tools

  1. insert_record
    • Inserts a name/address record into the database.
    • Vulnerability: Prone to SQL injection due to direct string interpolation of user input into SQL queries.
  2. query_records
    • Lists all records in the database.
    • Vulnerability: Exposes all data without authentication or access control.
  3. execute_sql
    • Executes arbitrary SQL queries provided by the client.
    • Vulnerability: Allows any SQL command, including destructive ones (e.g., data exfiltration, schema changes).
  4. get_env_variable
    • Returns the value of any environment variable requested.
    • Vulnerability: Leaks sensitive environment variables (e.g., secrets, API keys).

How to Run

1. Install Dependencies

pip install -r requirements.txt

2. Start the Server and Good Client

In one terminal:

python good-mcp-client.py vuln-mcp.py

Follow the prompts to insert/query records interactively.

3. Run the Attack Client

In another terminal:

python attack-mcp-client.py vuln-mcp.py

This will automatically:

  • Attempt SQL injection attacks
  • Execute arbitrary SQL queries
  • Attempt to read several common environment variables

Example Output

  • Attack client will show which payloads succeed or fail, and print out database contents and environment variable values if accessible.

Vulnerabilities Demonstrated

  • SQL Injection: User input is unsanitized, allowing attackers to manipulate SQL logic and insert arbitrary data.
  • Arbitrary Code Execution: The execute_sql tool allows attackers to run any SQL command, including data theft or destruction.
  • Sensitive Data Exposure: The get_env_variable tool allows attackers to read secrets and configuration values.
  • Lack of Access Control: Anyone can run all tools and access all data without authentication.

Mitigation Strategies

To secure a real-world MCP server, you should:

  1. Use Parameterized Queries:
    • Always use parameter substitution instead of string interpolation for SQL queries to prevent injection.
    • Example (secure):
      cursor.execute("INSERT INTO records (name, address) VALUES (?, ?)", (name, address))
      
  2. Restrict Dangerous Tools:
    • Remove or strictly limit tools like execute_sql and get_env_variable.
    • Only expose necessary functionality.
  3. Implement Authentication & Authorization:
    • Require users to authenticate and check permissions before allowing access to sensitive tools or data.
  4. Validate and Sanitize Input:
    • Check and sanitize all user inputs, especially those that interact with the database or system.
  5. Limit Environment Variable Access:
    • Only allow access to non-sensitive variables, or remove this tool entirely.
  6. Audit and Monitor Usage:
    • Log all tool invocations and monitor for suspicious or abusive behavior.
  7. Principle of Least Privilege:
    • Run the server with minimal privileges and restrict database and OS access as much as possible.

Disclaimer

This project is for educational and demonstration purposes only. Do not deploy this code in production environments.


For questions or further improvements, please open an issue or contact the project maintainer.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选