渗透测试服务器工具

MCP渗透测试服务器是一个集成了多种安全工具的平台,用于执行端口扫描、漏洞扫描、密码攻击等安全测试任务。

  • by VyomJain6904
  • Shell
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 vyomjain6904/pentest-mcp-server

使用说明

MCP渗透测试服务器设置指南

本指南将指导您为渗透测试工具设置一个全面的MCP(模型上下文协议)服务器。

先决条件

系统要求

  • Linux/macOS(推荐)或带WSL2的Windows
  • Node.js 18+和npm
  • Python 3.8+(适用于某些工具)
  • Git

安全工具安装

在Ubuntu/Debian上:

# Update package list
sudo apt update

# Install basic tools
sudo apt install -y nmap gobuster nikto hydra john hashcat ffuf

# Install dirsearch
sudo apt install -y python3-pip
pip3 install dirsearch

# Install nuclei
sudo apt install -y golang-go
go install -v github.com/projectdiscovery/nuclei/v2/cmd/nuclei@latest
sudo ln -s ~/go/bin/nuclei /usr/local/bin/nuclei

在 macOS 上:

# Install Homebrew if not already installed
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# Install tools
brew install nmap gobuster nikto hydra john hashcat ffuf
brew install nuclei

# Install dirsearch
pip3 install dirsearch

在Arch Linux上:

# Install from official repositories
sudo pacman -S nmap gobuster nikto hydra john hashcat

# Install from AUR
yay -S ffuf nuclei dirsearch

单词列表设置

# Create wordlists directory
sudo mkdir -p /usr/share/wordlists

# Download common wordlists
sudo git clone https://github.com/danielmiessler/SecLists.git /usr/share/wordlists/seclists

# Download dirb wordlists
sudo apt install -y dirb  # This installs wordlists in /usr/share/wordlists/dirb/

# Or manually download
sudo wget -O /usr/share/wordlists/common.txt https://raw.githubusercontent.com/danielmiessler/SecLists/master/Discovery/Web-Content/common.txt

MCP服务器设置

步骤1:创建项目目录

mkdir mcp-pentest-server
cd mcp-pentest-server

步骤2:初始化Node.js项目

npm init -y

步骤3:安装依赖项

# Install MCP SDK
npm install @modelcontextprotocol/sdk

# Install development dependencies
npm install -D nodemon

步骤4:创建服务器文件

将提供的JavaScript代码另存为 server.js 以及package.json配置。

步骤5:使服务器可执行

chmod +x server.js

步骤6:测试服务器

# Test if server starts correctly
node server.js

Claude桌面集成

步骤1:找到Claude桌面配置

配置文件位于:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • 视窗: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/claude_desktop/claude_desktop_config.json

步骤2:创建/更新配置

创建或更新包含以下内容的配置文件:

{
  "mcpServers": {
    "pentest-server": {
      "command": "node",
      "args": ["/full/path/to/your/mcp-pentest-server/server.js"],
      "env": {
        "NODE_ENV": "production"
      }
    }
  }
}

重要:替换 /full/path/to/your/mcp-pentest-server/server.js 使用服务器文件的实际绝对路径。

步骤3:重新启动克劳德桌面

关闭并重新打开Claude Desktop以加载新的MCP服务器配置。

使用示例

配置后,您可以在Claude Desktop中使用以下命令:

基本端口扫描

Please run an nmap scan on 192.168.1.1 using the quick scan type

Web目录枚举

Run a gobuster scan on http://example.com with php,html,txt extensions

漏洞扫描

Perform a nuclei scan on example.com focusing on CVE templates

综合侦察

Run a comprehensive scan on example.com including web and vulnerability scanning

密码攻击

Use hydra to brute force SSH on 192.168.1.100 with username admin and password list /usr/share/wordlists/rockyou.txt

配置选项

自定义单词列表路径

您可以在工具参数中指定自定义单词表路径:

