Nmap is a powerful enumeration tool for auditing, checking configurations, network mapping, identifying open ports, and vulnerability assessment. It can do host discovery, port scanning, service detection, OS detection, and scriptable interaction scans.

# Full TCP scan
sudo nmap -sS -v -p- -oA full_results <IP>
 
# Versioning specific ports
sudo nmap -sV -sC -p <Ports,> -oA versioning_results <IP>
-oA <filename>Save results
-sVScan versions
-sUUDP scan
-sSTCP partial scan
-sTTCP full scan
-sAACK scan for firewalls
-OOS version scan
-v/-vvSet verbose level
--reasonDisplay reasoning
-iL <filename>Scan targets in file
-T <0-5>Speed/aggression increasing
--max-retries <retries>Number of retries, defaults to 10
--min-rate <rate>Minimum rate speed when known
-D RND:<number>Generate random IP source addresses
-e <interface>Use specific interface
-nDisable DNS
-PnDisable ICMP echo
--disable-arp-pingDisable ARP ping
-S <ip>Use IP as source
--source-port <port>Use port as source
--dns-server <ns>Set a specific DNS server

Host Discovery

The -sn flag disables port scanning to just check the host. Multiple IPs can be specified with CIDR, a file, or a range.

Port Scanning

Nmap scans the top 1000 TCP ports with SYN scan by default as root or a TCP scan (-sT) as user. Specific ports can be set one by one (-p 80,445), range (-p 22-445), or all ports

TCP Scan

The -sS TCP-SYN scan is a default and common method that partially completes the SYN-ACK handshake. If the port sends back SYN-ACK, the port is open. If the port sends RST, the port is closed. If no packet is sent, the port is filtered.

The -sT TCP connect scan uses the full handshake to verify the port, but it is not stealthy.

UDP Scan

Because -sU UDP is stateless without an acknowledgment, these scans take longer than TCP scans.

Saving Results

Saving the scan results (-oA <filename>) allows for later comparison. This saves it in three formats, the typical Nmap output (-oN), a grepable version (-oG), and an XML version (-oX). The XML format is useful to generate HTML reports, like with xsltproc.

Scripting Engine

The Nmap Scripting Engine allows you to create Lua scripts for specific service interactions. The default scripts can be run with -sC, and a category can be specified with --script <category> from the categories below.

CategoryDescription
authAuthentication
broadcastHost discovery
bruteBrute-forcing credentials
defaultDefault scripts
discoveryOpen services
dosDenial of service vulnerabilities
exploitExploiting known vulnerabilities
externalUsing external services
fuzzerSending different fields
intrusiveIntrusive scripts
malwareScanning for some malware
safeNon-intrusive scripts
versionFurther service versioning
vulnIdentifying specific vulnerabilities

Useful Scripts

ScriptDescription
smtp-open-relaySMTP Protocol
smtp-enum-usersSMTP Protocol