Skip to content
Pwnversity
NET-NMAPintermediate · 15 min · upd. 2026-11

Nmap in depth

T1046T1018T1595.001

Nmap is the reference network scanner: it discovers hosts, ports, services, versions and operating systems, and with its scripting engine (NSE) it goes as far as checking for specific vulnerabilities. The difference between a scan that takes hours, trips every alarm and misses ports, and one that is fast and accurate lies in understanding which packet each option sends and which reply it expects. That is what this page is about; basic usage and installation live in the tool page.

flowchart LR
    H["1. Discovery<br/>is it up?"] --> P["2. Ports<br/>what listens?"]
    P --> V["3. Service and version<br/>which software?"]
    V --> N["4. NSE<br/>what can I get?"]
    N --> O["5. Output -oA<br/>report and next<br/>tools"]

Scanning is the first thing that touches the target and defines the attack surface. On an authorized engagement three constraints override any option:

  • Scope: only the IPs and ranges in the contract. Nmap does not care; -iL with the agreed list and --exclude with what must not be touched prevent expensive mistakes.
  • Impact: -T5, a very high --min-rate or intrusive/dos scripts can knock over industrial equipment, printers and legacy systems. In production, -T3 or -T4 and a bounded --max-rate.
  • Noise: a full scan is visible to any IDS. If the engagement measures detection (red team) that matters; on a pentest with the defenders informed, it does not.

Nmap always runs the same flow: host discovery → port scan → service/version detection → OS detection → NSE scripts. Each option enables or tweaks a phase, and any of them can be skipped (-Pn skips the first, -sn keeps only the first).

With no discovery options, a privileged user sends four probes: ICMP echo, SYN to 443, ACK to 80 and ICMP timestamp (equivalent to -PE -PS443 -PA80 -PP). Unprivileged, only SYN via connect() to 80 and 443. On a local Ethernet network Nmap uses ARP (or Neighbor Discovery on IPv6) even when other probes are requested, because it is faster and more reliable.

Ventana de terminal
nmap -sn 10.0.0.0/24 # discovery only (formerly -sP)
nmap -Pn 10.0.0.5 # skip discovery: everything is treated as up
nmap -sn -PS22,80,443 -PA80 10.0.0.0/24 # specific TCP probes
nmap -sn -PU53 10.0.0.0/24 # UDP: useful where only TCP is filtered
nmap -sn --disable-arp-ping 10.0.0.0/24 # proxy-ARP networks, where everything looks up
nmap -n -sn 10.0.0.0/24 # no reverse DNS: faster and less DNS noise

-Pn is the option that recovers the most ports on the Internet (many hosts block ICMP), but on a /16 it multiplies the time: it port-scans every address even when nobody is there.

State What Nmap saw
open SYN/ACK (TCP) or a UDP reply
closed RST (TCP) or ICMP port unreachable type 3 code 3 (UDP)
filtered nothing after retransmissions, or another ICMP unreachable
unfiltered only in -sA: an RST arrives, but open or closed is unknown
open|filtered UDP or NULL/FIN/Xmas scans with no reply: cannot be told apart

Only -sT works without privileges; the rest need root on Unix or administrator on Windows to send raw packets.

Type Packet When
-sS SYN SYN without completing the handshake default as root: fast and less logged by the application
-sT connect the OS connect(), full handshake without root, or through a SOCKS proxy/pivot
-sU UDP datagram (empty or with a known payload) DNS, SNMP, NTP, TFTP; slow because closed depends on rate-limited ICMP
-sA ACK ACK only map firewall rules: unfiltered versus filtered
-sN/-sF/-sX no flags / FIN / FIN+PSH+URG evade stateless filters; Windows and many Cisco devices reply RST to everything and invalidate it
-sW Window like ACK, reads the window size of the RST few systems
-sM Maimon FIN/ACK old BSD systems
-sI idle nothing from your IP: uses a zombie’s IP ID sourceless scan; needs a zombie with incremental IP ID
-sO one packet per IP protocol number which protocols the host accepts (ICMP, GRE, ESP…)
Ventana de terminal
nmap -p- 10.0.0.5 # all 65535 TCP
nmap -p 22,80,443,8000-8100 10.0.0.5
nmap -p U:53,161,T:22,80 10.0.0.5 # UDP and TCP in one command (with -sU -sS)
nmap --top-ports 1000 10.0.0.5 # by frequency (nmap-services); -F is the top 100
nmap -p- --exclude-ports 9100 10.0.0.5 # leave the printing port alone

