MCP映射器和开发树桩生成器
mcp_map.py 是一种攻击性安全工具,旨在枚举、映射和交互 模型上下文协议(MCP) 服务器。
它连接到MCP端点(通常通过SSE),枚举整个攻击面(工具、资源、模板),主动查询可用数据,并生成人类可读的审计图和即用型Python客户端存根,用于快速利用或测试。
🚀 特性
- 深度枚举:
- 资源: 列出所有公开的数据端点和 积极阅读 它们(带有安全截断)用于查找敏感数据或配置。
- 资源模板: 标识数据访问的动态URI模式。
- 工具: 转储工具名称、描述和参数的完整JSON模式(对于查找RCE或Logic缺陷至关重要)。
- 主动侦察:
- 自动尝试读取已发现的资源。
- 优雅地处理二进制数据和大型文本文件,以避免控制台泛滥。
- 双输出格式:
- Markdown(.md): 专门为 黑曜石 或Notion pentest报告(语法干净,代码块清晰,没有HTML混乱)。
- JSON(.json): 将管道的原始数据转储到其他自动化工具中。
- 漏洞生成(
--generate-stub):
- 自动创建独立 client.py 根据目标量身定制的脚本。
- 用发现的模式和虚拟值预填充函数调用,允许 即时互动/利用 无需手动编码。
📋 先决条件
- Python 3.10+
fastmcp(该工具依赖于此库实现稳定的SSE传输)
Bash
pip install fastmcp🛠️ 用法
基本映射(显示到控制台)
连接到目标并将Markdown摘要打印到stdout。
Bash
python mcp_map.py http://localhost:8000/sse审计报告生成
将完整地图保存到黑曜石友好的Markdown文件中。
Bash
python mcp_map.py http://target-ip:53060/mcp -o audit_report.md全面侦察和利用树桩生成
执行映射、保存映射并生成Python脚本(exploit.py)预先配置以攻击目标上发现的特定工具。
Bash
python mcp_map.py http://target-ip:53060/mcp -o map.md -g exploit.py用于自动化的JSON输出
Bash
python mcp_map.py http://target-ip:53060/mcp -f json -o raw_data.json📄 输出示例
1.Markdown地图(-o map.md)
_针对直接复制到pentest报告进行了优化。_
标记语言
# MCP Server Map: http://10.10.10.5:8000/sse
## 📂 Resources (Queried)
- **App Config**
- URI: `config://main`
- Desc: _Main application settings_
- **Content**:{ "debug": true, "db_host": "127.0.0.1" }
## 🛠️ Tools
- **execute_command**
- Desc: _Executes a shell command_
- Inputs: `command`, `timeout`
- Schema:{ "properties": { "command": { "type": "string" }, "timeout": { "type": "integer" } } }
2.客户失误(-g exploit.py)
_生成的Python代码已准备好运行。只需取消注释要测试的行即可。_
python
import asyncio
from fastmcp import Client
TARGET_URL = 'http://10.10.10.5:8000/sse'
client = Client(TARGET_URL)
async def main():
async with client:
print(f'[*] Connected to {TARGET_URL}')
# --- Tools ---
print('\n[+] Calling Tool: execute_command')
# Description: Executes a shell command
# Arguments Schema: {"command": {"type": "string"}, "timeout": {"type": "integer"}}
# UNCOMMENT TO EXECUTE:
# result = await client.call_tool(name='execute_command', arguments={'command': 'TEST_VALUE', 'timeout': 0})
# print(result)
if __name__ == '__main__':
asyncio.run(main())⚠️ 法律免责声明
此工具仅用于法律安全评估和授权渗透测试。在扫描或与任何MCP服务器交互之前,请确保您拥有明确的权限。
