nmap
nmap (Network Mapper) is the standard network and port scanner. It discovers hosts, open ports, services, versions and, with its scripts (NSE), detects vulnerabilities and enumerates services. It’s almost always the first step of any pentest or CTF (see Active recon, CTF methodology).
What it is
Section titled “What it is”nmap is an open-source network discovery tool. It sends specially crafted packets and analyzes the responses to work out which hosts are alive, which ports are listening, which services and versions run and, through the NSE scripting engine, many specific vulnerabilities and configurations.
What it is for
Section titled “What it is for”- Discover live hosts on a network (host discovery).
- Enumerate open TCP/UDP ports and the services listening on them.
- Detect service versions and operating system.
- Run NSE scripts for deep enumeration and vulnerability detection.
Installation
Section titled “Installation”sudo apt install nmap # Debian/Kali/Parrot# macOSbrew install nmapnmap --versionBasic usage
Section titled “Basic usage”nmap -sS -p- 10.10.10.10 # SYN scan of ALL ports (requires root)nmap -sV -sC -p 22,80,443 host # service versions + default scriptsnmap -sn 10.10.10.0/24 # host discovery (ping sweep), no port scannmap -Pn host # skip ping (host not answering ICMP)nmap -sU --top-ports 100 host # UDP scan of the 100 most common portsKey scan types: -sS (SYN, stealthy, root), -sT (TCP connect, no root), -sU (UDP), -sn (discovery only), -sV (versions), -O (OS).
Advanced usage
Section titled “Advanced usage”Typical two-phase flow: first all ports fast, then targeted enumeration.
# 1. discover ALL open ports, fastnmap -sS -p- --min-rate 5000 -T4 -Pn 10.10.10.10 -oG ports.txt# 2. deep-enumerate only the open portsnmap -sV -sC -p22,80,443 -Pn 10.10.10.10 -oN enum.txtNSE (Nmap Scripting Engine) — scripts in /usr/share/nmap/scripts/:
nmap --script vuln host # vuln category (known-flaw detection)nmap --script "http-*" -p80,443 host # all http scriptsnmap --script smb-enum-shares,smb-os-discovery -p445 hostnmap --script-help ftp-anon # see what a script doesOutput formats (-oA base writes all three at once):
nmap -sV -oA scan host # scan.nmap (normal), scan.xml, scan.gnmapnmap -iL hosts.txt -oN multi.txt # read targets from a fileTricks / workflow
Section titled “Tricks / workflow”flowchart TD
A[Target in scope] --> B["Phase 1: -p- --min-rate -Pn"]
B --> C{Open ports}
C --> D["Phase 2: -sV -sC on specific ports"]
D --> E{Interesting services}
E -->|HTTP| F[web fuzzing / ffuf]
E -->|SMB/445| G[SMB enum / netexec]
E -->|vuln NSE| H[--script vuln]
--min-ratespeeds things up, but raises noise and the risk of false negatives; tune it to the environment.-T4is a good balance;-T5may miss ports on lossy networks.- Always save with
-oA: you can reprocess the output (e.g.grepover.gnmap).
Detection (Blue Team)
Section titled “Detection (Blue Team)”- A SYN scan leaves many half-open connections (SYN with no final ACK): visible to IDS (Snort/Suricata) and to firewalls with logging.
- Full-port and UDP scans are especially noisy: traffic spikes toward many ports in a short time.
-sVsends probes to each service that show up in the applications’ logs (anomalous connect/disconnect lines).
Checklist
Section titled “Checklist”- Target within authorized scope.
- Phase 1 full-port scan completed and saved.
-
-sV -sCenumeration over the open ports. - Relevant NSE run (http, smb, vuln depending on services).
- Output saved with
-oAfor later analysis.