使用说明
MCP Pentest服务器
一个全面的模型上下文协议(MCP)服务器,用于具有教育指导的渗透测试。旨在为初学者提供专业的安全测试,同时为经验丰富的Pentester提供强大的功能。
⚠️ 法律声明
仅限授权使用
此工具仅用于授权的安全测试目的。未经授权的使用可能违反:
- 《计算机欺诈和滥用法案》(CFAA)-美国
- 英国计算机滥用法案-英国
- 其他司法管辖区的类似法律
在测试任何目标之前,务必获得书面许可。
特性
全面覆盖
- Web应用程序测试:Nmap、Nikto、Gobuster、SQLMap、WPScan、SSLScan
- 移动应用程序测试:JADX(APK反编译)、APKTool、MobSF、Frida/Objection
- 网络测试:端口扫描、服务检测、网络映射
- 专业报道:Markdown、PDF和JSON格式
教育方法
- 最大引导:每个发现都包括对它是什么、为什么它是危险的以及如何修复它的解释
- OWASP参考:直接链接到OWASP测试指南和补救资源
- CWE映射:每个漏洞的常见弱点枚举引用
- 逐步补救:为初学者提供详细的修复说明
安全功能
- 授权系统:基于令牌的访问控制,带审计日志记录
- 速率限制:防止滥用并管理并发扫描
- 输入验证:全面验证以防止命令注入
- 审计日志:完整记录所有渗透测试活动
安装
先决条件
# Node.js 18+ required
node --version
# Install required pentesting tools
# macOS (using Homebrew)
brew install nmap nikto gobuster sqlmap
# Ubuntu/Debian
sudo apt-get install nmap nikto gobuster sqlmap
# For APK analysis
brew install jadx # macOS
# or download from https://github.com/skylot/jadx
安装MCP服务器
cd mcp-pentest
npm install
npm run build
使用Claude代码进行配置
添加到您的Claude Code MCP设置中(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):
{
"mcpServers": {
"pentest": {
"command": "node",
"args": ["/absolute/path/to/mcp-pentest/dist/index.js"]
}
}
}
快速开始
1.生成授权令牌
# Generate a sample authorization token (64 characters)
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
2.基本网络扫描
在克劳德代码中:
Use the nmap_scan tool to scan example.com ports 80,443
Target: example.com
Ports: 80,443
Auth Token: [your-64-char-token]
3.运行工作流扫描
Use the quick_web_scan workflow to scan my website
Target: https://yourtestsite.com
Auth Token: [your-token]
4.生成报告
Use generate_report to create a PDF report from my scan results
Format: pdf
可用工具
网络扫描
nmap_scan
执行网络侦察和服务检测。
参数:
target(必填):IP地址、域或URLports(可选):端口规格(例如“80443”或“1-1000”)scanType(可选):“快速”、“标准”、“彻底”或“隐形”authToken(必填):授权令牌
例子:
{
"target": "192.168.1.1",
"ports": "1-10000",
"scanType": "standard",
"authToken": "your-token-here"
}
Web应用程序扫描
nikto_scan
扫描web服务器以查找已知漏洞和配置错误。
参数:
target(必填):web服务器的URLport(可选):端口号(默认值:80/443)ssl(可选):使用SSL/TLSauthToken(必填):授权令牌
gobuster_scan
在web服务器上强制使用目录和文件。
参数:
target(必填):基本URLwordlist(可选):单词表文件的路径extensions(可选):要检查的文件扩展名authToken(必填):授权令牌
sqlmap_scan
SQL注入漏洞测试。
参数:
target(必填):目标URLdata(可选):POST数据cookie(可选):Cookie标题level(可选):测试级别(1-5)risk(可选):风险等级(1-3)authToken(必填):授权令牌
移动应用分析
jadx_decompile
将Android APK文件分解为可读的Java源代码。
参数:
target(必填):APK文件的路径outputDir(可选):输出目录deobfuscate(可选):尝试删除代码authToken(必填):授权令牌
工作流扫描
quick_web_scan
快速侦察扫描(nmap+nikto)。
standard_web_scan
平衡扫描(nmap+nikto+gobuster+基本sqlmap)。
thorough_web_scan
全面扫描(所有具有激进设置的网络工具)。
报告
generate_report
生成专业安全报告。
参数:
format:“markdown”、“pdf”或“json”type:“执行”、“技术”或“详细”scanResults:扫描结果ID数组
教育特色
每个漏洞发现包括:
它是什么?
简明的英语解释适合初学者。
为什么这很危险?
清楚地解释了现实世界的影响和风险。
如何修复它
带有代码示例的逐步修复说明。
参考文献
- OWASP测试指南链接
- CWE(常见弱点枚举)引用
- 其他学习资源
输出示例
## Finding: SQL Injection in Login Form
**Severity**: Critical (CVSS: 9.8)
**Category**: WSTG-INPV-05 (SQL Injection)
**CWE**: CWE-89
### What Is It?
SQL Injection is a code injection technique that exploits security
vulnerabilities in an application's database layer. Attackers can
insert malicious SQL statements into application queries...
### Why It's Dangerous
- Unauthorized access to sensitive data
- Complete database compromise
- Possible remote code execution
- Data exfiltration and manipulation
### How To Fix It
1. **Use Prepared Statements** (Most Important)
```sql
PreparedStatement stmt = connection.prepareStatement(
"SELECT * FROM users WHERE username = ? AND password = ?"
);
stmt.setString(1, username);
stmt.setString(2, password);
- 使用具有内置保护的ORM框架
- 实施输入验证
- 对数据库帐户应用最小权限
参考文献
- https://owasp.org/www-community/attacks/SQL_Injection
- https://cheatsheetseries.owasp.org/cheatsheets/SQL_Injection_Prevention_Cheat_Sheet.html
## Security Considerations
### Authorization System
The MCP server requires authorization tokens for all scanning operations. To add a permanent authorization:
```typescript
import { authManager } from './src/utils/auth-manager.js';
authManager.addAuthorization('your-token', {
target: '*.example.com',
grantedBy: 'Security Team',
grantedAt: new Date(),
expiresAt: new Date(Date.now() + 30 * 24 * 60 * 60 * 1000), // 30 days
tools: ['nmap_scan', 'nikto_scan'], // Specific tools allowed
notes: 'Q4 2024 security assessment'
});
速率限制
不同的工具类别有不同的速率限制:
- 网络扫描:1个并发,最多5个/分钟
- Web扫描:2个并发,最多10个/分钟
- 移动分析:3个并发,最多20个/分钟
- 工作流:1个并发,最多3个/分钟
审计日志
所有活动都记录到 ./logs/audit-YYYY-MM-DD.log:
2024-11-17T10:30:45.123Z [SCAN_INITIATED] | Tool: nmap | Target: example.com | Success: true
2024-11-17T10:32:10.456Z [SCAN_COMPLETED] | Tool: nmap | Target: example.com | Duration: 85333ms | Details: 15 findings
发展
项目结构
mcp-pentest/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── server.ts # Main server class
│ ├── tools/ # Tool implementations
│ │ ├── web/ # Web testing tools
│ │ ├── mobile/ # Mobile testing tools
│ │ ├── network/ # Network testing tools
│ │ └── reporting/ # Report generation
│ ├── utils/ # Utilities
│ │ ├── command-executor.ts # Safe command execution
│ │ ├── input-validator.ts # Input validation
│ │ ├── output-parser.ts # Tool output parsing
│ │ ├── auth-manager.ts # Authorization
│ │ ├── audit-logger.ts # Audit logging
│ │ └── rate-limiter.ts # Rate limiting
│ ├── services/ # Business logic
│ │ └── vulnerability-knowledge-base.ts
│ ├── types/ # TypeScript types
│ │ ├── findings.ts
│ │ ├── tools.ts
│ │ └── reports.ts
│ └── templates/ # Report templates
├── config/ # Configuration files
├── logs/ # Audit logs
├── package.json
├── tsconfig.json
└── README.md
添加新工具
- 创建一个新的工具类来实现
BaseTool接口 - 使用添加命令执行逻辑
CommandExecutor - 使用验证输入
InputValidator - 使用解析输出
OutputParser - 在主服务器中注册该工具
- 从知识库中添加教育内容
例子:
import { BaseTool } from '../types/tools.js';
import { CommandExecutor } from '../utils/command-executor.js';
export class MyTool implements BaseTool {
name = 'my_tool';
description = 'Does something useful';
category = 'web' as const;
async execute(args: any) {
// Validate inputs
// Execute tool
// Parse output
// Return structured result
}
}
故障排除
未找到工具
Error: Failed to spawn process: ENOENT
解决方案:安装所需工具:
brew install nmap # or appropriate tool
which nmap # verify installation
授权失败
Error: Authorization token required
解决方案:提供有效的授权令牌(至少32个字符)。
超出费率限制
Error: Rate limit exceeded. Maximum 10 operations per minute.
解决方案:等待速率限制窗口清除或调整代码中的速率限制。
最佳实践
- 始终获得书面许可:未经明确授权,切勿扫描目标
- 从快速扫描开始:首先使用快速扫描,然后根据需要升级
- 尊重率限制:不要绕过速率限制-它保护您和目标
- 仔细审查调查结果:并非所有发现都是真阳性-手动验证
- 记录一切:使用报告功能记录所有调查结果
- 保持在范围内:只测试你的约定中授权的内容
贡献
欢迎投稿!拜托:
- 分叉存储库
- 创建要素分支
- 添加新功能的测试
- 确保所有TypeScript类型都正确
- 更新文档
- 提交拉取请求
许可证
MIT许可证-有关详细信息,请参阅许可证文件
支持
- 问题:https://github.com/baguskto/mcp-pentest/issues
- 文档:https://github.com/baguskto/mcp-pentest/wiki
- MCP-SDK:https://modelcontextprotocol.io
致谢
- OWASP安全测试指南
- MCP SDK团队提供卓越的协议
- 工具开发安全社区
- Claude为令人惊叹的IDE编写代码
记住权力越大,责任越大。在道德和法律上使用此工具。
