Fragment packets — chia nhỏ IP packet thành các fragment 8 byte. Bypass packet filter cũ
-f -f
nmap -ff target
Fragment 2 lần (16 byte mỗi fragment)
--mtu
nmap --mtu 24 target
Tự set MTU (phải là bội số của 8)
-D
nmap -D RND:10 target
Decoy scan — gửi từ nhiều IP giả ngẫu nhiên để làm khó trace
-D
nmap -D 10.0.0.1,10.0.0.2,ME target
Decoy cụ thể, ME là IP thật xen giữa
-sI
nmap -sI zombie_ip target
Idle/Zombie Scan — scan ẩn danh hoàn toàn qua host zombie
-S
nmap -S fake_ip target
Spoof source IP (cần -e và -Pn)
-g / --source-port
nmap -g 53 target
Giả mạo source port (ví dụ 53 để giả DNS traffic)
--proxies
nmap --proxies http://proxy:8080 target
Relay qua HTTP/SOCKS4 proxy
--data-length
nmap --data-length 200 target
Thêm random data vào packet để bypass fingerprinting
--randomize-hosts
nmap --randomize-hosts target_range
Ngẫu nhiên hóa thứ tự scan target
--spoof-mac
nmap --spoof-mac 0 target
Spoof MAC address ngẫu nhiên
--spoof-mac
nmap --spoof-mac Dell target
Spoof MAC theo vendor
--spoof-mac
nmap --spoof-mac AA:BB:CC:DD:EE:FF target
Spoof MAC cụ thể
--badsum
nmap --badsum target
Gửi packet với checksum sai — test firewall/IDS phản ứng thế nào
Lệnh IDS Evasion tổng hợp
# Kết hợp nhiều kỹ thuậtsudo nmap -f -T0 -n -Pn \
--data-length 200\
--spoof-mac 0\
-D RND:5,ME \
-g 53\
--source-port 53\
192.168.1.1
11. Output
Các định dạng output
Switch
Ví dụ
Mô tả
-oN
nmap -oN scan.txt target
Normal output — readable cho người đọc
-oX
nmap -oX scan.xml target
XML output — dùng với tools khác (Metasploit, custom parser)
-oG
nmap -oG scan.gnmap target
Grepable output — dễ xử lý với grep, awk, cut
-oA
nmap -oA scan_result target
All formats — tạo cả 3 file cùng lúc (.nmap, .xml, .gnmap)
-oS
nmap -oS l33t.txt target
“Script kiddie” output — encode kỳ quặc (ít dùng)
-oG -
nmap -oG - target
Grepable output ra stdout thay vì file
--append-output
nmap -oN file.txt --append-output target
Append vào file thay vì ghi đè
--stats-every
nmap --stats-every 10s target
In statistics mỗi N giây
Verbosity & Debug
Switch
Ví dụ
Mô tả
-v
nmap -v target
Verbose — thông tin thêm khi scan
-vv
nmap -vv target
Rất verbose
-d
nmap -d target
Debug level 1
-d9
nmap -d9 target
Debug level tối đa (rất nhiều output)
--reason
nmap --reason target
Giải thích lý do port ở trạng thái đó
--open
nmap --open target
Chỉ hiển thị open port (bỏ filtered/closed)
--packet-trace
nmap --packet-trace target
Hiện toàn bộ packet gửi/nhận
Xử lý output thực chiến
# Tìm web server đang chạy trong subnetnmap -p80 -sV -oG - --open 192.168.1.0/24 | grep open
# Lấy danh sách IP alivenmap -sn 192.168.1.0/24 -oG - | grep "Status: Up"| cut -d" " -f2
# Đếm port xuất hiện nhiều nhấtgrep " open " scan.nmap | awk '{print $1}'| sort | uniq -c | sort -rn
# Convert XML sang HTMLxsltproc nmap.xml -o nmap.html
# Import vào Metasploitmsf> db_import scan.xml
12. Troubleshooting & Debugging
Switch
Ví dụ
Mô tả
-h
nmap -h
Help nhanh
-V
nmap -V
Hiển thị version của Nmap
--iflist
nmap --iflist
Liệt kê network interfaces và routes
-e
nmap -e eth0 target
Chỉ định interface cụ thể
--reason
nmap --reason target
Lý do port state (reset, syn-ack, …)
--open
nmap --open target
Chỉ show open/open|filtered port
--packet-trace
nmap --packet-trace -T4 target
Trace từng packet gửi/nhận
-d
nmap -d target
Debug output
13. Ndiff — So sánh kết quả scan
ndiff là tool đi kèm Nmap để so sánh hai file kết quả scan XML, rất hữu ích khi theo dõi thay đổi mạng theo thời gian.
# So sánh hai file XMLndiff scan1.xml scan2.xml
# Verbose mode (hiện chi tiết hơn)ndiff -v scan1.xml scan2.xml
# Output dạng XMLndiff --xml scan1.xml scan2.xml
14. Lệnh thực chiến theo tình huống
# 1. Host discovery — ai đang sống trong mạngnmap -sn 192.168.1.0/24
# 2. Scan nhanh top 100 port trên subnetnmap -F 192.168.1.0/24
# 3. Scan chi tiết với version detectionnmap -sS -sV -O -T4 192.168.1.0/24
# 4. Scan toàn diện với default scriptsnmap -A -T4 target
# Scan web và detect tech stacknmap -p80,443,8080,8443 -sV --script "http-*" target
# Enum web directoriesnmap -p80 --script http-enum target
# Phát hiện WAFnmap -p80,443 --script http-waf-detect target
# Detect XSS, SQLinmap -p80 --script http-sql-injection,http-unsafe-output-escaping target
# Grab HTTP headersnmap -p80 --script http-headers target
# Aggressive scan toàn subnetsudo nmap -A -T4 192.168.1.0/24 -oA full_scan
# Chỉ scan port phổ biến, nhanhnmap --top-ports 100 192.168.1.0/24 -oG quick.gnmap
# Traceroute kết hợpnmap --traceroute -sn 192.168.1.0/24
# Chậm, phân mảnh packet, decoysudo nmap -sS -T1 -f -D RND:5 --data-length 100 target
# Xmas/NULL/FIN để bypass stateless firewallsudo nmap -sX target
sudo nmap -sN target
sudo nmap -sF target
# Source port giả là DNS (53)sudo nmap -g 53 -sS target
# Qua proxynmap --proxies socks4://proxy_ip:1080 target
TARGET=10.10.10.1
# Bước 1: Quick port discoverysudo nmap -sS -T4 --min-rate 5000 -p- $TARGET -oN ports.txt
# Bước 2: Extract open portsPORTS=$(grep "open" ports.txt | cut -d'/' -f1 | tr '\n'','| sed 's/,$//')# Bước 3: Deep scan các port opensudo nmap -sC -sV -p$PORTS$TARGET -oA detail_scan
# Bước 4: Vuln scansudo nmap --script vuln -p$PORTS$TARGET -oN vuln_scan.txt
# Phát hiện Samba/SMBnmap -p445 --script smb-os-discovery,smb-enum-shares target
# Phát hiện MS17-010 (EternalBlue)nmap -p445 --script smb-vuln-ms17-010 target
# SSH brute (cẩn thận với rate limit)nmap -p22 --script ssh-brute --script-args userdb=users.txt,passdb=pass.txt target
# SNMP community stringnmap -sU -p161 --script snmp-brute target
Tổng hợp Quick Reference
TARGET SPECIFICATION
nmap 192.168.1.1 Single IP
nmap 192.168.1.1-254 Range
nmap 192.168.1.0/24 CIDR
nmap -iL list.txt From file
nmap -iR 100 Random 100 hosts
nmap --exclude IP Exclude IP
nmap -6 IPv6 IPv6
HOST DISCOVERY
-sn Ping scan only (no port scan)
-Pn Skip ping (assume host up)
-PS 80,443 TCP SYN ping
-PA 80 TCP ACK ping
-PE ICMP Echo ping
-PP ICMP Timestamp ping
-PR ARP ping (LAN only)
-n No DNS resolution
-R Force DNS resolution
SCAN TYPES
-sS SYN (stealth, default+root)
-sT TCP Connect (no root)
-sU UDP scan
-sN NULL scan
-sF FIN scan
-sX Xmas scan
-sA ACK scan (firewall mapping)
-sI Idle/Zombie scan
-sO IP protocol scan
--scanflags SYNFIN Custom flags
PORT SPECIFICATION
-p 80 Single port
-p 80,443 Multiple ports
-p 1-1024 Range
-p- All 65535 ports
-p U:53,T:80 TCP+UDP
-F Top 100
--top-ports N Top N ports
SERVICE/VERSION DETECTION
-sV Version detection
-sV --version-all Max intensity
-A Aggressive (OS+Ver+Scripts+Trace)
OS DETECTION
-O OS detection
-O --osscan-guess Guess aggressively
NSE SCRIPTS
-sC Default scripts
--script [name] Specific script
--script "http-*" Wildcard
--script vuln Category
--script-updatedb Update DB
TIMING
-T0 Paranoid -T3 Normal
-T1 Sneaky -T4 Aggressive
-T2 Polite -T5 Insane
--min-rate N Min packets/sec
--max-rate N Max packets/sec
EVASION
-f Fragment packets
--mtu 24 Custom MTU
-D RND:5 Decoy scan
-g 53 Spoof source port
-S fake_ip Spoof source IP
--spoof-mac 0 Random MAC
--data-length N Add random data
OUTPUT
-oN file.txt Normal
-oX file.xml XML
-oG file.gnmap Grepable
-oA basename All three formats
-v / -vv Verbose
--reason Show port state reason
--open Only open ports
MISC
-V Nmap version
-h Help
--iflist List interfaces
-e eth0 Use specific interface