From 19bdff87b96164f43ef45dbad648504f338d3abf Mon Sep 17 00:00:00 2001 From: giveen Date: Wed, 14 Jan 2026 13:50:08 -0700 Subject: [PATCH] mcp: launch MetasploitMCP in stdio transport for manager compatibility --- pentestagent/mcp/mcp_servers.json | 6 +++--- scripts/setup.ps1 | 29 +++++++++++++++++++++++++++++ scripts/setup.sh | 29 +++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/pentestagent/mcp/mcp_servers.json b/pentestagent/mcp/mcp_servers.json index 4bbc5f6..dd8f080 100644 --- a/pentestagent/mcp/mcp_servers.json +++ b/pentestagent/mcp/mcp_servers.json @@ -16,9 +16,9 @@ "metasploit-local": { "command": "python3", "args": [ - "third_party/MetasploitMCP/metasploit_mcp.py", - "--server", - "http://127.0.0.1:7777" + "third_party/MetasploitMCP/MetasploitMCP.py", + "--transport", + "stdio" ], "description": "Metasploit MCP (vendored) - local server", "timeout": 300, diff --git a/scripts/setup.ps1 b/scripts/setup.ps1 index 4ea127c..d06bbae 100644 --- a/scripts/setup.ps1 +++ b/scripts/setup.ps1 @@ -91,6 +91,18 @@ PENTESTAGENT_DEBUG=false Write-Host "[!] Please edit .env and add your API keys" } +# Load .env into process environment variables (so the script can use them) +if (Test-Path -Path ".env") { + Get-Content .env | ForEach-Object { + if ($_ -match '^(?:\s*#)|(?:\s*$)') { return } + if ($_ -match '^(\s*([^=]+)?)=(.*)$') { + $name = $Matches[2].Trim() + $value = $Matches[3].Trim() + if ($name) { [Environment]::SetEnvironmentVariable($name, $value, 'Process') } + } + } +} + # Create loot directory for reports New-Item -ItemType Directory -Force -Path "loot" | Out-Null Write-Host "[OK] Loot directory created" @@ -138,6 +150,23 @@ if (Test-Path -Path $msReq) { } } +# Optionally auto-start msfrpcd if configured in .env +if (($env:LAUNCH_METASPLOIT_MCP -eq 'true') -and ($env:MSF_PASSWORD)) { + if (Get-Command bash -ErrorAction SilentlyContinue) { + $msfUser = if ($env:MSF_USER) { $env:MSF_USER } else { 'msf' } + $msfServer = if ($env:MSF_SERVER) { $env:MSF_SERVER } else { '127.0.0.1' } + $msfPort = if ($env:MSF_PORT) { $env:MSF_PORT } else { '55553' } + Write-Host "Attempting to start msfrpcd (user=$msfUser, host=$msfServer, port=$msfPort)..." + try { + & bash -lc "sudo msfrpcd -U $msfUser -P '$($env:MSF_PASSWORD)' -a $msfServer -p $msfPort -S" + } catch { + Write-Host "Warning: Failed to start msfrpcd via bash: $($_.Exception.Message)" -ForegroundColor Yellow + } + } else { + Write-Host "Warning: Cannot auto-start msfrpcd: 'bash' not available. Start msfrpcd manually with msfrpcd -U -P -a -p -S" -ForegroundColor Yellow + } +} + Write-Host "" Write-Host "Setup complete!" Write-Host "" diff --git a/scripts/setup.sh b/scripts/setup.sh index c0c4091..f4b98e4 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -94,6 +94,15 @@ EOF echo "[!] Please edit .env and add your API keys" fi +# Load .env into environment if present +if [ -f ".env" ]; then + # Export variables defined in .env for the duration of this script + set -a + # shellcheck disable=SC1091 + . .env + set +a +fi + # Create loot directory for reports mkdir -p loot echo "[OK] Loot directory created" @@ -116,6 +125,26 @@ if [ -f "third_party/MetasploitMCP/requirements.txt" ]; then bash scripts/install_metasploit_deps.sh || echo "Warning: failed to install MetasploitMCP dependencies." fi +# Optionally auto-start Metasploit RPC daemon if configured +# Requires `msfrpcd` (from metasploit-framework) and sudo to run as a service. +if [ "${LAUNCH_METASPLOIT_MCP,,}" = "true" ] && [ -n "${MSF_PASSWORD:-}" ]; then + if command -v msfrpcd >/dev/null 2>&1; then + MSF_USER="${MSF_USER:-msf}" + MSF_SERVER="${MSF_SERVER:-127.0.0.1}" + MSF_PORT="${MSF_PORT:-55553}" + MSF_SSL="${MSF_SSL:-false}" + echo "Starting msfrpcd (user=${MSF_USER}, host=${MSF_SERVER}, port=${MSF_PORT})..." + if sudo -n true 2>/dev/null; then + sudo msfrpcd -U "$MSF_USER" -P "$MSF_PASSWORD" -a "$MSF_SERVER" -p "$MSF_PORT" -S || echo "Warning: msfrpcd failed to start." + else + echo "msfrpcd requires sudo. You may be prompted for your password to start it interactively." + sudo msfrpcd -U "$MSF_USER" -P "$MSF_PASSWORD" -a "$MSF_SERVER" -p "$MSF_PORT" -S || echo "Failed to start msfrpcd. Start it manually with: sudo msfrpcd -U $MSF_USER -P -a $MSF_SERVER -p $MSF_PORT -S" + fi + else + echo "msfrpcd not found; please install Metasploit Framework to enable Metasploit RPC." + fi +fi + echo "" echo "==================================================================" echo "Setup complete!"