Post

Nmap Cheatsheet

Tổng hợp workflow, scan types, NSE scripts, evasion techniques và performance tuning cho Nmap.

Nmap Cheatsheet

Workflow Chuẩn

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Bước 1: Quick scan tìm ports mở
sudo nmap -p- --min-rate 10000 -T4 -n -Pn --open -oN ports.txt TARGET

# Bước 2: Lấy list ports từ kết quả
ports=$(grep "^[0-9]" ports.txt | cut -d'/' -f1 | tr '\n' ',' | sed 's/,$//')

# Bước 3: Deep scan chỉ những ports mở
sudo nmap -p$ports -sV -sC -O --reason -oA detailed TARGET

# Bước 4: Nếu có Web (80/443/8080)
nmap -p80,443,8080 --script http-enum,http-title,http-methods TARGET

# Bước 5: Nếu có SMB (445)
nmap -p445 --script smb-vuln-ms17-010,smb-enum-shares TARGET

# Bước 6: Nếu có FTP (21)
nmap -p21 --script ftp-anon,ftp-bounce TARGET

Phase 1 — Host Discovery

1
2
3
4
5
6
7
8
# Ping sweep
nmap -sn 192.168.1.0/24

# Bypass firewall block ICMP
nmap -Pn 192.168.1.0/24

# ARP discovery (chỉ dùng trong LAN)
nmap -PR 192.168.1.0/24

Phase 2 — Port Scanning

Scan Types

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Quick scan top 1000 ports
sudo nmap -Pn -sS -T5 192.168.1.100

# Full scan tất cả 65535 ports
sudo nmap -Pn -sS -T5 -p- 192.168.1.100

# Scan specific ports
nmap -Pn -sS -T5 -p 22,80,443,3389,8080 192.168.1.100

# Scan TCP + UDP cùng lúc
sudo nmap -sS -sU -p T:22,80,443,U:53,161 192.168.1.100

# UDP port + evasion
sudo nmap 10.129.26.102 -sU --top-ports 100 -Pn -n --source-port 53 -e tun0 --max-retries 1 --min-rate 1000 --open

# Tốc độ cao
nmap -p- --min-rate 10000 -T4 -n -Pn --open TARGET

Stealth Scan Types

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# NULL Scan — không set flag nào
sudo nmap -sN 192.168.1.100

# FIN Scan — chỉ set FIN flag
sudo nmap -sF 192.168.1.100

# Xmas Scan — set FIN + PSH + URG
sudo nmap -sX 192.168.1.100

# ACK Scan — xác định firewall rule
sudo nmap -sA 192.168.1.100

# Window Scan — phân biệt open/closed qua TCP window size
sudo nmap -sW 192.168.1.100

# Maimon Scan — FIN/ACK, bypass BSD-based firewall
sudo nmap -sM 192.168.1.100

# Idle/Zombie Scan — ẩn danh siêu cấp vip pro
sudo nmap -O --script ipidseq 192.168.1.50    # Bước 1: tìm zombie
sudo nmap -sI 192.168.1.50 192.168.1.100       # Bước 2: scan qua zombie

Khi nào dùng cái nào?

  • -sN/sF/sX → bypass firewall non-stateful, không hoạt động trên Windows
  • -sI → stealth tuyệt đối, không gửi packet nào từ IP thật
  • -sA/-sW → map firewall rules, xác định port bị filter hay không
  • -sS → mặc định, nhanh, ít log hơn full connect scan

Phase 3 — Service & Version Detection

1
2
3
4
5
6
7
8
# Detect service version
nmap -sV 192.168.1.100

# Aggressive version detection (intensity 0-9)
nmap -sV --version-intensity 5 192.168.1.100

# Evasion
sudo nmap <target> -p <port> -sV -sC -Pn -n --source-port 53 -D RND:5 -e tun0

Phase 4 — OS Detection

1
2
3
4
nmap -O 192.168.1.100

# Kết hợp tất cả (-sV -O -sC --traceroute)
nmap -A 192.168.1.100

Phase 5 — NSE Scripts

Categories

CategoryMô tả
authBypass authentication
broadcastDiscover hosts không cần target
bruteBrute force credentials
defaultTương đương -sC
discoveryThu thập thông tin
exploitThử khai thác lỗ hổng
fuzzerFuzzing input
intrusiveCó thể gây crash service
malwareDetect malware/backdoor
safeAn toàn, không gây hại
vulnVulnerability detection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Chạy theo category
nmap --script vuln TARGET
nmap --script "default and safe" TARGET
nmap --script "vuln and not intrusive" TARGET

# Script tôi hay dùng trong lab
nmap -sC TARGET
nmap --script smb-vuln-ms17-010 TARGET
nmap --script smb-enum-shares,smb-enum-users TARGET
nmap --script http-enum,http-title,http-methods TARGET
nmap --script ftp-anon,ftp-bounce TARGET
nmap --script ssh-auth-methods TARGET
nmap --script ssh-brute TARGET                                     # ⚠️
nmap --script dns-zone-transfer \
     --script-args dns-zone-transfer.domain=TARGET_DOMAIN TARGET

