Basic Scans
Scan Targets
nmap 192.168.1.1 # single host nmap 192.168.1.0/24 # entire subnet nmap 192.168.1.1-50 # IP range nmap -iL targets.txt # hosts from file
Target Specification
192.168.1.1Single IP address
192.168.1.0/24CIDR notation (256 hosts)
192.168.1.1-254IP range
example.comHostname (resolved to IP)
-iL file.txtRead targets from file
--exclude 192.168.1.1Exclude specific hosts
--excludefile skip.txtExclude hosts from file
Port Scanning
Scan Types
-sSTCP SYN scan (default, stealthy, needs root)
-sTTCP connect scan (full handshake, no root)
-sUUDP scan (slow, often filtered)
-sATCP ACK scan (detect firewalls)
-sNTCP NULL scan (no flags set)
-sFTCP FIN scan (only FIN flag)
-sXXmas scan (FIN+PSH+URG flags)
Port Selection
nmap -p 80,443 target # specific ports nmap -p 1-1000 target # port range nmap -p- target # all 65535 ports nmap --top-ports 100 target # most common 100 ports
Port States
openApplication is accepting connections
closedPort reachable but no service listening
filteredFirewall blocking, can't determine state
unfilteredPort accessible, open/closed unknown
open|filteredCan't determine if open or filtered
Host Discovery
Discovery Methods
-snPing scan only (no port scan)
-PnSkip host discovery (treat all as up)
-PS 80,443TCP SYN discovery on ports
-PA 80TCP ACK discovery
-PU 53UDP discovery
-PEICMP echo request
-PRARP discovery (local network)
Network Sweep
nmap -sn 192.168.1.0/24 # ping sweep subnet nmap -sn -n 10.0.0.0/24 # sweep, skip DNS nmap -sn -PR 192.168.1.0/24 # ARP scan (fastest)
Service Detection
Version Detection
nmap -sV target # detect service versions nmap -sV --version-intensity 5 target # deeper probing nmap -sV --version-all target # try every probe (slow) nmap -A target # OS + version + scripts + traceroute
Service Flags
-sVProbe open ports for service/version
--version-intensity 0-9Probe intensity (default 7)
--version-lightLight probing (intensity 2)
--version-allTry every probe (intensity 9)
-AAggressive: -sV -O --script=default -traceroute
-sCRun default NSE scripts
OS Detection
OS Fingerprinting
nmap -O target # OS detection (needs root) nmap -O --osscan-limit target # only scan promising hosts nmap -O --osscan-guess target # aggressive OS guessing nmap -A target # includes OS detection
OS Detection Flags
-OEnable OS detection
--osscan-limitSkip hosts without open+closed TCP ports
--osscan-guessGuess OS more aggressively
--max-os-tries NMax OS detection attempts per host
Scripts (NSE)
Script Usage
nmap --script=default target # default category nmap --script=vuln target # vulnerability scripts nmap --script=http-headers target nmap --script="http-*" target # wildcard match
Script Categories
defaultSafe, useful scripts (-sC shorthand)
vulnCheck for known vulnerabilities
safeNon-intrusive scripts
intrusiveMay crash targets or trigger IDS
discoveryNetwork & service discovery
authAuthentication-related checks
bruteBrute-force credential testing
exploitActive exploitation attempts
Useful Scripts
http-titleGrab web page titles
ssl-certShow SSL certificate details
ssh-hostkeyShow SSH host key fingerprints
dns-bruteEnumerate DNS subdomains
smb-os-discoveryDetect Windows OS via SMB
vulnRun all vulnerability checks
Output Formats
Output Options
nmap -oN scan.txt target # normal text output nmap -oX scan.xml target # XML output nmap -oG scan.gnmap target # grepable output nmap -oA scan_all target # all formats at once
Output Flags
-oN fileNormal output to file
-oX fileXML output (for tools/parsing)
-oG fileGrepable output (one host per line)
-oA basenameAll three formats (basename.nmap/xml/gnmap)
-vIncrease verbosity (-vv for more)
-dDebug output (-dd for more)
--openShow only open ports
--reasonShow reason for port state
Timing & Performance
Timing Templates
-T0 (paranoid)Very slow, IDS evasion (5 min between probes)
-T1 (sneaky)Slow, IDS evasion (15 sec between probes)
-T2 (polite)Reduced speed, less bandwidth
-T3 (normal)Default timing
-T4 (aggressive)Fast, assumes reliable network
-T5 (insane)Fastest, may miss results
Fine-Grained Tuning
--min-rate 1000Send at least 1000 packets/sec
--max-rate 500Cap at 500 packets/sec
--max-retries 2Max probe retransmissions
--host-timeout 30mSkip host if scan exceeds 30 min
--scan-delay 1sDelay between probes
--min-parallelism 10Min parallel probe groups
Firewall Evasion
Evasion Techniques
-fFragment packets (8-byte chunks)
-D RND:5Decoy scan with 5 random IPs
-S spoof_ipSpoof source IP (needs raw packets)
-e eth0Use specific network interface
--source-port 53Use specific source port (e.g. DNS)
--data-length 25Append random data to packets
--spoof-mac 0Randomize MAC address
Evasion Examples
nmap -f -D RND:3 target # fragments + decoys nmap --source-port 53 target # DNS port (often allowed) nmap -T1 --scan-delay 5s target # slow to evade IDS
Common Patterns
Quick Recon
nmap -T4 -F target # fast common ports nmap -T4 -A -v target # OS + service detection nmap -sV --top-ports 1000 target # top 1000 + versions
Comprehensive Scan
# Full TCP + service + OS + scripts nmap -sS -sV -O -sC -p- -T4 -oA full target # UDP scan on common ports nmap -sU --top-ports 50 target
Web Server Audit
nmap -p 80,443 --script=http-title,http-headers,\ ssl-cert,http-methods target # Check for open proxies and vulns nmap -p 80,443,8080 --script=http-open-proxy,vuln target
Network Inventory
# Discover all live hosts with OS info nmap -sn 192.168.1.0/24 -oG - | grep "Up" # Service inventory for subnet nmap -sV -T4 192.168.1.0/24 -oX inventory.xml