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 -sn for quick reconnaissance to identify live hosts.

  • -Pn is ideal when hosts block ping requests (e.g., firewalled environments).

  • Combine -PR with 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 -iL for large-scale scans with a pre-prepared list of targets.

  • --exclude is 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:

  • -sS is the go-to for most scans due to its speed and stealth (doesn’t complete TCP handshake).

  • Use -sU for services like DNS, SNMP, or DHCP, but expect slower scans.

  • Combine -sA or -sW to understand firewall behaviour.


Port Specification

Control which ports to scan, from specific ports to all 65,535 ports.

Tips:

  • Use -F for 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 -T4 for LANs or trusted networks; -T5 risks inaccurate results.

  • --host-timeout prevents scans from hanging on unresponsive hosts.

  • Fine-tune --min-rate and --max-rate for congested networks to avoid packet loss.


Service and Version Detection

Identify services and their versions running on open ports.

Tips:

  • -sV is essential for identifying vulnerable software versions.

  • Use --version-light for speed, --version-all for thoroughness.

  • -A is a comprehensive option for detailed reconnaissance.


OS Detection

Identify the operating system and its version on target hosts.

Tips:

  • Combine -O with -sV for a complete system profile.

  • --osscan-guess is 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 -f or --mtu to 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 -sC for safe, default scripts during initial scans.

  • --script vuln is great for identifying known vulnerabilities but requires -sV for 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 -oA to save in multiple formats for flexibility.

  • XML output (-oX) is ideal for integration with tools like Metasploit or custom scripts.

  • Use --append-output to 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 -sV and -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, or nmaptocsv.

  • Filter Results: Run grep open <file> on grepable output to quickly identify active services.


Best Practices

  1. Start Simple: Use -sn or -F for quick scans before diving into detailed scans.

  2. Stay Legal: Always obtain permission before scanning networks you don’t own.

  3. Combine Flags: Use -sS -sV -O for a balanced scan with port, service, and OS detection.

  4. Optimise Principled: Avoid intrusive scripts unless you have explicit permission.

  5. Optimise Performance: Adjust timing (-T) and parallelism based on network conditions.

  6. 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