Files
agentic-pentest-mcp/README.md
T
creinky a1bb028001 Revise implant details and add security notes
Updated README to reflect changes in implant functionality and security considerations.
2026-11-05 21:39:42 -07:00

5.2 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

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 (Kali host)
  • 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

Setup

# Install dependencies
pip install -r requirements.txt

# Start MCP server
python server.py --http 8000

# Start implant (on target network)
export MCP_SERVER_URL="http://<mcp-server-ip>:8001"
python implant.py --id test-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
apt update && apt install -y python3 python3-venv nmap
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

Configure and Start

# Run server (listens on :8000 for MCP, :8001 for implant beacons)
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
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

  • Optional API key authentication: Set the IMPLANT_API_KEY environment variable on both server and implant to require an X-API-Key header on all beacon traffic. 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