
Nmap Cheatsheet
Nmap (Network Mapper) is a powerful open-source tool I use for network discovery, port scanning, and security auditing. It's essential in ethical hacking, penetration testing, and system administration for identifying hosts, open ports, services, and potential vulnerabilities across networks. My experience with Nmap includes using advanced features like the Nmap Scripting Engine (NSE) for automation and detailed reconnaissance, helping ensure networks are secure and well-documented.
Nmap Is One of the Essentials
Nmap is typically one of the first tools I reach for during a security assessment (when applicable). It serves as a foundational utility in any cybersecurity professional’s toolkit, offering powerful capabilities for network discovery, port scanning, and service enumeration.
Key Features of Nmap:
- Host Discovery: Identifies devices on a network (e.g., ping sweeps).
- Port Scanning: Determines which ports are open on a target system.
- Service Detection: Identifies applications or services running on open ports.
- OS Detection: Attempts to determine the operating system of a target host.
- Scriptable Interaction: Uses the Nmap Scripting Engine (NSE) for custom vulnerability detection, backdoor detection, and advanced reconnaissance.
- Flexible Output: Supports multiple output formats (e.g., plain text, XML, grepable).
Common Use Cases:
- Mapping a network's topology.
- Detecting unauthorized devices or services.
- Finding vulnerable open ports.
- Conducting penetration tests.
Commands
Basic Commands
Command | Description |
---|---|
nmap -sP 127.0.0.1/24 | Ping scan to find live hosts in the subnet. |
nmap -p 1-65535 -sV -sS -T4 {target} | Scan all ports on the target with service version detection. |
nmap -v -sS -A -T4 {target} | Verbose scan with OS detection, service version detection, and script scanning. |
nmap -v -sS -A -T5 {target} | Aggressive scan with maximum speed. |
nmap -v -sV -O -sS -T5 {target} | Verbose scan with service version detection and OS detection. |
nmap -v -p 1-65535 -sV -O -sS -T4 {target} | Scan all ports with service version detection and OS detection. |
nmap -v -p 1-65535 -sV -O -sS -T5 {target} | Aggressive scan of all ports with service version detection and OS detection. |
Useful Commands
Flags
Basic Flags
Command | Description |
---|---|
nmap -sP 127.0.0.1/24 | Ping scan to find live hosts in the subnet. |
nmap -p 1-65535 -sV -sS -T4 {target} | Scan all ports on the target with service version detection. |
nmap -v -sS -A -T4 {target} | Verbose scan with OS detection, service version detection, and script scanning. |
nmap -v -sS -A -T5 {target} | Aggressive scan with maximum speed. |
nmap -v -sV -O -sS -T5 {target} | Verbose scan with service version detection and OS detection. |
nmap -v -p 1-65535 -sV -O -sS -T4 {target} | Scan all ports with service version detection and OS detection. |
nmap -v -p 1-65535 -sV -O -sS -T5 {target} | Aggressive scan of all ports with service version detection and OS detection. |
Flags for Various Scanning Techniques
Flag | Description |
---|---|
-sS | TCP SYN scan (stealth scan). |
-sT | TCP connect scan (full TCP handshake). |
-sA | TCP ACK scan (to map firewall rules). |
-sW | TCP Window scan (to determine open ports). |
-sM | TCP Maimon scan (stealth scan). |
Flag | Description |
---|---|
-sU | UDP scan. |
Flag | Description |
---|---|
-sN | TCP Null scan (no flags set). |
-sF | TCP FIN scan (only FIN flag set). |
-sX | TCP Xmas scan (FIN, PSH, URG flags set). |
Flag | Description |
---|---|
--scanflags | Custom TCP flags. |
Flag | Description |
---|---|
-sI zombie host[:probeport] | Idle scan (uses a third-party host to scan). |
Flag | Description |
---|---|
-sY | SCTP INIT scan. |
-sZ | SCTP COOKIE-ECHO scan. |
Flag | Description |
---|---|
-sO | IP protocol scan. |
Flag | Description |
---|---|
-b {ftp relay} | FTP bounce scan (uses an FTP server to scan). |
Flags for Port Specification and Scan Order
Flag | Description |
---|---|
-p {port range} | Specify ports to scan (e.g., -p 22,80,443 ). |
-p- | Scan all 65535 ports. |
-p U:{PORT} | Scan UDP ports. |
-F | Fast scan (scan fewer ports). |
-r | Scan ports in numerical order. |
--top-ports {number} | Scan the top N most common ports. |
--port-ratio {ratio} | Scan ports based on a specified ratio. |
Flags for Service and Version Detection
Flag | Description |
---|---|
-sV | Enable service version detection. |
--version-intensity {level} | Set the intensity level for version detection (0-9). |
--version-light | Use a light version detection scan. |
--version-all | Use all version detection probes. |
--version-trace | Show detailed version detection information. |
Flags for Script Scans
Flag | Description |
---|---|
-sC | Use the default set of scripts. |
--script={script} | Specify a specific script to run. |
--script-args=n1=v1,[n2=v2,...] | Pass arguments to scripts. |
--script-trace | Show detailed script execution information. |
--script-updatedb | Update the script database. |
--script-help | Show help for a specific script. |
Flags for OS Detection
Flag | Description |
---|---|
-O | Enable OS detection. |
--osscan-limit | Limit OS detection to open/filtered ports. |
--osscan-guess | Guess OS if not confident. |
Flags for Timing and Performance
Flag | Description |
---|---|
-T{0-5} | Set timing template (0=paranoid, 5=insane). |
--min-hostgroup {number} | Set minimum number of hosts per group. |
--max-hostgroup {number} | Set maximum number of hosts per group. |
--min-parallelism {number} | Set minimum number of parallel probes. |
--max-parallelism {number} | Set maximum number of parallel probes. |
--min-rtt-timeout {time} | Set minimum RTT timeout. |
--max-rtt-timeout {time} | Set maximum RTT timeout. |
--initial-rtt-timeout {time} | Set initial RTT timeout. |
--max-retries {number} | Set maximum number of retransmissions. |
--host-timeout {time} | Set timeout for host scan. |
--scan-delay {time} | Set delay between probes. |
--max-scan-delay {time} | Set maximum delay between probes. |
--min-rate {number} | Set minimum packet send rate. |
--max-rate {number} | Set maximum packet send rate. |
Flags for Firewalls IDS Evasion and Spoofing
Flag | Description |
---|---|
-f; --mtu {number} | Fragment packets to evade firewalls. |
-D {decoy} | Use decoy scanning to hide the source. |
-S {IP} | Spoof source address. |
-e {interface} | Use a specific network interface. |
-g {port} | Use a specific port for source routing. |
--source-port {port} | Use a specific source port. |
--proxies {url1,url2,...} | Use HTTP/SOCKS4 proxies. |
--data-length {number} | Append random data to packets. |
--ip-options {options} | Set custom IP options. |
--ttl {number} | Set the Time to Live (TTL) value. |
--spoof-mac {MAC} | Spoof the MAC address. |
--badsum | Send invalid TCP checksums. |
Flags for Output File Options
Flag | Description |
---|---|
-oN {file} | Output in normal format. |
-oX {file} | Output in XML format. |
-oG {file} | Output in greppable format. |
-oA {basename} | Output in all formats (normal, XML, greppable). |
-oS {file} | Output in script kiddie format. |
-v | Increase verbosity level. |
-d | Increase debugging level. |
--reason | Display the reason a port is in a particular state. |
--open | Only show open or possibly open ports. |
--packet-trace | Show all packets sent/received. |
--iflist | Print host interfaces and routes for debugging. |
--log-errors | Log errors/warnings to the normal-format output file. |
--append-output | Append to rather than clobber specified output files. |
--resume {filename} | Resume an aborted scan. |
--stylesheet {path/url} | XSL stylesheet to transform XML output to HTML. |
--webxml | Reference stylesheet from Nmap.Org for more portable XML. |
--no-stylesheet | Prevent associating of XSL stylesheet with XML output. |
Miscellaneous Flags
Flag | Description |
---|---|
-h | Show help message. |
-V | Show version information. |
-6 | Enable IPv6 scanning. |
-A | Enable OS detection, version detection, script scanning, and traceroute. |
--datedir {directory} | Use a specific directory for Nmap data files. |
--send-eth | Send raw Ethernet frames. |
--send-ip | Send raw IP packets. |
--privileged | Use privileged ports. |
--unprivileged | Use unprivileged ports. |
Parsing Commands
Command | Description |
---|---|
grep -oP '\d+/tcp\s+open' {file} | cut -d '/' -f1 | paste -sd, | Extract open TCP ports from the Nmap output file. |
Rustscan
RustScan is a modern, fast, and efficient port scanner written in Rust. It was created to significantly improve the speed of traditional port scanning by optimizing the scanning process and leveraging Rust's performance and safety. bee-san/RustScan 16.7K
RustScan uses Nmap
Commands after the --
are passed to Nmap, allowing you to use RustScan as a fast port scanner that integrates seamlessly with Nmap's powerful features.
The following is a basic example of how to use RustScan:
Help
Help
Last updated on
Tools
As a Offensive Security engineer, I rely on a curated set of tools to perform comprehensive security assessments across networks, web applications, and systems. This section provides a categorized overview of the tools I regularly use during red teaming, vulnerability assessments, and exploit development.
Sliver C2 Cheatsheet
A complete and practical cheatsheet for Sliver, the open-source Command and Control (C2) framework used by red teams and penetration testers for secure post-exploitation, beaconing, and multi-platform payload delivery.