pentesting, updated
nmap
Host discovery, port scanning, service and version detection, and scripted checks with the Nmap Scripting Engine.
What it’s for
The default scanner for host discovery, open ports, service and version detection, OS fingerprinting and scripted checks through the Nmap Scripting Engine (NSE).
Options
Target specification
| Flag | Effect |
|---|---|
10.0.0.5 / example.com | Single host |
10.0.0.0/24 | CIDR range |
10.0.0.1-50 | Octet range |
-iL hosts.txt | Read targets from a file |
-iR 100 | Pick 100 random internet hosts |
--exclude 10.0.0.1 | Skip these hosts |
--excludefile ex.txt | Skip hosts listed in a file |
Host discovery
| Flag | Effect |
|---|---|
-sn | Ping sweep only, no port scan |
-Pn | Skip discovery, treat every host as up |
-PS<ports> | TCP SYN ping to given ports |
-PA<ports> | TCP ACK ping |
-PU<ports> | UDP ping |
-PE / -PP / -PM | ICMP echo / timestamp / netmask ping |
-n / -R | Never / always do DNS resolution |
--dns-servers s1,s2 | Use specific resolvers |
Scan types
| Flag | Effect |
|---|---|
-sS | TCP SYN (stealth) scan — default as root |
-sT | TCP connect scan — default without root |
-sU | UDP scan |
-sA | ACK scan (map firewall rules) |
-sN / -sF / -sX | Null / FIN / Xmas scans (evade stateless filters) |
-sY | SCTP INIT scan |
-sO | IP protocol scan |
-b host | FTP bounce scan |
Ports
| Flag | Effect |
|---|---|
-p 22,80,443 | Specific ports |
-p- | All 65535 ports |
-p 1-1000 | Port range |
-p U:53,T:80 | UDP and TCP ports together |
-F | Fast mode (top 100 ports) |
--top-ports N | Scan the N most common ports |
-r | Scan ports in order, not randomised |
Service, version and OS detection
| Flag | Effect |
|---|---|
-sV | Service/version detection |
--version-intensity 0-9 | Probe effort (9 = all probes) |
--version-all | Shorthand for intensity 9 |
-O | OS fingerprinting |
--osscan-guess | Guess OS aggressively |
-A | Aggressive: -sV -O -sC --traceroute |
NSE scripts
| Flag | Effect |
|---|---|
-sC | Run the default script category |
--script <name/cat> | Run specific scripts or a category |
--script-args k=v | Pass arguments to scripts |
--script-help <name> | Describe a script |
--script-updatedb | Rebuild the script database |
Timing and performance
| Flag | Effect |
|---|---|
-T0–-T5 | Timing template (0 paranoid … 5 insane; -T4 is the usual choice) |
--min-rate / --max-rate N | Packets per second floor / ceiling |
--host-timeout 30m | Give up on slow hosts |
--max-retries N | Cap probe retransmissions |
Firewall and IDS evasion
| Flag | Effect |
|---|---|
-f / --mtu N | Fragment packets |
-D d1,d2,ME | Decoy source addresses |
-S <ip> | Spoof source address |
-g <port> | Fixed source port (e.g. 53, 88) |
--data-length N | Append random payload bytes |
--spoof-mac <mac> | Spoof MAC address |
Output
| Flag | Effect |
|---|---|
-oN / -oG / -oX | Normal / grepable / XML output |
-oA <base> | All three formats at once |
-v / -vv | Verbosity |
--reason | Why a port is in its state |
--open | Show only open ports |
--append-output | Append rather than overwrite |
Examples
Discovery and sweeps
nmap -sn 10.0.0.0/24 # ping sweep, list live hosts only
nmap -sn -PS22,80,443 10.0.0.0/24 # TCP-SYN discovery where ICMP is blocked
nmap -p- --min-rate 2000 -oA full 10.0.0.5 # all TCP ports fast, saved in every format
nmap -F 10.0.0.0/24 # quick top-100-port sweep across a subnet
Service and version detection
nmap -sV -sC -p 80,443 example.com # versions + default NSE on the web ports
nmap -sV -O --osscan-guess 10.0.0.5 # service versions + OS guess
nmap -A -T4 10.0.0.5 # aggressive: version, OS, scripts, traceroute
nmap -sU --top-ports 50 10.0.0.5 # 50 most common UDP ports
Targeted re-scan after a fast sweep
# pull the open ports out of a saved grepable scan, then deep-scan just those
ports=$(grep -oP '\d+/open' full.gnmap | cut -d/ -f1 | paste -sd,)
nmap -sV -sC -p "$ports" 10.0.0.5 # only the ports that were actually open
NSE by category and target
nmap --script http-title,http-headers -p 80,443 example.com # named scripts
nmap --script "vuln" -p 443 example.com # the whole vuln category
nmap --script smb-enum-shares,smb-os-discovery -p 445 10.0.0.5 # SMB enumeration
nmap --script ssl-enum-ciphers -p 443 example.com # TLS cipher review
nmap --script dns-brute example.com # subdomain brute via NSE
Evasion and quiet scans
nmap -Pn -p 443 example.com # skip discovery when ICMP is dropped
nmap -sS -T2 -f --data-length 25 10.0.0.5 # slow, fragmented, padded
nmap -D 10.0.0.9,10.0.0.12,ME -p 80 10.0.0.5 # hide among decoys
nmap -g 53 -p 1-1000 10.0.0.5 # fixed source port 53 to slip past filters
Working with output
nmap -p- -oG - 10.0.0.5 | grep open # grepable straight to a pipe
nmap -sV -oX scan.xml 10.0.0.5 # XML for import into other tools
xsltproc scan.xml -o scan.html # turn the XML into a readable report