Linux Kernel Local Privilege Escalation
Kernel exploits run at the highest privilege level. A failed attempt typically causes a kernel panic and crashes the system. Treat kernel exploitation as a last resort after exhausting all userspace vectors — sudo misconfigs, SUID binaries, cron jobs, and service misconfigs should all be checked first.
See https://hackindex.io/platforms/linux/privilege-escalation/privilege-escalation-enumeration-tools for automated enumeration before attempting kernel exploitation.
Prerequisites Check
Gather kernel version, distribution, and architecture:
Linux target 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 GNU/Linux
Check exact package patch level — distributions backport security patches without incrementing the version number. uname -r alone is unreliable:
A kernel build timestamp from 2024 is almost certainly patched against 2022 exploits regardless of version number.
Hardening Checks — Exploitability Gates
Several kernel settings can completely block a PoC even on a vulnerable version. Check these before spending time on a specific exploit:
Interpretation:
kptr_restrict=2— kernel addresses hidden even from root in logs. Many exploits need to leak these via other meansunprivileged_bpf_disabled=1— eBPF-based exploits will fail entirelyptrace_scope=3— no process attachment at all, blocks ptrace-based chains
Check Kernel Lockdown and Secure Boot — Lockdown mode restricts features even for root:
Check loaded modules — many exploits require specific subsystems:
Automated Enumeration
Run linux-exploit-suggester before picking a specific CVE:
If wget is unavailable, transfer from your attack box — see https://hackindex.io/platforms/linux/privilege-escalation/privilege-escalation-enumeration-tools for transfer methods.
Cross-reference with searchsploit. Exclude DoS exploits — they crash the target without giving you a shell:
Risk Assessment — Pick the Right Exploit
Logic bugs are stable. Memory corruption is not.
High safety — logic bugs: These abuse flaws in permission handling or filesystem logic. They rarely crash the system. Examples: Dirty Pipe, OverlayFS, PwnKit.
Low safety — memory corruption: These abuse buffer overflows, use-after-free, or heap corruption. If memory offsets do not match the exact build, the system crashes immediately. Examples: heap overflows, Netfilter UAF exploits.
Always prefer logic bugs when available.
CVE-2022-0847 — Dirty Pipe
Affected: Linux kernel 5.8 to 5.16.10 / 5.15.24 / 5.10.101
The most reliable kernel exploit for modern labs. A logic bug in the pipe buffer allows overwriting data in read-only files including SUID binaries and /etc/passwd. Extremely stable — does not crash the system.
Check if vulnerable:
Also requires a readable file with existing page cache (any non-empty readable file works):
Exploit — overwrite /etc/passwd to add a passwordless root user:
Exploit-1 modifies /etc/passwd and drops a root shell. After use it attempts to restore the original — verify the file is intact afterwards:
Alternative — exploit-2 injects a SUID shell:
For a dedicated Dirty Pipe page see https://hackindex.io/platforms/linux/privilege-escalation/dirty-pipe-cve-2022-0847.
CVE-2023-0386 — OverlayFS SUID Privilege Escalation
Affected: Ubuntu kernels prior to 6.2 (Ubuntu 22.04 LTS, 20.04 LTS with HWE kernel)
A logic bug in OverlayFS allows a SUID binary from a lower layer to be copied to the upper layer while retaining SUID permissions — even when the upper filesystem is nosuid. Extremely stable, logic bug, does not crash the system.
Check if vulnerable:
Exploit:
This drops a root shell via a SUID binary planted through the OverlayFS upper layer.
CVE-2021-4034 — PwnKit (Polkit pkexec)
Affected: All pkexec versions before patched releases (virtually every Linux distro pre-January 2022)
Technically a Polkit vulnerability but exploitable via userspace. Covered fully at https://hackindex.io/platforms/linux/privilege-escalation/polkit-local-auth-escalation.
Netfilter / nftables Exploits
Require nf_tables module loaded and CONFIG_USER_NS=y:
Notable CVEs in this family:
CVE-2022-32250 — use-after-free in nf_tables (kernel 5.18)
CVE-2022-1015 — out-of-bounds write (kernel 5.16)
CVE-2023-35001 — stack OOB (kernel 6.3)
These are memory corruption exploits — lower stability, architecture-specific offsets. Use as fallback when logic bugs are not applicable.
Compilation and Delivery
gcc is frequently absent on target systems. Compile on your attack box for the same architecture.
Static compilation — safest, no dependency issues:
Cross-compile for 32-bit target on a 64-bit host:
Match glibc version if not compiling static:
Deliver without wget/curl:
Warning
Always compile from source yourself on OSCP — pre-compiled binaries from internet sources may be backdoored or rejected by exam rules.
References
-
Linux Exploit Suggestergithub.com/mzet-/linux-exploit-suggester (opens in new tab)
Standard tool for kernel vulnerability identification
-
Exploit Databasewww.exploit-db.com (opens in new tab)
Primary source for exploit source code
-
CVE-2022-0847 Dirty Pipe Exploitsgithub.com/AlexisAhmed/CVE-2022-0847-DirtyPipe-Exploits (opens in new tab)
Two exploit variants for the Dirty Pipe vulnerability.
-
CVE-2023-0386 OverlayFS Exploitgithub.com/xkaneiki/CVE-2023-0386 (opens in new tab)
OverlayFS SUID escalation for Ubuntu 22.04/20.04.
Was this helpful?
Your feedback helps improve this page.