使用说明
OWASP MCP服务器
基于WebSocket的任务控制协议(MCP)服务器,用于OWASP ZAP安全扫描,实现对安全评估的实时控制和监控。
先决条件
- Python 3.8+
- OWASP ZAP 2.12.0+
- Java运行时环境(JRE)8+
- Sudo/管理员权限(ZAP需要)
为什么选择MCP服务器?
| 功能 | MCP服务器 | ZAP用户界面 | ZAP API |
|---|---|---|---|
| 自动化 | ✅ 已满 | ❌ 有限 | ✅ 基础 |
| 实时更新 | ✅ WebSocket | ✅ 视觉 | ❌ 民意调查 |
| CI/CD集成 | ✅ 本地 | ❌ 手册 | ✅ 综合体 |
| 批量处理 | ✅ 是 | ❌ 否 | ✅ 有限 |
| 学习曲线 | 🟡 中等 | 🟢 简单 | 🔴 硬 |
| 进度跟踪 | ✅ 实时 | ✅ 视觉 | ❌ 手册 |
| 多个域 | ✅ 并发 | ❌ 顺序 | 🟡 有限 |
| 错误处理 | ✅ 稳健 | ✅ 基础 | ❌ 手册 |
核心组件
-
mcp_server.py-为一切提供动力的发动机。首先,它是连接到OWASP ZAP的安全扫描引擎。 -
mcp_client.py-手术背后的大脑。其他组件用于与服务器通信的强大SDK(您不会直接使用它)。 -
mcp_cli.py-用于扫描的转到命令行工具。把它想象成你的瑞士军刀,用于安全扫描——使用简单,但功能强大。 -
test_client.py-一个向你展示诀窍的学习工具。非常适合了解一切的工作原理或测试您的设置。
快速开始
-
安装OWASP ZAP: 下载自https://www.zaproxy.org/download/
-
安装项目:
git clone https://github.com/shadsidd/Owasp-Zap-MCP-Server-Demo.git cd Owasp-Zap-MCP-Server-Demo python -m venv venv source venv/bin/activate # Windows: .\venv\Scripts\activate pip install -r requirements.txt -
启动ZAP (需要sudo/admin权限):
# macOS/Linux sudo /Applications/ZAP.app/Contents/Java/zap.sh -daemon -port 8080 # Windows (as Administrator) "C:\Program Files\OWASP\Zed Attack Proxy\zap.bat" -daemon -port 8080 -
启动MCP服务器:
python mcp_server.py -
使用CLI:
# Quick spider scan (passive) python mcp_cli.py scan example.com # Full active scan (comprehensive) python mcp_cli.py fullscan example.com # Specific scan type with HTML report python mcp_cli.py scan --scan-type=active --output=html example.com # Multiple domains scan python mcp_cli.py scan domain1.com domain2.com # Scan from file python mcp_cli.py scan -f domains.txt
示例文件
这 examples/ 目录包含演示关键功能的脚本:
安全扫描
basic_scan.py-带错误处理的岩芯扫描authenticated_scan.py-基于表单和其他身份验证方法scan_domains.py-多个域的并发扫描custom_scan_policy.py-自定义规则和阈值
集成与监控
ci_cd_integration.py-CI/CD管道集成real_time_monitor.py-实时进度和警报监控team_notifications.py-电子邮件、Slack和团队通知custom_rules.py-专门的安全规则
重要提示
-
Sudo要求:
- OWASP ZAP需要sudo/管理员权限才能运行
- 启动ZAP时,系统会提示您输入密码
-
端口配置:
- ZAP默认使用端口8080
- MCP服务器使用端口3000
- 启动前确保这些端口未被使用
-
常见问题:
- 如果您看到“地址已在使用中”错误:
# Check what's using port 8080 sudo lsof -i :8080 # Kill the process if needed sudo kill -9 <PID> - 如果ZAP无法启动,请尝试:
# Clear any existing ZAP processes pkill -f zap
- 如果您看到“地址已在使用中”错误:
扫描类型
MCP服务器支持多种扫描类型:
- 蜘蛛扫描 (默认):抓取网站以发现内容,速度最快,但发现的问题更少
- 主动扫描:对实际攻击进行安全测试,发现更多漏洞
- 全扫描:全面扫描(蜘蛛+主动),提供最彻底的结果