Nmap Cheat Sheet 2024

Nmap Cheat Sheet

Welcome to my Nmap Cheat Sheet page! Nmap is one of my favorite tools not only for pentesting or security purposes but also as one of my go-to troubleshooting tools.  

 

Nmap 2.00 was released on December 12, 1998Can you believe it?   I have been using Nmap since the early 2000s, and although I have tried MANY tools that do the same thing, nothing has yet to beat its place in my toolbox.

 

If you see an error, something I missed, or have a better way of doing something, please contact me.

Resources:

Nmap – https://nmap.org/ – Offical Nmap website

The Nmap Handbook: A Deep Dive into Network Mapping and Scanning – Great Reference with real-world up-to-date examples.

The Official Nmap Project Guide to Network Discovery and Security Scanning The orginal and still one of the best Nmap resources

 

Scanning Command Syntax:

nmap [scan types] [options] {IP-Address specification}

Scan a
Specific Target

SWITCHEXAMPLEDESCRIPTION
 nmap 10.1.1.1Scan a single IP
 nmap 10.1.1.1 10.1.1.8Scan specific IPs
 nmap 10.1.1.1-254Scan a range
 nmap scanme.nmap.orgScan a domain
 nmap 10.1.1.0/24Scan using CIDR notation
-iLnmap -iL targets.txtScan targets from a file
-iRnmap -iR 100Scan 100 random hosts
-excludenmap -exclude 10.1.1.254Exclude listed hosts

Nmap Scan Techniques

SWITCHEXAMPLEDESCRIPTION
-sSnmap 10.1.1.1 -sSTCP SYN port scan (Default)
-sTnmap 10.1.1.1 -sTTCP connect port scan (Default without root privilege)
-sUnmap 10.1.1.1 -sUUDP port scan
-sAnmap 10.1.1.1 -sATCP ACK port scan
-sWnmap 10.1.1.1 -sWTCP Window port scan
-sMnmap 10.1.1.1 -sMTCP Maimon port scan

Host Discovery

SWITCHEXAMPLEDESCRIPTION
-sLnmap 10.1.1.1-3 -sLNo Scan. List targets only
-snnmap 10.1.1.0/24 -snDisable port scanning. Host discovery only.
-Pnnmap 10.1.1.1-5 -PnDisable host discovery. Port scan only.
-PSnmap 10.1.1.1-5 -PS22-25,80TCP SYN discovery on port x.
Port 80 by default
-PAnmap 10.1.1.1-5 -PA22-25,80TCP ACK discovery on port x.
Port 80 by default
-PUnmap 10.1.1.1-5 -PU53UDP discovery on port x.
Port 40125 by default
-PRnmap 10.1.1.1-1/24 -PRARP discovery on local network
-nnmap 10.1.1.1 -nNever do DNS resolution

Port Specification

SWITCHEXAMPLEDESCRIPTION
-sVnmap 10.1.1.1 -sVAttempts to determine the version of the service running on port
-sV -version-intensitynmap 10.1.1.1 -sV -version-intensity 8Intensity level 0 to 9. Higher number increases possibility of correctness
-sV -version-lightnmap 10.1.1.1 -sV -version-lightEnable light mode. Lower possibility of correctness. Faster
-sV -version-allnmap 10.1.1.1 -sV -version-allEnable intensity level 9. Higher possibility of correctness. Slower
-Anmap 10.1.1.1 -AEnables OS detection, version detection, script scanning, and traceroute

OS Detection

SWITCHEXAMPLEDESCRIPTION
-Onmap 10.1.1.1 -ORemote OS detection using TCP/IP stack fingerprinting
-O -osscan-limitnmap 10.1.1.1 -O -osscan-limitIf at least one open and one closed TCP port are not found it will not try OS detection against host
-O -osscan-guessnmap 10.1.1.1 -O -osscan-guessMakes Nmap guess more aggressively
-O -max-os-triesnmap 10.1.1.1 -O -max-os-tries 1Set the maximum number x of OS detection tries against a target
-Anmap 10.1.1.1 -AEnables OS detection, version detection, script scanning, and traceroute

Timing and Performance

SWITCHEXAMPLEDESCRIPTION
-T0nmap 10.1.1.1 -T0Paranoid (0) Intrusion Detection System evasion
-T1nmap 10.1.1.1 -T1Sneaky (1) Intrusion Detection System evasion
-T2nmap 10.1.1.1 -T2Polite (2) slows down the scan to use less bandwidth and use less target machine resources
-T3nmap 10.1.1.1 -T3Normal (3) which is default speed
-T4nmap 10.1.1.1 -T4Aggressive (4) speeds scans; assumes you are on a reasonably fast and reliable network
-T5nmap 10.1.1.1 -T5Insane (5) speeds scan; assumes you are on an extraordinarily fast network

Timing and Performance Switches

SWITCHEXAMPLE INPUTDESCRIPTION
-host-timeout <time>1s; 4m; 2hGive up on target after this long
-min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>1s; 4m; 2hSpecifies probe round trip time
-min-hostgroup/max-hostgroup <size<size>50; 1024Parallel host scan group sizes
-min-parallelism/max-parallelism <numprobes>10; 1Probe parallelization
-max-retries <tries>3Specify the maximum number of port scan probe retransmissions
-min-rate <number>100Send packets no slower than <number> per second
-max-rate <number>100Send packets no faster than <number> per second

NSE Scripts

