mirror of
https://github.com/GH05TCREW/pentestagent.git
synced 2026-03-07 14:23:20 +00:00
mcp: launch MetasploitMCP in stdio transport for manager compatibility
This commit is contained in:
@@ -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 <user> -P <password> -a <host> -p <port> -S" -ForegroundColor Yellow
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Setup complete!"
|
||||
Write-Host ""
|
||||
|
||||
@@ -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 <password> -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!"
|
||||
|
||||
Reference in New Issue
Block a user