sahiloj/MCPScan

GitHub: sahiloj/MCPScan

首个针对 MCP 服务器的专用攻击性安全审计工具,检测工具投毒、凭证泄露、RCE、SSRF 等 8 类威胁并关联已知 CVE 漏洞

Stars: 0 | Forks: 0

MCPScan

首个针对 MCP 服务器的专用攻击安全审计器

Release MIT License

威胁格局 · 检查项 · 安装 · 使用 · CVEs · 输出

``` MCPScan — Offensive MCP Server Auditor ────────────────────────────────────────────────────────── Server: filesystem-server (stdio: npx @modelcontextprotocol/server-filesystem /home) Enumerated: 12 tools · 0 resources · 0 prompts CRITICAL MCP-701 RCE Vector: Shell/Execution Parameter Name Location: tool: bash_exec > inputSchema Evidence: Dangerous params: command, args CVE: CVE-2025-6514 (CVSS 9.6) Fix: Use allowlists; never pass raw input to shell functions HIGH MCP-304 Overprivileged: Unrestricted Filesystem Path Parameter Location: tool: write_file > inputSchema Evidence: Tool: write_file, capabilities: fs-write Fix: Add a path allow-list restricting access to approved directories HIGH MCP-202 Credential Leak: Anthropic API Key Location: tool: call_llm > description Evidence: sk-ant-api03-•••••••••••••••• Fix: Rotate immediately. Never embed secrets in tool metadata. ╭──────────────── MCPScan Results ─────────────────╮ │ │ │ Scanned 3 servers · Enumerated in 4.2s │ │ 2 critical · 5 high · 1 medium · 1 low │ │ │ ╰───────────────────────────────────────────────────╯ ``` ## 🔥 威胁格局 MCP 已成为连接 AI 代理与现实世界的标准 —— 而攻击者已率先抵达。研究人员已记录: | 威胁 | 影响 | 规模 | |---|---|---| | **Tool Poisoning (工具投毒)** | 隐藏指令劫持 LLM 行为 | 攻击成功率 >72% | | **通过 mcp-remote 实现远程代码执行 (RCE)** | 完整的操作系统命令执行 | 受影响开发者约 500,000 人 | | **暴露的服务器** | 未经认证即可访问工具和数据 | 发现 492+ 台公开服务器 | | **凭证泄露** | API 密钥嵌入在工具元数据中 | 数千次安装 | | **供应链** | 受损的 npm 包生成恶意 MCP 模块 | 正在野外活跃利用 | 此前不存在专用的攻击性扫描器。**MCPScan 填补了这一空白。** ## 🔍 检查项 MCPScan 运行 **8 个检查类别**,覆盖完整的 MCP 攻击面: | ID | 类别 | 检测内容 | |---|---|---| | MCP-1xx | `tool-poisoning` | 隐藏的 Unicode(零宽字符、RTL 重写)、HTML/XML 注入、提示词注入关键词、base64 载荷、超长描述、Markdown 数据窃取 | | MCP-2xx | `credential-leak` | AWS 密钥、API Token(Anthropic, OpenAI, GitHub, Stripe, Slack)、JWT、私钥、数据库连接字符串 | | MCP-3xx | `overprivileged` | Shell+文件系统组合、Shell+网络组合、不受限制的路径参数、代码执行(eval)、敏感路径访问(`~/.ssh`, `~/.aws`) | | MCP-4xx | `auth-missing` | 未认证的服务器枚举、CORS 通配符、`0.0.0.0` 绑定、缺失的安全标头 | | MCP-5xx | `session-hijack` | URL 参数中的会话 ID、可预测/基于时间的 ID、缺失 `Secure`/`HttpOnly` Cookie 标志 | | MCP-6xx | `ssrf` | 用户提供的 URL 参数、Webhook/回调端点、带变量的 HTTP 资源 URI 模板 | | MCP-7xx | `rce-vectors` | `command`/`exec`/`eval` 参数名称、描述中的执行语言、净化声明检测 | | MCP-8xx | `supply-chain` | CVE 版本范围、缺失的 lockfiles、抢注(typosquatted)的 MCP 包名 | ### 📋 CVE 参考 | CVE | 软件包 | CVSS | 摘要 | |---|---|---|---| | [CVE-2025-6514](https://jfrog.com/blog/2025-6514-critical-mcp-remote-rce-vulnerability/) | `mcp-remote` | **9.6** | 任意操作系统命令执行 —— 首个通过 MCP 实现的完整系统入侵 | | [CVE-2025-49596](https://nvd.nist.gov/vuln/detail/CVE-2025-49596) | `@modelcontextprotocol/inspector` | **9.4** | 通过 inspector-proxy 实现的未认证 RCE | | [CVE-2025-59536](https://research.checkpoint.com) | `@anthropic-ai/claude-code` | **9.1** | 项目文件 RCE + API Token 窃取 | | [CVE-2025-53967](https://nvd.nist.gov/vuln/detail/CVE-2025-53967) | `figma-developer-mcp` | **8.2** | 通过 Shell 字符串插值实现的命令注入 | | [CVE-2026-25536](https://nvd.nist.gov/vuln/detail/CVE-2026-25536) | `@modelcontextprotocol/sdk` | **7.5** | StreamableHTTP 跨客户端数据泄露 (v1.10.0–1.25.3) | ## ⚡ 安装 **需要 Node.js ≥ 18** ``` git clone https://github.com/sahiloj/MCPScan.git cd MCPScan npm install npm run build ``` 全局链接并从任意位置运行: ``` npm link mcpscan --help ``` ## 🚀 使用 ### 扫描 stdio 服务器 ``` mcpscan scan --command "npx" --args "-y @modelcontextprotocol/server-filesystem /home/user" ``` ### 从您的 AI 客户端配置扫描 ``` # Claude Desktop (macOS) mcpscan scan --config ~/Library/Application\ Support/Claude/claude_desktop_config.json # 自动发现所有已知 config 位置 (Claude, Cursor, 等) mcpscan scan --all-configs ``` ### 扫描远程 HTTP / SSE 服务器 ``` mcpscan scan --target http://localhost:3000/mcp ``` ### 扫描本地主机以发现暴露的 MCP 服务器 ``` mcpscan scan --all-configs --network ``` ### 仅运行指定检查 ``` mcpscan scan --all-configs --checks tool-poisoning,credential-leak,rce-vectors ``` ### 严重性过滤 ``` # 仅报告 high 和 critical mcpscan scan --all-configs --severity high ``` ### CI/CD 集成 ``` # Exit code 2 = critical 发现, exit code 1 = high 发现 mcpscan scan --all-configs --severity high --output sarif > findings.sarif ``` ### 仅发现不扫描 ``` mcpscan discover --all-configs --network mcpscan discover --all-configs --output json ``` ## ⚙️ 所有选项 ``` mcpscan scan [options] -c, --config Path to claude_desktop_config.json or .mcp.json -t, --target Direct HTTP/SSE MCP server URL --command Spawn and scan a stdio server --args Space-separated args for --command --all-configs Auto-discover all known MCP config locations --network Also probe localhost ports for exposed HTTP servers --checks Comma-separated checks to run (default: all) -o, --output terminal | json | sarif (default: terminal) --severity critical | high | medium | low | info (default: info) --timeout Per-server connection timeout (default: 30000) --verbose Show check errors and debug output ``` **`--all-configs` 搜索的配置位置:** | 平台 | 路径 | |---|---| | macOS | `~/Library/Application Support/Claude/claude_desktop_config.json` | | Linux | `~/.config/claude/claude_desktop_config.json` | | Windows | `%APPDATA%\Claude\claude_desktop_config.json` | | 任意 | `.mcp.json` · `.cursor/mcp.json` · `~/.config/mcp/config.json` | ## 📊 输出格式 ### 终端 *(默认)* 带有 CVE 参考和摘要框的严重性着色发现。专为人类阅读设计。 ### JSON 适用于 SIEM、自定义仪表板和自动化的机器可读报告: ``` { "tool": "mcpscan", "version": "0.1.0", "timestamp": "2026-03-10T12:00:00.000Z", "summary": { "serversScanned": 3, "totalFindings": 8, "findingsBySeverity": { "critical": 2, "high": 4, "medium": 1, "low": 1, "info": 0 } }, "results": [...] } ``` ### SARIF 2.1.0 直接导入 **GitHub Code Scanning**、VS Code SARIF Viewer 或任何支持 SARIF 的安全平台。每个发现都映射到带有 `security-severity` CVSS 分数的规则。 ## 🏗️ 架构 ``` src/ ├── cli.ts Entry point — commander argument parsing ├── scanner.ts Orchestrator: enumerate → checks → deduplicate → report ├── types.ts Shared interfaces (Finding, ScanResult, CheckFn …) ├── discovery/ │ ├── config-reader.ts Parses all known MCP config formats (Zod-validated) │ └── network-scan.ts Probes localhost ports for exposed HTTP servers ├── transport/ │ ├── stdio-client.ts StdioClientTransport + timeout + process cleanup │ └── http-client.ts StreamableHTTP with SSE fallback; captures response headers ├── checks/ │ ├── tool-poisoning.ts MCP-1xx — Unicode, injection, base64, exfil │ ├── credential-leak.ts MCP-2xx — 16 credential patterns with FP suppression │ ├── overprivileged.ts MCP-3xx — Dangerous capability combinations │ ├── auth-missing.ts MCP-4xx — Unauthenticated access, CORS, 0.0.0.0 │ ├── session-hijack.ts MCP-5xx — Session ID exposure and predictability │ ├── ssrf.ts MCP-6xx — User-controlled URL parameters │ ├── rce-vectors.ts MCP-7xx — Shell execution patterns │ └── supply-chain.ts MCP-8xx — CVE ranges, lockfiles, typosquats └── report/ ├── terminal.ts Chalk + Boxen rich terminal output └── json.ts JSON and SARIF 2.1.0 serialization ``` 每个检查导出 `async function check(data: ServerData): Promise`。所有检查通过 `Promise.allSettled` 并行运行 —— 单个检查损坏不会阻塞其余检查。 ## 🛡️ 发现模式 (Finding Schema) ``` interface Finding { id: string; // "MCP-701" title: string; // "RCE Vector: Shell/Execution Parameter Name" severity: "critical" | "high" | "medium" | "low" | "info"; category: string; // "rce-vectors" description: string; // Full explanation of the risk evidence: string; // The exact value that triggered the finding location: string; // "tool: bash_exec > inputSchema.properties.command" cve?: string; // "CVE-2025-6514" cvss?: number; // 9.6 remediation: string; // Actionable fix guidance } ``` ## 🔧 开发 ``` # Type-check 但不 build npm run typecheck # 不 build 直接运行 (使用 tsx) npm run dev -- scan --all-configs # 完整 rebuild npm run build ``` ## 📚 参考资料 - [MCP Specification (2025-11-25)](https://modelcontextprotocol.io/specification/2025-11-25) - [OWASP MCP Top 10 (2025)](https://owasp.org/www-project-mcp-top-10/) - [Tool Poisoning Attacks — Invariant Labs](https://invariantlabs.ai/blog/mcp-security-notification-tool-poisoning-attacks) - [MCP Attack Vectors — Palo Alto Unit 42](https://unit42.paloaltonetworks.com/model-context-protocol-attack-vectors/) - [CVE-2025-6514 Deep Dive — JFrog](https://jfrog.com/blog/2025-6514-critical-mcp-remote-rce-vulnerability/) - [MCP Security Best Practices](https://modelcontextprotocol.io/specification/draft/basic/security_best_practices) - [Network-Exposed MCP Servers — Trend Micro](https://www.trendmicro.com/vinfo/us/security/news/cybercrime-and-digital-threats/mcp-security-network-exposed-servers-are-backdoors-to-your-private-data)

基于 MIT License 发布 · 为安全社区构建

标签:CISA项目, CVE 检测, LLM 安全, LNA, MCP Server, MCP 安全, MITM代理, Model Context Protocol, PE 加载器, Python 安全工具, RCE 检测, SSRF 检测, 云安全监控, 会话劫持, 凭据泄露, 大模型安全, 安全测试, 工具投毒, 攻击性安全, 端点安全, 网络安全, 自动化攻击, 补丁管理, 隐私保护, 静态分析