The -T0…-T5 templates adjust timeouts, retries and parallelism. -T3 is the default; -T4 assumes a fast, reliable network (max RTT 1250 ms, 6 retries, max delay 10 ms) and is the one recommended on Ethernet and broadband; -T5 drops to 300 ms and 2 retries and the manual itself warns it loses results on networks that are not very fast. -T0 and -T1 wait 5 minutes and 15 seconds between probes and only make sense to evade IDS thresholds on very small scans.

Ventana de terminal
nmap -p- --min-rate 1000 --max-retries 3 10.0.0.5 # fast port sweep
nmap -p- --min-rate 1000 --max-retries 3 --host-timeout 20m 10.0.0.0/24
nmap --scan-delay 1s -sU --top-ports 50 10.0.0.5 # targets that rate-limit ICMP
nmap --min-hostgroup 256 -p 445 10.0.0.0/16 # large groups: more efficient, results when each group finishes

--min-rate sets global packets per second; above what the network can handle, Nmap retransmits and the scan can end up taking longer. --max-retries defaults to 10; on reliable networks 2 or 3 is enough. Explicit options take precedence over the template.

Ventana de terminal
nmap -sV 10.0.0.5 # nmap-service-probes + banner
nmap -sV --version-intensity 9 10.0.0.5 # every probe (slow); 0 = only the most likely
nmap -sV --version-light 10.0.0.5 # intensity 2
nmap -O --osscan-guess 10.0.0.5 # TCP/IP fingerprint; needs one open and one closed port
nmap -A 10.0.0.5 # -sV -O -sC --traceroute: noisy, for the lab

-sV is what turns 8088/tcp open radan-http (the nmap-services name by port number) into http SimpleHTTPServer 0.6 (Python 3.13); without it, the service name is a guess by port.

Categories matter because they define the risk: safe is not designed to crash anything; intrusive has a “high risk of crashing the target or being seen as malicious”; dos may cause denial of service as a side effect; exploit exploits; brute guesses credentials; external sends data to third-party services. default (-sC) was chosen for speed, usefulness, low intrusiveness and privacy. version runs only with -sV and cannot be selected by hand.

Ventana de terminal
nmap -sC -sV -p 22,80,445 10.0.0.5
nmap --script "default and safe" 10.0.0.5 # boolean expressions
nmap --script "smb-* and not brute" -p 445 10.0.0.5
nmap --script vuln -p 80,443 10.0.0.5 # only reports when it finds something
nmap --script http-title,http-headers -p 8080 10.0.0.5
nmap --script ssh-auth-methods --script-args ssh.user=admin -p 22 10.0.0.5
nmap --script-help "smb-enum-*" # name, categories and description
nmap --script-trace --script banner -p 21 10.0.0.5 # see every byte the script sends
nmap --script-updatedb # after adding scripts to scripts/
Ventana de terminal
nmap -oA target-tcp -p- 10.0.0.5 # .nmap (readable) + .gnmap (grep) + .xml (tools)
nmap -v --open --reason -p- 10.0.0.5 # open only, with the packet that justifies each state
grep -oP '\d+/open' target-tcp.gnmap | cut -d/ -f1 | paste -sd, # port list for the second pass
xsltproc target-tcp.xml -o target-tcp.html # HTML report with Nmap's stylesheet

The XML is the input for Metasploit (db_import), for Markdown/CSV converters and for any script of your own; the .gnmap is for grep and awk on the spot.

Ventana de terminal
# 1. What is open? Fast, no versions
sudo nmap -sS -p- --min-rate 1000 --max-retries 3 -n -Pn -oA tcp-all 10.0.0.5
# 2. What is it? Only on what is open
PORTS=$(grep -oP '\d+/open' tcp-all.gnmap | cut -d/ -f1 | paste -sd,)
sudo nmap -sS -sV -sC -O -p "$PORTS" -oA tcp-detail 10.0.0.5
# 3. UDP, bounded
sudo nmap -sU --top-ports 100 --open -oA udp-top 10.0.0.5

Version scanning across 65,535 ports is what turns a minutes-long scan into an hours-long one; splitting it into two passes is the most profitable optimization.

From a compromised host, raw packets do not travel: use -sT with proxychains or a TUN interface (see pivoting). With tunnels that turn SYN into connect() on the agent, -Pn and --unprivileged avoid false positives.

Ventana de terminal
proxychains -q nmap -sT -Pn -n --top-ports 100 10.10.10.5

Evasion (when the engagement measures detection)

Section titled “Evasion (when the engagement measures detection)”

