The Nmap cheat sheet covering host discovery, port scanning, service/version detection, OS fingerprinting, NSE scripts, timing and performance tuning, output formats, firewall evasion techniques, and practical scanning workflows.
# CTF / quick recon - all ports, versions, default scripts
nmap -sV -sC -p- -T4 -oA quick <target>
# Full pentest recon - OS, version, scripts, traceroute
nmap -A -T4 -p- -oA full <target>
# Stealth SYN scan, top 1000 ports, no ping
nmap -sS -Pn -T2 --randomize-hosts -oA stealth <target>
# Subnet sweep - find live hosts fast
nmap -sn --min-parallelism 100 192.168.1.0/24 -oG hosts.gnmap
# UDP top 20 ports (DNS, SNMP, DHCP, NTP ...)
nmap -sU --top-ports 20 -T4 -oA udp <target>
Select your goal and context - the advisor builds the right nmap command with an explanation of why each flag is used.
| Goal | Flags | When to use |
|---|---|---|
| Find live hosts (LAN) | -sn -PR |
ARP ping on local network, fastest host discovery |
| Find live hosts (remote) | -sn -PS80 -PA443 |
ICMP often blocked, TCP SYN/ACK on common ports bypasses firewalls |
| Quick port scan (default) | -sS |
SYN stealth scan, never completes TCP handshake, requires root |
| Port scan without root | -sT |
Full TCP connect, noisier but works without privileges |
| All 65535 ports | -sS -p- |
Don't miss non-standard ports, slower but thorough |
| UDP services (DNS, SNMP, NTP) | -sU --top-ports 20 |
UDP is slow, limit to top ports unless you have time |
| Service + version detection | -sV |
Banner grabbing, fingerprinting, essential for exploitation |
| OS detection | -O or -A |
OS fingerprint via TCP/IP stack analysis. -A combines -sV -sC -O --traceroute |
| Vulnerability scan | --script=vuln |
NSE vuln category, checks CVEs, misconfigurations |
| Safe recon scripts | -sC |
Default scripts (safe), equivalent to --script=default |
| Brute-force services | --script=brute |
SSH, FTP, HTTP basic auth, SMB. Noisy, use with caution |
| Bypass stateless firewall | -sN / -sF / -sX |
NULL, FIN, Xmas scans - no SYN flag, bypasses simple packet filters |
| Map firewall rules | -sA |
ACK scan - doesn't find open ports, but reveals which ports are filtered vs unfiltered |
| Stealth (fragment) | -sS -f --mtu 16 |
Fragment packets to evade IDS/IPS reassembly |
| Stealth (decoys) | -sS -D RND:10 |
Mix your scan with 10 random decoy IPs |
| Stealth (source port) | --source-port 53 |
Spoof source port as DNS (53) or HTTP (80), bypasses lazy firewall rules |
nmap 192.168.1.1 # single IP
nmap 192.168.1.1-254 # IP range
nmap 192.168.1.0/24 # CIDR subnet
nmap 10.0.0.1 10.0.0.2 10.0.0.3 # multiple IPs
nmap -iL targets.txt # from file
nmap -iR 100 # 100 random targets
nmap --exclude 192.168.1.5 # exclude host
nmap --excludefile skip.txt # exclude from file
nmap scanme.nmap.org # hostname
nmap -6 ::1 # IPv6 loopback
nmap -6 2001:db8::1 # IPv6 address
nmap -6 fe80::1%eth0 # IPv6 link-local with iface
| Option | Effect |
|---|---|
-p 22 |
Single port |
-p 22,80,443 |
Multiple ports |
-p 1-1023 |
Port range |
-p- |
|
-p U:53,T:80 |
UDP port 53, TCP port 80 |
-F |
Top 100 ports (fast) |
--top-ports 500 |
Top N most common ports |
--port-ratio 0.1 |
Ports more common than ratio |
-r |
Sequential order (no randomize) |
--exclude-ports 8080 |
Skip specific ports |
| Option | Name | Requires Root | Stealth | Notes |
|---|---|---|---|---|
-sS |
Yes | High | Default when root; half-open, fast | |
-sT |
Connect Scan | No | Low | Full 3-way handshake; works unprivileged |
-sA |
ACK Scan | Yes | Medium | Maps firewall rules; open/filtered not shown |
-sW |
Window Scan | Yes | Medium | Like ACK but checks TCP window field |
-sM |
Maimon Scan | Yes | Medium | FIN+ACK; bypasses some BSD-based filters |
-sN |
Yes | High | No flags; RFC-compliant FW evasion | |
-sF |
Yes | High | FIN only; evades stateless packet filters | |
-sX |
Yes | High | FIN+PSH+URG; does not work on Windows | |
-sI <zombie> |
Yes | Max | Spoofs via zombie IPID; truly anonymous | |
-sO |
IP Protocol Scan | Yes | - | Determine supported IP protocols |
-b <relay> |
FTP Bounce | No | - | Scan through FTP server (legacy) |
-sY |
SCTP INIT | Yes | High | SCTP equivalent of SYN scan |
-sZ |
SCTP COOKIE | Yes | Medium | More intrusive SCTP scan |
# UDP scan - slow but critical (DNS/SNMP/DHCP)
nmap -sU -p 53,67,68,69,111,123,137,161,500 <target>
# Combine UDP + TCP in one run
nmap -sU -sS -p U:53,161,T:22,80,443 <target>
# IP protocol scan (find which IP protocols are supported)
nmap -sO <target>
# Idle/zombie scan - uses zombie's IPID to stay invisible
nmap -sI 10.0.0.10:80 <target>
# Custom TCP flags
nmap --scanflags SYNFIN <target>
nmap --scanflags URGACKPSHRSTSYNFIN <target>
| Option | Type | When to Use |
|---|---|---|
-sn |
Live host discovery only | |
-Pn |
Skip discovery (treat all as up) | When ICMP is blocked |
-sL |
List scan (DNS only, no packets) | Verify target list without scanning |
-PS[ports] |
TCP SYN ping | Discover via SYN to given ports |
-PA[ports] |
TCP ACK ping | Works through some SYN-blocking firewalls |
-PU[ports] |
UDP ping | Finds hosts with open UDP services |
-PE |
ICMP echo request | Classic ping; often blocked |
-PP |
ICMP timestamp request | Evades echo-blocking firewalls |
-PM |
ICMP netmask request | Alternative when echo/timestamp blocked |
-PO[protos] |
IP protocol ping | Send packets of specified IP protocols |
-PR |
ARP ping | |
-n |
No DNS resolution | Faster; avoids leaving DNS traces |
-R |
Always resolve DNS | Force reverse lookup |
# ARP sweep on local subnet (fastest + most reliable)
nmap -sn -PR 192.168.1.0/24
# Remote subnet - SYN to 80,443 + ICMP
nmap -sn -PS80,443 -PE 10.10.10.0/24
# ACK ping bypasses some SYN-filtering firewalls
nmap -sn -PA80,443 10.10.10.0/24
# UDP ping on common ports
nmap -sn -PU53,161 10.10.10.0/24
# Combine multiple probe types for thorough discovery
nmap -sn -PS22,80,443 -PA80 -PE -PP 10.10.10.0/24
# List targets without sending any packets
nmap -sL 192.168.1.0/24
# Skip discovery entirely (assume all hosts up)
nmap -Pn -p 80,443 10.10.10.0/24
| Option | Purpose |
|---|---|
-sV |
|
--version-intensity <0-9> |
0=fastest/light, 9=try all probes |
--version-light |
Intensity 2 (fast, less accurate) |
--version-all |
Intensity 9 (thorough) |
--version-trace |
Debug version detection |
-O |
|
--osscan-limit |
Only try OS detection on promising targets |
--osscan-guess |
Aggressive guess even without perfect match |
-A |
|
--traceroute |
Trace packet path to target |
# Standard version scan
nmap -sV -p 22,80,443 <target>
# Aggressive version (all probes)
nmap -sV --version-all -p- <target>
# OS detection (needs open + closed port)
nmap -O --osscan-guess <target>
# Full aggressive detection
nmap -A -T4 <target>
| Template | Name | scan-delay | max-rtt-timeout | max-retries | host-timeout | Use When |
|---|---|---|---|---|---|---|
-T0 |
5 min | 300 s | 10 | - | Maximum IDS evasion; very slow | |
-T1 |
15 s | 15 s | 10 | - | IDS evasion; extremely slow | |
-T2 |
400 ms | 10 s | 10 | - | Low bandwidth / impact | |
-T3 |
0 | 10 s | 10 | - | Default; balanced | |
-T4 |
0 | 1.25 s | 6 | - | Fast LAN / reliable networks | |
-T5 |
0 | 300 ms | 2 | 15 min | CTF / lab only; may miss results |
| Option | Purpose |
|---|---|
--min-rate <n> |
Send at least N packets/sec |
--max-rate <n> |
Send at most N packets/sec |
--min-parallelism <n> |
Minimum parallel probes |
--max-parallelism <n> |
Maximum parallel probes |
--min-hostgroup <n> |
Minimum hosts scanned in parallel |
--max-hostgroup <n> |
Maximum hosts scanned in parallel |
--max-retries <n> |
Max probe retransmissions |
--scan-delay <time> |
Delay between probes (e.g. 500ms, 1s) |
--max-scan-delay <time> |
Cap dynamic scan delay growth |
--host-timeout <time> |
Abandon host after this long |
--min-rtt-timeout <time> |
Lower bound on RTT estimate |
--max-rtt-timeout <time> |
Upper bound on RTT estimate |
# Tuned for fast internal network pentest
nmap -sS -p- --min-rate 5000 --max-retries 2 -T4 <target>
# Large subnet with controlled parallelism
nmap -sn --min-hostgroup 64 --min-parallelism 64 192.168.0.0/16
# Slow IDS-safe scan
nmap -sS -T1 --scan-delay 2s --max-retries 1 <target>
# Rate-limited to avoid triggering thresholds
nmap -sS -p- --max-rate 100 -T2 <target>
| Option | Technique | Notes |
|---|---|---|
-f |
Splits TCP header across packets; use -ff for 16-byte frags |
|
--mtu <val> |
Custom fragment size | Must be multiple of 8; mutually exclusive with -f |
-D <d1,d2,ME,...> |
Mix real IP among decoys; RND:10 = 10 random decoys |
|
-S <IP> |
Target sees this IP; responses go to spoofed addr (need -e) |
|
-e <iface> |
Specify interface | Required when spoofing source |
-g / --source-port <n> |
Use 53 or 80 to pass port-trusting FW rules |
|
-sI <zombie[:port]> |
Scan via zombie's IPID; your IP never touches target | |
--data-length <n> |
Append random payload | Makes packets look less like scans |
--badsum |
Responses reveal FW/IDS (real hosts drop these) | |
--spoof-mac <val> |
Spoof MAC address | Vendor name, hex prefix, or 0 for random |
--ttl <val> |
Set custom TTL | Evade TTL-based fingerprinting / probes |
--ip-options <opts> |
Custom IP options | R=record route, L=loose source route |
--proxies <urls> |
Relay through proxy | HTTP/SOCKS4; affects TCP connect scans only |
--randomize-hosts |
Randomize target order | Distribute scan traffic across time |
-n |
No DNS resolution | Avoid DNS log traces |
# Fragment packets to bypass basic packet filters
nmap -f -sS -p 80,443 <target>
# Double fragment (16-byte chunks)
nmap -ff -sS <target>
# Custom MTU fragmentation
nmap --mtu 16 -sS <target>
# Decoy: hide among 10 random IPs
nmap -D RND:10 -sS <target>
# Decoy: specify exact decoys + mark your position
nmap -D 10.0.0.2,10.0.0.3,ME,10.0.0.5 -sS <target>
# Spoof source IP (requires proper routing; need -e)
nmap -S 192.168.1.100 -e eth0 <target>
# Spoof source port 53 (DNS trust bypass)
nmap --source-port 53 -sS <target>
# Look less like a scan by adding payload noise
nmap --data-length 25 -sS <target>
# Detect FW/IDS presence with bogus checksums
nmap --badsum <target>
# Spoof MAC to a Cisco vendor prefix
nmap --spoof-mac Cisco <target>
# Spoof MAC to random address
nmap --spoof-mac 0 <target>
# Idle scan via zombie (your IP never contacts target)
nmap -sI 10.0.0.10:80 -p 1-1024 <target>
# Combine evasion: fragment + decoys + source port spoof
nmap -f --source-port 53 -D RND:5 -sS -T2 <target>
# Relay through SOCKS4 proxy
nmap --proxies socks4://127.0.0.1:9050 -sT -Pn <target>
# ACK scan to determine if ports are filtered
nmap -sA -p 22,80,443 <target>
# Window scan - can distinguish open/closed on some systems
nmap -sW -p 22,80,443 <target>
# Null/FIN/Xmas to probe stateless (non-stateful) filters
nmap -sN -p 22,80 <target> # null
nmap -sF -p 22,80 <target> # FIN
nmap -sX -p 22,80 <target> # Xmas
# Compare SYN vs ACK results to identify FW rules
nmap -sS -p 1-100 <target> -oG syn.gnmap
nmap -sA -p 1-100 <target> -oG ack.gnmap
# Enable IPv6 mode with -6
nmap -6 ::1
nmap -6 2001:db8::1
nmap -6 fe80::1%eth0 # link-local requires interface
# Full recon over IPv6
nmap -6 -A -T4 2001:db8::1
# SYN scan IPv6 target
nmap -6 -sS -p- <target>
# UDP over IPv6
nmap -6 -sU --top-ports 20 <target>
# Subnet scan (IPv6 /64 too large for full sweep)
nmap -6 -sn 2001:db8::/120 # use small subnets only
# NSE over IPv6
nmap -6 --script=http-title -p 80,443 2001:db8::1
# IPv6 neighbor discovery on local segment
nmap -6 -sn --script=targets-ipv6-multicast-invalid-dst fe80::1%eth0
# Multicast ping sweep
nmap -6 -sn ff02::1%eth0
# EUI-64 address generation from MAC (manual conversion)
# MAC: 00:50:56:ab:cd:ef
# EUI-64: 0250:56ff:feab:cdef -> 2001:db8::250:56ff:feab:cdef
# Run default scripts (equivalent to -sC)
nmap --script=default <target>
# Run specific script
nmap --script=http-title <target>
# Run multiple scripts
nmap --script=http-title,http-headers <target>
# Run entire category
nmap --script=vuln <target>
nmap --script=auth <target>
# Wildcard match
nmap --script="smb-*" <target>
nmap --script="http-vuln-*" <target>
# Combine categories with boolean
nmap --script="default and safe" <target>
nmap --script="vuln and not intrusive" <target>
# Pass script arguments
nmap --script=http-brute --script-args="http-brute.path=/admin,brute.firstonly=true" <target>
# Load args from file
nmap --script=smb-brute --script-args-file=args.txt <target>
# Trace script I/O (debug)
nmap --script=http-title --script-trace <target>
# Get script help
nmap --script-help=smb-vuln-ms17-010
# Update NSE database after adding scripts
nmap --script-updatedb
# Find scripts on disk
ls /usr/share/nmap/scripts/ | grep smb
| Category | Description | Default? | Risk |
|---|---|---|---|
default |
Yes | Low | |
safe |
Will not harm target or use excessive resources | No | Low |
discovery |
Enumerate hosts, services, resources | No | Low |
auth |
Authentication bypass + credential checks | No | Low |
brute |
No | Medium | |
vuln |
No | Medium | |
exploit |
No | High | |
intrusive |
May crash services or be logged | No | High |
dos |
No | High | |
malware |
Detect malware / backdoor indicators | No | Low |
version |
Extend -sV detection (auto-selected) |
Auto | Low |
broadcast |
LAN broadcast discovery | No | Low |
external |
Uses external resources (DNS, WHOIS) | No | Low |
fuzzer |
Send malformed/random data to services | No | Medium |
# --- Critical CVEs ---
# EternalBlue (MS17-010) - WannaCry / NotPetya vector
nmap --script=smb-vuln-ms17-010 -p 445 <target>
# MS08-067 - Classic Windows RCE
nmap --script=smb-vuln-ms08-067 -p 445 <target>
# Heartbleed - OpenSSL memory leak
nmap --script=ssl-heartbleed -p 443 <target>
# ShellShock - Bash CGI RCE
nmap --script=http-shellshock -p 80,443 <target>
# SQL injection scan
nmap --script=http-sql-injection -p 80 <target>
# Slowloris DoS check
nmap --script=http-slowloris-check -p 80 <target>
# POODLE - SSLv3 downgrade
nmap --script=ssl-poodle -p 443 <target>
# DROWN - SSLv2 exposure
nmap --script=sslv2-drown -p 443 <target>
# VNC auth bypass
nmap --script=realvnc-auth-bypass -p 5900 <target>
# Run all vuln scripts at once
nmap -sV --script=vuln <target>
# Check anonymous FTP login
nmap --script=ftp-anon -p 21 <target>
# Check for anonymous/guest SMB access
nmap --script=smb-security-mode -p 445 <target>
# Check for open X11 display
nmap --script=x11-access -p 6000 <target>
# Check for open SNMP (community strings)
nmap --script=snmp-info -p 161 <target>
# HTTP auth methods
nmap --script=http-auth-finder -p 80,443 <target>
# LDAP anonymous bind
nmap --script=ldap-rootdse -p 389 <target>
# SMTP open relay check
nmap --script=smtp-open-relay -p 25,465,587 <target>
# Redis no-auth check
nmap --script=redis-info -p 6379 <target>
# MongoDB no-auth check
nmap --script=mongodb-info -p 27017 <target>
# SSH brute force
nmap -p 22 --script=ssh-brute \
--script-args="userdb=users.txt,passdb=pass.txt" <target>
# FTP brute force
nmap -p 21 --script=ftp-brute \
--script-args="userdb=users.txt,passdb=pass.txt" <target>
# SMB brute force
nmap -p 445 --script=smb-brute \
--script-args="userdb=users.txt,passdb=pass.txt" <target>
# HTTP basic/digest/NTLM brute
nmap -p 80 --script=http-brute \
--script-args="http-brute.path=/login" <target>
# MySQL brute force
nmap -p 3306 --script=mysql-brute \
--script-args="userdb=users.txt,passdb=pass.txt" <target>
# MSSQL brute force
nmap -p 1433 --script=ms-sql-brute \
--script-args="userdb=users.txt,passdb=pass.txt" <target>
# Telnet brute force
nmap -p 23 --script=telnet-brute \
--script-args="userdb=users.txt,passdb=pass.txt" <target>
# VNC brute force
nmap -p 5900 --script=vnc-brute \
--script-args="passdb=pass.txt" <target>
# Stop on first valid credential
nmap --script=ssh-brute \
--script-args="brute.firstonly=true,userdb=u.txt,passdb=p.txt" -p 22 <target>
# Page titles across subnet
nmap --script=http-title -p 80,443,8080,8443 192.168.1.0/24
# Enumerate web directories / files
nmap --script=http-enum -p 80,443 <target>
# HTTP headers + server version
nmap --script=http-headers,http-server-header -p 80 <target>
# Allowed HTTP methods (PUT/DELETE/TRACE dangerous)
nmap --script=http-methods -p 80,443 <target>
# Security headers audit
nmap --script=http-security-headers -p 80,443 <target>
# Web app firewall detection
nmap --script=http-waf-detect -p 80,443 <target>
# Wordpress scan
nmap --script=http-wordpress-enum -p 80,443 <target>
# WebDAV detection
nmap --script=http-webdav-scan -p 80 <target>
# Default credentials on web apps
nmap --script=http-default-accounts -p 80,8080 <target>
# Robots.txt + sitemap crawl
nmap --script=http-robots.txt -p 80 <target>
# Apache Struts CVE-2017-5638 (Jakarta RCE)
nmap --script=http-vuln-cve2017-5638 -p 80,8080 <target>
# PHP-CGI source disclosure (CVE-2012-1823)
nmap --script=http-vuln-cve2012-1823 -p 80 <target>
# Drupal SQLi (Drupageddon CVE-2014-3704)
nmap --script=http-vuln-cve2014-3704 -p 80 <target>
# Full HTTP recon combo
nmap --script="http-title,http-headers,http-enum,http-methods,http-auth-finder" \
-sV -p 80,443,8080,8443 <target>
# OS and domain info via SMB
nmap --script=smb-os-discovery -p 445 <target>
# Enumerate SMB shares
nmap --script=smb-enum-shares -p 445 <target>
# Enumerate SMB users
nmap --script=smb-enum-users -p 445 <target>
# Enumerate sessions, groups, domains
nmap --script=smb-enum-sessions,smb-enum-groups,smb-enum-domains -p 445 <target>
# Security mode (signing, auth level)
nmap --script=smb-security-mode -p 445 <target>
# SMB2 protocol info
nmap --script=smb2-security-mode,smb2-capabilities -p 445 <target>
# Vulnerability checks
nmap --script=smb-vuln-ms17-010 -p 445 <target> # EternalBlue
nmap --script=smb-vuln-ms08-067 -p 445 <target> # Netapi RCE
nmap --script=smb-vuln-cve-2017-7494 -p 445 <target> # SambaCry
nmap --script=smb-vuln-ms10-054 -p 445 <target> # SMB pool overflow
nmap --script=smb-vuln-ms10-061 -p 445 <target> # Print spooler RCE
# All SMB vuln scripts at once
nmap --script="smb-vuln-*" -p 445 <target>
# Full SMB recon
nmap --script="smb-os-discovery,smb-enum-shares,smb-enum-users,smb-security-mode" \
-p 445 <target>
# Show host keys (fingerprint + algorithm)
nmap --script=ssh-hostkey -p 22 <target>
# Enumerate auth methods
nmap --script=ssh-auth-methods -p 22 <target>
# Check for weak CBC/MD5 ciphers
nmap --script=ssh2-enum-algos -p 22 <target>
# Brute force
nmap --script=ssh-brute --script-args="userdb=u.txt,passdb=p.txt" -p 22 <target>
# Run user-defined commands via authenticated session
nmap --script=ssh-run --script-args="ssh-run.cmd=id,ssh-run.username=root,ssh-run.password=root" -p 22 <target>
# FTP anonymous login
nmap --script=ftp-anon -p 21 <target>
# FTP banner + syst info
nmap --script=ftp-syst -p 21 <target>
# FTP bounce attack capability
nmap --script=ftp-bounce -p 21 <target>
# FTP brute force
nmap --script=ftp-brute --script-args="userdb=u.txt,passdb=p.txt" -p 21 <target>
# DNS zone transfer (AXFR)
nmap --script=dns-zone-transfer --script-args="dns-zone-transfer.domain=target.com" -p 53 <target>
# DNS subdomain brute force
nmap --script=dns-brute --script-args="dns-brute.domain=target.com,dns-brute.threads=8" <target>
# DNS recursion check (open resolver)
nmap --script=dns-recursion -p 53 <target>
# DNS service info
nmap --script=dns-service-discovery <target>
# Certificate info (SAN, expiry, issuer)
nmap --script=ssl-cert -p 443,8443 <target>
# Enumerate supported cipher suites + strength
nmap --script=ssl-enum-ciphers -p 443 <target>
# Heartbleed (OpenSSL memory disclosure)
nmap --script=ssl-heartbleed -p 443 <target>
# POODLE / SSLv3
nmap --script=ssl-poodle -p 443 <target>
# Full TLS audit
nmap --script="ssl-cert,ssl-enum-ciphers,ssl-heartbleed,ssl-poodle" -p 443 <target>
# Banner grab (any port)
nmap --script=banner -p 21,22,25,80,110 <target>
# SNMP system description
nmap --script=snmp-sysdescr -p 161 -sU <target>
# SNMP full walk (community=public)
nmap --script=snmp-walk --script-args="snmpcommunity=public" -p 161 -sU <target>
# NTP monlist (DDoS amplification check)
nmap --script=ntp-monlist -p 123 -sU <target>
# IPMI cipher zero (auth bypass)
nmap --script=ipmi-cipher-zero -p 623 -sU <target>
# VNC info + auth type
nmap --script=vnc-info,vnc-auth-bypass -p 5900 <target>
# RDP encryption info
nmap --script=rdp-enum-encryption -p 3389 <target>
| Option | Format | Best For |
|---|---|---|
-oN <file> |
Human reading | |
-oX <file> |
Tools / parsing / import | |
-oG <file> |
Grepable (gnmap) | Shell one-liner parsing |
-oS <file> |
Script kiddie | Novelty only |
-oA <base> |
Always use in pentests | |
--append-output |
Append vs overwrite | Running incremental scans |
--resume <file> |
Resume aborted scan | Long interrupted scans |
| Option | Effect |
|---|---|
-v |
Verbose (show open ports in real time) |
-vv |
Very verbose |
-d |
Debug level 1 |
-dd |
Debug level 2 |
--reason |
|
--open |
Only show open/possibly-open ports |
--packet-trace |
Show every packet sent/received |
--iflist |
Print interfaces and routes |
--stats-every 5s |
Print progress every N seconds |
# --- Grepable (.gnmap) parsing ---
# Extract all live hosts from ping sweep
grep "Status: Up" sweep.gnmap | cut -d' ' -f2 | sort -u > live.txt
# Extract all open ports per host
grep "Ports:" scan.gnmap | grep -oP '\d+/open' | cut -d/ -f1 | sort -un
# Get hosts with port 445 open
grep "445/open" scan.gnmap | cut -d' ' -f2 > smb_hosts.txt
# Get hosts with port 80 open
awk '/80\/open/{print $2}' scan.gnmap > web_hosts.txt
# Extract all unique open ports from entire scan
grep -oP '\d+/open/tcp' scan.gnmap | cut -d/ -f1 | sort -un
# List host:port for all open TCP services
grep "Ports:" scan.gnmap | awk '{
host=$2
for(i=1;i<=NF;i++) if($i~/\/open\/tcp/) {
split($i,a,"/"); print host":"a[1]
}
}'
# --- Normal (.nmap) parsing ---
# Extract open ports from normal output
grep "^[0-9]" scan.nmap | grep "open" | awk '{print $1}'
# Extract service names and versions
grep "^[0-9]" scan.nmap | grep "open" | awk '{print $1, $3, $4, $5}'
# Pull all open port numbers as comma-separated list (for follow-up -p)
grep "^[0-9]" scan.nmap | grep "open" | cut -d/ -f1 | tr '\n' ',' | sed 's/,$/\n/'
# --- XML parsing with xmllint ---
xmllint --xpath "//host[status/@state='up']/address/@addr" scan.xml 2>/dev/null
# --- Convert XML to HTML report ---
xsltproc /usr/share/nmap/nmap.xsl scan.xml > report.html
# Phase 1 - fast top-port scan
nmap -sV -sC -T4 --top-ports 1000 <target> -oA ctf_quick
# Phase 2 - full port sweep (background)
nmap -p- -T4 --min-rate 5000 <target> -oN ctf_allports.txt
# Phase 3 - deep scan on discovered open ports only
ports=$(grep "^[0-9]" ctf_allports.txt | grep "open" | cut -d/ -f1 | tr '\n' ',')
nmap -sV -sC -O -p "$ports" <target> -oA ctf_full
# Step 1: Subnet host discovery
nmap -sn -PS22,80,443 -PA80 -PE 10.10.10.0/24 -oG alive.gnmap
# Step 2: Extract live hosts
grep "Up" alive.gnmap | cut -d' ' -f2 > live_hosts.txt
# Step 3: All-port SYN scan on live hosts
nmap -iL live_hosts.txt -sS -p- --min-rate 3000 -T4 -oG allports.gnmap
# Step 4: Targeted service scan on open ports
ports=$(grep -oP '\d+/open' allports.gnmap | cut -d/ -f1 | sort -un | tr '\n' ',' | sed 's/,$//')
nmap -iL live_hosts.txt -sV -sC -O -p "$ports" -oA deep_recon
# Step 5: Vuln scan on interesting ports
nmap -iL live_hosts.txt --script=vuln -p "$ports" -oA vuln_scan
# Low-and-slow with source port spoofing (bypass DNS-trusting FWs)
nmap -sS -T1 --source-port 53 --data-length 15 -p 1-1024 <target>
# Fragmented + decoys + randomized host order
nmap -f -D RND:8 --randomize-hosts -T2 -sS -p 80,443,445 <target>
# Zombie/idle scan (your IP never touches target)
# First, find a suitable zombie with predictable IPID:
nmap -O -v <zombie_candidate> # check for "IP ID Sequence: Incremental"
# Then scan via zombie:
nmap -sI <zombie_ip>:80 -p 22,80,443 <target> -Pn
# Use FIN scan to probe stateless ACL rules
nmap -sF -T2 -p 1-1024 <target>
# Custom source port 80 (HTTP trust bypass)
nmap --source-port 80 -sU -p 53,161 <target>
# Proxy chain through Tor
nmap --proxies socks4://127.0.0.1:9050 -sT -Pn -n -p 80,443 <target>
# Common UDP services
nmap -sU -p 53,67,68,69,111,123,137,138,161,162,389,500,514,520,631,1900,4500 \
--max-retries 1 -T4 <target>
# SNMP community string brute force
nmap -sU -p 161 --script=snmp-brute <target>
# SNMP full enumeration
nmap -sU -p 161 --script="snmp-*" <target>
# NFS exports
nmap -p 111 --script=nfs-showmount <target>
# DHCP info
nmap -sU -p 67 --script=dhcp-discover <target>
| Option | Purpose |
|---|---|
-iL <file> |
Read targets from file |
-iR <n> |
Scan N random internet hosts |
--exclude <hosts> |
Exclude specific hosts |
--excludefile <f> |
Exclude from file |
-6 |
IPv6 mode |
-A |
Aggressive: -sV -O -sC --traceroute |
--datadir <dir> |
Custom nmap data directory |
--send-eth |
Force raw Ethernet (bypass IP stack) |
--send-ip |
Force raw IP |
--privileged |
Assert root-equivalent privileges |
--unprivileged |
Assert no raw socket access |
-V |
Print nmap version |
-h |
Print help |
# Import XML into Metasploit
msf> db_import /path/to/scan.xml
# Convert gnmap to IP list for other tools
awk '/Up/{print $2}' hosts.gnmap | tee ips.txt | wc -l
# Feed to gobuster/nikto for web targets
awk '/80\/open/{print "http://"$2}' scan.gnmap | while read url; do nikto -h "$url"; done
# Combine nmap host discovery + masscan for speed
nmap -sn 10.0.0.0/8 -oG - | awk '/Up/{print $2}' > hosts.txt
masscan -iL hosts.txt -p0-65535 --rate=10000 -oG masscan.gnmap
# Resume an interrupted scan
nmap --resume /path/to/scan.nmap
# Scan with no internet-touching (no version db updates)
nmap --datadir /usr/share/nmap -sV <target>