Skip to content

Cheatsheet · Infrastructure and AD pentesting · Web pentesting

Nmap: from host discovery to service enumeration

Copy-ready Nmap commands: host discovery, TCP and UDP port scanning, version detection, NSE scripts and output formats for your reports.

By Steven Carrier Published

Official website: Nmap

Nmap is still where almost every network penetration test begins. The commands below follow the order of an engagement: find live hosts, list their ports, identify services, then dig deeper with NSE scripts. Replace 10.0.0.0/24, 10.0.0.12 and target.example with your authorised scope, agreed beforehand using the penetration test scoping checklist.

Discover live hosts

# Host discovery only, no port scan
nmap -sn 10.0.0.0/24

# List the targets in a range without contacting them (scope check)
nmap -sL -n 10.0.0.0/24

# Treat the host as up (ICMP blocked by a firewall)
nmap -Pn 10.0.0.12

# Targets read from a file, with exclusions
nmap -sn -iL scope.txt --excludefile exclusions.txt

On a local network, -sn relies on ARP and is reliable. Remotely, if ICMP is filtered, combine several probes: -PS22,80,443 -PA80 -PE.

Scan ports

# The 1,000 most common TCP ports, SYN scan (root required)
sudo nmap -sS 10.0.0.12

# Every TCP port
sudo nmap -sS -p- 10.0.0.12

# Specific ports, or the 100 most common
nmap -p 22,80,443,8080 10.0.0.12
nmap --top-ports 100 10.0.0.12

# The most common UDP ports (slow: keep the list short)
sudo nmap -sU --top-ports 50 10.0.0.12

# TCP connect scan, no root required
nmap -sT 10.0.0.12
State Meaning
open a service is listening on the port
closed the port responds, but nothing is listening
filtered no response: filtering is likely
open|filtered cannot tell, common with UDP

Identify services and versions

# Service versions on open ports
nmap -sV 10.0.0.12

# Operating system detection (root required)
sudo nmap -O 10.0.0.12

# Versions, default scripts, OS and traceroute
sudo nmap -A 10.0.0.12

-A is handy in a lab, but noisy. On an engagement, prefer -sV -sC on the open ports found in the previous step only.

Go further with NSE scripts

# Scripts in the "default" category
nmap -sC -p 22,80,443 10.0.0.12

# Specific scripts
nmap -p 443 --script ssl-enum-ciphers target.example
nmap -p 80 --script http-title,http-headers 10.0.0.12

# A combination of non-intrusive categories
nmap --script "safe and discovery" 10.0.0.12

# Help for a script
nmap --script-help ssl-enum-ciphers

The intrusive, exploit, brute and dos categories can disrupt a service. Only run them if the engagement agreement explicitly allows it.

Tune the rate

# Timing templates: -T2 (polite) to -T4 (aggressive)
nmap -T2 10.0.0.0/24
nmap -T4 10.0.0.12

# Cap the send rate and the number of retries
nmap --max-rate 100 --max-retries 2 10.0.0.0/24

# Give up on a host that is too slow
nmap --host-timeout 15m 10.0.0.0/24

In production, start from -T3 (the default) with a moderate --max-rate, and stay within the testing windows agreed with the client.

Save the results

# All three formats at once: .nmap, .gnmap and .xml
nmap -sV -oA scans/host-10-0-0-12 10.0.0.12

# Resume an interrupted scan
nmap --resume scans/host-10-0-0-12.gnmap

# Reason for each port state, and progress every 30 seconds
sudo nmap -sS --reason --stats-every 30s 10.0.0.0/24

Always keep the XML output (-oX or -oA). Most reporting tools import it, and it is timestamped evidence of the scope actually tested.

Useful combinations

Need Command
Quick inventory of a /24 nmap -sn 10.0.0.0/24 -oA discovery
Every port on a host sudo nmap -sS -p- --min-rate 500 10.0.0.12
Then versions on the ports found nmap -sV -sC -p 22,80,443 10.0.0.12
TLS configuration of a website nmap -p 443 --script ssl-enum-ciphers,ssl-cert target.example
Web services on non-standard ports nmap -sV -p 8000-8999 --script http-title 10.0.0.12

Sources

Related resources

  • AI prompt · Web pentesting · Infrastructure and AD pentesting

    Critical vulnerability alert prompt

    Prompt that drafts the urgent client notification when a critical vulnerability is found during testing: facts, impact and immediate containment advice.

    Published

  • AI prompt · Infrastructure and AD pentesting · Web pentesting

    CVE summary prompt

    Prompt that summarises a CVE or vendor advisory: affected versions, conditions, impact, applicability questions for the client, fix and limits.

    Published

  • Tool · Web pentesting · Infrastructure and AD pentesting

    CVSS 3.1 calculator

    Compute the CVSS 3.1 base score, severity and vector string of a vulnerability, or paste an existing vector to review it. Runs in your browser.

    Published

BEAROPS

Need a penetration test?

BEAROPS experts test your applications, infrastructure and cloud, black box or grey box, following OWASP, NIST and ANSSI guidance.