SWITCHEXAMPLEDESCRIPTION
-sCnmap 10.1.1.1 -sCScan with default NSE scripts. Considered useful for discovery and safe
-script defaultnmap 10.1.1.1 -script defaultScan with default NSE scripts. Considered useful for discovery and safe
-scriptnmap 10.1.1.1 -script=bannerScan with a single script. Example banner
-scriptnmap 10.1.1.1 -script=http*Scan with a wildcard. Example http
-scriptnmap 10.1.1.1 -script=http,bannerScan with two scripts. Example http and banner
-scriptnmap 10.1.1.1 -script “not intrusive”Scan default, but remove intrusive scripts
-script-argsnmap -script snmp-sysdescr -script-args snmpcommunity=admin 10.1.1.1NSE script with arguments

NSE Script Examples

COMMANDDESCRIPTION
nmap -Pn -script=http-sitemap-generator scanme.nmap.orghttp site map generator
nmap -n -Pn -p 80 -open -sV -vvv -script banner,http-title -iR 1000Fast search for random web servers
nmap -Pn -script=dns-brute domain.comBrute forces DNS hostnames guessing subdomains
nmap -n -Pn -vv -O -sV -script smb-enum*,smb-ls,smb-mbenum,smb-os-discovery,smb-s*,smb-vuln*,smbv2* -vv 10.1.1.1Safe SMB scripts to run
nmap -script whois* domain.comWhois query
nmap -p80 -script http-unsafe-output-escaping scanme.nmap.orgDetect cross site scripting vulnerabilities
nmap -p80 -script http-sql-injection scanme.nmap.orgCheck for SQL injections

Firewall / IDS Evasion

SWITCHEXAMPLEDESCRIPTION
-fnmap 10.1.1.1 -fRequested scan (including ping scans) use tiny fragmented IP packets. Harder for packet filters
-mtunmap 10.1.1.1 -mtu 32Set your own offset size
-Dnmap -D 10.1.1.101,10.1.1.102,10.1.1.103,10.1.1.23 10.1.1.1Send scans from spoofed IPs
-Dnmap -D decoy-ip1,decoy-ip2,your-own-ip,decoy-ip3,decoy-ip4 remote-host-ipAbove example explained
-Snmap -S www.twitter.com www.facebook.comScan Facebook from twitter (-e eth0 -Pn may be required)
-gnmap -g 53 10.1.1.1Use given source port number
-proxiesnmap -proxies http://10.1.1.1::8080, http://10.1.1.2:8080 10.1.1.1Relay connections through HTTP/SOCKS4 proxies
-data-lengthnmap -data-length 200 10.1.1.1Appends random data to sent packets

Output Control

SWITCHEXAMPLEDESCRIPTION
-oNnmap 10.1.1.1 -oN normal.fileNormal output to the file normal.file
-oXnmap 10.1.1.1 -oX xml.fileXML output to the file xml.file
-oGnmap 10.1.1.1 -oG grep.fileGrepable output to the file grep.file
-oAnmap 10.1.1.1 -oA resultsOutput in the three major formats at once
-oG –nmap 10.1.1.1 -oG –Grepable output to screen. -oN -, -oX – also usable
-append-outputnmap 10.1.1.1 -oN file.file -append-outputAppend a scan to a previous scan file
-vnmap 10.1.1.1 -vIncrease the verbosity level (use -vv or more for greater effect)
-dnmap 10.1.1.1 -dIncrease debugging level (use -dd or more for greater effect)
-reasonnmap 10.1.1.1 -reasonDisplay the reason a port is in a particular state, same output as -vv
-opennmap 10.1.1.1 -openOnly show open (or possibly open) ports
-packet-tracenmap 10.1.1.1 -T4 -packet-traceShow all packets sent and received
-iflistnmap -iflistShows the host interfaces and routes
-resumenmap -resume results.fileResume a scan

Nmap Output Examples

COMMANDDESCRIPTION
nmap -p80 -sV -oG – -open 10.1.1.1/24 | grep openScan for web servers and grep to show which IPs are running web servers
nmap -iR 10 -n -oX out.xml | grep “Nmap” | cut -d ” ” -f5 > live-hosts.txtGenerate a list of the IPs of live hosts
nmap -iR 10 -n -oX out2.xml | grep “Nmap” | cut -d ” ” -f5 >> live-hosts.txtAppend IP to the list of live hosts
ndiff scanl.xml scan2.xmlCompare output from nmap using the ndif
xsltproc nmap.xml -o nmap.htmlConvert nmap xml files to html files
grep ” open ” results.nmap | sed -r ‘s/ +/ /g’ | sort | uniq -c | sort -rn | lessReverse sorted list of how often ports turn up

Misc Nmap Flags

SWITCHEXAMPLEDESCRIPTION
-6nmap -6 2607:f0d0:1002:51::3Enable IPv6 scanning
-hnmap -hnmap help screen
-opennmap -openShow open ports only

Useful Nmap Commands

COMMANDDESCRIPTION
nmap -iR 10 -PS22-25,80,113,1050,35000 -v -snDiscovery only on ports x, no port scan
nmap 192.168.1.1-1/24 -PR -sn -vvArp discovery only on local network, no port scan
nmap -iR 10 -sn -tracerouteTraceroute to random targets, no port scan
nmap 192.168.1.1-50 -sL -dns-server 192.168.1.1Query the Internal DNS for hosts, list targets only

nmap 192.168.1.1 –packet-trace

Show the details of the packets that are sent and received during a scan and capture the traffic

Pings and Traceroutes

COMMANDDESCRIPTION
nmap -sP 10.1.1.1Ping scan only
nmap -PU 10.1.1.1UDP ping scan
nmap -PE 10.1.1.1ICMP echo ping
nmap -PO 10.1.1.1IP protocal ping
nmap -PR 10.1.1.1ARP ping
nmap -Pn 10.1.1.1Scan without pinging
nmap -traceroute 10.1.1.1Traceroute