You've enumerated the kernel and found a potential vulnerability. Now comes the scary part - actually running the exploit. Kernel exploitation is like performing surgery on a running patient. One wrong move and the whole system crashes.Related
This lesson covers the practical steps: compiling exploits, transferring them, executing them safely, and what to do when things go wrong. We'll walk through real examples step by step.
Last Resort Warning
Kernel exploits should be your LAST option. Always try sudo, SUID, cron, and other safer methods first. Kernel exploits can crash systems, corrupt data, and leave traces. In CTFs, a crash means losing your shell.
Compiling Kernel Exploits
Cross-Compilation
Compile on Target
If the target has GCC installed, compile there to avoid architecture mismatches. Just transfer the source code instead of the binary.
Transferring Exploits
/dev/shm for Stealth
/dev/shm is stored in RAM, not disk. Files here don't persist after reboot and leave fewer forensic traces. Perfect for exploit staging.
Running Kernel Exploits
Handling Exploit Failures
DirtyCow Walkthrough
DirtyCow (CVE-2016-5195) is one of the most famous kernel exploits. Let's walk through using it step by step.
DirtyCow Side Effects
DirtyCow exploits a race condition and can corrupt files. Always backup files before overwriting. The /etc/passwd modification persists - remember to clean up!
PwnKit Walkthrough
PwnKit is Reliable
Unlike many kernel exploits, PwnKit rarely crashes systems. It's a good first choice when available. Always check pkexec version first.
Fixing Compilation Errors
Post-Exploitation Steps
Kernel Exploitation Methodology
Kernel Exploit Execution Flow
1
BackupCreate backup shell connection first
2
CompileCompile for correct architecture with needed libraries
3
TransferUpload via HTTP, nc, or base64
4
StagePlace in /tmp or /dev/shm, chmod +x
5
ExecuteRun with any required arguments
6
PersistCreate SUID bash or SSH key immediately
Knowledge Check
Challenges
Key Takeaways
- Always create backup shell before running kernel exploits
- Match compile architecture to target (x86_64 vs i686)
- Use -static to include all libraries in binary
- /dev/shm is RAM-based, good for staging exploits
- Read exploit headers for compile instructions
- Create persistent access immediately after gaining root