The manual’s evasion options, with their real limits:

  • -f / --mtu 16: splits the TCP header across several IP fragments. Raw scans only; firewalls that reassemble fragments defeat it, and some old software crashes on tiny fragments.
  • -D RND:5,ME: decoys; the IDS sees several sources. Decoys should be up (otherwise the target may end up SYN-flooded) and too many slow the scan and degrade accuracy.
  • -g 53 / --source-port 53: source from a port some stateless filters trust. No effect on -sT, DNS, -sV, NSE or -O.
  • --data-length 25: appends random bytes so probes are not identical to Nmap signatures. Does not affect -O packets.
  • --ttl, --spoof-mac 0: change headers; --spoof-mac only on raw packets.
  • -S IP -e eth0 -Pn: spoof the source. Replies never come back: it confuses, it does not produce results.
  • --badsum: invalid checksum; if something replies, there is a firewall or IDS that does not verify.
  • --proxies socks4://…: NSE and -sV only; no ping, no ports, no OS; no authentication or TLS.
  • -T1/-T2 and --scan-delay: what actually evades rate thresholds; at the cost of hours.

What does not evade anything: -sS versus -sT (the IDS sees the SYN either way), -sV (its probes have signatures, including the Nmap Scripting Engine User-Agent), and -A. More in firewall and IDS evasion.

  1. Confirm scope in a file (-iL) and exclusions (--exclude, --exclude-ports).
  2. Discovery (-sn) or -Pn if the target filters ICMP and the range is small.
  3. Pass 1: full TCP ports, fast, no versions.
  4. Pass 2: -sV -sC on the open ones; bounded UDP.
  5. NSE driven by service; vuln only if the engagement covers it.
  6. Save everything with -oA and a date; the XML feeds the other tools.
  7. Move on to service enumeration.
  • nmap (7.993 as of Oct 2026): scanning, versions, NSE.
  • masscan, rustscan: very fast port discovery; then nmap -sV on the result. RustScan is officially distributed only via cargo install rustscan.
  • ncat/nc: banners by hand; xsltproc: HTML report from the XML.
  • Metasploit db_nmap / db_import: results into the framework’s database.

The scan is not a finding in itself: it is the map. Findings come from what follows: enumeration of each service, common ports and services, and from a shell, the same scan repeated from the inside through a pivot to discover the internal network.

  • Pattern: one source touching many ports of one destination (port scan) or one port of many destinations (sweep) in a short time; SYN with no later ACK; connect() calls closed with no data.
  • Signatures: Suricata’s ET Open ruleset has the ET SCAN category (for instance ET SCAN Possible Nmap User-Agent Observed when -sV or NSE touch HTTP). “Normal” SYN scans generate many low-value alerts, and slow ones (-T1/-T2) pass under the default thresholds.
  • Thresholds: rules with threshold per source (N ports in M seconds) in Suricata/Snort, and SIEM correlation of firewall deny events per source.
  • On the host: application logs (-sT leaves full connections), Windows EID 5156 (filtering platform) and auditd for rejected inbound connections.

NetFlow/Zeek (conn.log with many S0/REJ connections), firewall logs with denials, IDS at the perimeter and on internal segments, honeypots with ports nobody legitimate should touch.

  • Expose only what is needed: every closed service is a port nobody has to watch.
  • Default-deny inbound and segmentation: a scan from a compromised host should not see the whole network.
  • Rate limiting of new connections per source on the firewall.
  • Banners without version where the software allows it; it does not stop -sV, but it reduces what is handed out for free.

An internal scan from a host that is not a security asset is an indicator of compromise: isolate the source and review what came before (phishing, credentials). A massive external scan is Internet background noise and is handled by thresholds, not by alert.

  • Log4Shell (CVE-2021-44228, Dec 2021): within days, community NSE scripts appeared (Diverto nse-log4shell, giterlizzi nmap-log4shell) that injected the JNDI payload over HTTP, SSH and IMAP with a callback server; Nmap was one of the mass-triage routes, and the same pattern repeats with every critical network-exposed CVE.
  • Nmap 7.993 (Oct 23, 2026): fixes a regression that prevented most version-category scripts from running. A reminder that the Nmap version influences results: note which one you used in the report.
  • Scope in a file and exclusions applied; Nmap version noted.
  • Discovery done or -Pn justified.
  • Pass 1 full TCP ports (-p-) with reasonable --min-rate and --max-retries.
  • Pass 2 -sV -sC -O only on open ports.
  • Bounded UDP (--top-ports) with --open.
  • NSE by service; intrusive categories only with authorization.
  • Everything saved with -oA; port list extracted from the .gnmap.