MCP安全扫描工具

一款针对Model Context Protocol (MCP)服务器的全面安全扫描工具,用于检测认证弱点、沙箱配置错误、数据泄露向量和速率限制问题。

  • by Cybathreat
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Cybathreat/mcp-security-scanner

使用说明

MCP安全扫描器

用于模型上下文协议(MCP)服务器的全面安全扫描程序。检测身份验证漏洞、沙盒配置错误、数据泄露向量和速率限制问题。

概述

MCP服务器为AI模型提供对外部工具和数据源的访问。此扫描程序在部署之前审核MCP配置中的安全漏洞。

特性

  • 身份验证扫描程序:检测敏感端点上的弱身份验证配置、硬编码凭据、缺少身份验证
  • 工具沙盒验证器:标识命令注入、路径遍历、SSRF、容器转义向量
  • 数据过滤检测器:发现不安全的数据传输、日志泄漏、缺少分类
  • 速率限制分析仪:检测丢失的速率限制、DDoS放大、资源耗尽风险
  • 秘密检测:扫描硬编码API密钥、令牌、密码、数据库凭据和私钥

安装

# Clone the repository
git clone https://github.com/Cybathreat/mcp-security-scanner.git
cd mcp-security-scanner

# Install dependencies
pip install -r requirements.txt

用法

基本扫描

# Run all security modules
python src/cli.py scan config/config.yaml

# Run specific modules
python src/cli.py scan config/config.yaml --modules auth sandbox

# Specify output format
python src/cli.py scan config/config.yaml --output json
python src/cli.py scan config/config.yaml --output markdown
python src/cli.py scan config/config.yaml --output both

# Set output directory
python src/cli.py scan config/config.yaml --output-dir ./reports

# Filter by minimum severity
python src/cli.py scan config/config.yaml --min-severity high

# Quiet mode (suppress progress)
python src/cli.py scan config/config.yaml --quiet

验证配置

# Check YAML syntax
python src/cli.py validate config/config.yaml

可用命令

mcp-security-scanner scan     Run security scans
mcp-security-scanner validate Validate config syntax
mcp-security-scanner version  Show version

输出

报告生成于 ./reports/ 默认情况下:

  • JSON:用于CI/CD集成的机器可读格式
  • 标记语言:带有执行摘要的可读报告

报告结构示例

{
  "report_metadata": {
    "tool": "MCP Security Scanner",
    "version": "0.1.0",
    "generated_at": "2026-03-21T..."
  },
  "executive_summary": {
    "total_findings": 15,
    "by_severity": {
      "critical": 3,
      "high": 5,
      "medium": 4,
      "low": 3
    },
    "overall_risk_level": "CRITICAL"
  },
  "scan_results": {...},
  "recommendations": [...]
}

安全模块

1.身份验证(auth)

扫描:

  • 已禁用身份验证
  • 弱令牌算法(无、MD5、SHA1)
  • 短密钥
  • 硬编码凭证
  • 不安全的会话Cookie
  • 未经身份验证的敏感端点
  • 未经授权的危险工具

CWES:CWE-306、CWE-327、CWE-326、CWE-798、CWE-614、CWE-284

2.工具沙盒(沙盒)

扫描:

  • 指令注入向量
  • 不受限制的shell访问
  • 路径遍历漏洞
  • 通过内部网络访问SSRF
  • 不安全协议(文件://,gopher://)
  • 禁用沙盒
  • 特权集装箱
  • 缺少资源限制

CWES:CWE-78、CWE-22、CWE-918、CWE-400、CWE-377

3.数据过滤(exfil)

扫描:

  • 无限制的数据访问
  • 未加密传输
  • TLS配置较弱
  • 敏感数据记录
  • 缺少PII检测
  • 未经身份验证的批量端点
  • 定时神谕

CWES:CWE-284、CWE-311、CWE-327、CWE-532、CWE-359、CWE-208

4.速率限制(速率)

扫描:

  • 禁用全局速率限制
  • 缺少身份验证端点限制
  • 没有登录尝试限制
  • 缺少资源限制
  • DDoS放大向量
  • 查询复杂性限制

CWES:CWE-400、CWE-307、CWE-208

5.秘密检测(秘密)

扫描:

  • AWS访问密钥和密钥
  • 私钥(RSA、EC、DSA、OPENSSH)
  • 通用API密钥和承载令牌
  • 带有凭据的数据库连接字符串
  • JWT机密和OAuth客户端机密
  • GitHub代币(ghp_、gho、gh_、ghs_、ghr_)
  • Slack 令牌( xoxb, xoxa, xoxp, xoxr-)
  • Stripe API密钥(sk_live_、rk_live_和pk_live_)
  • SendGrid API密钥
  • 硬编码密码
  • 加密密钥
  • Webhook的秘密

CWES:CWE-798、CWE-321

检测模式:15种以上高置信度秘密模式,具有自动屏蔽功能,可安全报告。

配置

创建一个 config.yaml 对于您的MCP服务器:

authentication:
  enabled: true
  token_algorithm: "RS256"
  secret: "${MCP_SECRET_KEY}"

session:
  secure_cookie: true
  http_only: true

rate_limiting:
  enabled: true
  requests_per_minute: 100

tools:
  - name: "shell_exec"
    type: "shell"
    requires_auth: true
    sandbox:
      enabled: true

看 config/config.yaml 对于完整的默认配置。

退出代码

  • 0:扫描完成,无关键发现
  • 1:错误(找不到配置,YAML无效)
  • 2:检测到关键发现

CI/CD集成

# GitHub Actions example
- name: MCP Security Scan
  run: |
    pip install -r requirements.txt
    python src/cli.py scan mcp-config.yaml --output json
    if [ $? -eq 2 ]; then
      echo "Critical security issues found!"
      exit 1
    fi

程序化使用

from mcp_auth import scan_mcp_auth
from tool_sandbox import validate_tool_sandbox
from data_exfil import detect_data_exfil_vectors
from rate_limiting import detect_rate_limit_issues

# Run individual scanners
auth_results = scan_mcp_auth("config.yaml")
sandbox_results = validate_tool_sandbox("config.yaml")
exfil_results = detect_data_exfil_vectors("config.yaml")
rate_results = detect_rate_limit_issues("config.yaml")

# Check for critical findings
if auth_results["summary"]["critical"] > 0:
    print("Critical auth issues found!")

运行测试

# Run all tests
python -m pytest tests/ -v

# Run specific test file
python -m pytest tests/test_mcp_auth.py -v
python -m pytest tests/test_sandbox.py -v

许可证

MIT许可证-请参阅许可证文件

免责声明

此工具用于安全审计目的。有关法律条款,请参阅免责声明.md。

贡献

  1. 分叉存储库
  2. 创建要素分支
  3. 添加新功能的测试
  4. 提交拉取请求

版本

v0.1.0-MVP版本