Nmap Mastery
Table of Contents
- Nmap Overview and Architecture
- Nmap Scan Types
- Nmap Timing Templates
- Essential Nmap Commands
- Nmap Scripting Engine (NSE)
- Nmap Output Interpretation
- Nmap Port States
- Recommended OSCP Nmap Workflow
- OSCP Exam Tips
- Attack Chain Position
1. Nmap Overview and Architecture
What is Nmap?
Nmap (Network Mapper) is the most powerful and widely used open-source network scanner and security auditing tool. Created by Gordon Lyon (also known as “Fyodor”), it was first released in 1997 and remains the gold standard for network discovery and security auditing.
How Nmap Works Internally
Nmap operates by crafting raw IP packets and analyzing the responses. Here is the internal architecture:
┌─────────────────────────────────────────────────┐
│ Nmap Architecture │
├─────────────────────────────────────────────────┤
│ │
│ ┌──────────────┐ ┌──────────────────────┐ │
│ │ Target │ │ Target Resolution │ │
│ │ Specification │ │ (DNS / IP Lookup) │ │
│ └──────┬───────┘ └──────────┬───────────┘ │
│ │ │ │
│ ▼ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ Host Discovery Engine │ │
│ │ (ICMP, TCP, UDP, ARP Probes) │ │
│ └────────────────┬─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ Port Scanner Engine │ │
│ │ (SYN, Connect, FIN, XMAS, NULL, etc.) │ │
│ └────────────────┬─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ Service & OS Detection Engine │ │
│ │ (Banner Grabbing, TCP/IP Fingerprint) │ │
│ └────────────────┬─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ Nmap Scripting Engine (NSE) │ │
│ │ (Lua-based vulnerability scripts) │ │
│ └────────────────┬─────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ Output Engine │ │
│ │ (Console, XML, grep, Nmap scripts) │ │
│ └──────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────┘
Key Internal Components
| Component | Description |
|---|---|
| Packet Generator | Crafts raw IP packets with custom headers, flags, and payloads |
| Packet Sender | Sends crafted packets to targets using libpcap (or raw sockets) |
| Packet Receiver | Captures and processes responses from targets |
| OS Detection Engine | Analyzes TCP/IP stack fingerprints to identify operating systems |
| Service Detection Engine | Probes open ports to determine running services and versions |
| NSE Engine | Executes Lua-based scripts for advanced enumeration and exploitation |
| Output Engine | Formats results in multiple output formats (normal, XML, grepable, script) |
Nmap Installation
# Kali Linux (pre-installed)
nmap --version
# Ubuntu/Debian
sudo apt install nmap
# macOS
brew install nmap
# Windows - download from https://nmap.org/download.html
2. Nmap Scan Types
2.1 TCP SYN Scan (-sS) — The Half-Open Scan
The most popular and default scan type when running as root. It never completes the TCP handshake, making it faster and stealthier than a connect scan.
TCP SYN Scan — Packet Flow
Scanner Target
│ │
│─── [SYN] ──────────────────────▶│ Step 1: Send SYN to probe port
│ │
│◀─── [SYN-ACK] ─────────────────│ Step 2: Open port responds SYN-ACK
│ │
│─── [RST] ──────────────────────▶│ Step 3: Send RST to abort (no ACK!)
│ │
Result: Port is OPEN │
(Half-open — connection never established)
Scanner Target
│ │
│─── [SYN] ──────────────────────▶│ Step 1: Send SYN to probe port
│ │
│◀─── [RST] ─────────────────────│ Step 2: Closed port responds RST
│ │
Result: Port is CLOSED │
Scanner Target
│ │
│─── [SYN] ──────────────────────▶│ Step 1: Send SYN to probe port
│ │
│ (No Response) │ Step 2: Firewall drops the packet
│ │
Result: Port is FILTERED │
Commands
# Basic SYN scan on common ports
nmap -sS 192.168.1.100
# SYN scan on all 65535 ports
nmap -sS -p- 192.168.1.100
# SYN scan with service version detection
nmap -sS -sV 192.168.1.100
# SYN scan on specific ports
nmap -sS -p 22,80,443,3306,8080 192.168.1.100
# SYN scan with timing template
nmap -sS -T4 192.168.1.0/24
When to Use
- Default choice for OSCP when running as root
- Fast and relatively stealthy
- Works against most targets
- Requires root/administrator privileges
2.2 TCP Connect Scan (-sT) — Full Handshake
Completes the full TCP three-way handshake. Used when you don’t have root privileges or when SYN scans are blocked.
TCP Connect Scan — Packet Flow
Scanner Target
│ │
│─── [SYN] ──────────────────────▶│ Step 1: Send SYN
│ │
│◀─── [SYN-ACK] ─────────────────│ Step 2: Open port responds SYN-ACK
│ │
│─── [ACK] ──────────────────────▶│ Step 3: Complete handshake
│ │
│─── [FIN, ACK] ─────────────────▶│ Step 4: Graceful close
│◀─── [FIN, ACK] ────────────────│
│─── [ACK] ──────────────────────▶│
│ │
Result: Port is OPEN │
(Full connection established)
Commands
# Basic connect scan
nmap -sT 192.168.1.100
# Connect scan on all ports
nmap -sT -p- 192.168.1.100
# Connect scan when not root (Windows default)
nmap -sT 192.168.1.100
When to Use
- Running as non-root user (Windows default)
- SYN scans are blocked by firewall
- You don’t mind being more detectable
- Full connection is needed for certain tests
2.3 UDP Scan (-sU)
Scans UDP ports. UDP is connectionless, so Nmap determines port state based on ICMP error responses.
UDP Scan — Packet Flow
Scanner Target
│ │
│─── [UDP Probe] ───────────────▶│ Step 1: Send UDP packet
│ │
│ (No Response) │ Step 2: No response = port open
│ │
Result: Port is OPEN|FILTERED │
(Could be open or filtered)
Scanner Target
│ │
│─── [UDP Probe] ───────────────▶│ Step 1: Send UDP packet
│ │
│◀─── [ICMP Port Unreachable] ───│ Step 2: ICMP Type 3 Code 3
│ │
Result: Port is CLOSED │
Scanner Target
│ │
│─── [UDP Probe] ───────────────▶│ Step 1: Send UDP packet
│ │
│◀─── [ICMP Admin Prohibited] ───│ Step 2: ICMP Type 3 Code 10
│ │
Result: Port is FILTERED │
Commands
# Scan common UDP ports
nmap -sU 192.168.1.100
# Scan specific UDP ports
nmap -sU -p 53,161,162,137,138,139,500,1900 192.168.1.100
# UDP scan with version detection (slow but thorough)
nmap -sU -sV -p 53,161,162,135,137,138,139,389,445,500 192.168.1.100
# Top 100 UDP ports with aggressive timing
nmap -sU --top-ports 100 -T4 192.168.1.100
When to Use
- Always check UDP on OSCP targets — many easy wins live here
- UDP is often overlooked by defenders
- Critical services: DNS (53), SNMP (161), NetBIOS (137-139), Kerberos (88), NTP (123)
2.4 TCP ACK Scan (-sA) — Firewall Mapping
Used to determine if a target is behind a firewall and whether the firewall is stateful.
TCP ACK Scan — Packet Flow
Scanner Target
│ │
│─── [ACK] ──────────────────────▶│ Send ACK (pretend connection exists)
│ │
│◀─── [RST] ─────────────────────│ RST = unfiltered port
│ │
Result: Port is UNFILTERED │
(Firewall lets it through)
Scanner Target
│ │
│─── [ACK] ──────────────────────▶│ Send ACK
│ │
│ (No Response) │ No response = filtered
│ │
Result: Port is FILTERED │
(Firewall is blocking)
Commands
# ACK scan to map firewall rules
nmap -sA 192.168.1.100
# ACK scan on all ports
nmap -sA -p- 192.168.1.100
When to Use
- Mapping firewall rulesets
- Determining if a firewall is stateful
- Cannot determine open/closed — only filtered/unfiltered
2.5 NULL Scan (-sN)
Sends TCP packets with no flags set. On TCP-compliant systems (Linux, Windows), closed ports respond with RST. Open ports ignore the packet.
NULL Scan — Packet Flow
Scanner Target
│ │
│─── [NULL - no flags] ─────────▶│ Send packet with no flags
│ │
│◀─── [RST] ─────────────────────│ Closed port responds RST
│ │
Result: Port is CLOSED|FILTERED │
Scanner Target
│ │
│─── [NULL - no flags] ─────────▶│ Send packet with no flags
│ │
│ (No Response) │ Open port ignores (RFC compliant)
│ │
Result: Port is OPEN|FILTERED │
Commands
# NULL scan
nmap -sN 192.168.1.100
# NULL scan on all ports
nmap -sN -p- 192.168.1.100
When to Use
- Bypassing simple firewalls that don’t inspect flags
- Works against Linux and most Unix-like systems
- Does NOT work against Windows (Windows responds to all probes per RFC)
2.6 FIN Scan (-sF)
Sends TCP packets with only the FIN flag set. Similar behavior to NULL scan.
FIN Scan — Packet Flow
Scanner Target
│ │
│─── [FIN] ──────────────────────▶│ Send packet with FIN flag only
│ │
│◀─── [RST] ─────────────────────│ Closed port responds RST
│ │
Result: Port is CLOSED|FILTERED │
Scanner Target
│ │
│─── [FIN] ──────────────────────▶│ Send packet with FIN flag only
│ │
│ (No Response) │ Open port ignores
│ │
Result: Port is OPEN|FILTERED │
Commands
# FIN scan
nmap -sF 192.168.1.100
# FIN scan on all ports
nmap -sF -p- 192.168.1.100
When to Use
- Same as NULL scan — bypassing flag-inspecting firewalls
- Works against Linux/Unix, NOT Windows
2.7 XMAS Scan (-sX)
Sends TCP packets with FIN, PSH, and URG flags set (lights up like a Christmas tree).
XMAS Scan — Packet Flow
Scanner Target
│ │
│─── [FIN+PSH+URG] ─────────────▶│ Send packet with all three flags
│ │
│◀─── [RST] ─────────────────────│ Closed port responds RST
│ │
Result: Port is CLOSED|FILTERED │
Scanner Target
│ │
│─── [FIN+PSH+URG] ─────────────▶│ Send packet with all three flags
│ │
│ (No Response) │ Open port ignores
│ │
Result: Port is OPEN|FILTERED │
Commands
# XMAS scan
nmap -sX 192.168.1.100
# XMAS scan on all ports
nmap -sX -p- 192.168.1.100
When to Use
- Bypassing firewalls that don’t inspect for unusual flag combinations
- Works against Linux/Unix, NOT Windows
- Often used alongside NULL and FIN scans
2.8 Service Version Detection (-sV)
Probes open ports to determine the service name and version number.
How It Works
- Nmap connects to the open port
- Sends a series of probes from its version detection database (
nmap-service-probes) - Analyzes responses to match against known service signatures
- Returns service name, version, and sometimes device type
Commands
# Version detection on open ports
nmap -sV 192.168.1.100
# Intensive version detection (tries more probes)
nmap -sV --version-intensity 9 192.168.1.100
# Light version detection (fewer probes)
nmap -sV --version-intensity 2 192.168.1.100
# Version detection on specific ports
nmap -sV -p 80,443,8080 192.168.1.100
Version Intensity Levels
| Level | Description | Use Case |
|---|---|---|
| 0 | Lightest, just a few probes | Quick check |
| 1-3 | Light detection | Fast scanning |
| 4-7 | Default intensity | Normal use |
| 8-9 | Most intensive | Maximum accuracy |
2.9 Aggressive Scan (-A)
Enables OS detection, version detection, script scanning, and traceroute in a single flag.
What -A Enables
-A = --osscan-guess + -sV + --script=default + --traceroute
Commands
# Aggressive scan on a single target
nmap -A -T4 192.168.1.100
# Aggressive scan on specific ports
nmap -A -p 22,80,443,3306 192.168.1.100
When to Use
- Quick comprehensive scan on a single target
- NOT recommended for entire subnets (too slow, too noisy)
- Great for final detailed enumeration of a specific machine
2.10 Ping Scan (-sn)
Performs host discovery only — no port scanning.
Commands
# Ping scan of a subnet
nmap -sn 192.168.1.0/24
# Ping scan of a range
nmap -sn 192.168.1.1-254
# Ping scan with multiple targets
nmap -sn target1.com target2.com 192.168.1.100
When to Use
- Quick network sweep to find live hosts
- First step in reconnaissance
- When you only need to know which hosts are alive
2.11 IP Protocol Scan (-sO)
Scans for IP protocols (not ports) — checks which protocols (ICMP, TCP, UDP, OSPF, GRE, etc.) the target supports.
Commands
# IP protocol scan
nmap -sO 192.168.1.100
# Scan specific protocols
nmap -sO -p 1,2,6,17,47 192.168.1.100
Common Protocol Numbers
| Protocol | Number | Description |
|---|---|---|
| ICMP | 1 | Internet Control Message Protocol |
| IGMP | 2 | Internet Group Management Protocol |
| TCP | 6 | Transmission Control Protocol |
| UDP | 17 | User Datagram Protocol |
| OSPF | 89 | Open Shortest Path First |
| GRE | 47 | Generic Routing Encapsulation |
Scan Types Comparison Table
| Scan Type | Flag | Root Required | Stealthy | Works on Windows | Primary Use |
|---|---|---|---|---|---|
| SYN | -sS |
Yes | Yes | Yes | Default port scan |
| Connect | -sT |
No | No | Yes | Non-root scanning |
| UDP | -sU |
Yes (recommended) | Moderate | Yes | UDP service discovery |
| ACK | -sA |
Yes | Yes | Yes | Firewall mapping |
| NULL | -sN |
Yes | Yes | No | Firewall evasion |
| FIN | -sF |
Yes | Yes | No | Firewall evasion |
| XMAS | -sX |
Yes | Yes | No | Firewall evasion |
| Version | -sV |
No | No | Yes | Service identification |
| Aggressive | -A |
Yes | No | Yes | Comprehensive scan |
| Ping | -sn |
No | Yes | Yes | Host discovery only |
| Protocol | -sO |
Yes | Moderate | Yes | Protocol discovery |
3. Nmap Timing Templates
Nmap timing templates control the speed of scanning. They affect packet send rates, retransmission timeouts, and parallelization.
Timing Template Overview
┌────┬──────────┬──────────┬──────────┬──────────────────────────────────┐
│ T# │ Name │ Speed │ Use Case │
├────┼──────────┼──────────┼──────────────────────────────────┤
│ T0 │ Paranoid │ Slowest │ Heavy IDS/IPS evasion │
│ T1 │ Sneaky │ Very Slow│ IDS evasion, stealth │
│ T2 │ Polite │ Slow │ Reduce bandwidth, be courteous │
│ T3 │ Normal │ Medium │ Default speed │
│ T4 │ Aggressive│ Fast │ Fast networks, OSCP default │
│ T5 │ Insane │ Fastest │ Very fast networks, may miss hosts │
└────┴──────────┴──────────┴──────────────────────────────────┘
Detailed Timing Descriptions
| Template | Flag | Max Retries | Host Timeout | Scan Delay | Min Rate | Max Rate | Best For |
|---|---|---|---|---|---|---|---|
| T0 | -T0 |
10 | 30 min | 15000ms | 1.5/s | 150/s | IDS evasion, maximum stealth |
| T1 | -T1 |
7 | 15 min | 4000ms | 1.5/s | 150/s | Stealth scanning |
| T2 | -T2 |
5 | 10 min | 1000ms | 1.5/s | 150/s | Slow networks, being polite |
| T3 | -T3 |
4 | 5 min | 0ms | 1.5/s | 150/s | Default, balanced |
| T4 | -T4 |
2 | 90s | 0ms | 1.5/s | 150/s | OSCP recommended |
| T5 | -T5 |
1 | 30s | 0ms | 1.5/s | 150/s | Very fast local networks |
Timing Commands
# Paranoid (slowest, most stealthy)
nmap -T0 192.168.1.100
# Sneaky
nmap -T1 192.168.1.100
# Polite (reduces bandwidth usage)
nmap -T2 192.168.1.100
# Normal (default)
nmap -T3 192.168.1.100
# Aggressive (recommended for OSCP)
nmap -T4 192.168.1.100
# Insane (fastest, may miss results)
nmap -T5 192.168.1.100
# Custom timing
nmap --min-rate 1000 --max-retries 2 192.168.1.100
OSCP Timing Recommendations
┌─────────────────────────────────────────────────────────┐
│ OSCP Timing Strategy │
├─────────────────────────────────────────────────────────┤
│ │
│ Initial Recon: -T4 (fast, reliable) │
│ Detailed Enum: -T4 (balanced speed/accuracy) │
│ UDP Scanning: -T4 (UDP is slow anyway) │
│ All-Port Scan: -T4 (T5 may miss ports) │
│ IDS Present: -T2 or -T1 (slow down) │
│ │
│ ⚠️ Avoid T5 on OSCP — may miss critical ports │
│ ⚠️ Avoid T0/T1 unless IDS is actively blocking │
│ │
└─────────────────────────────────────────────────────────┘
4. Essential Nmap Commands
4.1 Host Discovery
# Default host discovery (ICMP echo + TCP SYN 443 + TCP ACK 80 + ICMP timestamp)
nmap 192.168.1.0/24
# Ping scan only (no port scan)
nmap -sn 192.168.1.0/24
# Skip host discovery (assume all hosts are up)
nmap -Pn 192.168.1.100
# TCP SYN discovery on port 80
nmap -PS80 192.168.1.0/24
# TCP SYN discovery on multiple ports
nmap -PS22,80,443 192.168.1.0/24
# TCP ACK discovery
nmap -PA80 192.168.1.0/24
# UDP discovery on port 161 (SNMP)
nmap -PU161 192.168.1.0/24
# ICMP echo discovery
nmap -PE 192.168.1.0/24
# ICMP timestamp discovery
nmap -PP 192.168.1.0/24
# ICMP netmask discovery
nmap -PM 192.168.1.0/24
# IP protocol discovery
nmap -PO 192.168.1.0/24
# ARP discovery (local network only)
nmap -PR 192.168.1.0/24
# Combine multiple discovery methods
nmap -PS22,80 -PA443 -PU53 -PE -PP 192.168.1.0/24
4.2 Port Scanning
# Scan common 1000 ports (default)
nmap 192.168.1.100
# Scan all 65535 ports
nmap -p- 192.168.1.100
# Scan specific ports
nmap -p 22,80,443,3306,8080 192.168.1.100
# Scan port range
nmap -p 1-1000 192.168.1.100
# Scan top 100 ports
nmap --top-ports 100 192.168.1.100
# Scan top 1000 ports
nmap --top-ports 1000 192.168.1.100
# Scan specific port list from file
nmap -p ports.txt 192.168.1.100
# UDP scan on common ports
nmap -sU --top-ports 100 192.168.1.100
# SYN scan on all ports
nmap -sS -p- 192.168.1.100
# Connect scan on all ports
nmap -sT -p- 192.168.1.100
4.3 Service and OS Detection
# Service version detection
nmap -sV 192.168.1.100
# Intensive version detection
nmap -sV --version-intensity 9 192.168.1.100
# OS detection
nmap -O 192.168.1.100
# OS detection with guessing
nmap --osscan-guess 192.168.1.100
# OS and service detection combined
nmap -sV -O 192.168.1.100
# OS detection on specific ports (need at least 1 open + 1 closed)
nmap -O -p 22,80,443,8080,9999 192.168.1.100
4.4 Script Scanning (NSE)
# Default script set
nmap --script=default 192.168.1.100
# Safe scripts only
nmap --script=safe 192.168.1.100
# Specific script
nmap --script=http-enum 192.168.1.100
# Multiple scripts
nmap --script=http-enum,http-title,ssl-cert 192.168.1.100
# Script category
nmap --script=vuln 192.168.1.100
# Scripts with arguments
nmap --script=http-enum --script-args http-enum.basepath=/admin 192.168.1.100
# All scripts (very slow)
nmap --script=all 192.168.1.100
# Exclude certain scripts
nmap --script="default,not brute" 192.168.1.100
4.5 Output and Formatting
# Normal output to file
nmap -oN scan_results.txt 192.168.1.100
# XML output
nmap -oX scan_results.xml 192.168.1.100
# Grepable output
nmap -oG scan_results.gnmap 192.168.1.100
# All output formats at once
nmap -oA scan_results 192.168.1.100
# Append to existing file
nmap -oN scan_results.txt --append-output 192.168.1.100
# Verbose output
nmap -v 192.168.1.100
# Very verbose
nmap -vv 192.168.1.100
# Debug mode
nmap -d 192.168.1.100
4.6 Advanced Techniques
# Decoy scan (use 6 decoys + your IP as the 7th)
nmap -D RND:6 192.168.1.100
# Fragment packets (bypass simple firewalls)
nmap -f 192.168.1.100
# Custom MTU fragmentation
nmap -f --mtu 8 192.168.1.100
# Spoof source IP
nmap -S 10.0.0.1 192.168.1.100
# Use custom source port
nmap -g 53 192.168.1.100
# Randomize port order
nmap --randomize-hosts -p- 192.168.1.100
# Send packets directly (no ARP)
nmap --send-ip 192.168.1.100
# Never resolve DNS
nmap -n 192.168.1.100
# Force DNS resolution
nmap -R 192.168.1.100
# Traceroute
nmap --traceroute 192.168.1.100
# Data rate control (packets per second)
nmap --min-rate 1000 192.168.1.100
nmap --max-rate 500 192.168.1.100
# Reason for port state
nmap --reason 192.168.1.100
# Open ports only
nmap --open 192.168.1.100
5. Nmap Scripting Engine (NSE)
What is NSE?
The Nmap Scripting Engine (NSE) is a powerful framework that allows you to write and share scripts for tasks like vulnerability detection, backdoor detection, brute-forcing, and advanced enumeration. Scripts are written in Lua.
NSE Script Categories
| Category | Description | Safety |
|---|---|---|
| default | Scripts run with --script=default |
Safe |
| safe | Scripts considered safe (non-intrusive) | Safe |
| vuln | Vulnerability detection scripts | Read-only |
| auth | Scripts requiring authentication | Read-only |
| brute | Brute-force authentication attacks | Intrusive |
| discovery | Additional network discovery | Safe |
| exploit | Scripts that can exploit vulnerabilities | DANGEROUS |
| external | Scripts using external resources/services | Varies |
Essential NSE Scripts for OSCP
HTTP Scripts
# Enumerate common web directories and files
nmap --script=http-enum -p 80,443,8080 192.168.1.100
# Get HTTP page title
nmap --script=http-title -p 80,443 192.168.1.100
# Get HTTP headers
nmap --script=http-headers -p 80,443 192.168.1.100
# Check for HTTP methods (OPTIONS, TRACE, etc.)
nmap --script=http-methods -p 80,443 192.168.1.100
# Detect web servers
nmap --script=http-server-header -p 80,443 192.168.1.100
# Enumerate web applications
nmap --script=http-enum-apps -p 80,443 192.168.1.100
# Check for robots.txt
nmap --script=http-robots.txt -p 80,443 192.168.1.100
# Check for sitemap.xml
nmap --script=http-sitemap-generator -p 80,443 192.168.1.100
# Detect CMS (WordPress, Joomla, Drupal, etc.)
nmap --script=http-wordpress-enum -p 80,443 192.168.1.100
# Check for default credentials
nmap --script=http-default-accounts -p 80,443 192.168.1.100
# Find interesting URLs
nmap --script=http-enum -p 80,443 192.168.1.100
SSL/TLS Scripts
# Get SSL certificate information
nmap --script=ssl-cert -p 443 192.168.1.100
# Enumerate SSL ciphers
nmap --script=ssl-enum-ciphers -p 443 192.168.1.100
# Check for SSL vulnerabilities (Heartbleed, POODLE, etc.)
nmap --script=ssl-heartbleed -p 443 192.168.1.100
nmap --script=ssl-poodle -p 443 192.168.1.100
# Check SSL configuration
nmap --script=ssl-enum-ciphers,ssl-cert,ssl-known-key -p 443 192.168.1.100
SMB Scripts
# Enumerate SMB shares
nmap --script=smb-enum-shares -p 445 192.168.1.100
# List contents of SMB shares
nmap --script=smb-ls --script-args smb-ls.share=C$ -p 445 192.168.1.100
# Enumerate SMB users
nmap --script=smb-enum-users -p 445 192.168.1.100
# Check SMB security mode
nmap --script=smb-security-mode -p 445 192.168.1.100
# Enumerate SMB sessions
nmap --script=smb-enum-sessions -p 445 192.168.1.100
# Check for null sessions
nmap --script=smb-enum-shares,smb-enum-users --script-args smbnull=true -p 445 192.168.1.100
# SMB OS detection
nmap --script=smb-os-discovery -p 445 192.168.1.100
FTP Scripts
# Check for anonymous FTP access
nmap --script=ftp-anon -p 21 192.168.1.100
# FTP bounce attack
nmap --script=ftp-bounce -p 21 192.168.1.100
# FTP vsftpd backdoor detection
nmap --script=ftp-vsftpd-backdoor -p 21 192.168.1.100
SNMP Scripts
# Get SNMP system information
nmap --script=snmp-info -p 161 192.168.1.100
# Enumerate SNMP
nmap --script=snmp-enum -p 161 192.168.1.100
# Enumerate SNMP users
nmap --script=snmp-users -p 161 192.168.1.100
# Enumerate SNMP netstat
nmap --script=snmp-netstat -p 161 192.168.1.100
# Enumerate SNMP processes
nmap --script=snmp-processes -p 161 192.168.1.100
# Full SNMP enumeration
nmap --script="snmp-*" -p 161 192.168.1.100
Vulnerability Scripts
# Run all vulnerability scripts
nmap --script=vuln 192.168.1.100
# Run vulnerability scripts on specific ports
nmap --script=vuln -p 80,443,445 192.168.1.100
# Specific vulnerability checks
nmap --script=smb-vuln-ms17-010 -p 445 192.168.1.100
nmap --script=http-vuln-cve2017-5638 -p 8080 192.168.1.100
nmap --script=ssl-heartbleed -p 443 192.168.1.100
Brute-Force Scripts
# HTTP brute force
nmap --script=http-brute -p 80,443 192.168.1.100
# FTP brute force
nmap --script=ftp-brute -p 21 192.168.1.100
# SMB brute force
nmap --script=smb-brute -p 445 192.168.1.100
# MySQL brute force
nmap --script=mysql-brute -p 3306 192.168.1.100
# SSH brute force
nmap --script=ssh-brute -p 22 192.168.1.100
NSE Script Arguments
# Custom wordlist for http-enum
nmap --script=http-enum --script-args http-enum.basepath=/admin 192.168.1.100
# Custom credentials
nmap --script=ftp-brute --script-args userdb=users.txt,passdb=pass.txt -p 21 192.168.1.100
# SNMP community string
nmap --script=snmp-info --script-args snmpcommunity=public -p 161 192.168.1.100
# HTTP proxy
nmap --script=http-enum --script-args http.proxyhost=127.0.0.1,http.proxyport=8080 192.168.1.100
Finding and Reading NSE Scripts
# List all NSE scripts
ls /usr/share/nmap/scripts/
# Search for scripts by name
ls /usr/share/nmap/scripts/ | grep http
# Read a script's documentation
nmap --script-help=http-enum
# Read script source
cat /usr/share/nmap/scripts/http-enum.nse
# Find scripts by category
ls /usr/share/nmap/scripts/ | grep smb
6. Nmap Output Interpretation
Sample Nmap Output
Starting Nmap 7.94 ( https://nmap.org )
Nmap scan report for 192.168.1.100
Host is up (0.0023s latency).
Not shown: 997 closed tcp ports (reset)
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2
80/tcp open http Apache httpd 2.4.38
443/tcp closed https
3306/tcp open mysql MySQL 5.5.5-10.3.27
8080/tcp filtered http-proxy
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 12.34 seconds
Output Components Explained
| Component | Meaning |
|---|---|
Host is up |
Target responded to discovery probes |
(0.0023s latency) |
Round-trip time to the target |
Not shown: 997 closed |
997 ports were closed (not displayed individually) |
PORT |
Port number and protocol |
STATE |
Port state (open, closed, filtered, etc.) |
SERVICE |
Default service name for the port |
VERSION |
Detected service version (with -sV) |
Reading Port States
PORT STATE SERVICE MEANING
─────────────────────────────────────────────────────────
22/tcp open ssh Port is accessible, service is running
80/tcp closed http Port is accessible, no service listening
443/tcp filtered https Firewall is blocking/dropping packets
3306/tcp open|filtered mysql Can't determine if open or filtered
8080/tcp closed|filtered http-proxy Can't determine if closed or filtered
7. Nmap Port States
Port State Definitions
┌─────────────────┬──────────────────────────────────────────────────────┐
│ State │ Meaning │
├─────────────────┼──────────────────────────────────────────────────────┤
│ open │ An application is listening and accepting connections │
│ closed │ Port is accessible but no application is listening │
│ filtered │ A firewall/device is blocking the port │
│ open|filtered │ Can't determine — no response received │
│ closed|filtered │ Can't determine — ambiguous response │
└─────────────────┴──────────────────────────────────────────────────────┘
Detailed State Analysis
| State | Response Received | Scan Types | What to Do |
|---|---|---|---|
| open | SYN-ACK (SYN scan), Connection established (Connect) | All | Target this port! Enumerate the service, look for vulnerabilities |
| closed | RST (reset) | SYN, Connect, FIN, XMAS, NULL | Port is reachable but no service. May indicate a service was stopped |
| filtered | No response, ICMP unreachable | SYN, Connect, UDP | Firewall is blocking. Try different scan types, ACK scan, or fragmentation |
| open|filtered | No response | UDP, FIN, XMAS, NULL | Can’t tell if open or filtered. Try a different scan type to confirm |
| closed|filtered | ICMP unreachable (types 3, 9, 10, 13) | ACK | Can’t tell if closed or filtered. Try a different scan type |
State Determination by Scan Type
┌────────────┬────────────┬──────────┬────────────┬─────────────────┐
│ Scan Type │ Open Port │ Closed │ Filtered │ Result │
├────────────┼────────────┼──────────┼────────────┼─────────────────┤
│ SYN (-sS) │ SYN-ACK │ RST │ No resp │ Definitive │
│ Connect │ Connected │ RST │ Timeout │ Definitive │
│ UDP (-sU) │ No resp │ ICMP 3/3 │ No resp │ open|filtered │
│ ACK (-sA) │ RST │ RST │ No resp │ filtered/unfiltered │
│ NULL (-sN) │ No resp │ RST │ No resp │ open|filtered │
│ FIN (-sF) │ No resp │ RST │ No resp │ open|filtered │
│ XMAS (-sX) │ No resp │ RST │ No resp │ open|filtered │
└────────────┴────────────┴──────────┴────────────┴─────────────────┘
8. Recommended OSCP Nmap Workflow
5-Step OSCP Nmap Process
flowchart TD
A[Step 1: Quick Host Discovery] --> B[Step 2: TCP SYN Scan - Top 1000 Ports]
B --> C[Step 3: Service Version Detection]
C --> D[Step 4: UDP Scan - Common Ports]
D --> E[Step 5: Full Port Scan + NSE Scripts]
E --> F[Document All Findings]
F --> G[Begin Exploitation]
style A fill:#e1f5fe
style B fill:#e1f5fe
style C fill:#fff3e0
style D fill:#fff3e0
style E fill:#e8f5e9
style F fill:#fce4ec
style G fill:#f3e5f5
Step 1: Quick Host Discovery
# Find live hosts in the subnet
nmap -sn 192.168.1.0/24 -oN initial_hosts.txt
# If ICMP is blocked, use TCP SYN discovery
nmap -sn -PS22,80,443 192.168.1.0/24 -oN initial_hosts.txt
# If still blocked, skip discovery entirely
nmap -Pn -sn 192.168.1.0/24 -oN initial_hosts.txt
Step 2: TCP SYN Scan — Top 1000 Ports
# Quick scan of common ports
nmap -sS -T4 --top-ports 1000 -oN tcp_top1000.txt 192.168.1.100
# If you know the target IP range
nmap -sS -T4 --top-ports 1000 -oN tcp_top1000.txt 192.168.1.100-200
Step 3: Service Version Detection
# Version detection on discovered open ports
nmap -sV -T4 -p 22,80,443,3306,8080 -oN service_versions.txt 192.168.1.100
# With OS detection
nmap -sV -O -T4 -p 22,80,443,3306,8080 -oN service_versions.txt 192.168.1.100
Step 4: UDP Scan — Common Ports
# Scan common UDP ports
nmap -sU -T4 --top-ports 100 -oN udp_scan.txt 192.168.1.100
# Specific critical UDP ports
nmap -sU -p 53,67,68,69,123,135,137,138,139,161,162,389,445,500,514,520,521,1433,1900,3306,5353,6901 -T4 -oN udp_critical.txt 192.168.1.100
Step 5: Full Port Scan + NSE Scripts
# Full TCP port scan
nmap -sS -T4 -p- -oN tcp_allports.txt 192.168.1.100
# Full scan with version detection
nmap -sS -sV -T4 -p- -oN tcp_allports_version.txt 192.168.1.100
# NSE scripts on relevant ports
nmap --script=safe -p 22,80,443,445,3306,8080 -T4 -oN nse_safe.txt 192.168.1.100
# HTTP-specific scripts
nmap --script=http-enum,http-title,http-headers -p 80,443,8080 -T4 -oN nse_http.txt 192.168.1.100
# SMB-specific scripts
nmap --script=smb-enum-shares,smb-enum-users,smb-os-discovery -p 445 -T4 -oN nse_smb.txt 192.168.1.100
# Vulnerability scripts
nmap --script=vuln -p 22,80,443,445,3306,8080 -T4 -oN nse_vuln.txt 192.168.1.100
Complete One-Liner for OSCP
# The ultimate OSCP scan command
nmap -sS -sV -sU -O -T4 --top-ports 1000 --script=safe -oA nmap_initial 192.168.1.100
# Full enumeration (after initial scan)
nmap -sS -sV -O -T4 -p- --script=safe -oA nmap_full 192.168.1.100
9. OSCP Exam Tips
Critical Nmap Tips for OSCP
┌─────────────────────────────────────────────────────────────────┐
│ OSCP Nmap Exam Tips │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. ALWAYS scan all 65535 ports (-p-) — hidden services often │
│ run on non-standard ports (e.g., 8080, 8443, 3000, 9090) │
│ │
│ 2. ALWAYS scan UDP ports — SNMP (161) and DNS (53) are │
│ common easy wins on OSCP machines │
│ │
│ 3. Use -T4 timing — it's the best balance of speed and │
│ reliability for the OSCP lab environment │
│ │
│ 4. Use -Pn when hosts don't respond to ping — many OSCP │
│ targets block ICMP │
│ │
│ 5. Always use -sV for version detection — version info is │
│ critical for finding the right exploit │
│ │
│ 6. Save ALL output with -oA — you'll need it for your report │
│ │
│ 7. Use --script=safe for NSE — avoid intrusive scripts that │
│ could crash services or trigger alerts │
│ │
│ 8. Don't skip the full port scan — many OSCP machines have │
│ services on high ports that are the key to root access │
│ │
│ 9. If a port shows open|filtered, try a different scan type │
│ to confirm (SYN scan for TCP, connect scan as fallback) │
│ │
│ 10. Document everything — your report needs evidence of │
│ thorough enumeration │
│ │
└─────────────────────────────────────────────────────────────────┘
Common OSCP Scan Patterns
# Pattern 1: Initial recon on assigned IP
nmap -sS -T4 -Pn --top-ports 1000 -oN initial.txt <TARGET_IP>
# Pattern 2: After finding open ports, go deeper
nmap -sS -sV -O -T4 -p- -oN full_scan.txt <TARGET_IP>
# Pattern 3: UDP scan (don't skip this!)
nmap -sU -T4 --top-ports 100 -oN udp.txt <TARGET_IP>
# Pattern 4: NSE enumeration on discovered services
nmap --script=safe -p <PORTS> -T4 -oN nse.txt <TARGET_IP>
# Pattern 5: When ICMP is blocked
nmap -sS -T4 -Pn -PS22,80,443 --top-ports 1000 -oN no_icmp.txt <TARGET_IP>
Time Management
| Scan Type | Expected Time | When to Use |
|---|---|---|
| Top 1000 TCP | 30-60 seconds | Initial recon |
| All TCP ports | 2-5 minutes | After finding interesting services |
| Top 100 UDP | 1-3 minutes | After TCP scan |
| NSE scripts | 1-5 minutes | On specific interesting ports |
| Full scan + versions | 5-10 minutes | Final enumeration before exploitation |
10. Attack Chain Position
Where Nmap Fits in the Attack Chain
flowchart LR
A[Reconnaissance] --> B[Scanning<br/>Nmap]
B --> C[Enumeration<br/>Service Details]
C --> D[Vulnerability<br/>Analysis]
D --> E[Exploitation<br/>Gaining Access]
E --> F[Post-Exploitation<br/>Privilege Escalation]
F --> G[Pivoting<br/>Lateral Movement]
style B fill:#4CAF50, color:white
style C fill:#8BC34A, color:white
Nmap’s Role in Each Phase
| Phase | Nmap’s Role | Key Commands |
|---|---|---|
| Reconnaissance | Discover live hosts and network topology | -sn, -PR, -PE |
| Scanning | Identify open ports and services | -sS, -sU, -p- |
| Enumeration | Determine service versions and OS | -sV, -O, --script |
| Vulnerability Analysis | Detect known vulnerabilities | --script=vuln, --script=http-enum |
| Exploitation | NSE exploit scripts (rarely used on OSCP) | --script=exploit |
| Post-Exploitation | Scan internal networks from compromised host | -sS -p-, --script=smb-enum-shares |
Nmap as a Pivoting Tool
Once you gain access to a machine, use Nmap to scan internal networks:
# From compromised host, scan internal network
nmap -sS -T4 --top-ports 1000 -oN internal_scan.txt 10.10.10.0/24
# Check for internal services
nmap -sS -sV -T4 -p 22,80,443,445,3306,3389 -oN internal_services.txt 10.10.10.0/24
# Use Nmap through a proxy (if needed)
nmap --proxies http://127.0.0.1:8080 -sT -p 80,443 10.10.10.50
Quick Reference Card
Most Used OSCP Nmap Commands
# 1. Host discovery
nmap -sn 192.168.1.0/24
# 2. Quick TCP scan
nmap -sS -T4 --top-ports 1000 -Pn 192.168.1.100
# 3. Full TCP scan with versions
nmap -sS -sV -O -T4 -p- -Pn 192.168.1.100
# 4. UDP scan
nmap -sU -T4 --top-ports 100 -Pn 192.168.1.100
# 5. NSE scripts
nmap --script=safe -p 22,80,443,445 -T4 192.168.1.100
# 6. Save all output
nmap -sS -sV -O -T4 -p- -Pn -oA results 192.168.1.100
Port State Quick Reference
| State | Action |
|---|---|
| open | Enumerate the service, look for exploits |
| closed | No service, move on |
| filtered | Try different scan type or firewall evasion |
| open|filtered | Confirm with SYN or Connect scan |
| closed|filtered | Try ACK scan or different approach |
This guide covers the essential Nmap knowledge needed for the OSCP exam. Practice these commands in the Proving Grounds or TryHackMe labs to build muscle memory before exam day.