一个生产就绪的模型上下文协议(MCP)服务器,使AI代理能够通过SSH在任何Linux发行版上执行自主渗透测试。该服务器使用持久tmux会话、智能触发器、自动重连和全面的资源管理构建。
🚀 关键差异点:与运行独立命令的其他MCP服务器不同,此服务器提供基于tmux的持久会话管理,支持复杂的交互工作流和长时间运行的操作。
🎥 视频教程: 观看完整的YouTube教程
LinkedIn: Abdallah Ndiaye

此MCP服务器通过SSH为AI代理提供了对任何Linux发行版的持久会话控制,支持:
💡 优势: 我们的服务器提供持久会话管理,支持复杂的多步骤渗透测试工作流程,并且完全支持交互式工具。
┌─────────────────────┐
│ AI代理 │
│ (Claude/ChatGPT) │
└──────────┬──────────┘
│ MCP协议
▼
┌─────────────────────┐
│ MCP服务器 │
│ (Python) │
│ │
│ ┌───────────────┐ │
│ │会话管理器 │ │
│ │自动重连 │ │
│ │资源管理 │ │
│ └───────────────┘ │
└──────────┬──────────┘
│ SSH + PTY
▼
┌─────────────────────┐
│ 渗透测试系统 │
│ (Kali/Parrot等) │
│ │
│ ┌───────────────┐ │
│ │ tmux │ │
│ │ ┌─────────┐ │ │
│ │ │会话1 │ │ │
│ │ │会话2 │ │ │
│ │ │会话N │ │ │
│ │ └─────────┘ │ │
│ └───────────────┘ │
└─────────────────────┘
# 1. 克隆仓库
git clone https://github.com/LayeSec006/pentest-mcp-server.git
cd pentest-mcp-server
# 2. 安装包
pip install -e .
# 3. 配置
cp .env.example .env
# 编辑.env文件以包含您的渗透测试操作系统详细信息
# 4. 在目标系统上安装tmux
ssh kali@<TARGET_HOST>
# 对于Debian/Ubuntu/Kali/Parrot:
sudo apt update && sudo apt install tmux
# 对于Arch/BlackArch:
sudo pacman -S tmux
# 对于RHEL/CentOS/Fedora:
sudo yum install tmux
# 或对于更新版本:
sudo dnf install tmux
# 对于Alpine Linux:
sudo apk add tmux
exit
# 5. 测试
python -m pytest tests/ -v
创建一个.env文件,包含您的目标系统详细信息:
# SSH连接
TARGET_HOST=192.168.1.100
TARGET_PORT=22
TARGET_USER=kali
TARGET_PASSWORD=your_password
# 或使用SSH密钥代替
# TARGET_SSH_KEY=/path/to/private/key
# 资源限制
MAX_SESSIONS=20
MAX_HEAVY_TASKS=3
# 监控
POLL_INTERVAL=1.0
DEFAULT_TIMEOUT=300
添加到您的Claude桌面配置中:
Windows: %APPDATA%\Claude\claude_desktop_config.json
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"pentest-mcp": {
"command": "python",
"args": ["-m", "pentest_mcp_server"],
"env": {
"TARGET_HOST": "192.168.1.100",
"TARGET_USER": "kali",
"TARGET_PASSWORD": "your_password"
}
}
}
}
添加到您的Windsurf设置中:
{
"mcpServers": {
"pentest-mcp": {
"command": "python",
"args": ["-m", "pentest_mcp_server"],
"env": {
"TARGET_HOST": "192.168.1.100",
"TARGET_USER": "kali",
"TARGET_PASSWORD": "your_password"
}
}
}
}
添加到您的Cursor设置中:
{
"mcpServers": {
"pentest-mcp": {
"command": "python",
"args": ["-m", "pentest_mcp_server"],
"env": {
"TARGET_HOST": "192.168.1.100",
"TARGET_USER": "kali",
"TARGET_PASSWORD": "your_password"
}
}
}
}
在5ire中:
pentest-mcpPentest MCP(可选)AI驱动的渗透测试服务器(可选)始终(推荐)python -m pentest_mcp_serverTARGET_HOST = 192.168.1.100TARGET_USER = kaliTARGET_PASSWORD = your_passwordpentest-mcp条目上,点击右侧出现的切换按钮以启用它在Warp终端中:
{
"mcpServers": {
"pentest-mcp": {
"command": "python",
"args": ["-m", "pentest_mcp_server"],
"env": {
"TARGET_HOST": "192.168.1.100",
"TARGET_USER": "kali",
"TARGET_PASSWORD": "your_password"
}
}
}
}
# 1. 克隆并安装
git clone https://github.com/LayeSec006/pentest-mcp-server.git
cd pentest-mcp-server
pip install -e .
# 2. 配置
cp .env.example .env
# 编辑.env文件以包含您的目标系统详细信息
# 3. 测试配置
python -c "from pentest_mcp_server.config import Config; c = Config(); print('配置加载:', c.TARGET_HOST)"
启动并交互使用如Metasploit框架这样的复杂工具:
{
"tool": "execute",
"args": {
"session_id": "msf_session",
"command": "msfconsole -q"
}
}
与正在运行的工具交互:
{
"tool": "send_input",
"args": {
"session_id": "msf_session",
"input": "use exploit/multi/handler"
}
}
无缝处理传入的反向shell:
{
"tool": "execute",
"args": {
"session_id": "reverse_shell",
"command": "nc -lvp 4444"
}
}
与连接的shell交互:
{
"tool": "send_input",
"args": {
"session_id": "reverse_shell",
"input": "whoami"
}
}
支持多步骤渗透测试工作流:
会话在网络中断或崩溃后仍然存活:
{
"tool": "recover_sessions",
"args": {}
}
关键优势:
| 工具 | 描述 | 目的 |
|---|---|---|
create_session | 创建新的持久tmux会话 | 开始隔离的工作空间进行渗透测试任务 |
list_sessions | 列出所有活动会话 | 监控运行的操作 |
kill_session | 终止特定会话 | 清理已完成的任务 |
create_session创建一个新的持久tmux会话,用于隔离的渗透测试操作。
参数:
{
"session_id": "scan_network",
"shell": "bash"
}
list_sessions列出所有活动的tmux会话及其状态。
参数:
{}
kill_session终止特定会话并清理资源。
参数:
{
"session_id": "scan_network"
}
| 工具 | 描述 | 目的 |
|---|---|---|
execute | 在持久会话中执行命令 | 运行渗透测试工具和脚本 |
read_output | 获取会话的当前输出 | 监控命令进度和结果 |
send_input | 向交互式工具发送输入 | 控制交互式应用程序 |
execute在持久会话中执行命令。
{
"session_id": "scan_network",
"command": "nmap -sV 192.168.1.0/24",
"background": false
}
read_output获取会话的当前输出。
{
"session_id": "scan_network",
"lines": 50
}
send_input向交互式工具发送输入。
{
"session_id": "msf_session",
"input": "use exploit/multi/handler",
"press_enter": true
}
get_system_status获取系统资源使用情况和会话状态。
{}
recover_sessions重新连接后恢复孤立的会话。
{}
upload_file通过SFTP上传文件到您的系统。
{
"local_path": "/path/to/local/file",
"remote_path": "/tmp/uploaded_file"
}
download_file通过SFTP从您的系统下载文件。
{
"remote_path": "/tmp/scan_results.xml",
"local_path": "/path/to/local/results.xml"
}
parse_tool_output解析常见的渗透测试工具输出(nmap XML、JSON等)。
{
"tool": "nmap",
"file_path": "/tmp/scan.xml",
"format": "xml"
}
AI: 我需要扫描网络192.168.1.0/24
工具:create_session
参数:{"session_id": "network_scan"}
工具:execute
参数:{
"session_id": "network_scan",
"command": "nmap -sV 192.168.1.0/24 -oX /tmp/scan.xml"
}
工具:read_output
参数:{"session_id": "network_scan"}
AI: 让我启动Metasploit并设置一个处理器
工具:create_session
参数:{"session_id": "metasploit"}
工具:execute
参数:{
"session_id": "metasploit",
"command": "msfconsole -q"
}
工具:send_input
参数:{
"session_id": "metasploit",
"input": "use exploit/multi/handler"
}
工具:send_input
参数:{
"session_id": "metasploit",
"input": "set PAYLOAD linux/x64/meterpreter/reverse_tcp"
}
工具:send_input
参数:{
"session_id": "metasploit",
"input": "exploit"
}
AI: 我将