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

FlagEffect
10.0.0.5 / example.comSingle host
10.0.0.0/24CIDR range
10.0.0.1-50Octet range
-iL hosts.txtRead targets from a file
-iR 100Pick 100 random internet hosts
--exclude 10.0.0.1Skip these hosts
--excludefile ex.txtSkip hosts listed in a file

Host discovery

FlagEffect
-snPing sweep only, no port scan
-PnSkip 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 / -PMICMP echo / timestamp / netmask ping
-n / -RNever / always do DNS resolution
--dns-servers s1,s2Use specific resolvers

Scan types

FlagEffect
-sSTCP SYN (stealth) scan — default as root
-sTTCP connect scan — default without root
-sUUDP scan
-sAACK scan (map firewall rules)
-sN / -sF / -sXNull / FIN / Xmas scans (evade stateless filters)
-sYSCTP INIT scan
-sOIP protocol scan
-b hostFTP bounce scan

Ports

FlagEffect
-p 22,80,443Specific ports
-p-All 65535 ports
-p 1-1000Port range
-p U:53,T:80UDP and TCP ports together
-FFast mode (top 100 ports)
--top-ports NScan the N most common ports
-rScan ports in order, not randomised

Service, version and OS detection

FlagEffect
-sVService/version detection
--version-intensity 0-9Probe effort (9 = all probes)
--version-allShorthand for intensity 9
-OOS fingerprinting
--osscan-guessGuess OS aggressively
-AAggressive: -sV -O -sC --traceroute

NSE scripts

FlagEffect
-sCRun the default script category
--script <name/cat>Run specific scripts or a category
--script-args k=vPass arguments to scripts
--script-help <name>Describe a script
--script-updatedbRebuild the script database

Timing and performance

FlagEffect
-T0–-T5Timing template (0 paranoid … 5 insane; -T4 is the usual choice)
--min-rate / --max-rate NPackets per second floor / ceiling
--host-timeout 30mGive up on slow hosts
--max-retries NCap probe retransmissions

Firewall and IDS evasion

FlagEffect
-f / --mtu NFragment packets
-D d1,d2,MEDecoy source addresses
-S <ip>Spoof source address
-g <port>Fixed source port (e.g. 53, 88)
--data-length NAppend random payload bytes
--spoof-mac <mac>Spoof MAC address

Output

FlagEffect
-oN / -oG / -oXNormal / grepable / XML output
-oA <base>All three formats at once
-v / -vvVerbosity
--reasonWhy a port is in its state
--openShow only open ports
--append-outputAppend 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

References

§ home
~/knubertus/home/
1,1 Top