{
  "target": "http://example.com",
  "wordlist": "/custom/path/to/wordlist.txt"
}

扫描优化

为了获得更好的性能,您可以调整:

  • 线程数(通常为10-50,具体取决于目标)
  • 服务器代码中的超时值
  • 扫描强度级别

安全考虑

网络分段

  • 仅在您拥有或具有明确测试权限的网络上运行扫描
  • 尽可能使用隔离的测试环境

速率限制

  • 实现请求之间的延迟,以避免目标过多
  • 考虑使用代理链进行匿名

日志记录

  • 启用详细的日志记录以实现合规性和调试
  • 安全地存储扫描结果

故障排除

常见问题

未找到工具

# Check if tool is in PATH
which nmap
which gobuster

# Add to PATH if necessary
export PATH=$PATH:/usr/local/bin

权限错误

# Some tools require root privileges
sudo chmod +x server.js
sudo node server.js

港口准入问题

# For privileged ports, run with sudo
sudo node server.js

调试模式

通过设置环境变量启用调试日志记录:

DEBUG=true node server.js

日志文件

检查系统日志以获取详细的错误信息:

# On Linux
journalctl -u mcp-pentest-server

# Manual log file
tail -f /var/log/mcp-pentest.log

高级配置

自定义工具集成

要添加新工具,请扩展服务器类:

async runCustomTool(args) {
  const { target, options } = args;
  const command = `custom-tool ${target} ${options}`;
  
  try {
    const { stdout } = await execAsync(command);
    return {
      content: [{
        type: 'text',
        text: JSON.stringify({
          tool: 'custom-tool',
          target,
          results: this.parseCustomOutput(stdout)
        }, null, 2)
      }]
    };
  } catch (error) {
    throw new Error(`Custom tool failed: ${error.message}`);
  }
}

数据库集成

对于结果存储,考虑与数据库集成:

const sqlite3 = require('sqlite3');
const db = new sqlite3.Database('pentest_results.db');

// Store scan results
async storeScanResult(result) {
  const query = `
    INSERT INTO scans (target, tool, timestamp, results)
    VALUES (?, ?, ?, ?)
  `;
  
  return new Promise((resolve, reject) => {
    db.run(query, [
      result.target,
      result.tool,
      result.timestamp,
      JSON.stringify(result.parsed_results)
    ], function(err) {
      if (err) reject(err);
      else resolve(this.lastID);
    });
  });
}

API集成

对于外部API集成:

const axios = require('axios');

async queryThreatIntel(target) {
  try {
    const response = await axios.get(`https://api.threatintel.com/lookup/${target}`, {
      headers: { 'Authorization': `Bearer ${process.env.THREAT_INTEL_API_KEY}` }
    });
    return response.data;
  } catch (error) {
    console.error('Threat intel lookup failed:', error);
    return null;
  }
}

安全最佳实践

  1. 最小特权原则:以所需的最小权限运行服务器
  2. 输入验证:对所有用户输入进行消毒,以防止命令注入
  3. 速率限制:实施请求限制以防止滥用
  4. 审计日志:记录所有扫描活动以确保合规性
  5. 网络隔离:使用专用网络进行测试
  6. 数据加密:静态加密敏感扫描结果
  7. 定期更新:保持所有工具和依赖项的更新

法律考虑

  • 仅限您拥有或有明确书面许可进行测试的扫描系统
  • 遵守当地有关安全测试的法律法规
  • 对授权的测试活动进行适当的记录
  • 考虑漏洞赏金计划规则和范围限制
  • 实施适当的数据处理和隐私保护措施

支持和贡献

对于问题、改进或疑问:

  1. 检查故障排除部分
  2. 审查工具文档
  3. 提交带有详细错误日志的问题
  4. 考虑为项目做出改进

许可证

此项目根据MIT许可证获得许可-有关详细信息,请参阅许可证文件。