Comprehensive Cheatsheet for Nmap: Your Go-To Tool for Network Security Analysis

πŸ“± Mobile Security Tips

Sarah Chen — iOS Security Specialist

What is Nmap?

Nmap (Network Mapper) is an open-source tool designed for network discovery and security auditing. It’s widely used by security professionals to discover hosts and services on a computer network, thus creating a ‘map’ of the network. Nmap is versatile and capable of performing a range of tasks, from simple host discovery to complex network scanning and vulnerability identification.

Installation

To install Nmap, you can either compile it from source or install a pre-compiled version via your package manager.

  • On Debian/Ubuntu: sudo apt install nmap
  • On CentOS/RHEL: sudo yum install nmap
  • On macOS: brew install nmap

Basic Syntax

The basic syntax of Nmap is as follows:

nmap [Scan Type(s)] [Options] {target specification}

Where target specification can be an IP address, hostname, or subnet.

Discovery

Utilizing Nmap for host discovery helps identify active devices on your network.

  • nmap -sn 192.168.1.0/24 – Conducts a ping scan to discover live hosts in the subnet.
  • nmap -sP 192.168.1.1-50 – Scans a range of IPs to discover which hosts are active.

Scanning

Scanning involves probing discovered hosts to gather more detailed information about their open ports and services.

  • nmap -sS -p 1-65535 192.168.1.1 – Conducts a SYN scan on all ports of the given IP.
  • nmap -sV 192.168.1.1 – Detects versions of services running on open ports.

Exploitation

While Nmap is not an exploitation tool, it can provide crucial information for identifying vulnerabilities.

  • nmap --script vuln 192.168.1.1 – Runs vulnerability scripts against the target.

Analysis

For deeper analysis, Nmap allows you to export results in various formats.

  • nmap -oN output.txt 192.168.1.1 – Saves the scan results in a normal text file.
  • nmap -oX output.xml 192.168.1.1 – Outputs results in XML format, suitable for further processing.

Evasion

When stealth is necessary, Nmap supports various evasion techniques.

  • nmap -D RND:5 192.168.1.1 – Uses decoy packets to obscure the origin of the scan.
  • nmap -T0 192.168.1.1 – Performs a scan at a slow pace to avoid detection by IDS/IPS.

Reporting

For reporting purposes, combine Nmap’s output formats for comprehensive documentation.

  • nmap -oN output.txt -oX output.xml 192.168.1.1 – Outputs results in both text and XML formats simultaneously.

Quick Reference Table

Flag Description
-sn Ping scan
-sS SYN scan
-sV Service version detection
–script vuln Run vulnerability detection scripts
-oN Normal output
-oX XML output
-D Decoy scan
-T Timing template

Pro Tips

  • Always run as a non-privileged user first to avoid triggering alarms, using the `-sP` option.
  • Combine scanning flags for a more comprehensive attack surface analysis.
  • Utilize the Nmap Scripting Engine (NSE) for advanced scriptable interactions.
  • Review the Nmap Book and online resources regularly to stay updated on the latest scripts and functionalities.

Real-World Examples

Example 1: Simple Network Audit

nmap -sS -sV -O -oN simple_audit.txt 192.168.1.0/24

This command performs a SYN scan, detects services and OS information, and exports the results to a text file.

Example 2: Stealthy Ports Scan

nmap -sS -T0 -p 1-1024 192.168.1.1

This command scans the first 1024 ports quietly to evade detection.