Lesson 3 of 10 · 19 min · Advanced

Host discovery and Nmap mastery

Scan like a professional: host discovery, TCP/UDP techniques, timing and evasion, the NSE scripting engine, output you can parse, and masscan/RustScan for speed at scale.

In this lesson you will

  • Choose the right discovery and scan technique for the situation
  • Drive Nmap's timing, output and NSE scripts fluently
  • Scan UDP and large ranges without wasting days
  • Parse scan output into a clean, actionable service list

Scanning is where amateurs run nmap -A on a /16 and wait a week, and professionals get a clean service inventory in the right order without knocking anything over. This chapter makes you fluent.

Host discovery

Before port-scanning, find live hosts, unless you already have a target list.

bash
# ICMP + common ports, no port scan (fast sweep)
nmap -sn 10.10.10.0/24 -oA loot/nmap/sweep
# Hosts that block ping: probe common ports instead
nmap -sn -PS22,80,443,445,3389 -PA80 -PU161 10.10.10.0/24
# Huge range, just "what's up"
fping -a -g 10.10.0.0/16 2>/dev/null > live.txt

On an internal engagement, ARP is the most reliable discovery on your local segment (it can't be firewalled on-link):

bash
nmap -sn -PR 10.10.10.0/24          # ARP sweep
# or
arp-scan --localnet

The scan types that matter

Flag Scan Use
-sS SYN (half-open) Default, fast, needs root
-sT Full TCP connect No root, or through proxychains
-sU UDP DNS, SNMP, TFTP, IKE, NTP — slow but vital
-sV Version detection Identify the exact service and version
-O OS detection Fingerprint the OS
-sC Default NSE scripts Safe enumeration scripts
-A Aggressive (-sV -O -sC --traceroute) Loud; use on a known host, not a range

A professional scan workflow

Scan in two passes: fast and wide to find ports, then deep on the ports you found.

bash
# Pass 1: all TCP ports, fast, just find open ones
nmap -p- --min-rate 2000 -T4 -Pn 10.10.10.10 -oA loot/nmap/allports
# Extract the open ports
ports=$(grep -oP '^\d+(?=/open)' loot/nmap/allports.gnmap | paste -sd,)
# Pass 2: deep enumeration on only those ports
nmap -p$ports -sVC -O -Pn 10.10.10.10 -oA loot/nmap/deep
text
 -p-  all 65535 ports (never assume 1-1000)
 --min-rate  packets/sec floor (speed)
 -Pn  skip host discovery (you know it's up)
 -sVC = -sV -sC  version + default scripts

Don't forget UDP

Most testers skip UDP and miss SNMP (community strings → device config), DNS, TFTP, IKE/VPN and NFS. Scan the top UDP ports at least:

bash
nmap -sU --top-ports 100 -T4 10.10.10.10 -oA loot/nmap/udp
# Follow up the juicy ones
nmap -sU -p 161 --script snmp-info 10.10.10.10

Timing and stealth

-T0..-T5 trade speed for noise. -T4 is the usual working pace; -T2 for fragile targets; -T1/-T0 for stealth.

bash
# Fine-grained control beats the -T presets
nmap --min-rate 1000 --max-retries 2 --host-timeout 15m 10.10.10.10
# Evasion options (external, where IDS is in play)
nmap -f --mtu 24 -D RND:5 --source-port 53 --data-length 25 TARGET
Option Effect
-f / --mtu Fragment packets
-D RND:5 Decoy source IPs
--source-port 53 Masquerade as DNS
--scan-delay Slow to dodge rate-based IDS
--data-length Pad packets past signatures

Evasion is for authorised stealth tests. On a normal assessment, don't bother: it just slows you down.

The NSE scripting engine

NSE is Nmap's superpower. Scripts live in categories: safe, default, discovery, vuln, auth, brute, exploit.

bash
# Run a category
nmap --script vuln 10.10.10.10
# Targeted enumeration
nmap -p445 --script "smb-enum-shares,smb-os-discovery,smb-enum-users" 10.10.10.10
nmap -p445 --script smb-vuln-ms17-010 10.10.10.10     # EternalBlue check
# Find scripts for a service
ls /usr/share/nmap/scripts/ | grep -i smb
nmap --script-help "ssl-*"

⚠️ Avoid brute and exploit categories on production unless the RoE allows: they lock accounts and crash services.

Scanning at scale: masscan and RustScan

For large ranges, Nmap alone is too slow. Use a fast scanner to find open ports, then hand them to Nmap for enumeration.

bash
# masscan: find open ports across a /16 in minutes
masscan 10.10.0.0/16 -p1-65535 --rate 10000 -oL mass.txt
# RustScan: fast discovery that pipes straight into nmap
rustscan -a 10.10.10.10 --range 1-65535 -- -sVC -oA loot/nmap/rs

⚠️ A high --rate can saturate links and trip the client's monitoring. Start at a few thousand and coordinate.

Output you can use

Always save output in all formats (-oA = normal, grepable, XML). The XML feeds other tools.

bash
# Grep live services fast
grep '/open/' loot/nmap/deep.gnmap
# Pretty HTML report from XML
xsltproc loot/nmap/deep.xml -o report.html
# Feed nmap XML into Metasploit
# msf> db_import loot/nmap/deep.xml

🧪 Lab

  1. On your lab network, do an ARP sweep, then a two-pass scan (-p- then deep) on one target.
  2. Run a UDP top-100 scan and enumerate any SNMP you find.
  3. Use NSE to enumerate SMB shares and check for MS17-010 on a Windows target.
  4. Run masscan or RustScan across the whole subnet and compare speed with pure Nmap.
  5. Save -oA output and extract a clean list of open ports per host with grep.

Checkpoint

  1. Why scan in two passes instead of nmap -A on everything?
  2. Which discovery method is most reliable on a local segment, and why?
  3. Name three services you'd miss by skipping UDP.
  4. What does -sC do, and which NSE categories should you avoid on production?
  5. How do masscan and Nmap complement each other at scale?