nmap_scan
Perform comprehensive port scanning to identify open ports and services on target systems for security assessment and penetration testing.
Instructions
Perform comprehensive port scan using Nmap
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target | Yes | Target IP or domain | |
| scan_type | No | Type of scan to perform |
Implementation Reference
- src/tools/recon.ts:171-221 (handler)Core handler function that executes Nmap scans with configurable scan types, parses XML output, and returns structured ScanResult.async nmapScan(target: string, scanType: string = 'quick'): Promise<ScanResult> { try { let nmapArgs = ''; switch (scanType) { case 'quick': nmapArgs = '-F -sV'; break; case 'full': nmapArgs = '-p- -sV -sC'; break; case 'stealth': nmapArgs = '-sS -T2 -f'; break; case 'aggressive': nmapArgs = '-A -T4'; break; default: nmapArgs = '-F -sV'; } const command = `nmap ${nmapArgs} -oX - ${target}`; console.error(`Executing: ${command}`); const { stdout, stderr } = await execAsync(command, { timeout: 300000 }); // 5 min timeout // Parse XML output const ports = this.parseNmapXML(stdout); return { target, timestamp: new Date().toISOString(), tool: 'nmap', results: { scan_type: scanType, open_ports: ports, raw_output: stdout }, status: 'success' }; } catch (error) { return { target, timestamp: new Date().toISOString(), tool: 'nmap', results: {}, status: 'error', error: error instanceof Error ? error.message : String(error) }; } }
- src/index.ts:76-90 (schema)Input schema definition for the nmap_scan tool, specifying required target and optional scan_type parameters.name: "nmap_scan", description: "Perform comprehensive port scan using Nmap", inputSchema: { type: "object", properties: { target: { type: "string", description: "Target IP or domain" }, scan_type: { type: "string", enum: ["quick", "full", "stealth", "aggressive"], description: "Type of scan to perform" } }, required: ["target"] } },
- src/index.ts:505-506 (registration)Tool dispatch registration in the main CallToolRequestSchema handler switch statement.case "nmap_scan": return respond(await this.reconTools.nmapScan(args.target, args.scan_type || "quick"));
- src/tools/recon.ts:9-16 (schema)Output type definition (ScanResult interface) used by the nmapScan handler.export interface ScanResult { target: string; timestamp: string; tool: string; results: any; status: 'success' | 'error'; error?: string; }
- src/utils/validation.ts:310-335 (helper)Input validation logic for nmap_scan tool arguments, including target validation and scan_type enum check.case 'nmap_scan': this.validateNmapArgs(args); break; case 'nuclei_scan': this.validateNucleiArgs(args); break; case 'exploit_attempt': this.validateExploitArgs(args); break; // Add more tool-specific validations as needed } } private validateNmapArgs(args: any): void { if (args.target) { const validation = this.targetValidator.validateTarget(args.target); if (!validation.isValid) { throw new ValidationError(`Invalid nmap target: ${validation.error}`, 'INVALID_NMAP_TARGET'); } } const allowedScanTypes = ['quick', 'full', 'stealth', 'aggressive']; if (args.scan_type && !allowedScanTypes.includes(args.scan_type)) { throw new ValidationError('Invalid scan type', 'INVALID_SCAN_TYPE'); } }