#!/bin/bash # Agentic Pentest MCP - Implant Service Installer # Configures the implant as a systemd service that starts on boot. set -e echo "=== Agentic Pentest MCP - Implant Service Setup ===" echo "" # Check for Python 3 if ! command -v python3 &> /dev/null; then echo "Error: python3 not found." exit 1 fi PYTHON_VERSION=$(python3 --version | cut -d' ' -f2) echo "Found Python $PYTHON_VERSION" # Get script directory (where implant.py lives) SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" echo "" echo "This will install the implant as a systemd service that starts on boot." echo "" # Prompt for configuration read -p "MCP Server IP/Hostname: " SERVER_HOST read -p "MCP Server Port [8001]: " SERVER_PORT SERVER_PORT=${SERVER_PORT:-8001} read -p "Implant ID (leave blank for auto): " IMPLANT_ID IMPLANT_ID=${IMPLANT_ID:-$(cat /proc/sys/kernel/random/uuid | cut -c1-8)} read -p "Beacon Interval in seconds [30]: " INTERVAL INTERVAL=${INTERVAL:-30} # API key (optional) read -sp "API Key (leave blank if none): " API_KEY echo "" SERVER_URL="http://${SERVER_HOST}:${SERVER_PORT}" # Test connection to MCP server echo "" echo "Testing connection to ${SERVER_URL} ..." if command -v curl &> /dev/null; then # Just check if we can connect, don't validate HTTP response (port 8001 has different endpoints) if curl -s --connect-timeout 5 --max-time 10 "${SERVER_URL}/check_in" -X POST -H "Content-Type: application/json" -d '{"implant_id":"test-connectivity"}' > /dev/null 2>&1; then echo "✓ Connected to MCP server successfully." else # Try a simple TCP connection test if curl -s --connect-timeout 5 -o /dev/null "${SERVER_URL}" 2>/dev/null || python3 -c "import socket; s=socket.socket(); s.settimeout(5); s.connect(('$(echo $SERVER_HOST)', $(echo $SERVER_PORT))); s.close()" 2>/dev/null; then echo "✓ TCP connection to MCP server successful." else echo "⚠ Could not reach MCP server at ${SERVER_URL}. Service will still be installed but implant may fail to beacon." read -p "Continue anyway? [y/N] " CONTINUE if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then echo "Aborted." exit 0 fi fi fi else # Fallback to python socket test if curl isn't available if python3 -c "import socket; s=socket.socket(); s.settimeout(5); s.connect(('$(echo $SERVER_HOST)', $(echo $SERVER_PORT))); s.close()" 2>/dev/null; then echo "✓ TCP connection to MCP server successful." else echo "⚠ Could not reach MCP server at ${SERVER_URL}. Service will still be installed but implant may fail to beacon." read -p "Continue anyway? [y/N] " CONTINUE if [ "$CONTINUE" != "y" ] && [ "$CONTINUE" != "Y" ]; then echo "Aborted." exit 0 fi fi fi # Check for common pentest tools echo "" echo "Checking installed pentest tools..." echo "" TOOLS=( "nmap:nmap" "impacket:python3 -c 'import impacket' 2>/dev/null && echo ok || echo missing" "hydra:hydra" "john:john" "hashcat:hashcat" "sqlmap:sqlmap" "nikto:nikto" "dirb:dirb" "gobuster:gobuster" "ffuf:ffuf" ) for tool in "${TOOLS[@]}"; do NAME="${tool%%:*}" CHECK="${tool##*:}" if [ "$NAME" = "impacket" ]; then if python3 -c 'import impacket' 2>/dev/null; then echo "✓ $NAME: installed" else echo "✗ $NAME: not found" fi elif command -v "$CHECK" &> /dev/null; then echo "✓ $NAME: installed ($(which $CHECK))" else echo "✗ $NAME: not found" fi done echo "" # Build command-line arguments for the implant CLI_ARGS="--id ${IMPLANT_ID} --interval ${INTERVAL}" if [ -n "$API_KEY" ]; then CLI_ARGS="$CLI_ARGS --api-key ${API_KEY}" fi # Create systemd service file SERVICE_FILE="/etc/systemd/system/mcp-implant.service" echo "Creating systemd service at $SERVICE_FILE ..." cat > "$SERVICE_FILE" << EOF [Unit] Description=Agentic Pentest MCP Implant After=network-online.target Wants=network-online.target [Service] Type=simple ExecStart=/usr/bin/python3 ${SCRIPT_DIR}/implant.py ${CLI_ARGS} Environment=MCP_SERVER_URL=${SERVER_URL} Restart=always RestartSec=10 User=root [Install] WantedBy=multi-user.target EOF # Reload systemd and enable/start the service systemctl daemon-reload systemctl enable mcp-implant.service systemctl start mcp-implant.service echo "" echo "=== Implant Service Installed ===" echo "" echo "Service: mcp-implant.service" echo "Implant ID: ${IMPLANT_ID}" echo "Server: ${SERVER_URL}" echo "Interval: ${INTERVAL}s" echo "" echo "Useful commands:" echo " systemctl status mcp-implant # Check status" echo " journalctl -u mcp-implant # View logs" echo " systemctl stop mcp-implant # Stop service" echo " systemctl disable mcp-implant # Remove from boot"