Series: Kali Linux By HRL — Notebook #1

Video: Using NMAP Like a Red Team Operator (OPSEC Matters!)

Why OPSEC Matters in Nmap

Running a default nmap <target> or nmap -A -T4 <target> is loud. It triggers IDS/IPS, firewalls, and SOC alerts almost immediately. Red Team operators prioritize Operational Security (OPSEC)—gathering the exact intelligence needed while minimizing noise, packet volume, and detection surface.

1. Host Discovery & DNS OPSEC

  • -n (No DNS Resolution): Prevents Nmap from making reverse DNS queries to local/target DNS servers, which can leak your scanning activity.
  • -Pn (Skip Host Discovery): Treats all hosts as online. Useful when ICMP/ping probes are blocked or monitored, though it will scan all specified ports even on down hosts.
  • -sn (Ping Scan): Host discovery only (no port scan) when you only need to map live hosts.

2. Stealth & Scan Types

  • -sS (TCP SYN / Half-Open Scan): Default for privileged users (sudo). Sends a SYN, waits for SYN/ACK, and sends RST without completing the 3-way handshake. Quieter than -sT (full TCP connect).
  • -sT (TCP Connect Scan): Completes the full handshake; logged by applications. Use only when raw socket privileges aren't available.
  • -sU (UDP Scan): Slow and noisy if unfiltered; target specific UDP ports (e.g., 53, 161, 500) rather than broad ranges.

3. Timing, Throttling & Rate Control

Default -T4 or -T5 templates blast packets rapidly and are easily flagged by rate-based detection.

  • -T2 (Polite) / -T1 (Sneaky): Slows down the scan to reduce bandwidth and IDS/IPS alerting.
  • --scan-delay <time>: Adds a delay between probes (e.g., --scan-delay 500ms or 2s).
  • --max-rate <number>: Caps packets per second (e.g., --max-rate 10).
  • --randomize-hosts: Randomizes target IP order instead of scanning sequentially.

4. Targeted Port & Service Enumeration

Avoid scanning all 65,535 ports (-p-) or even the top 1,000 unless necessary.

  • -p <ports>: Scan only relevant ports (e.g., -p 22,80,443,445,3389).
  • --top-ports <N>: Limit to top N ports (e.g., --top-ports 20).
  • -sV --version-intensity <0-9>: Service version detection. Lower intensity (e.g., 2 or 3) sends fewer probes and reduces noise compared to the default (7).
  • NSE Scripts (--script): Avoid -sC or -A blindly, as they run intrusive/noisy scripts. Specify exact scripts needed (e.g., --script=http-title).

5. Evasion & Spoofing (Use Carefully)

  • -f / --mtu <val>: Fragments IP packets to evade simple packet-inspection firewalls.
  • -D <decoy1,decoy2,ME>: Decoy scan—mixes your real IP with decoy IPs in logs.
  • --source-port <port> / -g <port>: Spoofs source port (e.g., 53 for DNS or 443 for HTTPS) to bypass stateless firewall rules.

6. Output & Documentation

Always save scan results for reporting and offline analysis so you never have to re-scan:

sudo nmap -sS -n -Pn -T2 -p 22,80,443 --max-rate 10 -oA opsec_scan <target> 
  • -oA <basename> saves .nmap (normal), .xml (XML), and .gnmap (grepable) formats simultaneously.

Quick Reference Cheat Sheet

Flag Purpose OPSEC Benefit
-n Disable DNS resolution Avoids DNS query logs
-Pn Skip ping/host discovery Bypasses ICMP blocks
-sS TCP SYN stealth scan Avoids full TCP handshake logs
-T2 / --max-rate Throttle scan speed Evades rate-based IDS/IPS
-p <ports> Target specific ports Minimizes packet volume
--randomize-hosts Randomize target order Breaks sequential scan patterns
-oA <name> Save all output formats Prevents redundant re-scans