# Kernel Exploit Basics

> Use when learning kernel exploitation fundamentals in a lab with your own vulnerable VMs. Covers kernel attack surface, common bug classes, SMEP/SMAP/KASLR bypass concepts, and safe lab practices. Also use when triaging whether a kernel bug is exploitable.

- Skill: `mizazhaider-ceh/kernel-exploit-basics` (Agent Skill)
- Install (CLI): `npx get-skill add mizazhaider-ceh/kernel-exploit-basics`
- Raw SKILL.md: https://api.skillmd.com/api/skills/mizazhaider-ceh/kernel-exploit-basics/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Security
- Author: mizazhaider-ceh (https://skillmd.com/u/mizazhaider-ceh)
- Updated: 2026-11-22
- Page: https://skillmd.com/skills/mizazhaider-ceh/kernel-exploit-basics

---


Kernel exploitation turns a kernel bug into ring 0 code execution:
the stakes and the mitigations are both higher than userspace. This
skill covers the fundamentals for lab learning on your own VMs:
attack surface, bug classes, mitigation concepts, and the safe lab
setup. Learning only; never test kernels you do not own.

## Quick Workflow

1. Build the lab: a vulnerable kernel VM with snapshots, and a
   matching debug setup.
2. Learn the attack surface: syscalls, ioctls, and drivers reachable
   from unprivileged users.
3. Study the bug class: UAF, overflow, or race in kernel context.
4. Understand the mitigations: SMEP, SMAP, KASLR, KPTI, and what
   each stops.
5. Plan the primitive: what the bug gives you (read, write, where).
6. Plan the escalation: from primitive to credential overwrite or
   modprobe_path.
7. Develop against snapshots: snapshot before each attempt.
8. Document the full chain for learning, with the mitigations
   noted.

## 1. Lab setup and recon

```bash
# Lab VM: vulnerable kernel, snapshot before you start
# Check the mitigations on your lab kernel
cat /proc/cmdline
dmesg | grep -i -E "smep|smap|kaslr" | head -5
# Find reachable attack surface: world accessible device nodes
find /dev -type c 2>/dev/null | head -20
ls -l /dev/vuln* 2>/dev/null
```

```bash
# Identify the bug: dmesg after a crash tells you the class
dmesg | tail -30
# KASAN builds give precise reports; use a KASAN kernel for learning
```

## 2. Classic escalation primitives (lab)

```bash
# Concept: overwrite creds (uid=0) or modprobe_path, then trigger
# Modern path: ROP in kernel, bypassing SMEP with ret2usr alternatives
# or SMAP bypass via controlled kernel memory writes
echo "learn each mitigation bypass separately before chaining"
```

```python
#!/usr/bin/env python3
"""Lab notes template for a kernel bug."""
bug = {
    "location": "driver ioctl 0x1337",
    "class": "heap UAF",
    "primitive": "write-what-where (limited)",
    "mitigations": "SMEP on, SMAP on, KASLR on",
    "plan": "1. defeat KASLR via info leak 2. ROP to commit_creds(prepare_kernel_cred(0))",
}
for k, v in bug.items():
    print(f"{k}: {v}")
```

## Edge cases

- The bug is not reachable unprivileged. Then it is a lower
  severity local issue; adjust the learning goal.
- KASLR defeats your hardcoded addresses. Learn info leaks first;
  guessing is not a method.
- The VM keeps crashing. That is the process; snapshots make it
  cheap, and each crash teaches the constraint.

## Escalation

- Stuck on a mitigation: study that mitigation's known bypasses
  in isolation before returning to the chain.
- Need a real target assessment: kernel exploitation against
  production is specialized work; scope it separately.

## Detection and defender view

Defenders detect kernel exploitation with kernel integrity
monitoring, audit of privileged operations, and crash analysis.
They defend with the mitigations (keep them on), timely patching,
and reducing attack surface (unneeded drivers, unprivileged
namespaces). The durable lesson: patch quickly, because public
kernel exploits follow disclosure fast.

## Key references

- MITRE ATT&CK T1068 (Exploitation for Privilege Escalation).
- Linux kernel self protection documentation.
- Kernel exploitation learning resources (lab focused).

