Nmap & port scanning¶
Port scanning answers one question: what is this machine offering to talk to me about? Every open port is a door, and the single most common way people lose an OSCP box is scanning too few ports and never seeing the door that was the answer (WinRM on 5985, an admin panel on 8080, a second web app on 8000). So the governing principle is: scan all of it first, then go deep.
The standard workflow¶
# 1) fast full TCP sweep — find EVERY open port (not just the top 1000)
sudo nmap -p- --min-rate 1000 -T4 $IP -oN nmap/allports.txt
# 2) pull the open ports into a variable
ports=$(grep '^[0-9]' nmap/allports.txt | cut -d/ -f1 | tr '\n' ',' | sed 's/,$//')
# 3) deep scan: version + default scripts on just those ports
sudo nmap -p$ports -sC -sV -A $IP -oN nmap/detailed.txt
# 4) top UDP (slow — run in the background while you work)
sudo nmap -sU --top-ports 100 $IP -oN nmap/udp.txt
Why two scans? The -p- sweep is fast because it only checks which ports are open — no version detection. Running -sC -sV against all 65535 ports would take forever, so you first find the ~handful that are open, then spend the expensive version/script scan only on those. Best of both: complete coverage, reasonable time.
Why UDP matters despite being slow. UDP is skipped by most people, which is exactly why exam boxes hide things there — SNMP (161) leaking process credentials, DNS (53) allowing a zone transfer, TFTP (69), SNMP community strings. You don't need all UDP ports; the top 100 catches the usual suspects. Launch it and forget it while you work TCP.
How to read nmap output¶
The detailed scan is where the leads are. For every line, ask three questions (the same three from the mindset page):
PORT STATE SERVICE VERSION
80/tcp open http Apache httpd 2.4.49
445/tcp open smb Windows Server 2016 microsoft-ds
- The VERSION column is a to-do list.
Apache 2.4.49→ that's CVE-2021-41773 (path traversal → RCE); search every version string. Don't move on from a line until you've noted its version and searched it. - The SERVICE column tells you which enumeration to run — each port has its own playbook (service enumeration). Seeing 445 means "go do SMB enumeration," not "note it and look at the website."
-sCscript output is free intel. Default scripts already pull SMB shares, HTTP titles, anonymous FTP, SSL cert names (often leaking hostnames and emails you'll need). Read it — the answer is sometimes sitting in the default-script output.- Port 88 (Kerberos) = Domain Controller. That single fact reframes the whole box as an Active Directory target.
Flags worth knowing¶
| Flag | Meaning / when |
|---|---|
-p- |
all 65535 TCP ports — your default first scan |
-sC |
default NSE scripts (quick wins, leaks) |
-sV |
version detection (your to-do list) |
-A |
OS + version + scripts + traceroute (aggressive, noisy, fine for the exam) |
-sU |
UDP (slow but hides things) |
-Pn |
skip ping — use when the host seems down but you know it's up (Windows blocks ping by default) |
--min-rate 1000 |
send ≥1000 pkts/s — the speed knob |
--script vuln |
single-target vuln NSE (allowed; not a mass scanner) |
-oN / -oA |
save output — always save, you'll reference it for hours |
Failure modes & what they mean¶
- "Host seems down / 0 ports" but you know it's alive → it's blocking ICMP ping. Add
-Pn. (This bites people constantly on Windows targets.) - Scan is crawling → lower
--min-rate, add--max-retries 2; a congested network drops probes and nmap re-sends endlessly. - You found a foothold fast and skipped the full scan → don't. Finish
-p-anyway; the privesc or the second service is often on a high port you haven't seen. - After a pivot, your scans find nothing → internal hosts have their own firewalls, and through a SOCKS proxy nmap must use
-sT -Pn(it can't send raw packets through a proxy). See pivoting.
autorecon / nmapAutomator automate this whole loop and are allowed (they enumerate, they don't auto-exploit) — but understand the manual flow above, because you'll need to adjust it by hand when the automation misses something.