Nmap (Network Mapper) คืออะไร?
Nmap คือเครื่องมือสแกนเครือข่าย (Network Scanner) ฟรีและ Open Source พัฒนาโดย Gordon Lyon (Fyodor) ใช้สำหรับ:
- Network Discovery (Host Discovery)
- Port Scanning
- Service/Version Detection
- OS Fingerprinting
- Vulnerability Detection (NSE Scripts)
- Network Inventory & Mapping
ใช้ได้ทั้ง Blue Team (Defensive) และ Red Team (Offensive)
Nmap ช่วย Network Security (Blue Team / Defensive) อย่างไร?
1. Network Asset Discovery & Inventory
nmap -sn 192.168.1.0/24 # Ping Sweep (Host Discovery)
nmap -sS -T4 192.168.1.0/24 # SYN Scan ทุก Port
nmap -sV 192.168.1.0/24 # Version Detection
- รู้ว่า "มีอะไรบนเครือข่าย" (Shadow IT, Unauthorized Devices)
- สร้าง Asset Inventory สำหรับ CMDB, Vulnerability Management
2. Security Auditing & Hardening Verification
nmap -sS -p- --open 192.168.1.100 # หา Port ที่เปิดอยู่ทั้งหมด
nmap --script vuln 192.168.1.100 # Vulnerability Scan ด้วย NSE
nmap --script ssl-cert,ssl-enum-ciphers 192.168.1.100 # SSL/TLS Audit
- ตรวจสอบ: Unnecessary Open Ports, Outdated Services, Weak Ciphers, Expired Certs
- ตรวจสอบ Firewall Rules: Port ที่ควรบล็อกแต่เปิดอยู่
3. Network Segmentation Verification
nmap -sS -Pn 10.0.1.0/24 -oA seg_test # ทดสอบจาก Segment หนึ่งไปอีก Segment
- ยืนยันว่า Segmentation ทำงานจริง (East-West Traffic Control)
- ทดสอบ Jump Host / Bastion Access
4. Compliance & Baseline Monitoring
- รัน Nmap เป็น Scheduled Job (Cron/Systemd Timer)
- เปรียบเทียบกับ Baseline (ndiff) → Alert หากมี Port/Service ใหม่
- Integration กับ SIEM (Splunk, Elastic) สำหรับ Correlation
5. IoT/OT Device Discovery
nmap -sS -p 80,443,8080,8443,502,102,44818 192.168.10.0/24 # Common OT Ports
nmap --script banner,http-title 192.168.10.0/24
Nmap ใช้โดย Red Team / Attackers อย่างไร? (เพื่อให้ Blue Team เข้าใจ威脅)
- Reconnaissance: Mapping Target Network, Finding Entry Points
- Vulnerability Scanning:
nmap --script vulnหรือnmap -sV --script auth - Lateral Movement Planning: หา SMB, RDP, SSH, WinRM, Database Ports
- Firewall Evasion:
-f (fragment), -D (decoy), -S (spoof), --mtu, --data-length - Exploitation: NSE Scripts สำหรับ Exploit (ms17-010, eternalblue, vsftpd-backdoor)
Nmap Scripting Engine (NSE) - แกนความสามารถ
หมวดหมู่ Scripts (ใน /usr/share/nmap/scripts/):
| Category | ตัวอย่าง Scripts |
|---|---|
| auth | ssh-auth-methods, ftp-anon, smb-enum-users |
| vuln | smb-vuln-ms17-010, http-shellshock, cve-2021-44228 |
| exploit | exploit-cve-2019-19781 (Citrix), redis-rce |
| discovery | dns-zone-transfer, snmp-sysdescr, ssh-hostkey |
| malware | http-malware-host, smb-malware-detection |
| default | Safe scripts ที่รันอัตโนมัติด้วย -sC |