nmap & masscan port scanning
When it applies
You have in-scope hosts or IP ranges (confirmed in scope.txt — see tradecraft-scope-roe) and
need the network attack surface: open ports, service versions, OS guesses. This is the
active-scanning step that follows passive enumeration (recon-subdomain-enum, recon-arsenal) and
feeds service-specific testing (network-service-attacks, web-arsenal for anything HTTP).
Why it works
nmap crafts raw packets to classify ports (open/closed/filtered) and then speaks each discovered
service's protocol just enough to fingerprint its version; its NSE script engine adds per-service
checks on top. masscan trades per-host depth for raw speed (its own TCP stack, millions of pps), so
the efficient pattern is: masscan for breadth across many hosts/ports, nmap for depth on the hits.
Method
- Host discovery on a range (skip port scan):
nmap -sn 192.168.1.0/24.
- Pick the scan type:
nmap -sS target # SYN half-open scan — default when root; fast, less logging
nmap -sT target # full TCP connect — use when unprivileged or raw sockets fail
nmap -sU --top-ports 100 target # UDP is slow; always bound it to top ports
- Identify what is listening:
nmap -sV --version-intensity 5 -sC target # service versions + default scripts
nmap -O target # OS fingerprint (needs root)
nmap -A target # OS + version + scripts + traceroute (loud)
- Size the port list to the phase:
-F (fast, top 100) for a first look; -p 22,80,443 for a
targeted check; -p- for full 65535 when the rules of engagement allow the noise.
- NSE scripts after fingerprinting — never
--script vuln as a first move:nmap --script vuln target # known-vuln checks (loud)
nmap --script smb-enum-shares,smb-enum-users target # SMB surface
nmap --script http-enum,http-vuln* -p 80,443 target # web surface
- Always save output for the engagement record:
-oN normal, -oX XML (importable, feeds
other tools — e.g. ncrack -iX scan.xml), -oG greppable.
- Wide/fast with masscan, then deep with nmap:
masscan -p1-65535 target --rate=1000 # rate is packets/sec — tune to the link
masscan -p80,443,8080 10.0.0.0/24 --rate=500 --banners
masscan -p1-65535 10.0.0.0/8 --rate=10000 -e eth0 --excludefile exclude.txt
--excludefile is how you hard-exclude out-of-scope addresses from a wide sweep; masscan output
flags (-oJ/-oX/-oG) mirror nmap's.
Gotchas
- Windows:
dnet: Failed to open device eth0 — raw-socket scans fail on some Windows installs;
fall back to nmap -sT -sV --top-ports 50 -Pn -T3 target (connect scan, no host-discovery
dependency). If it still fails, record it as an environment limitation and continue with
HTTP-layer recon — do not let nmap block the engagement.
- Targets behind Cloudflare/CDN — a full raw port scan of a CDN edge tells you almost nothing
and burns rate budget; pivot to the application layer (HTTPS/API/JS) instead.
- Scanner output is not a finding — a
vuln script hit or an open port is a lead; verify
exploitability before it goes in the report (reporting-triage-validation).
- Rate = detection + DoS risk — high
--rate / -T5 trips IDS and can flatten weak services;
match tempo to the RoE. masscan against ranges you don't own is exactly what scope.txt forbids.
-Pn when hosts "look down" — many hosts drop ICMP; -Pn skips ping discovery, at the cost
of scanning dead hosts.
- SYN scan needs root —
-sS as an unprivileged user silently degrades or errors; use -sT.
Verify success
You have a saved scan file (-oX/-oN) whose results you can restate as: live hosts, open ports,
service + version per port, and a prioritized list of which services get deep testing next — every
entry inside scope.txt.
References
nmap.org reference guide; NSE script library; masscan GitHub (robertdavidgraham). Pipeline context:
automation-recon-pipeline; next step per service: network-service-attacks.
Portions adapted from reverse-skill by zhaoxuya520, MIT License.
1---2name: tools-nmap3description: >4 Operate nmap and masscan for port/service scanning of in-scope hosts — scan-type selection5 (SYN/connect/UDP), version and OS detection, NSE vuln scripts, output formats, and the6 masscan-wide-then-nmap-deep pattern. Load when recon surfaces hosts/IPs and you need open ports,7 service versions, or OS fingerprints. Signals: nmap, masscan, -sV -sC -O, --script vuln,8 -p1-65535, --rate, "dnet: Failed to open device", top-ports, -oX.9domain: tools10type: technique11stability: learning12modes: [pentest, bugbounty, defense]13severity: info14mitre: [T1595.001, T1046]15tools: [nmap, masscan]16schema_version: 117metadata:18 source: https://skillmd.com/skills/noorqureshi/tools-nmap19---2021# nmap & masscan port scanning2223## When it applies24You have in-scope hosts or IP ranges (confirmed in `scope.txt` — see `tradecraft-scope-roe`) and25need the network attack surface: open ports, service versions, OS guesses. This is the26active-scanning step that follows passive enumeration (`recon-subdomain-enum`, `recon-arsenal`) and27feeds service-specific testing (`network-service-attacks`, `web-arsenal` for anything HTTP).2829## Why it works30nmap crafts raw packets to classify ports (open/closed/filtered) and then speaks each discovered31service's protocol just enough to fingerprint its version; its NSE script engine adds per-service32checks on top. masscan trades per-host depth for raw speed (its own TCP stack, millions of pps), so33the efficient pattern is: masscan for breadth across many hosts/ports, nmap for depth on the hits.3435## Method361. **Host discovery on a range** (skip port scan): `nmap -sn 192.168.1.0/24`.372. **Pick the scan type:**38 ```bash39 nmap -sS target # SYN half-open scan — default when root; fast, less logging40 nmap -sT target # full TCP connect — use when unprivileged or raw sockets fail41 nmap -sU --top-ports 100 target # UDP is slow; always bound it to top ports42 ```433. **Identify what is listening:**44 ```bash45 nmap -sV --version-intensity 5 -sC target # service versions + default scripts46 nmap -O target # OS fingerprint (needs root)47 nmap -A target # OS + version + scripts + traceroute (loud)48 ```494. **Size the port list to the phase:** `-F` (fast, top 100) for a first look; `-p 22,80,443` for a50 targeted check; `-p-` for full 65535 when the rules of engagement allow the noise.515. **NSE scripts after fingerprinting** — never `--script vuln` as a first move:52 ```bash53 nmap --script vuln target # known-vuln checks (loud)54 nmap --script smb-enum-shares,smb-enum-users target # SMB surface55 nmap --script http-enum,http-vuln* -p 80,443 target # web surface56 ```576. **Always save output** for the engagement record: `-oN` normal, `-oX` XML (importable, feeds58 other tools — e.g. `ncrack -iX scan.xml`), `-oG` greppable.597. **Wide/fast with masscan, then deep with nmap:**60 ```bash61 masscan -p1-65535 target --rate=1000 # rate is packets/sec — tune to the link62 masscan -p80,443,8080 10.0.0.0/24 --rate=500 --banners63 masscan -p1-65535 10.0.0.0/8 --rate=10000 -e eth0 --excludefile exclude.txt64 ```65 `--excludefile` is how you hard-exclude out-of-scope addresses from a wide sweep; masscan output66 flags (`-oJ/-oX/-oG`) mirror nmap's.6768## Gotchas69- **Windows: `dnet: Failed to open device eth0`** — raw-socket scans fail on some Windows installs;70 fall back to `nmap -sT -sV --top-ports 50 -Pn -T3 target` (connect scan, no host-discovery71 dependency). If it still fails, record it as an environment limitation and continue with72 HTTP-layer recon — do not let nmap block the engagement.73- **Targets behind Cloudflare/CDN** — a full raw port scan of a CDN edge tells you almost nothing74 and burns rate budget; pivot to the application layer (HTTPS/API/JS) instead.75- **Scanner output is not a finding** — a `vuln` script hit or an open port is a lead; verify76 exploitability before it goes in the report (`reporting-triage-validation`).77- **Rate = detection + DoS risk** — high `--rate` / `-T5` trips IDS and can flatten weak services;78 match tempo to the RoE. masscan against ranges you don't own is exactly what `scope.txt` forbids.79- **`-Pn` when hosts "look down"** — many hosts drop ICMP; `-Pn` skips ping discovery, at the cost80 of scanning dead hosts.81- **SYN scan needs root** — `-sS` as an unprivileged user silently degrades or errors; use `-sT`.8283## Verify success84You have a saved scan file (`-oX`/`-oN`) whose results you can restate as: live hosts, open ports,85service + version per port, and a prioritized list of which services get deep testing next — every86entry inside `scope.txt`.8788## References89nmap.org reference guide; NSE script library; masscan GitHub (robertdavidgraham). Pipeline context:90`automation-recon-pipeline`; next step per service: `network-service-attacks`.9192---93_Portions adapted from [reverse-skill](https://github.com/zhaoxuya520/reverse-skill) by zhaoxuya520, MIT License._