Port Scanning Techniques
Table of Contents
- Port Scanning Overview
- TCP Scan Types Deep Dive
- UDP Scanning
- Port Scanning Strategy for OSCP
- Common TCP Ports Reference
- Common UDP Ports Reference
- Port State Meanings
- Firewall Evasion Techniques
- Scan Rate and Timing Optimization
- Combining Scan Types
- Scan Type Decision Matrix
- OSCP Exam Tips
- Attack Chain Position
1. Port Scanning Overview
What is Port Scanning?
Port Scanning is the process of systematically probing a target’s network ports to determine which ones are open, closed, or filtered. Open ports indicate running services that can potentially be enumerated and exploited.
Why Port Scanning is Critical
┌─────────────────────────────────────────────────────────────┐
│ Why Port Scanning Matters │
├─────────────────────────────────────────────────────────────┤
│ │
│ • Identifies Attack Surface: Every open port is a │
│ potential entry point │
│ • Service Discovery: Open ports reveal running services │
│ • Vulnerability Mapping: Services have known vulnerabilities│
│ • Prioritization: Focus effort on the most promising ports │
│ • Report Evidence: OSCP reports require │
│ thorough port scanning documentation │
│ │
└─────────────────────────────────────────────────────────────┘
The Port Number Space
┌─────────────────────────────────────────────────────────────┐
│ TCP/UDP Port Number Space │
├─────────────────────────────────────────────────────────────┤
│ │
│ Well-Known Ports: 0 - 1023 (system services) │
│ Registered Ports: 1024 - 49151 (application services) │
│ Dynamic/Private: 49152 - 65535 (ephemeral ports) │
│ │
│ Total: 65,536 ports per protocol (TCP + UDP) │
│ │
└─────────────────────────────────────────────────────────────┘
2. TCP Scan Types Deep Dive
2.1 TCP SYN Scan (Half-Open Scan) — Detailed Packet Flow
The SYN scan is the default and most popular scan type. It is fast, reliable, and relatively stealthy because it never completes the TCP connection.
Complete Packet Flow — Open Port
Step 1: Scanner sends SYN
┌─────────────────────────────────────────────────────────────┐
│ Ethernet Header │
│ ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │
│ │ Dst MAC │ Src MAC │ Type │ │ │ │
│ └──────────┴──────────┴──────────┴──────────┴──────────┘ │
│ │
│ IP Header │
│ ┌──────────┬──────────┬──────────┬──────────┬──────────┐ │
│ │ Version │ IHL │ TOS │ Total Len│ ID │ │
│ ├──────────┴──────────┴──────────┴──────────┴──────────┤ │
│ │ Flags+Fragment Offset │ TTL │ Protocol(TCP=6) │ Chksum │ │
│ ├──────────┬──────────┬──────────┬──────────┬──────────┤ │
│ │ Src IP │ │ Dst IP │ │ │ │
│ └──────────┴──────────┴──────────┴──────────┴──────────┘ │
│ │
│ TCP Header │
│ ┌──────────┬──────────┬──────────────────┬──────────┐ │
│ │ Src Port │ Dst Port │ Seq Number │ Ack Num │ │
│ ├──────────┴──────────┴──────────────────┴──────────┤ │
│ │ Data Offset │ Reserved │ SYN=1 │ Flags │ Window │ │
│ ├──────────┬──────────┬──────────┬──────────┬──────────┤ │
│ │ Chksum │ Urgent │ Options │ Padding │ Data │ │
│ └──────────┴──────────┴──────────┴──────────┴──────────┘ │
└─────────────────────────────────────────────────────────────┘
Step 2: Target responds with SYN-ACK (port is OPEN)
┌─────────────────────────────────────────────────────────────┐
│ TCP Header │
│ ┌──────────┬──────────┬──────────────────┬──────────┐ │
│ │ Src Port │ Dst Port │ Seq Number │ Ack Num │ │
│ ├──────────┴──────────┴──────────────────┴──────────┤ │
│ │ Data Offset │ Reserved │ SYN=1,ACK=1 │ Flags │ Win│ │
│ └───────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Step 3: Scanner sends RST to abort (NEVER sends ACK!)
┌─────────────────────────────────────────────────────────────┐
│ TCP Header │
│ ┌──────────┬──────────┬──────────────────┬──────────┐ │
│ │ Src Port │ Dst Port │ Seq Number │ Ack Num │ │
│ ├──────────┴──────────┴──────────────────┴──────────┤ │
│ │ Data Offset │ Reserved │ RST=1 │ Flags │ Window │ │
│ └───────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Result: Port is OPEN (connection never fully established)
Complete Packet Flow — Closed Port
Step 1: Scanner sends SYN
──[SYN]──▶
Step 2: Target responds with RST (port is CLOSED)
◀──[RST]──
Result: Port is CLOSED
Complete Packet Flow — Filtered Port
Step 1: Scanner sends SYN
──[SYN]──▶
Step 2: No response (firewall drops the packet)
(silence...)
Step 3: Scanner retries (based on timing template)
──[SYN]──▶ (retry 1)
──[SYN]──▶ (retry 2)
...
Result: Port is FILTERED
SYN Scan Commands
# Basic SYN scan
nmap -sS 192.168.1.100
# SYN scan on all ports
nmap -sS -p- 192.168.1.100
# SYN scan with version detection
nmap -sS -sV 192.168.1.100
# SYN scan on specific ports
nmap -sS -p 22,80,443,3306,8080,3389 192.168.1.100
# SYN scan with aggressive timing
nmap -sS -T4 -p- 192.168.1.100
# SYN scan with OS detection
nmap -sS -O 192.168.1.100
2.2 TCP Connect Scan — Full Handshake Flow
The Connect scan completes the full TCP three-way handshake. It is the default when running as a non-root user.
Complete Packet Flow — Open Port
Step 1: SYN
Scanner ──[SYN]────────────────▶ Target
Step 2: SYN-ACK
Scanner ◀──[SYN-ACK]──────────── Target
Step 3: ACK (connection established)
Scanner ──[ACK]────────────────▶ Target
═══ CONNECTION OPEN ═══
Step 4: Application layer interaction (optional)
Scanner ──[Data]───────────────▶ Target
Scanner ◀──[Data]─────────────── Target
Step 5: FIN (graceful close)
Scanner ──[FIN, ACK]───────────▶ Target
Scanner ◀──[FIN, ACK]─────────── Target
Scanner ──[ACK]────────────────▶ Target
═══ CONNECTION CLOSED ═══
Result: Port is OPEN
Complete Packet Flow — Closed Port
Step 1: SYN
Scanner ──[SYN]────────────────▶ Target
Step 2: RST (connection refused)
Scanner ◀──[RST]──────────────── Target
Result: Port is CLOSED
Connect Scan Commands
# Basic connect scan
nmap -sT 192.168.1.100
# Connect scan on all ports
nmap -sT -p- 192.168.1.100
# Connect scan with version detection
nmap -sT -sV 192.168.1.100
# Connect scan (Windows default, no root needed)
nmap -sT -T4 192.168.1.100
2.3 TCP ACK Scan — Firewall Mapping
The ACK scan is used to map firewall rules. It cannot determine if a port is open or closed — only whether it is filtered or unfiltered.
Complete Packet Flow
Scenario 1: Unfiltered Port (no firewall or firewall allows)
Scanner ──[ACK]────────────────▶ Target
Scanner ◀──[RST]──────────────── Target
Result: Port is UNFILTERED
Scenario 2: Filtered Port (firewall blocks)
Scanner ──[ACK]────────────────▶ Target
(no response — firewall drops)
Result: Port is FILTERED
Scenario 3: Firewall sends ICMP error
Scanner ──[ACK]────────────────▶ Target
Scanner ◀──[ICMP Admin Prohibited]── Target
Result: Port is FILTERED
ACK Scan Commands
# ACK scan
nmap -sA 192.168.1.100
# ACK scan on all ports
nmap -sA -p- 192.168.1.100
# ACK scan to map firewall rules
nmap -sA -T4 192.168.1.100
2.4 Stealth Scans: NULL, FIN, XMAS
These scans exploit the TCP specification (RFC 793) to bypass firewalls that don’t properly inspect TCP flags.
How Stealth Scans Work
According to RFC 793, if a TCP packet doesn’t fit any expected state in the connection table, the target should respond with RST. The behavior differs based on the TCP stack implementation:
| OS Type | Open Port Response | Closed Port Response |
|---|---|---|
| Linux/Unix (RFC compliant) | No response (ignores) | RST |
| Windows (NOT RFC compliant) | RST | RST |
Critical: Stealth scans (NULL, FIN, XMAS) do NOT work against Windows because Windows responds with RST to all unexpected packets, regardless of port state.
NULL Scan — No Flags Set
Scanner sends packet with NO TCP flags set:
TCP Header Flags:
┌────┬────┬────┬────┬────┬────┐
│ URG│ ACK│ PSH│ RST│ SYN│ FIN│
├────┼────┼────┼────┼────┼────┤
│ 0 │ 0 │ 0 │ 0 │ 0 │ 0 │ ← All flags OFF
└────┴────┴────┴────┴────┴────┘
Open Port (Linux): No response → OPEN|FILTERED
Closed Port (Linux): RST → CLOSED|FILTERED
Any Port (Windows): RST → CLOSED|FILTERED (doesn't work!)
# NULL scan
nmap -sN 192.168.1.100
# NULL scan on all ports
nmap -sN -p- 192.168.1.100
FIN Scan — FIN Flag Only
Scanner sends packet with only FIN flag set:
TCP Header Flags:
┌────┬────┬────┬────┬────┬────┐
│ URG│ ACK│ PSH│ RST│ SYN│ FIN│
├────┼────┼────┼────┼────┼────┤
│ 0 │ 0 │ 0 │ 0 │ 0 │ 1 │ ← Only FIN ON
└────┴────┴────┴────┴────┴────┘
Open Port (Linux): No response → OPEN|FILTERED
Closed Port (Linux): RST → CLOSED|FILTERED
Any Port (Windows): RST → CLOSED|FILTERED (doesn't work!)
# FIN scan
nmap -sF 192.168.1.100
# FIN scan on all ports
nmap -sF -p- 192.168.1.100
XMAS Scan — FIN + PSH + URG
Scanner sends packet with FIN, PSH, and URG flags set:
TCP Header Flags:
┌────┬────┬────┬────┬────┬────┐
│ URG│ ACK│ PSH│ RST│ SYN│ FIN│
├────┼────┼────┼────┼────┼────┤
│ 1 │ 0 │ 1 │ 0 │ 0 │ 1 │ ← FIN, PSH, URG ON
└────┴────┴────┴────┴────┴────┘
Open Port (Linux): No response → OPEN|FILTERED
Closed Port (Linux): RST → CLOSED|FILTERED
Any Port (Windows): RST → CLOSED|FILTERED (doesn't work!)
# XMAS scan
nmap -sX 192.168.1.100
# XMAS scan on all ports
nmap -sX -p- 192.168.1.100
Stealth Scan Comparison
| Scan Type | Flags Set | Works on Linux | Works on Windows | Bypasses Firewalls |
|---|---|---|---|---|
| NULL | None | Yes | No | Sometimes |
| FIN | FIN only | Yes | No | Sometimes |
| XMAS | FIN+PSH+URG | Yes | No | Sometimes |
When Stealth Scans Succeed
┌─────────────────────────────────────────────────────────────┐
│ When Stealth Scans Work │
├─────────────────────────────────────────────────────────────┤
│ │
│ ✓ Target is Linux/Unix (RFC 793 compliant TCP stack) │
│ ✓ Firewall only checks for SYN flag │
│ ✓ Firewall doesn't inspect TCP flags deeply │
│ ✓ Stateless firewall (no connection tracking) │
│ │
│ ✗ Target is Windows (always responds with RST) │
│ ✗ Stateful firewall with proper flag inspection │
│ ✗ IDS/IPS with anomaly detection │
│ │
└─────────────────────────────────────────────────────────────┘
3. UDP Scanning
Why UDP Matters
UDP is often overlooked by both attackers and defenders, making it a goldmine for OSCP engagements. Many critical services run over UDP, and misconfigured UDP services are common entry points.
┌─────────────────────────────────────────────────────────────┐
│ Why UDP Scanning is Critical │
├─────────────────────────────────────────────────────────────┤
│ │
│ • SNMP (161) — Full system information disclosure │
│ • DNS (53) — Zone transfers, cache dumping │
│ • NetBIOS (137-139) — Windows enumeration │
│ • Kerberos (88) — Authentication attacks │
│ • NTP (123) — Amplification, monlist │
│ • TFTP (69) — Unauthenticated file transfer │
│ • RPC (111) — Remote procedure calls │
│ │
│ UDP is the #1 overlooked attack vector on OSCP machines │
│ │
└─────────────────────────────────────────────────────────────┘
How UDP Scanning Works
Unlike TCP, UDP has no handshake. Nmap determines port state based on ICMP error responses:
Scenario 1: Port is OPEN
Scanner ──[UDP Probe]──────────▶ Target
(No response)
Result: OPEN|FILTERED
(Could be open — no way to tell without application response)
Scenario 2: Port is CLOSED
Scanner ──[UDP Probe]──────────▶ Target
Scanner ◀──[ICMP Port Unreachable]── Target
(Type 3, Code 3)
Result: CLOSED
Scenario 3: Port is FILTERED
Scanner ──[UDP Probe]──────────▶ Target
Scanner ◀──[ICMP Admin Prohibited]── Target
(Type 3, Code 10)
Result: FILTERED
Scenario 4: Application Response
Scanner ──[UDP Probe]──────────▶ Target
Scanner ◀──[UDP Response]───────── Target
(Application sent data back)
Result: OPEN
Common UDP Services to Check
| Port | Service | Why Check | Common Vulnerabilities |
|---|---|---|---|
| 53 | DNS | Zone transfers, cache poisoning | AXFR, DNS rebinding |
| 67/68 | DHCP | Network configuration info | DHCP spoofing |
| 69 | TFTP | Unauthenticated file transfer | File read/write |
| 123 | NTP | Time synchronization | NTP amplification, monlist |
| 135 | MSRPC | Windows RPC services | RPC exploitation |
| 137 | NetBIOS Name | Windows name resolution | NetBIOS enumeration |
| 138 | NetBIOS Datagram | Windows datagram service | NetBIOS enumeration |
| 139 | NetBIOS Session | Windows session service | SMB over NetBIOS |
| 161 | SNMP | Network management | Community string brute-force |
| 162 | SNMP Trap | SNMP notifications | Trap analysis |
| 389 | LDAP | Directory services | LDAP injection, null bind |
| 445 | SMB | File sharing | EternalBlue, SMB exploits |
| 500 | ISAKMP | IPsec key exchange | IPsec analysis |
| 514 | Syslog | Logging service | Log injection |
| 520 | RIP | Routing protocol | Routing attacks |
| 1433 | MS-SQL | Database | SQL injection |
| 1900 | SSDP | UPnP discovery | UPnP exploitation |
| 3306 | MySQL | Database | MySQL over UDP |
| 5353 | mDNS | Multicast DNS | mDNS spoofing |
| 6901 | XMPP | Jabber/IM | XMPP enumeration |
UDP Scan Commands
# Scan common UDP ports (default top 100)
nmap -sU 192.168.1.100
# Scan specific critical UDP ports
nmap -sU -p 53,67,68,69,123,135,137,138,139,161,162,389,445,500,514,520,1433,1900,3306,5353,6901 192.168.1.100
# Top 100 UDP ports
nmap -sU --top-ports 100 192.168.1.100
# Top 1000 UDP ports
nmap -sU --top-ports 1000 192.168.1.100
# UDP scan with version detection
nmap -sU -sV -p 53,161,162,135,137,138,139,389,445,500 192.168.1.100
# UDP scan with aggressive timing
nmap -sU -T4 --top-ports 100 192.168.1.100
# UDP scan with NSE scripts
nmap -sU --script=snmp-info,snmp-enum -p 161 192.168.1.100
# Combined TCP and UDP scan
nmap -sS -sU --top-ports 100 192.168.1.100
UDP Scanning Tips
┌─────────────────────────────────────────────────────────────┐
│ UDP Scanning Tips │
├─────────────────────────────────────────────────────────────┤
│ │
│ • UDP scanning is SLOW — be patient │
│ • Use -T4 to speed up (but may reduce accuracy) │
│ • Focus on common ports first, then expand │
│ • OPEN|FILTERED means the port MIGHT be open │
│ — follow up with application-specific probes │
│ • SNMP (161) is the most common UDP win on OSCP │
│ • DNS (53) zone transfers are another common win │
│ │
└─────────────────────────────────────────────────────────────┘
4. Port Scanning Strategy for OSCP
Recommended OSCP Port Scanning Workflow
flowchart TD
A[Start: Target IP Assigned] --> B[Step 1: Quick TCP Scan<br/>Top 1000 Ports]
B --> C{Interesting Ports Found?}
C -->|Yes| D[Step 2: Service Version Detection<br/>-sV on open ports]
C -->|No| E[Step 3: Full TCP Scan<br/>All 65535 Ports]
D --> E
E --> F{More Ports Found?}
F -->|Yes| G[Step 4: Version Detection<br/>on new ports]
F -->|No| H[Step 5: UDP Scan<br/>Common UDP Ports]
G --> H
H --> I{UDP Ports Open?}
I -->|Yes| J[Step 6: UDP Service Enum<br/>SNMP, DNS, etc.]
I -->|No| K[Step 7: NSE Scripts<br/>Safe scripts on open ports]
J --> K
K --> L[Step 8: Document Everything]
L --> M[Begin Exploitation]
style A fill:#e3f2fd
style B fill:#e1f5fe
style D fill:#fff3e0
style E fill:#fff3e0
style H fill:#e8f5e9
style J fill:#e8f5e9
style K fill:#fce4ec
style L fill:#f3e5f5
style M fill:#c8e6c9
Step-by-Step Commands
# Step 1: Quick TCP scan (top 1000 ports)
nmap -sS -T4 -Pn --top-ports 1000 -oN step1_quick_tcp.txt 192.168.1.100
# Step 2: Service version detection on found ports
nmap -sS -sV -T4 -Pn -p 22,80,443,3306,8080 -oN step2_versions.txt 192.168.1.100
# Step 3: Full TCP scan (all 65535 ports)
nmap -sS -T4 -Pn -p- -oN step3_full_tcp.txt 192.168.1.100
# Step 4: Version detection on ALL open ports
nmap -sS -sV -O -T4 -Pn -p- -oN step4_full_versions.txt 192.168.1.100
# Step 5: UDP scan (common ports)
nmap -sU -T4 -Pn --top-ports 100 -oN step5_udp.txt 192.168.1.100
# Step 6: UDP service enumeration
nmap -sU -sV -T4 -Pn -p 53,161,162,135,137,138,139,389,445,500 -oN step6_udp_enum.txt 192.168.1.100
# Step 7: NSE scripts
nmap --script=safe -T4 -Pn -p 22,80,443,445,3306,8080 -oN step7_nse.txt 192.168.1.100
# Step 8: Save everything
nmap -sS -sV -O -T4 -Pn -p- --script=safe -oA final_scan 192.168.1.100
Alternative: Masscan + Nmap Pipeline
# Fast all-port scan with Masscan
masscan 192.168.1.100 -p 1-65535 --rate 10000 -oL masscan_quick.txt
# Extract open ports
grep "open" masscan_quick.txt | awk '{print $4}' | tr -d '/' | tr '\n' ',' | sed 's/,$//'
# Detailed Nmap scan on open ports
nmap -sV -sS -O -T4 -Pn -p 22,80,443,3306,8080,8443 -oN masscan_followup.txt 192.168.1.100
5. Common TCP Ports Reference
Essential TCP Ports for OSCP
| Port | Service | Protocol | Common Vulnerabilities | OSCP Priority |
|---|---|---|---|---|
| 21 | FTP | TCP | Anonymous login, weak creds, vsftpd backdoor | High |
| 22 | SSH | TCP | Weak passwords, old versions, key theft | High |
| 23 | Telnet | TCP | Cleartext credentials, brute force | Medium |
| 25 | SMTP | TCP | Open relay, mail injection | Medium |
| 53 | DNS | TCP | Zone transfer (AXFR), cache poisoning | High |
| 80 | HTTP | TCP | Web app vulns, directory traversal, RCE | Critical |
| 110 | POP3 | TCP | Weak credentials, cleartext | Low |
| 111 | RPCBind | TCP | RPC service enumeration | Medium |
| 135 | MSRPC | TCP | RPC exploitation, DCOM | Medium |
| 139 | NetBIOS | TCP | SMB over NetBIOS, null sessions | Medium |
| 143 | IMAP | TCP | Weak credentials, cleartext | Low |
| 389 | LDAP | TCP | Null bind, LDAP injection | Medium |
| 443 | HTTPS | TCP | Same as HTTP + SSL/TLS vulns | Critical |
| 445 | SMB | TCP | EternalBlue, null sessions, weak creds | Critical |
| 512 | Rexec | TCP | Remote execution | Low |
| 513 | Rlogin | TCP | Remote login | Low |
| 514 | Rsh | TCP | Remote shell | Low |
| 587 | SMTP/TLS | TCP | Open relay | Low |
| 631 | CUPS | TCP | Printer exploitation, RCE | Medium |
| 636 | LDAPS | TCP | LDAP over SSL | Low |
| 873 | Rsync | TCP | Unauthenticated sync, file read | Medium |
| 993 | IMAPS | TCP | IMAP over SSL | Low |
| 995 | POP3S | TCP | POP3 over SSL | Low |
| 1099 | RMI | TCP | Java RMI exploitation | Medium |
| 1433 | MS-SQL | TCP | SQL injection, weak creds | High |
| 1521 | Oracle | TCP | Oracle DB exploits | Medium |
| 2049 | NFS | TCP | NFS misconfigurations, root squashing | High |
| 2082 | cPanel | TCP | cPanel exploits | Low |
| 3306 | MySQL | TCP | Weak creds, default root, SQL injection | High |
| 3389 | RDP | TCP | BlueKeep, weak creds, pass-the-hash | High |
| 5432 | PostgreSQL | TCP | Weak creds, default postgres user | Medium |
| 5900 | VNC | TCP | Weak passwords, no auth | High |
| 5985 | WinRM | TCP | Windows Remote Management | Medium |
| 5986 | WinRM/SSL | TCP | WinRM over SSL | Medium |
| 6379 | Redis | TCP | No auth, RCE via module loading | High |
| 7001 | WebLogic | TCP | WebLogic deserialization | Medium |
| 8080 | HTTP-Alt | TCP | Same as port 80 (proxy/app server) | Critical |
| 8443 | HTTPS-Alt | TCP | Same as port 443 (alt HTTPS) | High |
| 8888 | HTTP-Alt | TCP | Alternative HTTP service | Medium |
| 9090 | HTTP-Alt | TCP | Alternative HTTP service | Medium |
| 9200 | Elasticsearch | TCP | No auth, RCE, data exfil | High |
| 27017 | MongoDB | TCP | No auth, default creds | High |
High Ports to Watch On OSCP
| Port Range | Common Services | Why Check |
|---|---|---|
| 3000-3999 | Dev servers, Node.js, Docker | Development services often exposed |
| 4000-4999 | Custom apps, Jenkins | CI/CD servers |
| 5000-5999 | Flask, Django, VNC | Web frameworks, remote desktop |
| 6000-6999 | X11, custom services | X11 forwarding attacks |
| 7000-7999 | WebLogic, custom apps | Enterprise apps |
| 8000-8999 | HTTP alt, proxies | Alternative web services |
| 9000-9999 | Elasticsearch, custom | Search engines, apps |
| 10000+ | Webmin, custom | Admin panels, custom services |
6. Common UDP Ports Reference
Essential UDP Ports for OSCP
| Port | Service | Why Check | Common Vulnerabilities |
|---|---|---|---|
| 53 | DNS | Zone transfers, cache dumping | AXFR, DNS rebinding |
| 67 | DHCP Server | Network config info | DHCP spoofing |
| 68 | DHCP Client | Network config info | DHCP spoofing |
| 69 | TFTP | Unauthenticated file transfer | Arbitrary file read/write |
| 123 | NTP | Time sync, amplification | monlist, NTP reflection |
| 135 | MSRPC | Windows RPC | RPC exploitation |
| 137 | NetBIOS Name | Windows enumeration | NetBIOS info disclosure |
| 138 | NetBIOS Datagram | Windows enumeration | NetBIOS info disclosure |
| 161 | SNMP | Most common UDP win | Community string brute-force |
| 162 | SNMP Trap | SNMP notifications | Trap data analysis |
| 389 | LDAP | Directory services | LDAP null bind |
| 445 | SMB | File sharing | SMB over UDP |
| 500 | ISAKMP | IPsec | IPsec analysis |
| 514 | Syslog | Logging | Log injection |
| 520 | RIP | Routing | Routing attacks |
| 1433 | MS-SQL | Database | SQL over UDP |
| 1900 | SSDP | UPnP | UPnP exploitation |
| 3306 | MySQL | Database | MySQL over UDP |
| 5353 | mDNS | Multicast DNS | mDNS spoofing |
| 6901 | XMPP | Jabber/IM | XMPP enumeration |
7. Port State Meanings
Complete Port State Reference
┌─────────────────┬──────────────────────────────────────────────────────┐
│ State │ Meaning and Response Strategy │
├─────────────────┼──────────────────────────────────────────────────────┤
│ open │ Application is listening and accepting connections │
│ │ → ENUMERATE THIS PORT! │
│ │ → Check for known vulnerabilities │
│ │ → Attempt exploitation │
├─────────────────┼──────────────────────────────────────────────────────┤
│ closed │ Port is reachable but no application is listening │
│ │ → Move on, no service to exploit │
│ │ → But confirms the host is alive and reachable │
├─────────────────┼──────────────────────────────────────────────────────┤
│ filtered │ Firewall/device is blocking or dropping packets │
│ │ → Try different scan type (ACK, FIN, XMAS) │
│ │ → Try fragmentation (-f) │
│ │ → Try decoy scans │
│ │ → May still be exploitable via other means │
├─────────────────┼──────────────────────────────────────────────────────┤
│ open|filtered │ Can't determine — no response received │
│ │ → Common with UDP, FIN, XMAS, NULL scans │
│ │ → Try a different scan type to confirm │
│ │ → For UDP: try application-specific probes │
├─────────────────┼──────────────────────────────────────────────────────┤
│ closed|filtered │ Can't determine — ambiguous response │
│ │ → Common with ACK scans │
│ │ → Try a different scan type to confirm │
└─────────────────┴──────────────────────────────────────────────────────┘
State Determination Matrix
┌────────────┬────────────┬──────────┬────────────┬─────────────────┐
│ Scan Type │ Open Port │ Closed │ Filtered │ Result │
├────────────┼────────────┼──────────┼────────────┼─────────────────┤
│ SYN (-sS) │ SYN-ACK │ RST │ No resp │ Definitive │
│ Connect │ Connected │ RST │ Timeout │ Definitive │
│ UDP (-sU) │ No resp │ ICMP 3/3 │ No resp │ open|filtered │
│ ACK (-sA) │ RST │ RST │ No resp │ filtered/unfiltered │
│ NULL (-sN) │ No resp │ RST │ No resp │ open|filtered │
│ FIN (-sF) │ No resp │ RST │ No resp │ open|filtered │
│ XMAS (-sX) │ No resp │ RST │ No resp │ open|filtered │
└────────────┴────────────┴──────────┴────────────┴─────────────────┘
Response Strategy by State
| State | Scan Type Used | Next Action |
|---|---|---|
| open | SYN/Connect | Enumerate service, find exploits |
| closed | SYN/Connect | Skip, no service |
| filtered | SYN/Connect | Try ACK scan, fragmentation, or different approach |
| open|filtered | UDP/FIN/XMAS/NULL | Confirm with SYN scan (TCP) or app probe (UDP) |
| closed|filtered | ACK | Try SYN scan to determine actual state |
8. Firewall Evasion Techniques
Firewall Evasion Methods
Method 1: Packet Fragmentation
Split packets into small fragments to bypass firewalls that don’t reassemble before inspection.
# Fragment packets (default MTU 24)
nmap -f 192.168.1.100
# Custom MTU (must be multiple of 8)
nmap -f --mtu 8 192.168.1.100
# Fragment + SYN scan
nmap -f -sS -p- 192.168.1.100
Method 2: Decoy Scans
Use decoy IPs to make it harder to identify the real scanner.
# 6 random decoys + your IP
nmap -D RND:6 192.168.1.100
# Specific decoys
nmap -D 10.0.0.1,10.0.0.2,10.0.0.3,RND:3 192.168.1.100
# Decoy + SYN scan
nmap -D RND:10 -sS -p- 192.168.1.100
Method 3: Source Port Spoofing
Use a trusted source port to bypass firewall rules.
# Use port 53 (DNS) as source
nmap -g 53 192.168.1.100
# Use port 80 (HTTP) as source
nmap -g 80 192.168.1.100
# Source port + SYN scan
nmap -g 53 -sS -p- 192.168.1.100
Method 4: Source IP Spoofing
Spoof the source IP address (note: you won’t receive responses with this method).
# Spoof source IP
nmap -S 10.0.0.1 192.168.1.100
# Note: You won't get responses when spoofing
# Use with decoy scans instead
Method 5: Timing Adjustment
Slow down scanning to avoid rate limiting and IDS detection.
# Polite scanning
nmap -T2 192.168.1.100
# Sneaky scanning
nmap -T1 192.168.1.100
# Paranoid scanning
nmap -T0 192.168.1.100
# Custom delay between packets
nmap --scan-delay 1s 192.168.1.100
nmap --max-rate 100 192.168.1.100
Method 6: Raw IP Packets
Bypass ARP and send raw IP packets.
# Send as IP packets
nmap --send-ip 192.168.1.100
# Raw IP + no DNS
nmap --send-ip -n 192.168.1.100
Method 7: Idle/Zombie Scan
Use a third-party “zombie” host to perform blind scans.
# Idle scan (advanced, rarely needed on OSCP)
nmap -sI zombie.host.com 192.168.1.100
Firewall Evasion Comparison
| Technique | Effectiveness | Stealth | Speed Impact | OSCP Relevance |
|---|---|---|---|---|
| Fragmentation | Medium | Medium | Slight slowdown | Medium |
| Decoys | Low-Medium | Medium | No impact | Low |
| Source Port | Medium | Medium | No impact | Medium |
| Timing | High | High | Significant slowdown | High |
| Raw IP | Low | Low | No impact | Low |
| Idle Scan | High | High | N/A | Very Low |
9. Scan Rate and Timing Optimization
Timing Templates Deep Dive
┌────┬──────────┬─────────────────┬──────────────────────────────────┐
│ T# │ Name │ Packet Delay │ Best Use Case │
├────┼──────────┼─────────────────┼──────────────────────────────────┤
│ T0 │ Paranoid │ 15 seconds │ Maximum stealth, IDS evasion │
│ T1 │ Sneaky │ 4 seconds │ Stealth scanning │
│ T2 │ Polite │ 1 second │ Reduce load, be courteous │
│ T3 │ Normal │ 0 seconds │ Default, balanced │
│ T4 │ Aggressive│ 0 seconds │ Fast networks, OSCP default │
│ T5 │ Insane │ 0 seconds │ Very fast, may miss results │
└────┴──────────┴─────────────────┴──────────────────────────────────┘
Rate Control Options
# Minimum packet rate
nmap --min-rate 1000 192.168.1.100
# Maximum packet rate
nmap --max-rate 500 192.168.1.100
# Fixed rate
nmap --min-rate 1000 --max-rate 1000 192.168.1.100
# Custom timing parameters
nmap --max-retries 2 --host-timeout 30m 192.168.1.100
# Combine timing with rate
nmap -T4 --min-rate 500 -p- 192.168.1.100
OSCP Timing Recommendations
┌─────────────────────────────────────────────────────────────┐
│ OSCP Timing Recommendations │
├─────────────────────────────────────────────────────────────┤
│ │
│ Initial Recon: -T4 (fast and reliable) │
│ All-Port TCP Scan: -T4 (T5 may miss ports) │
│ UDP Scan: -T4 (UDP is inherently slow) │
│ Service Detection: -T4 (balanced) │
│ NSE Scripts: -T4 (scripts are slow anyway) │
│ IDS Detected: -T2 or -T1 (slow down) │
│ │
│ ⚠️ NEVER use T5 on OSCP — you may miss critical ports │
│ ⚠️ T4 is the sweet spot for speed vs. accuracy │
│ │
└─────────────────────────────────────────────────────────────┘
10. Combining Scan Types
Effective Scan Combinations
Combination 1: SYN + Version + OS
# The most common OSCP combination
nmap -sS -sV -O -T4 -p- -Pn -oA combined_scan 192.168.1.100
Combination 2: TCP + UDP
# TCP and UDP in one command
nmap -sS -sU -T4 --top-ports 100 -Pn -oA tcp_udp_scan 192.168.1.100
# TCP all ports + UDP common
nmap -sS -p- -sU --top-ports 100 -T4 -Pn -oA full_tcp_udp 192.168.1.100
Combination 3: SYN + NSE
# SYN scan with safe NSE scripts
nmap -sS --script=safe -T4 -p 22,80,443,445,3306,8080 -Pn -oA syn_nse 192.168.1.100
# SYN scan with specific scripts
nmap -sS --script=http-enum,ssl-cert,smb-enum-shares -T4 -p 80,443,445 -Pn -oA syn_scripts 192.168.1.100
Combination 4: Aggressive Full Scan
# The ultimate OSCP scan
nmap -sS -sV -O -T4 -p- --script=safe -Pn -oA ultimate_scan 192.168.1.100
# With UDP
nmap -sS -sU -sV -O -T4 -p- --top-ports 100 --script=safe -Pn -oA ultimate_with_udp 192.168.1.100
Combination 5: Firewall Evasion Combo
# Fragmented + decoy + slow timing
nmap -f -D RND:5 -T2 -sS -p- -Pn -oA evasion_scan 192.168.1.100
# Source port + fragmentation
nmap -g 53 -f -sS -T4 -p- -Pn -oA port_frag_scan 192.168.1.100
11. Scan Type Decision Matrix
When to Use Each Scan Type
┌─────────────────────────────────────────────────────────────────────────────┐
│ Scan Type Decision Matrix │
├─────────────────────────────────────────────────────────────────────────────┤
│ │
│ Are you root? │
│ ├── Yes → Use SYN scan (-sS) │
│ └── No → Use Connect scan (-sT) │
│ │
│ Is ICMP blocked? │
│ ├── Yes → Use -Pn (skip discovery) │
│ └── No → Use default discovery │
│ │
│ Do you need speed? │
│ ├── Yes → Use Masscan for initial scan, Nmap for details │
│ └── No → Use Nmap directly │
│ │
│ Do you need UDP? │
│ ├── Yes → Use -sU (always check UDP on OSCP) │
│ └── No → TCP only │
│ │
│ Is there a firewall? │
│ ├── Yes → Try ACK scan (-sA) to map rules │
│ │ Try fragmentation (-f) │
│ │ Try stealth scans (-sN, -sF, -sX) if target is Linux │
│ └── No → Use SYN scan (-sS) │
│ │
│ Do you need service details? │
│ ├── Yes → Add -sV (version detection) │
│ └── No → Port scan only │
│ │
│ Do you need OS detection? │
│ ├── Yes → Add -O (needs root + at least 1 open + 1 closed port) │
│ └── No → Skip OS detection │
│ │
│ Do you need advanced enumeration? │
│ ├── Yes → Add --script=safe (NSE scripts) │
│ └── No → Skip scripting │
│ │
└─────────────────────────────────────────────────────────────────────────────┘
Quick Decision Table
| Situation | Recommended Command |
|---|---|
| Quick recon | nmap -sS -T4 --top-ports 1000 -Pn <IP> |
| Full TCP scan | nmap -sS -T4 -p- -Pn <IP> |
| With versions | nmap -sS -sV -T4 -p- -Pn <IP> |
| With OS detection | nmap -sS -sV -O -T4 -p- -Pn <IP> |
| UDP scan | nmap -sU -T4 --top-ports 100 -Pn <IP> |
| TCP + UDP | nmap -sS -sU -T4 --top-ports 100 -Pn <IP> |
| With NSE scripts | nmap --script=safe -T4 -p <PORTS> -Pn <IP> |
| Firewall mapping | nmap -sA -T4 -p- -Pn <IP> |
| Stealth (Linux) | nmap -sN -T4 -p- -Pn <IP> |
| Maximum detail | nmap -sS -sV -O -T4 -p- --script=safe -Pn -oA full <IP> |
| Non-root | nmap -sT -T4 --top-ports 1000 <IP> |
| Masscan + Nmap | masscan <IP> -p 1-65535 --rate 10000 then nmap -sV -p <PORTS> <IP> |
12. OSCP Exam Tips
Critical Port Scanning Tips
┌─────────────────────────────────────────────────────────────────┐
│ OSCP Port Scanning Exam Tips │
├─────────────────────────────────────────────────────────────────┤
│ │
│ 1. ALWAYS scan all 65535 ports (-p-) — hidden services on │
│ non-standard ports are the key to many OSCP machines │
│ │
│ 2. ALWAYS scan UDP — SNMP (161) and DNS (53) are the most │
│ common UDP-based entry points on OSCP │
│ │
│ 3. Use -Pn (skip discovery) — many OSCP machines block │
│ ICMP and discovery probes │
│ │
│ 4. Use -T4 timing — best balance of speed and accuracy │
│ │
│ 5. Use -sV for version detection — version info is critical │
│ for selecting the right exploit │
│ │
│ 6. Save ALL output with -oA — needed for your report │
│ │
│ 7. Don't rush — thorough scanning saves time later │
│ (finding the right exploit is easier with good intel) │
│ │
│ 8. Check high ports — services on ports 3000-9999+ are │
│ common on OSCP machines (web apps, databases, etc.) │
│ │
│ 9. Use Masscan for quick all-port scans, but always follow │
│ up with Nmap for service details │
│ │
│ 10. Document every scan command and its output — your report │
│ needs evidence of thorough enumeration │
│ │
│ 11. If you find an open port, ENUMERATE IT immediately — │
│ don't wait to finish scanning before starting enumeration │
│ │
│ 12. Stealth scans (NULL, FIN, XMAS) rarely help on OSCP — │
│ most targets are Linux but SYN scan works fine │
│ │
└─────────────────────────────────────────────────────────────────┘
Time Management for Scanning
| Activity | Expected Time | Priority |
|---|---|---|
| Top 1000 TCP scan | 30-60 seconds | Must do |
| All TCP ports scan | 2-5 minutes | Must do |
| Service version detection | 1-3 minutes | Must do |
| Top 100 UDP scan | 1-3 minutes | Must do |
| NSE scripts | 1-5 minutes | Should do |
| OS detection | 30-60 seconds | Should do |
| Stealth scans | 5-10 minutes | Optional |
| Full UDP all ports | 30+ minutes | Skip (too slow) |
Common OSCP Scan Patterns
# Pattern 1: The minimum viable scan
nmap -sS -T4 -Pn --top-ports 1000 <IP>
# Pattern 2: The standard OSCP scan
nmap -sS -sV -O -T4 -Pn -p- <IP>
# Pattern 3: The thorough scan
nmap -sS -sV -O -T4 -Pn -p- --script=safe -oA thorough <IP>
# Pattern 4: The complete scan (TCP + UDP)
nmap -sS -sU -sV -O -T4 -Pn -p- --top-ports 100 -oA complete <IP>
# Pattern 5: Quick Masscan + Nmap follow-up
masscan <IP> -p 1-65535 --rate 10000 -oL masscan.txt
nmap -sV -Pn -p <PORTS_FROM_MASSCAN> <IP>
13. Attack Chain Position
Where Port Scanning Fits in the Attack Chain
flowchart LR
A[Reconnaissance<br/>Passive Intel] --> B[Host Discovery<br/>Find Live Hosts]
B --> C[Port Scanning<br/>Find Open Ports]
C --> D[Service Enumeration<br/>Identify Services]
D --> E[Vulnerability Analysis<br/>Find Exploits]
E --> F[Exploitation<br/>Gain Access]
F --> G[Post-Exploitation<br/>Priv Esc + Pivot]
style C fill:#4CAF50, color:white
style D fill:#8BC34A, color:white
Port Scanning in Each Phase
| Phase | Port Scanning Role | Key Commands |
|---|---|---|
| Initial Recon | Quick top-ports scan | -sS --top-ports 1000 |
| Detailed Scanning | Full port scan | -sS -p- |
| Service Enumeration | Version detection | -sV -sS |
| Vulnerability Analysis | NSE vulnerability scripts | --script=vuln |
| Post-Exploitation | Scan internal networks | -sS -p- from compromised host |
| Pivoting | Discover new targets | -sS --top-ports 1000 on new subnet |
Port Scanning as a Continuous Process
Initial Scan → Find Service → Enumerate → Find Vuln → Exploit
↓ ↓ ↓ ↓ ↓
Open ports Service info Config/data Exploit Access
↓ ↓ ↓ ↓ ↓
Full scan Version Attack Gain Pivot
UDP scan OS surface shell to new
Quick Reference Card
Most Used Port Scanning Commands for OSCP
# 1. Quick TCP scan
nmap -sS -T4 -Pn --top-ports 1000 <IP>
# 2. Full TCP scan with versions
nmap -sS -sV -O -T4 -Pn -p- <IP>
# 3. UDP scan
nmap -sU -T4 -Pn --top-ports 100 <IP>
# 4. Complete scan with NSE
nmap -sS -sV -O -T4 -Pn -p- --script=safe -oA full <IP>
# 5. Masscan quick scan
masscan <IP> -p 1-65535 --rate 10000
# 6. Firewall mapping
nmap -sA -T4 -p- <IP>
Port State Quick Reference
| State | Meaning | Action |
|---|---|---|
| open | Service running | Enumerate and exploit |
| closed | No service | Skip |
| filtered | Firewall blocking | Try different scan type |
| open|filtered | Uncertain | Confirm with different scan |
| closed|filtered | Uncertain | Confirm with SYN scan |
Master port scanning to build a comprehensive picture of your target’s attack surface. Every open port is a potential path to root.