Nmap Scanning Basics
Nmap (Network Mapper) is a powerful open-source tool for network exploration, security auditing, and reconnaissance. It allows users to discover hosts, services, operating systems, and vulnerabilities on a network. This cheat sheet organises Nmap’s key commands and flags into categories, with explanations and practical tips to help you use them effectively. Use this guide for quick reference during network scanning tasks, whether you're performing host discovery, port scanning, or advanced vulnerability assessments.
Host Discovery
Host discovery identifies live hosts on a network before performing detailed scans. These flags help determine which hosts are active without necessarily scanning ports.
-sL nmap 192.168.1.1-3 -sL # Lists targets without scanning (useful for planning)
-sn nmap 192.168.1.1/24 -sn # Ping scan, disables port scanning (quick host check)
-Pn nmap 192.168.1.1-5 -Pn # Skips host discovery, assumes hosts are up (use for firewalled networks)
-PS nmap 192.168.1.1-5 -PS22-25,80 # TCP SYN discovery on specified ports (e.g., 22, 23, 24, 25, 80)
-PA nmap 192.168.1.1-5 -PA22-25,80 # TCP ACK discovery (bypasses some firewalls)
-PU nmap 192.168.1.1-5 -PU53 # UDP discovery on port 53 (common for DNS servers)
-PR nmap 192.168.1.0/24 -PR # ARP discovery for local networks (fast and reliable)
-n nmap 192.168.1.1 -n # Disables DNS resolution (speeds up scans)Tips:
Use
-snfor quick reconnaissance to identify live hosts.-Pnis ideal when hosts block ping requests (e.g., firewalled environments).Combine
-PRwith local network scans for faster results, as ARP is more reliable than ICMP.
Target Specification
Define which hosts or networks to scan. Nmap supports various input formats for flexibility.
Tips:
Use
-iLfor large-scale scans with a pre-prepared list of targets.--excludeis useful to avoid sensitive systems (e.g., critical servers).CIDR notation (
/24) is efficient for scanning entire subnets.
Scan Techniques
Choose the type of scan based on your goals, network conditions, and stealth requirements.
Tips:
-sSis the go-to for most scans due to its speed and stealth (doesn’t complete TCP handshake).Use
-sUfor services like DNS, SNMP, or DHCP, but expect slower scans.Combine
-sAor-sWto understand firewall behaviour.
Port Specification
Control which ports to scan, from specific ports to all 65,535 ports.
Tips:
Use
-Ffor quick scans when time is limited.-p-is thorough but time-consuming; use it for critical systems.Specify service names (
http,https) for readability and flexibility.
Timing and Performance
Adjust scan speed and behaviour to balance accuracy, stealth, and performance.
Tips:
Use
-T4for LANs or trusted networks;-T5risks inaccurate results.--host-timeoutprevents scans from hanging on unresponsive hosts.Fine-tune
--min-rateand--max-ratefor congested networks to avoid packet loss.
Service and Version Detection
Identify services and their versions running on open ports.
Tips:
-sVis essential for identifying vulnerable software versions.Use
--version-lightfor speed,--version-allfor thoroughness.-Ais a comprehensive option for detailed reconnaissance.
OS Detection
Identify the operating system and its version on target hosts.
Tips:
Combine
-Owith-sVfor a complete system profile.--osscan-guessis useful when OS detection is uncertain but may produce less accurate results.
Firewall / IDS Evasion and Spoofing
Bypass firewalls and intrusion detection systems (IDS) with these techniques.
Tips:
Use
-for--mtuto fragment packets and bypass simple firewalls.-D(decoy scan) floods the target with fake scans to obscure your IP.Test spoofing (
-S, -g) in controlled environments, as it may require specific permissions.
NSE (Nmap Scripting Engine) Scripts
Leverage Nmap’s scripting engine for advanced tasks like vulnerability scanning and enumeration.
Example NSE Scripts:
Web App-Specific NSE Scripts:
Advanced NSE Script Usage:
Vulnerability Scanning Scripts:
Tips:
Use
-sCfor safe, default scripts during initial scans.--script vulnis great for identifying known vulnerabilities but requires-sVfor best results.Be cautious with intrusive scripts (e.g., brute-forcing) to avoid disrupting services.
Output Options
Save scan results in various formats for analysis or reporting.
Tips:
Use
-oAto save in multiple formats for flexibility.XML output (
-oX) is ideal for integration with tools like Metasploit or custom scripts.Use
--append-outputto avoid overwriting previous scans.
Scan Output Analysis & Tips
Maximise the value of your scan results with these strategies:
Focus on Open Ports: Prioritise services like HTTP, SMB, or FTP for further enumeration.
Understand Port States:
Open: Service is running and accepting connections.
Closed: Port responds, but no service is running.
Filtered: Likely firewalled, no response received.
Use
-sVand-A: Combine for detailed service and OS information.Enable
--reason: Shows why ports are marked open, closed, or filtered.Save Everything: Use -oA to store results for later analysis with tools like
grep, xsltproc, ornmaptocsv.Filter Results: Run g
rep open <file>on grepable output to quickly identify active services.
Best Practices
Start Simple: Use
-snor-Ffor quick scans before diving into detailed scans.Stay Legal: Always obtain permission before scanning networks you don’t own.
Combine Flags: Use
-sS -sV -Ofor a balanced scan with port, service, and OS detection.Optimise Principled: Avoid intrusive scripts unless you have explicit permission.
Optimise Performance: Adjust timing (
-T) and parallelism based on network conditions.Review Output: Regularly analyse results to identify next steps (e.g., manual testing of vulnerabilities).
For additional cheatsheets and Nmap guides, visit StationX Nmap Cheat Sheet
Last updated