Linux Kernel Exploits
When escalation via misconfigurations (sudo, SUID, cron, capabilities) bears no fruit, what remains is exploiting a vulnerability in the Linux kernel itself. A successful kernel exploit gives root directly, regardless of permissions and configurations. But it’s the last resort: many exploits are unstable, can cause a kernel panic and take down the host, and are very noisy. First exhaust the configuration paths (see Privilege Escalation).
Threat model
Section titled “Threat model”The kernel is the ultimate trust boundary: it runs in ring 0 and mediates everything. A memory bug (use-after-free, overflow, race condition) in code reachable from an unprivileged user allows corrupting kernel structures and, ultimately, executing with root credentials (typically by calling commit_creds(prepare_kernel_cred(0))). The attacker gains absolute root, but accepts the risk of destabilizing the system.
Theory / Why it’s the last resort
Section titled “Theory / Why it’s the last resort”- Crash risk: a badly ported exploit can cause a kernel panic and bring down the server; in a real pentest against production, this is serious.
- Noise: they tend to be EDR-detectable and leave traces (
dmesgoops, loaded modules). - Variable reliability: they depend on the exact version, architecture, and mitigations (KASLR, SMEP/SMAP, KPTI). The same CVE can be trivial on one build and non-exploitable on another.
So: enumerate and try everything else first; the kernel only when there’s no other way.
Red Team
Section titled “Red Team”Identify the version and map exploits
Section titled “Identify the version and map exploits”uname -a # exact version and architecturecat /etc/os-release # distro (affects which patches are backported)cat /proc/version# version-based exploit suggesters./linux-exploit-suggester.sh # (LES) maps CVEs/exploits to the kernelsearchsploit linux kernel 5.8 # cross-reference manuallyCareful: the distro may have backported the patch without changing the version number. LES helps, but verify the package changelog (dpkg -l linux-image*, rpm -q kernel).
Known kernel CVEs (real)
Section titled “Known kernel CVEs (real)”- Dirty COW — CVE-2016-5195: copy-on-write race condition → write to read-only mapped files → root.
- Dirty Pipe — CVE-2022-0847: pipe/page-cache flaw allowing overwrite of read-only files (e.g.
/etc/passwd) → root. Usually stable. - nf_tables — CVE-2024-1086: use-after-free in netfilter
nf_tables→ local LPE. - OverlayFS: CVE-2021-3493 (Ubuntu), CVE-2023-0386 → LPE via setuid copy-up.
- GameOver(lay): CVE-2023-2640 and CVE-2023-32629 in Ubuntu’s OverlayFS → root.
- Sequoia — CVE-2021-33909:
size_tunderflow in the VFSseq_file→ root. - PwnKit — CVE-2021-4034: actually
pkexec(SUID), not kernel, but “universal root”; see SUID.
If you don’t know a CVE for certain, describe the class (UAF in a subsystem, COW race…) and don’t invent identifiers.
Exploitation flow (carefully)
Section titled “Exploitation flow (carefully)”uname -a→ exact version and architecture.- LES / searchsploit → candidates.
- Verify applicability (version, arch, active mitigations).
- Prefer known, well-tested exploits (Dirty Pipe is usually stable).
- Compile on the target (needs
gcc) or port a compatible binary (mind glibc/arch). - Test in a lab/snapshot first; never debut on production.
- Run, confirm root (
id), and stabilize the shell.
gcc exploit.c -o exploit && ./exploit # if gcc is on the targetid # uid=0(root) -> successBlue Team
Section titled “Blue Team”Detection
Section titled “Detection”dmesg/journalctl -k: kernel oops, warnings, and stack traces right before an escalation are a strong IOC.- auditd: unexpected module loads (
init_module/finit_module), execution of freshly compiled binaries in/tmp,gccfollowed by an EUID 0 process. - EDR/eBPF that detects exploitation patterns (credential manipulation,
commit_creds).
Hardening
Section titled “Hardening”- Keep the kernel patched (unattended-upgrades; livepatch/kpatch to avoid reboots): the #1 defense.
- Active mitigations: KASLR, SMEP/SMAP, KPTI;
kernel.unprivileged_userns_clone=0,kernel.kptr_restrict=2,kernel.dmesg_restrict=1. - Reduce surface: disable unnecessary modules and functionality; seccomp; AppArmor/SELinux.
- Hardened kernels (grsecurity, lockdown) in critical environments; see hardening and patch management.
Response
Section titled “Response”If kernel exploitation is confirmed: isolate, capture memory/artifacts (Linux DFIR), and rebuild the host (a compromised kernel isn’t trustworthy); prioritize patching across the whole fleet on the same version.
Checklist
Section titled “Checklist”-
uname -a+ distro → exact version and architecture - LES / searchsploit to map exploits
- Verify applicability (version, arch, mitigations)
- Having exhausted configuration paths first (privesc)
- Prefer stable exploits (Dirty Pipe CVE-2022-0847)
- Test in a lab/snapshot before the real target
- Confirm root and stabilize the shell
- Blue: patched kernel, mitigations, EDR, dmesg_restrict?