# Script với arguments
nmap --script smb-brute \
     --script-args userdb=users.txt,passdb=pass.txt TARGET
nmap --script http-title \
     --script-args http.useragent="Mozilla/5.0" TARGET

Kỹ thuật Evasion

Timing

1
2
3
4
5
6
7
# T0=paranoid, T5=insane
nmap -sS -T2 TARGET

# Kiểm soát tốc độ thủ công
nmap --min-rate 5000 --max-rate 10000 TARGET
nmap --scan-delay 500ms TARGET
nmap --max-scan-delay 1s TARGET

Packet Manipulation

1
2
3
4
5
6
7
8
9
10
11
12
# Fragment packets (chia nhỏ packet để bypass DPI)
nmap -f TARGET

# MTU tùy chỉnh (phải là bội số của 8)
nmap --mtu 16 TARGET
nmap --mtu 24 TARGET

# Thêm data rác vào packet
nmap --data-length 50 TARGET

# Chỉnh TTL
nmap --ttl 64 TARGET

IP Spoofing & Decoys

1
2
3
4
5
6
# Decoy — tạo IP giả lẫn với IP thật
nmap -D RND:5 TARGET
nmap -D RND:10 TARGET

# Spoof source IP hoàn toàn
sudo nmap -n -Pn -p 445 -O -S 10.129.2.200 -e tun0 TARGET

Các IP decoy phải đang hoạt động (alive). Nếu không, target có thể bị SYN flood dẫn đến bị phát hiện hoặc service crash.

Source Port Spoofing

1
2
3
4
5
6
7
8
9
10
11
12
# Giả source port DNS (port 53 thường được firewall tin tưởng)
nmap --source-port 53 TARGET

# Sau khi confirm bypass → kết nối thật bằng Netcat
ncat -nv --source-port 53 TARGET PORT

# Dùng DNS server khác
nmap --dns-servers 8.8.8.8,1.1.1.1 TARGET

# Nâng cao — tránh IDS/IPS
sudo nmap <target> -p- -sS -Pn -n --disable-arp-ping --source-port 53 \
  -e tun0 -D RND:10 --min-rate 5000 --max-retries 1 -T4

Detect IDS/IPS

1
2
3
# Gửi packet checksum sai
# Nếu nhận response → có IDS đang monitor traffic
nmap --badsum TARGET

Misc Evasion

1
2
3
4
5
6
# Random thứ tự scan host
nmap --randomize-hosts 192.168.1.0/24

# Kết hợp nhiều kỹ thuật (stealth tối đa)
sudo nmap -sS -T2 -f --mtu 16 --data-length 50 \
     -D RND:5 --source-port 53 --randomize-hosts TARGET

Performance Tuning

1
2
3
4
5
6
7
8
9
10
11
# Giới hạn retry (mặc định 10)
nmap --max-retries 2 TARGET

# Timeout per host
nmap --host-timeout 30s TARGET

# Parallel host scanning
nmap --min-hostgroup 64 --max-hostgroup 256 TARGET/24

# Combo tốc độ cao (CTF/HTB)
sudo nmap -p- --min-rate 10000 --max-retries 2 -T4 -n -Pn --open TARGET

Output

1
2
3
4
5
6
7
8
9
nmap -oN output.txt TARGET      # Normal — human readable
nmap -oX output.xml TARGET      # XML — dùng cho Metasploit
nmap -oG output.gnmap TARGET    # Grepable — dễ parse
nmap -oA basename TARGET        # Tất cả 3 format cùng lúc

# Parse nhanh từ grepable output
grep "open" output.gnmap
grep "22/open" output.gnmap
grep "Up" output.gnmap | awk '{print $2}'

Debug & Verbose

1
2
3
4
5
6
7
8
9
nmap -v TARGET
nmap -vv TARGET
nmap -d TARGET
nmap -d2 TARGET
nmap --reason TARGET
nmap --open TARGET
nmap --packet-trace TARGET
nmap -6 TARGET
nmap --traceroute TARGET

Quick Reference

FlagTác dụng
-sS / -sT / -sASYN / Connect / ACK scan
-sN / -sF / -sXNULL / FIN / Xmas (stealth)
-sI <zombie>Idle scan — ẩn danh tuyệt đối
-sUUDP scan
-sVVersion detection
-sCDefault NSE scripts
-OOS detection
-AAll-in-one (-sV -O -sC --traceroute)
-p-Tất cả 65535 ports
--openChỉ show open ports
--reasonGiải thích trạng thái port
-T0~T5Timing (0=chậm nhất, 5=nhanh nhất)
--min-rate <n>Tối thiểu n packets/giây
-f / --mtuFragment packets
-D RND:nn decoy IPs
-S <ip>Spoof source IP
--source-port 53Giả source port DNS
--data-length <n>Thêm n bytes rác
--badsumDetect IDS/IPS
--max-retries <n>Giới hạn retry
-oA / -oN / -oX / -oGOutput formats
-v / -vv / -dVerbosity / Debug
This post is licensed under CC BY 4.0 by the author.