Files
agentic-pentest-mcp/README.md
T

6.9 KiB

Agentic Penetration Testing MCP Server & Implant

An MCP (Model Context Protocol) server and implant pair for autonomous penetration testing. The AI agent calls pentest tools through the MCP server, which queues commands that implants pick up via outbound beaconing — no inbound ports needed on target networks.

Architecture

┌─────────┐     ┌──────────────┐     ┌─────────────────┐     ┌──────────┐
│  Agent  │────▶│ MCP Client   │────▶│ MCP Server      │◀────│ Implant  │
│ (Bionic)│     │ (FastMCP)    │     │ (command queue) │     │ (Kali)   │
└─────────┘     └──────────────┘     └─────────────────┘     └──────────┘
                                                        ▲ beacons out
                                                        │ periodically

This agentic C2 framework is designed for the model and MCP to be on the same network with the implant being on a separate, target network.

Beaconing Flow:

  1. Agent calls MCP tool (e.g., nmap_scan) → command queued on server
  2. Implant periodically POSTs to /check_in endpoint
  3. Server returns any pending commands for that implant
  4. Implant executes commands locally, reports results via /report_result
  5. Agent retrieves results using get_result(request_id)

This works through NAT/firewalls because the implant only makes outbound connections.

Components

MCP Server (server.py)

  • Exposes pentest tools via FastMCP
  • Maintains command queue per implant
  • HTTP endpoint for implant check-ins (port 8001)
  • MCP transport on port 8000

Implant (implant.py)

  • Runs on target network (Linux host with tools installed)
  • Beacons out periodically to check for commands with time-aware jitter:
    • Business hours (Mon-Fri 8AM-6PM): base interval ±10% jitter
    • Off-hours: 2x base interval ±30% jitter for improved stealth
  • Executes nmap scans, shell commands, Impacket tools, etc. locally
  • Reports results back to MCP server

Quick Start

Server Setup (One Command)

# Clone the repo and run the setup script
git clone https://github.com/creinky/agentic-pentest-mcp.git
cd agentic-pentest-mcp
./setup.sh

The setup script will:

  • Check for Python 3 installation
  • Create a virtual environment (installing python3-venv if needed)
  • Install all dependencies from requirements.txt

After setup, start the server:

source .venv/bin/activate
export MCP_API_KEY="your-secret-key"  # Optional but recommended
python server.py --http 8000

Implant Setup (One Command)

On your target machine (requires Python 3 and internet access):

# Download the installer script
curl -O https://raw.githubusercontent.com/creinky/agentic-pentest-mcp/main/install_implant_service.sh
chmod +x install_implant_service.sh
./install_implant_service.sh

The installer will:

  • Prompt for your MCP server IP, port (default 8001), and API key
  • Test connectivity to the MCP server
  • Check which pentest tools are installed on the implant
  • Install a systemd service that auto-starts on boot with a 30-second beacon interval

Manual Implant Setup (Alternative)

If you prefer not to use the installer:

# On target machine
export MCP_SERVER_URL="http://<mcp-server-ip>:8001"
export IMPLANT_API_KEY="your-secret-key"  # Must match server's MCP_API_KEY
python implant.py --id my-implant --interval 30

Available Tools

Tool Description Parameters
nmap_scan Queue nmap scan on implant target, scan_type, ports, output_format
list_network_interfaces List implant's network interfaces implant_id (optional)
run_command Execute shell command on implant command, implant_id (optional)
impacket Queue Impacket tool execution script_name, target, username, password, domain, extra_args
get_result Retrieve result of queued command request_id
list_implants Show all registered implants none
server_status Check MCP server status none

nmap_scan Parameters

  • target: IP address or hostname to scan (required)
  • scan_type: Nmap flags (default: -sT). Options: -sS, -sT, -sU, -sV
  • ports: Port spec like "80,443" or "1-1024". Default: top 1000
  • output_format: normal, xml, or grepable. Default: normal

impacket Parameters

  • script_name: Impacket script name (e.g., secretsdump, smbclient, getusers, lookupsid, samrdump, wmiexec, psexec)
  • target: Target IP address or hostname (optional)
  • username: Username for authentication (optional)
  • password: Password for authentication (optional)
  • domain: Domain name (optional)
  • extra_args: Additional command-line arguments to pass to the script

Proxmox LXC Deployment (MCP Server)

To host the MCP server 24/7 in a Proxmox LXC container:

Create LXC Container

pct create <CTID> local:vztmpl/ubuntu-24.04-standard_24.04-1_amd64.tar.gz \
    --password yourpassword \
    --hostname mcp-pentest \
    --net0 name=eth0,bridge=vmbr0,ip=<IP>/24,gw=<GATEWAY> \
    --unprivileged 1

Deploy Application

pct push <CTID> agentic-pentest-mcp/ /opt/agentic-pentest-mcp/
pct enter <CTID>
cd /opt/agentic-pentest-mcp
./setup.sh

Configure and Start

source .venv/bin/activate
export MCP_API_KEY="your-secret-key"
python server.py --http 8000 &

Auto-start on Boot

Create a systemd service or add to /etc/rc.local:

#!/bin/bash
cd /opt/agentic-pentest-mcp
source .venv/bin/activate
export MCP_API_KEY="your-secret-key"
python server.py --http 8000 &

Verify Deployment

# Check MCP server is running
curl http://localhost:8000/mcp

# From Bionic/LM Studio, connect to:
# http://<lxc-ip>:8000/mcp

Security Considerations

  • API key authentication: Set MCP_API_KEY on the server and pass the same key to implants via IMPLANT_API_KEY environment variable or --api-key CLI argument. Without it, any host can register as an implant.
  • run_command tool is powerful; consider restricting in production
  • Use HTTPS transport for remote deployments
  • Implant IDs are auto-generated truncated UUIDs by default (8 hex chars), suitable for multi-implant environments

Troubleshooting

Implant gets 401 Unauthorized

Ensure the API key matches on both ends:

  • Server: export MCP_API_KEY="your-key"
  • Implant: --api-key your-key or export IMPLANT_API_KEY="your-key"

Implant can't reach server

Verify network connectivity and that port 8001 is open on the server. The implant only makes outbound connections, so no inbound ports are needed on the target network.

Service doesn't start after reboot

Check systemd service status: systemctl status mcp-implant View logs: journalctl -u mcp-implant