安全漏洞演示工具

一个教育项目,用于演示模型上下文协议(MCP)服务器架构中的安全漏洞链,包括漏洞实现和安全缓解措施。

  • by lodetomasi
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 lodetomasi/mcp-security-research

使用说明

MCP安全演示

演示模型上下文协议(MCP)服务器架构中安全漏洞链的教育项目。

概述

该项目演示了漏洞如何在多个MCP服务器之间连锁,强调了每一层安全验证的重要性。它包括易受攻击和安全的实现进行比较。

建筑

┌─────────────────────────────────────────────────────────────┐
│                     ORCHESTRATOR                             │
│                  (Attack Coordinator)                        │
└────┬──────────────────┬──────────────────┬──────────────────┘
     │                  │                  │
     v                  v                  v
┌─────────┐      ┌─────────────┐    ┌──────────────┐
│ Server 1│      │  Server 2   │    │   Server 3   │
│ Input   │─────▶│ Processing  │───▶│  Execution   │
│(Fetch)  │      │  (Parse)    │    │   (Shell)    │
└─────────┘      └─────────────┘    └──────────────┘
     │                  │                  │
     │ No validation    │ Weak validation  │ Accepts from #2
     │                  │                  │
     └──────────────────┴──────────────────┴────▶ Vulnerability Chain

攻击流

  1. 输入服务器:在不进行URL验证的情况下获取内容
  2. 处理服务器:提取命令而不进行内容清理
  3. 执行服务器:执行命令而不重新验证
  4. 结果:命令注入成功

项目结构

/mcp-security-demo
├── servers/              # Unsafe MCP server implementations
│   ├── 01-unsafe-input-server
│   ├── 02-processing-server
│   └── 03-execution-server
├── servers-secured/      # Hardened implementations
├── orchestrator/         # Attack automation & demos
├── monitoring/           # Real-time dashboard
├── scripts/              # Setup & utility scripts
├── tests/                # Integration & security tests
└── docs/                 # Documentation

快速开始

先决条件

  • Node.js 18+
  • npm 9+
  • Docker(可选)

安装

# Clone and setup
git clone <repo-url>
cd mcp-security-demo
npm run setup

# This will:
# - Install all dependencies
# - Build all servers
# - Create sandbox directory
# - Setup environment

运行演示

# Terminal 1: Start unsafe servers
npm run dev:unsafe

# Terminal 2: Start monitoring dashboard
npm run monitor

# Terminal 3: Run attack demonstration
npm run demo:attack

比较安全与不安全

# Run side-by-side comparison
npm run demo:compare

# Or start secured servers
npm run dev:secured

攻击场景

场景1:简单的命令注入

演示通过HTML注释负载进行基本命令注入。

场景2:多步攻击

使用分段有效负载模拟权限升级。

场景3:数据过滤

展示如何从沙盒中提取数据。

安全缓解措施

安全版本实现了:

  • 输入服务器:URL白名单、内容类型验证、HTML净化
  • 处理服务器:命令块列表、用户批准、shell转义
  • 执行服务器:严格的白名单、审计日志、网络隔离

安全注意事项

这是一个 教育示范 内置安全功能:

  • 所有执行都是 沙盒 到 /tmp/mcp-demo-sandbox
  • 命令白名单可防止危险操作
  • 无法从执行环境访问网络
  • 演示后自动清理
  • 以非root用户身份运行

文档

测试

# Run all tests
npm test

# Security-specific tests
npm run test:security

# Integration tests
npm run test:integration

发展

# Clean build artifacts
npm run clean

# Clean sandbox
npm run clean:sandbox

# Build all packages
npm run build

监控

访问实时仪表板 http://localhost:3000 运行后:

npm run monitor

特征:

  • 攻击时间线可视化
  • 命令执行跟踪
  • 安全警报面板
  • 沙盒文件系统视图

许可证

麻省理工学院-仅用于教育目的

免责声明

这个项目是为了 仅用于教育和安全研究目的它展示了受控沙盒环境中的安全漏洞。未经明确授权,请勿对系统使用这些技术。

贡献

这是一个教育示范。欢迎提高教育价值或增加新的攻击/防御场景的贡献。

资源