151 lines
4.0 KiB
Bash
Executable File
151 lines
4.0 KiB
Bash
Executable File
#!/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
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" --connect-timeout 5 "${SERVER_URL}/mcp" 2>/dev/null || echo "000")
|
|
else
|
|
# Fallback to python if curl isn't available
|
|
HTTP_CODE=$(python3 -c "
|
|
import urllib.request, sys
|
|
try:
|
|
r = urllib.request.urlopen('${SERVER_URL}/mcp', timeout=5)
|
|
print(r.status)
|
|
except Exception as e:
|
|
print('000')
|
|
" 2>/dev/null || echo "000")
|
|
fi
|
|
|
|
if [ "$HTTP_CODE" = "200" ]; then
|
|
echo "✓ Connected to MCP server successfully."
|
|
else
|
|
echo "⚠ Could not reach MCP server (HTTP $HTTP_CODE). 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
|
|
|
|
# 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 environment variables string for systemd
|
|
ENV_VARS="Environment=MCP_SERVER_URL=${SERVER_URL}"
|
|
if [ -n "$API_KEY" ]; then
|
|
ENV_VARS="$ENV_VARS Environment=IMPLANT_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 --id ${IMPLANT_ID} --interval ${INTERVAL}
|
|
${ENV_VARS}
|
|
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"
|