Carlos-Projects/mcpwn
GitHub: Carlos-Projects/mcpwn
MCPwn 是一款针对 MCP 服务器的主动式红队安全测试框架,通过发送真实攻击 payload 验证命令注入、SSRF、Blind RCE 等漏洞。
Stars: 1 | Forks: 1
# MCPwn
[](https://github.com/Carlos-Projects/mcpwn/actions/workflows/ci.yml)
[](https://www.python.org)
[](LICENSE)
[](https://pypi.org/project/mcpwn-core/)
[](Dockerfile)
[](https://github.com/Carlos-Projects/mcpwn)
[](https://api.star-history.com/svg?repos=Carlos-Projects/mcpwn&type=Date)
用于 [MCP (Model Context Protocol)](https://modelcontextprotocol.io) 服务器的攻击性安全测试框架。
与被动扫描器(Cisco MCP Scanner、mcp-scan)不同,**MCPwn 通过发送真实的攻击 payload 并分析响应来主动测试** MCP 服务器。包含一个专门用于练习的故意存在漏洞的实验服务器。
## 30秒演示
```
pip install mcpwn-core
mcpwn demo
```
预期输出:
```
* vulnerable tools discovered
* command injection confirmed
* SSRF candidates detected
* HTML report generated
```
## MCPwn 的独特之处
| 功能 | MCPwn | Cisco MCP Scanner | mcp-scan |
|---|---|---|---|
| **主动 payload 注入** | ✅ 发送真实攻击 | ❌ 仅限被动 | ❌ 仅限被动 |
| **易受攻击的实验服务器** | ✅ 7 个易受攻击的工具 | ❌ | ❌ |
| **命令注入测试** | ✅ | ❌ | ❌ |
| **SSRF 测试** | ✅ | ❌ | ❌ |
| **SQL 注入测试** | ✅ | ❌ | ❌ |
| **工具投毒活动** | ✅ | ❌ | ❌ |
| **A2A 协议探测** | ✅ | ❌ | ❌ |
| **生成 HTML 报告** | ✅ | ❌ | ❌ |

## 安装说明
```
# 从 PyPI(推荐)
pip install mcpwn-core
# 或者从源码
git clone https://github.com/Carlos-Projects/mcpwn
cd mcpwn
pip install -e ".[dev]"
```
### Docker
```
docker build -t mcpwn-core .
docker run -p 8080:8080 mcpwn-core # lab server
# 或者
docker compose up
```
## 使用说明
### 探测 MCP 服务器
```
# 通过 HTTP
mcpwn survey --url http://localhost:8080/mcp
# 通过 stdio(本地进程)
mcpwn survey --stdio "uv run my_server.py"
# 保存结果
mcpwn survey --url http://localhost:8080/mcp --output results.json
# 生成 HTML 报告
mcpwn survey --url http://localhost:8080/mcp --html report.html
# 增加 HTTP 请求超时时间
mcpwn survey --url http://localhost:8080/mcp --timeout 60
# 跳过主动注入测试
mcpwn survey --url http://localhost:8080/mcp --no-injection
```
### 启动易受攻击的实验环境
```
mcpwn lab --http --port 8080
# 在另一个终端中:
mcpwn survey --url http://localhost:8080/mcp
```
### 生成 HTML 报告
```
mcpwn report results.json --output report.html
```
### 运行自动化演示
```
mcpwn demo
```
## 示例输出
```
$ mcpwn survey --url http://localhost:8080/mcp
Phase 1: Enumerating tools...
Found 5 tool(s)
• execute_command: Execute a system command on the server...
• read_file: Read the contents of any file on the server...
• search_database: Search for users in the internal employee database...
• system_update: System update utility...
• delete_logs: Delete old log files...
Phase 2: Passive analysis (tool poisoning detection)...
Found 4 passive findings
Phase 3: Active injection testing...
! execute_command: 5 command injection vector(s)
! system_update: 5 command injection vector(s)
Found 11 active findings
Summary: 15 total finding(s)
critical: 11
high: 1
medium: 3
```
## 攻击模块
### 被动分析(始终运行)
- **工具投毒检测**:标记危险的工具名称(`exec`、`eval`、`shell`、`delete`、`system` 等)
- **工具影子攻击**:检测与常见 MCP 工具同名的工具
- **可疑描述**:在工具描述中查找类似指令的内容
- **Schema 分析**:标记没有验证的参数(例如没有 enum/pattern 的 `type: string`)
### 主动注入测试(需要工具调用)
- **命令注入**:针对每个字符串参数测试 5 种 payload 类型(`;`、`&&`、`|`、`$()`、反引号)。通过响应标记检测进行确认。
- **路径遍历**:在与文件相关的参数上测试 `../../../etc/passwd` 模式
- **SSRF**:使用内部地址(127.0.0.1、云元数据 endpoint)测试接受 URL 的工具
- **Blind RCE**:通过基于时间的分析(`sleep`、`ping` payload)检测命令执行
## 安全态势
MCPwn 解决了 2026 年 AI 安全态势中的以下威胁类别:
| 威胁 | 来源 | MCPwn 覆盖范围 |
|---|---|---|
| MCP 服务器工具投毒 | [arXiv 2601.17549](https://arxiv.org/abs/2601.17549) | `tool_analysis` — 检测恶意名称、描述、schema |
| 恶意 agent 技能 (A2A) | [Google GTIG Report](https://cloud.google.com/blog/topics/threat-intelligence/ai-vulnerability-exploitation-initial-access) | `a2a_scanner` — 验证 agent 卡片,标记可疑技能 |
| 通过 MCP 工具进行命令注入 | OWASP LLM Top 10 | `injection_tester` — 5 种 payload 类型,标记确认 |
| 通过工具参数进行 SSRF | [CrowdStrike 2026 GTR](https://www.crowdstrike.com/en-us/global-threat-report) | `ssrf_tester` — 内部地址探测 |
| Blind RCE | MITRE ATLAS AML.T0054 | `rce_blind_tester` — 基于时间的检测 |
| AI 供应链攻击 | [CISA Secure AI](https://www.cisa.gov) | 输入大小限制,格式验证 |
| 反扫描操纵 | Adversa AI / Claude Code 研究 | 描述模式分析 |
## 安全警告
## 实验服务器
实验环境(`mcpwn lab`)会启动一个专门用于安全测试的故意存在漏洞的 MCP 服务器。它包含 5 个故意存在漏洞的工具:
| 工具 | 漏洞 | 描述 |
|---|---|---|
| `execute_command` | 命令注入 | `subprocess.run(cmd, shell=True)` |
| `read_file` | 路径遍历 | `open(path).read()` 无清理 |
| `search_database` | SQL 注入 | 直接查询插值 |
| `system_update` | 命令注入 | 版本参数的 shell 插值 |
| `delete_logs` | 参数注入 | 模式参数的 shell 插值 |
| `fetch_url` | SSRF | 接受任意 URL,包括内部地址 |
| `delayed_operation` | Blind RCE | 带有基于时间检测的 shell 插值 |
## 架构
```
mcpwn/
├── mcpwn/
│ ├── cli.py # Typer CLI (survey, lab, report, demo)
│ ├── core/
│ │ ├── findings.py # Finding, ScanResult models
│ │ └── report.py # HTML report generator
│ ├── attacks/
│ │ ├── tool_analysis.py # Passive tool scrutiny
│ │ └── injection_tester.py # Active injection tests
│ ├── lab/
│ │ └── server.py # Vulnerable MCP server
│ └── utils/
│ └── mcp_connect.py # MCP connection helpers
├── tests/
│ ├── test_findings.py
│ └── test_tool_analysis.py
└── pyproject.toml
```
## 为什么不直接使用 Cisco MCP Scanner?
| 工具 | 方法 | MCPwn 的区别 |
|---|---|---|
| Cisco MCP Scanner | 静态 YARA + LLM 分析 | MCPwn 使用攻击 payload **调用工具** |
| mcp-scan | 配置/工具元数据检查 | MCPwn 通过执行来**确认**漏洞 |
| MCPwn | 主动红队测试 | 包含**实验环境**、**路径遍历**、**报告生成** |
## 环境要求
- Python 3.10+
- `mcp>=1.0.0`, `typer>=0.12.0`, `rich>=13.0.0`, `httpx>=0.27.0`, `jinja2>=3.0.0`
## 测试
```
pip install -e ".[dev]"
pytest -v
```
## GitHub Action
```
- uses: Carlos-Projects/mcpwn/.github/actions/mcpwn-scan@main
with:
url: http://localhost:8080/mcp
fail-on: high
```
## 生态系统
MCPwn 是 **Carlos-Projects** 面向 AI agent 的安全基础设施的一部分:
```
Palisade Scanner → Scan content before agents consume it.
MCPwn → Attack MCP servers before attackers do. ← you are here
AgentGate → Control how agents access your website.
MCPscop → Centralize scanner results and security posture.
MCPGuard → Runtime security proxy for MCP/A2A protocols.
```
- [Palisade Scanner](https://github.com/Carlos-Projects/palisade-scanner) — 扫描 Web 内容以检测 prompt 注入和对抗性内容
- [AgentGate](https://github.com/Carlos-Projects/agentgate) — 面向 AI agent 的基于策略的防火墙和蜜罐 middleware
- [MCPscop](https://github.com/Carlos-Projects/mcpscope) — 用于 MCP/A2A 扫描器结果的统一安全仪表板
- [MCPGuard](https://github.com/Carlos-Projects/mcpguard) — MCP/A2A 协议的 runtime 安全代理
## 安全
发现漏洞?请参阅 [SECURITY.md](SECURITY.md)。
## 许可证
MIT
标签:AI安全, Chat Copilot, CISA项目, MCP协议, Python, XXE攻击, 无后门, 网络安全, 请求拦截, 逆向工具, 隐私保护