Enumeration with Nmap
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
Set victim target (ease for repeating commands)
export TARGET=. # target IPmkdir -p scans # scan output folderAlways scan all 65535 ports before concluding a port is closed.
Workflow
-
Quick sweep: find open ports fast, start working immediately.
sudo nmap -sS --top-ports 1000 -T4 -oA scans/quick $TARGET # top 1000 TCP ports -
Full TCP: confirm you missed nothing (all 65535 ports).
sudo nmap -p- --min-rate 5000 -T4 -oA scans/allports $TARGET # all 65535 TCP ports -
Targeted deep scan:
-sC -sVonly on the ports found open.# open ports from the step 2 scan as a comma listports=$(grep open scans/allports.gnmap | grep -oP '\d+/open' | cut -d/ -f1 | paste -sd,)sudo nmap -p $ports -sC -sV -oA scans/deep $TARGET # scripts and versions on those ports -
UDP: top ports, runs in the background while you work TCP.
sudo nmap -sU --top-ports 100 -T4 -oA scans/udp $TARGET # top 100 UDP ports
Host discovery
Ping sweep
sudo nmap -sn -oA scans/hosts 192.168.1.0/24 # live hosts, no port scanIf a host “looks down” but you know it’s there, add
-Pn. Nmap skips host discovery entirely and treats the target as up, so it port-scans even when a firewall drops the discovery probes.
Skip host discovery, scan every target as up
sudo nmap -Pn -oA scans/pn $TARGET # skip discovery, treat as upOn host lists Ping sweep
sudo nmap -sn -oA scans/hostslst -iL hosts.lst # live hosts from hosts.lstTCP SYN ping to specific ports
sudo nmap -oA scans/2280443 -PS22,80,443 $TARGET # SYN ping on 22, 80, and 443Scan types
| Flag | Scan | Notes |
|---|---|---|
-sS |
TCP SYN (stealth) | Default when root. Fast, half-open. |
-sT |
TCP connect | Non-root fallback. Full handshake, noisier. |
-sU |
UDP | Slow. Catches SNMP/DNS/TFTP/SMB. |
-sV |
Version detection | Probes banners to ID service versions. |
-sC |
Default scripts | --script=default. Safe recon NSE. |
-A |
Aggressive | -sC -sV -O --traceroute combined. |
-O |
OS detection | Needs root. Guesses from TCP/IP stack. |
Port states
Nmap reports one of six states per port.
| State | When you see it | Likely cause | What you deduce |
|---|---|---|---|
| open | Probe got a positive reply (SYN scan SYN/ACK, UDP a service response) |
An application is actively listening and accepting connections | Service is live. enumerate it. Your main attack surface. |
| closed | Probe reached the port and got a RST (TCP) or ICMP port-unreachable (UDP) |
Port is reachable but nothing is listening on it | Host is up and not firewalling this port. No service now, but confirms reachability. Could open later. |
| filtered | No reply at all, or an ICMP admin-prohibited/unreachable error | A firewall / IPS / router is dropping the probe before it reaches the port | Something is blocking you. Can’t tell if a service exists. Try -Pn, different source port, or another scan type. |
| open|filtered | No response, so Nmap can’t decide | Either an open service that simply doesn’t reply, or a firewall silently dropped the probe | Treat as maybe open, worth probing with -sV / manual connection. Very common in UDP and stealth scans (-sF/-sN/-sX). |
| closed|filtered | Only with Idle scan (-sI) |
Nmap can’t tell whether closed or filtered | Rare on HTB-like boxes. Ignore unless doing idle scans. |
| unfiltered | Only with ACK scan (-sA), port got a RST |
Port is reachable (no stateful firewall blocking) but open/closed is unknown | Firewall-mapping info only. Follow up with a SYN/connect scan to learn open vs closed. |
Key intuition, why “no reply” is ambiguous:
- TCP SYN scan:
SYN/ACK→ open,RST→ closed, silence → filtered. - UDP: a service reply → open, ICMP unreachable → closed, silence → open|filtered (most UDP services don’t answer empty probes).
filteredandopen|filteredwaste real time. If a known-useful port shows filtered, add-Pn, try-sT, or--source-port 53before assuming it’s dead.--reasonto see why each port got its state.
Timing & performance
| Flag | Effect |
|---|---|
-T4 |
Aggressive timing. Good default for labs. |
--min-rate 5000 |
Push packets/sec. Big speedup on -p- scans. |
--max-retries 1 |
Don’t waste time retrying filtered ports. |
--open |
Only show open ports in output. |
-v |
Verbose. Reports open ports as they’re found. |
-T5is faster but drops accuracy on flaky targets. Stick to-T4.
Version detection
-sV IDs the service and version behind a port. When it returns tcpwrapped or an
unsure guess, push the intensity: 0 is light, 9 tries every probe.
sudo nmap -p 22,80,445 -sV --version-intensity 9 -oA scans/version $TARGET # try every version probeWhen even that fails, Nmap prints a service fingerprint. --version-all is the shortcut
for --version-intensity 9.
A wrong or missing version is a dead end for exploit search. Confirm the version by hand (
nc,curl -I, the service banner) before you trust it.
NSE scripts
Run the vuln category:
sudo nmap --script vuln -oA scans/vuln $TARGET # vuln category scriptsRun safe and discovery categories:
sudo nmap --script safe,discovery -oA scans/safe-discovery $TARGET # safe and discovery scriptsSMB enumeration:
sudo nmap -p445 --script smb-enum-shares,smb-os-discovery -oA scans/smb $TARGET # shares and OS over SMBHTTP enumeration:
sudo nmap -p80 --script http-enum,http-title -oA scans/http $TARGET # common web paths and the page titleFTP anonymous login test:
sudo nmap -p21 --script ftp-anon -oA scans/ftp-anon $TARGET # test anonymous FTP loginFind scripts by keyword:
sudo ls /usr/share/nmap/scripts | grep smb # scripts with smb in the nameRead a script’s help:
sudo nmap --script-help http-enum # what the script does and its argumentsPass arguments to a script with --script-args. Scripts that take creds, a wordlist, or
a target path read them here:
# list SMB shares as the guest usersudo nmap -p445 --script smb-enum-shares --script-args smbusername=guest,smbpassword= -oA scans/smb-guest $TARGET# look for web paths under /app/sudo nmap -p80 --script http-enum --script-args http-enum.basepath=/app/ -oA scans/http-app $TARGET
--script vulnis handy but noisy and not exhaustive. Never a substitute for manual service enumeration.
Virtual hosts
A web port scanned by IP often serves a bare default page. The real site answers only to a
hostname sent in the Host: header. http-title and the page redirect usually leak that
name:
sudo nmap -p80,443 --script http-title -oA scans/vhost $TARGET # page title and redirect targetMap the name to the IP in /etc/hosts (Editing Files), then re-enumerate against the name:
export NAME=box.htb # hostname from the scanecho "$TARGET $NAME" | sudo tee -a /etc/hosts # map the name to the IPNmap scans IPs, not vhosts. Once you have a hostname, fuzz for more subdomains with
ffuf/gobuster vhost
Output
| Flag | Format |
|---|---|
-oN file.nmap |
Normal (human-readable). |
-oG file.gnmap |
Greppable (extract ports easily). |
-oX file.xml |
XML (feed into other tools). |
-oA scans/base |
All three at once. Always use this. |
Save every scan under
scans/. You need this evidence for the report, and re-scanning wastes time.
UDP notes
UDP is slow because closed ports rarely reply. Don’t scan all 65535 UDP. Top 100-200 is enough. High-value UDP finds (Port References has the full map):
| Port | Service | Follow-up |
|---|---|---|
| 53 | DNS | zone transfer, subdomain enum |
| 69 | TFTP | anon file read/write |
| 161 | SNMP | snmpwalk community strings |
| 500 | IKE/VPN | ike-scan |
sudo nmap -sU -sV --top-ports 200 --open -T4 -oA scans/udp-top200 $TARGET # versions on the top 200 UDP portsFirewall / filtering basics
Target drops ICMP, treat as up
sudo nmap -Pn -oA scans/fw-pn $TARGET # skip discovery, treat as upConnect scan when SYN is filtered
sudo nmap -sT -oA scans/fw-connect $TARGET # full TCP connect scanSpoof source port (some filters trust DNS)
sudo nmap --source-port 53 -oA scans/fw-sport53 $TARGET # send probes from port 53Fragment packets (basic IDS evasion)
sudo nmap -f -oA scans/fw-frag $TARGET # split probes into small fragmentsPad packets
sudo nmap --data-length 25 -oA scans/fw-pad $TARGET # add 25 bytes to each probeOn HTB-like boxes you rarely fight real firewalls. Start simple, add
-Pnif discovery fails, and don’t burn time on evasion unless a port is clearly filtered.