Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบเครือข่าย >> ความปลอดภัยเครือข่าย

Nmap ช่วย Network Security อย่างไร? เครื่องมือสแกนเครือข่ายยอดนิยมสำหรับ Blue Team และ Red Team

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/):

คำสั่ง Nmap ที่ควรจดจำ (Cheat Sheet)

# Basic
nmap -sS -T4 target                    # SYN Scan (Default, Fast)
nmap -sT target                        # Connect Scan (No Root)
nmap -sU target                        # UDP Scan (Slow)

# Discovery
nmap -sn 192.168.1.0/24                # Ping Sweep (No Port Scan)
nmap -PS22,80,443 -PA3389 target       # TCP SYN/ACK Ping

# Version & OS
nmap -sV target                        # Version Detection
nmap -O target                         # OS Fingerprinting
nmap -A target                         # Aggressive (-sV -O -sC --traceroute)

# Scripts
nmap -sC target                        # Default Scripts
nmap --script vuln target              # Vulnerability Scripts
nmap --script "http-*" target          # All HTTP Scripts
nmap --script "smb-*" -p 445 target    # All SMB Scripts

# Output
nmap -oN normal.txt -oX xml.xml -oG grepable.txt target
nmap -oA basename target               # All 3 formats

การป้องกัน Nmap Scanning (Anti-Reconnaissance)

  • Firewall: Drop/Reject Unsolicited Traffic, Rate Limiting
  • Port Knocking / Single Packet Authorization (SPA)
  • Host-based Firewall (iptables, nftables, Windows Firewall)
  • IDS/IPS: Suricata/Snort Rules สำหรับ Nmap Signatures
  • Honeypots / Deception Technology (Detect Scanners)
  • Network Segmentation: จำกัด Visibility
  • Disable ICMP Echo Reply (แต่แนะนำให้ Allow สำหรับ Troubleshooting)

ข้อควรระวังทางกฎหมายและจริยธรรม

  • สแกนเฉพาะระบบที่ได้รับอนุญาต (Authorized Scope)
  • US: CFAA, State Laws - Unauthorized Scanning อาจผิดกฎหมาย
  • ไทย: พ.ร.บ.คอมพิวเตอร์ฯ มาตรา 9, 14 - การเข้าถึงข้อมูลคอมพิวเตอร์โดยไม่ได้รับอนุญาต
  • Bug Bounty: อ่าน Scope และ Rules of Engagement อย่างละเอียด
  • Enterprise: มี Rules of Engagement (RoE), Get Written Permission

สรุป: Nmap เป็น "Naval Knife" ของ Network Security - ใช้ได้ทั้ง Attack และ Defense Blue Team ควรใช้ Nmap เป็นประจำสำหรับ Asset Discovery, Hardening Verification, Segmentation Testing, Compliance Monitoring และ Threat Hunting

Categoryตัวอย่าง Scripts
authssh-auth-methods, ftp-anon, smb-enum-users
vulnsmb-vuln-ms17-010, http-shellshock, cve-2021-44228
exploitexploit-cve-2019-19781 (Citrix), redis-rce
discoverydns-zone-transfer, snmp-sysdescr, ssh-hostkey
malwarehttp-malware-host, smb-malware-detection
defaultSafe scripts ที่รันอัตโนมัติด้วย -sC