Nmap
Table of Contents
Description
Nmap (Network Mapper) is an open-source tool for network discovery and security auditing. It sends crafted packets to target hosts and analyses responses to determine host availability, open ports, running services, service versions, and operating system information. It is the de facto standard for network reconnaissance in both legitimate penetration testing and adversarial contexts.
Nmap operates at multiple levels of aggressiveness and stealth, making it suitable for both passive-style enumeration and active scanning phases of an engagement.
Related: Network Discovery Enumeration
Scan Types
| Flag | Scan Type | Notes |
|---|---|---|
| -sS | SYN (stealth) scan | Default with root. Sends SYN, does not complete handshake. Less logged. |
| -sT | TCP connect scan | Default without root. Completes full handshake. More likely to be logged. |
| -sU | UDP scan | Slower. Used for DNS (53), SNMP (161), DHCP (67). |
| -sN | TCP Null scan | No flags set. May evade some firewalls. |
| -sF | FIN scan | FIN flag only. Evasion technique. |
| -sX | Xmas scan | FIN, PSH, URG flags set. Evasion technique. |
| -sA | ACK scan | Maps firewall rules, not open ports. |
| -sV | Version detection | Probes open ports to identify service/version. |
| -sC | Default scripts | Runs default NSE scripts. Equivalent to –script=default. |
| -O | OS detection | Requires root. Guesses OS from TCP/IP fingerprint. |
Flags
Targeting
| Flag | Description |
|---|---|
| -iL <file> | Read targets from file |
| –exclude <host> | Exclude hosts |
Port Specification
| Flag | Description |
|---|---|
| -p <port> | Specific port(s). e.g. -p 80,443 or -p 1-1000 |
| -p- | All 65535 ports |
| –top-ports <n> | n most common ports |
| -F | Fast scan (top 100 ports) |
Timing
Higher is faster but noisier.
| Flag | Template | Use Case |
|---|---|---|
| -T0 | Paranoid | IDS evasion, very slow |
| -T1 | Sneaky | IDS evasion |
| -T2 | Polite | Less bandwidth |
| -T3 | Normal | Default |
| -T4 | Aggressive | Fast, reliable networks |
| -T5 | Insane | Very fast, may miss results |
Output
| Flag | Description |
|---|---|
| -oN <file> | Normal output |
| -oX <file> | XML output |
| -oG <file> | Grepable output |
| -oA <basename> | All formats simultaneously |
| -v / -vv | Verbosity |
Other
| Flag | Description |
|---|---|
| -A | Aggressive: enables -O, -sV, -sC, traceroute |
| -Pn | Skip host discovery. Useful when ICMP is blocked. |
| -n | Disable DNS resolution (faster) |
| –open | Show only open ports |
| –reason | Show reason for port state |
| -D <decoy> | Use decoy IPs to obscure source |
| –script <name> | Run specific NSE script |
| –script-args | Pass arguments to NSE scripts |
NSE Scripts
Scripts extend Nmap with additional detection and exploitation
capabilities. Located at /usr/share/nmap/scripts/.
| Category | Description |
|---|---|
| auth | Authentication bypass and credential testing |
| brute | Brute force attacks against services |
| default | Run with -sC; safe and informative |
| discovery | Additional host/service discovery |
| exploit | Active exploitation (use within scope only) |
| safe | Scripts unlikely to crash services |
| vuln | Check for known vulnerabilities |
Search scripts:
nmap --script-help <name> ls /usr/share/nmap/scripts/ | grep <keyword>
Workflow
Replace $IP with the target before running. Always save output — re-running
scans wastes time and generates noise.
. Quick top-port scan
nmap -sV -sC --open -T4 -oA nmap/initial $IP
2. Full port scan
nmap -p- --min-rate 5000 -oA nmap/full $IP
3. Targeted scan on discovered ports
nmap -sV -sC -p <ports> -oA nmap/targeted $IP
4. UP scan on common ports
nmap -sU --top-ports 20 -oA nmap/udp $IP
5. Firewalled host (no ping response)
nmap -Pn -sV -sC -p- -oA nmap/pn $IP
6. Vuln scripts on discovered ports
nmap --script=vuln -p <ports> $IP
Tips
- Use
-Pnwhen targets appear down — common on CTF and exam machines. -sVincreases scan time; combine with--version-intensity 0for a lighter probe.- NSE
vulnscripts can be noisy and may trigger IDS; use deliberately and within scope. - Combine with
-D RND:10for basic decoy-based evasion during authorised testing. - Start with the quick scan, run the full port scan in the background simultaneously.