Add available tools section and improve example prompts
This commit is contained in:
1 parent
1cb5597932
commit
bf414cb1ef
1 file changed
+72
-171
@@ -1,186 +1,87 @@
|
|||||||
# Agentic Penetration Testing MCP Server & Implant
|
# Agentic Pentest MCP
|
||||||
|
|
||||||
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.
|
*For educational/testing purposes only.*
|
||||||
|
|
||||||
## Architecture
|
Pentest networks with a local agent!
|
||||||
|
|
||||||
|
This is an **MCP (Model Context Protocol) server** paired with a beaconing implant. The server queues commands from your AI agent, and the implant on the target network periodically checks in to pick up and execute them.
|
||||||
|
|
||||||
|
## Quick Setup
|
||||||
|
|
||||||
|
1. Clone this repo: `git clone https://github.com/creinky/agentic-pentest-mcp.git`
|
||||||
|
2. Start a fresh Debian 13 server
|
||||||
|
3. On the server run `setup.sh`
|
||||||
|
4. Connect your agent to the MCP at `http://<mcp-server-ip>:8000/mcp` and enter your API key if set
|
||||||
|
5. On the implant run `install_implant_service.sh`
|
||||||
|
|
||||||
|
> **Optional:** Set an API key for authentication. On the server, export `MCP_API_KEY="your-key"` before starting. When installing the implant service, enter the same key when prompted.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
This agentic C2 framework utilizes a local model, an MCP server, and an implant that beacons to the MCP. You should set system instructions for your agent so it knows what to do when you ask it to run commands. Here are the system instructions I use:
|
||||||
|
|
||||||
```
|
```
|
||||||
┌─────────┐ ┌──────────────┐ ┌─────────────────┐ ┌──────────┐
|
You have access to an MCP server (mcp-name) that relays commands to implants on target networks. The implant executes actual pentest tools and returns results via a beacon cycle (~30 second intervals).
|
||||||
│ Agent │────▶│ MCP Client │────▶│ MCP Server │◀────│ Implant │
|
|
||||||
│ (Bionic)│ │ (FastMCP) │ │ (command queue) │ │ (Kali) │
|
Architecture:
|
||||||
└─────────┘ └──────────────┘ └─────────────────┘ └──────────┘
|
|
||||||
▲ beacons out
|
You → MCP Server (port 8000) → Command Queue → Implant beacons in (port 8001) → Executes → Returns Results
|
||||||
│ periodically
|
Commands are queued, not executed immediately. Results arrive on the next beacon cycle.
|
||||||
|
|
||||||
|
Standard Workflow:
|
||||||
|
|
||||||
|
Discover implants: Call list_implants() to see what's online and their last check-in time
|
||||||
|
Identify networks: For a new implant, call list_network_interfaces(implant_id) to discover its subnet(s)
|
||||||
|
Queue reconnaissance: Start with non-intrusive scans (ping sweeps, service enumeration) before active exploitation
|
||||||
|
Retrieve results: Use get_result(result_id) after queuing commands; poll if needed as results arrive on beacon cycle
|
||||||
|
Analyze and iterate: Interpret results, identify targets/vulnerabilities, queue follow-up commands
|
||||||
|
|
||||||
|
Tool Usage Guidelines:
|
||||||
|
|
||||||
|
nmap_scan: Always specify appropriate flags. Start with -sn (ping sweep) or -sV -p common before full scans
|
||||||
|
run_command: Use for ad-hoc commands not covered by dedicated tools. Be precise and safe
|
||||||
|
get_result: If result is still pending, wait and retry on next interaction
|
||||||
|
|
||||||
|
Safety Considerations:
|
||||||
|
|
||||||
|
Confirm destructive or noisy operations with the user before queuing
|
||||||
|
Prefer stealthy enumeration over aggressive scanning unless instructed otherwise
|
||||||
|
Track what you've already scanned to avoid redundant work across sessions
|
||||||
|
|
||||||
|
When Starting Fresh (No Prior Context):
|
||||||
|
|
||||||
|
List implants and check their status/last seen time
|
||||||
|
Ask the user which implant(s) to focus on if multiple are online
|
||||||
|
Discover network topology via interface listing before scanning
|
||||||
|
Begin with reconnaissance, not exploitation, unless explicitly directed
|
||||||
```
|
```
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 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:
|
|
||||||
```bash
|
|
||||||
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):
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 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:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# 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
|
## Available Tools
|
||||||
|
|
||||||
| Tool | Description | Parameters |
|
These are the commands your agent can call through the MCP:
|
||||||
|------|-------------|------------|
|
|
||||||
| `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
|
| Tool | Description |
|
||||||
- **target**: IP address or hostname to scan (required)
|
|------|-------------|
|
||||||
- **scan_type**: Nmap flags (default: `-sT`). Options: `-sS`, `-sT`, `-sU`, `-sV`
|
| `nmap_scan` | Queue an nmap network scan (target, scan type, ports) |
|
||||||
- **ports**: Port spec like `"80,443"` or `"1-1024"`. Default: top 1000
|
| `list_network_interfaces` | List network interfaces on an implant |
|
||||||
- **output_format**: `normal`, `xml`, or `grepable`. Default: normal
|
| `run_command` | Execute a shell command on an implant |
|
||||||
|
| `impacket` | Run Impacket tools (secretsdump, smbclient, wmiexec, etc.) |
|
||||||
|
| `get_result` | Retrieve results of a queued command by request ID |
|
||||||
|
| `list_implants` | Show all registered implants and their status |
|
||||||
|
| `server_status` | Check MCP server configuration and status |
|
||||||
|
|
||||||
### impacket Parameters
|
Example prompts that work:
|
||||||
- **script_name**: Impacket script name (e.g., `secretsdump`, `smbclient`, `getusers`, `lookupsid`, `samrdump`, `wmiexec`, `psexec`)
|
- "Scan the network implant X is on and report results"
|
||||||
- **target**: Target IP address or hostname (optional)
|
- "Find all open ports on 192.168.1.50"
|
||||||
- **username**: Username for authentication (optional)
|
- "Run secretsdump against dc.example.com as admin"
|
||||||
- **password**: Password for authentication (optional)
|
- "What implants are currently online?"
|
||||||
- **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:
|
The MCP does not have any tools installed; rather it defines tools that should be installed on the implant and looks for user input from the model to pass the commands onto the implant.
|
||||||
|
|
||||||
### Create LXC Container
|
It is designed for the agent and MCP to be on the same network. **Port 8000** is for the agent to connect to the MCP and **port 8001** for the implant to beacon home, but can be configured however you like.
|
||||||
```bash
|
|
||||||
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
|
MCP and setup script are tested and working on Debian 13. The implant only needs python3 and the appropriate tools installed. The install script for the implant is to set the script up as a systemd service for autorun on startup.
|
||||||
```bash
|
|
||||||
pct push <CTID> agentic-pentest-mcp/ /opt/agentic-pentest-mcp/
|
|
||||||
pct enter <CTID>
|
|
||||||
cd /opt/agentic-pentest-mcp
|
|
||||||
./setup.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
### Configure and Start
|
|
||||||
```bash
|
|
||||||
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`:
|
|
||||||
```bash
|
|
||||||
#!/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
|
|
||||||
```bash
|
|
||||||
# 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`
|
|
||||||
Reference in new issue
Block a user