If penetration testing tools were superheroes, Nmap would be Batman - no superpowers, just incredible utility and preparation. Short for "Network Mapper," Nmap is arguably the most important tool in any pentester's arsenal. It discovers hosts, scans ports, detects services, and even finds vulnerabilities.
Created in 1997 by Gordon Lyon (Fyodor), Nmap has appeared in countless movies (The Matrix Reloaded, anyone?) and is used by everyone from script kiddies to nation-state actors. Understanding Nmap isn't just useful - it's essential.
Nmap is Free
Understanding TCP (The Foundation)
Before diving into Nmap, you need to understand TCP handshakes. When two computers establish a TCP connection, they perform a "three-way handshake":
- SYN: Client sends a synchronize packet
- SYN-ACK: Server responds with synchronize-acknowledge
- ACK: Client sends acknowledge, connection established
Nmap exploits this handshake in various ways to determine port states without completing full connections.
Port States
Nmap reports ports in six possible states:
- Open: Application is accepting connections
- Closed: Port accessible but no application listening
- Filtered: Firewall blocking - can't determine state
- Unfiltered: Accessible but open/closed undetermined
- Open|Filtered: Open or filtered, can't tell which
- Closed|Filtered: Closed or filtered, can't tell which
Filtered is Interesting
Scan Types
TCP SYN Scan (-sS) - The Default
The "stealth scan" sends SYN packets and analyzes responses without completing the handshake. Fast, reliable, and harder to detect.
TCP Connect Scan (-sT)
Completes the full TCP handshake. More detectable but doesn't require root. Use when you can't run as root or need full connections.
UDP Scan (-sU)
UDP has no handshake - it's like shouting into a void and hoping someone answers. Much slower than TCP scanning but essential for services like DNS, SNMP, and DHCP.
UDP is Slow
Stealth Scans (FIN, NULL, Xmas)
These scans exploit TCP specification quirks to evade simple firewalls. They don't work against Windows (which doesn't follow spec) but can be useful against Unix systems.
Port Specification
The Magic Numbers
Service & Version Detection
Version Detection Takes Time
Nmap Scripting Engine (NSE)
NSE transforms Nmap from a port scanner into a full vulnerability scanner. It comes with 600+ scripts for everything from banner grabbing to exploit checking.
Useful Script Categories
- auth: Authentication bypass and testing
- broadcast: Network discovery via broadcast
- brute: Brute force attacks
- default: Safe, useful scripts
- discovery: Service and host discovery
- exploit: Active exploitation
- safe: Won't crash services or use exploits
- vuln: Vulnerability checking
Be Careful with Exploit Scripts
Output Formats
Always Save Output
Timing & Performance
T4 for CTFs, T3 for Real Life
Common Command Combinations
Scanning Methodology
Nmap Scanning Process
Knowledge Check
Challenges
Key Takeaways
- Nmap is THE essential network scanning tool - master it
- SYN scan (-sS) is default and stealthiest for port scanning
- Always scan all ports (-p-) for thorough assessments
- Service detection (-sV) reveals versions for vulnerability research
- NSE scripts (-sC or --script) extend Nmap into vulnerability scanning
- Save output (-oA) in all formats for later analysis
- T4 timing is good for labs, T3 for production