nmap_scan
Scan network targets with nmap and automatically import results into Metasploit database for security testing workflows. Supports various scan types including quick, stealth, full, and UDP scans.
Instructions
Run an nmap scan and import results into Metasploit database
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target | Yes | Target IP address or CIDR range | |
| ports | No | Optional: port range or specific ports (e.g., '80,443' or '1-1000') | |
| scanType | No | Optional: type of scan to perform | quick |
Input Schema (JSON Schema)
{
"properties": {
"ports": {
"description": "Optional: port range or specific ports (e.g., '80,443' or '1-1000')",
"type": "string"
},
"scanType": {
"default": "quick",
"description": "Optional: type of scan to perform",
"enum": [
"quick",
"stealth",
"full",
"udp"
],
"type": "string"
},
"target": {
"description": "Target IP address or CIDR range",
"type": "string"
}
},
"required": [
"target"
],
"type": "object"
}
Implementation Reference
- src/index.ts:547-631 (handler)Handler for the nmap_scan tool. Checks if nmap is available, constructs Nmap arguments based on scanType (quick, stealth, full, udp), ports, and target. Executes 'db_nmap' via msfconsole to scan and import results into Metasploit DB. Returns success/error JSON.case "nmap_scan": { const { target, ports, scanType } = args as { target: string; ports?: string; scanType?: string; }; const nmapAvailable = await checkNmapAvailable(); if (!nmapAvailable) { return { content: [ { type: "text", text: JSON.stringify({ success: false, error: "nmap not found. Please install nmap.", hint: process.platform === "win32" ? "Download nmap from https://nmap.org/" : "Install with: sudo apt-get install nmap", }), }, ], }; } let nmapArgs: string[] = []; switch (scanType) { case "quick": nmapArgs.push("-F"); break; case "stealth": nmapArgs.push("-sS"); break; case "full": nmapArgs.push("-sV", "-sC"); break; case "udp": nmapArgs.push("-sU"); break; } if (ports) { nmapArgs.push("-p", ports); } nmapArgs.push(target); // Run nmap through msfconsole to automatically import results const dbNmapCommand = `db_nmap ${nmapArgs.join(" ")}`; try { const results = await executeMsfCommand([dbNmapCommand]); return { content: [ { type: "text", text: JSON.stringify( { success: true, target, ports: ports || "default", scanType: scanType || "quick", results, }, null, 2 ), }, ], }; } catch (error: any) { return { content: [ { type: "text", text: JSON.stringify({ success: false, error: error.message, }), }, ], }; } }
- src/index.ts:179-202 (registration)Registration of the nmap_scan tool in the MCP tools array, including name, description, and input schema.{ name: "nmap_scan", description: "Run an nmap scan and import results into Metasploit database", inputSchema: { type: "object", properties: { target: { type: "string", description: "Target IP address or CIDR range", }, ports: { type: "string", description: "Optional: port range or specific ports (e.g., '80,443' or '1-1000')", }, scanType: { type: "string", enum: ["quick", "stealth", "full", "udp"], description: "Optional: type of scan to perform", default: "quick", }, }, required: ["target"], }, },
- src/index.ts:182-200 (schema)Input schema for nmap_scan tool defining parameters: target (required), ports (optional), scanType (optional with enum).inputSchema: { type: "object", properties: { target: { type: "string", description: "Target IP address or CIDR range", }, ports: { type: "string", description: "Optional: port range or specific ports (e.g., '80,443' or '1-1000')", }, scanType: { type: "string", enum: ["quick", "stealth", "full", "udp"], description: "Optional: type of scan to perform", default: "quick", }, }, required: ["target"],
- src/index.ts:56-68 (helper)Helper function to check if nmap is installed and available on the system, used by nmap_scan handler.// Check if nmap is available async function checkNmapAvailable(): Promise<boolean> { try { if (process.platform === "win32") { await execAsync("where nmap"); } else { await execAsync("which nmap"); } return true; } catch { return false; } }