Aprende › Vulnerabilidades web

Kernel exploitation: SMEP, SMAP, KASLR, CFI y bypass techniques modernos

· 10 min de lectura

Los kernels modernos tienen múltiples defensas (SMEP, SMAP, KASLR, CFI, kPTI). Aprende el modelo kernel vs user-space, vulnerabilities comunes (UAF, race conditions), bypass techniques y toolkit de kernel exploit development en Linux y Windows.

El kernel exploitation es la especialización técnica más profunda de offensive security: desarrollar exploits que ejecutan código con privilegios kernel-mode (anillo 0 en x86), bypassing todas las user-mode protections. Un kernel exploit típicamente escala privileges desde unprivileged user a root/SYSTEM, puede evadir EDRs user-mode, y en algunos casos otorga access a hardware directly. Es el nivel técnico donde operan operadores N-day/0-day professionals, researchers de vendors (Microsoft Security Response Center, Google Project Zero, VX Underground), y attackers de alta sofisticación (Pegasus-style spyware, state-sponsored APTs).

Esta lección cubre el modelo kernel vs user-space en Linux y Windows 2026, las defensas modernas (SMEP, SMAP, KASLR, kPTI, CFI, hypervisor isolation), vulnerabilities comunes (use-after-free, race conditions, type confusion, out-of-bounds), bypass techniques canonicales, y el toolkit (QEMU + GDB, WinDbg, kernel debuggers). Es la segunda lección de la Tanda 7, dedicada a especializaciones profundas.

Kernel exploit development en own systems o lab VMs. Testing contra systems ajenos es intrusion. Research en kernels open source (Linux) está active + welcome; Windows research requires MSRC coordination para disclosure.

Modelo kernel vs user-space#

Kernel vs user-space: ring 0 full privileges, ring 3 restricted, syscalls bridge
Kernel vs user-space: ring 0 full privileges, ring 3 restricted, syscalls bridge

CPU x86-64 tiene 4 privilege levels (rings):

  • Ring 0: kernel-mode. Full privileges, access all memory, all instructions.
  • Ring 3: user-mode. Restricted. Para hardware access, invoca kernel via syscalls.
  • Rings 1, 2 unused típicamente.

Transition user → kernel vía syscall:

  • User program invokes syscall instruction (x86-64) con syscall number en RAX.
  • CPU switches to Ring 0, jumps to kernel's syscall handler.
  • Handler executes, returns result via sysret.

Kernel memory separated: user cannot read/write kernel memory directly. Syscalls copy data across boundary with validation.

Si kernel bug → attacker in user-mode puede trigger execution in Ring 0 context, taking over system.

Defensas modernas#

Linux + Windows kernels implementan multiple mitigations:

SMEP (Supervisor Mode Execution Prevention)#

CPU feature desde Intel Ivy Bridge (2012). Blocks execution de user-mode code desde kernel mode. Prevents classic "ret2usermode" exploits que pivoted a user-space shellcode.

Bypass: ROP chains stay en kernel memory (no jumps to user-mode).

SMAP (Supervisor Mode Access Prevention)#

Haswell+ (2013). Blocks kernel access to user-mode pages salvo via specific instructions (stac/clac). Prevents kernel reading user shellcode.

Bypass: data stays in kernel memory, or stac gadgets.

KASLR (Kernel ASLR)#

Randomizes kernel base address at boot. Makes targeting specific addresses hard.

Bypass:

  • Info leak: any bug leaking address (dmesg, prctl errors, timing).
  • Spectre/Meltdown descendant attacks.
  • SysV procfs leaks historical.

Finding infoleak es primer paso en modern exploit chain.

kPTI (Kernel Page Table Isolation)#

Post-Meltdown (2018). Separates kernel y user page tables. Mitigates Meltdown-style attacks.

Minor performance cost; mostly transparent.

CFI (Control Flow Integrity)#

Enforces indirect calls only to valid targets. Linux: CFI patches. Windows: Control Flow Guard (CFG), xFG (extended).

Bypass research continues; requires matching valid signatures.

Stack canaries kernel#

Random values on stack; corruption detected before return.

HVCI (Hypervisor-Code-Integrity)#

Windows: kernel code signed, verified by hypervisor. Prevents arbitrary code execution en kernel.

Bypass: data-only attacks (modify data structures, no code injection).

Hardware features#

  • MPX, CET (shadow stack + indirect branch tracking): hardware-enforced.
  • Intel TDX, AMD SEV: encrypted memory.
  • ARM MTE: memory tagging extension.

Modern kernel exploits son multi-stage chains bypassing varios de estos simultaneously.

Vulnerability classes#

Use-after-free (UAF)#

Objeto freed, reference still used. Allocator may reuse memory, attacker controls contents.

Pattern:

struct obj *p = alloc_obj();
free_obj(p);
// ... later ...
p->callback();  // UAF

Classic + still very common. Mitigation: better allocator design, lifetime tracking.

Race conditions#

Multi-threaded kernel paths. Attacker triggers concurrent operations, exploits intermediate state.

Dirty Pipe (CVE-2022-0847): race in pipe buffer flag handling. Allowed writes to read-only files.

Dirty COW (CVE-2016-5195): older but famous race UAF-style.

Type confusion#

Pointer treated as wrong type. Especially en kernel code casting structs manually.

Out-of-bounds read/write#

Buffer boundaries miscalculated. Read leaks data (infoleak), write corrupts.

Integer overflow/underflow#

Common en size calculations. Leads to OOB.

Null pointer dereferences#

Historically exploitable con mmap(NULL,...) (pre-2009). Mitigated with mmap_min_addr sysctl. Still relevant in uncommon cases.

Stack overflow#

Less common en kernel (stack size controlled), still occurs.

Exploit development workflow#

Exploit chain: infoleak → control flow → privilege escalation → cleanup
Exploit chain: infoleak → control flow → privilege escalation → cleanup

Modern kernel exploit chain:

Step 1 - Infoleak:

Find bug leaking kernel address. Defeats KASLR. Required por bypasses subsiguientes.

Step 2 - Control flow hijack:

Trigger bug granting control: UAF, type confusion, ROP chain building.

Step 3 - SMEP bypass:

ROP chain entirely in kernel memory. Or disable SMEP (modify CR4) via known gadgets.

Step 4 - SMAP bypass:

Data operations stay in kernel. Or stac gadget to allow brief user access.

Step 5 - Privilege escalation:

Overwrite cred struct (Linux) o token (Windows) setting uid=0 / SYSTEM.

Common technique Linux: find init_cred o modify current task's creds.

Step 6 - Cleanup:

Restore kernel state. Avoid crash. Return to user-mode cleanly.

Each step requires deep OS internals knowledge. Teams specialized develop over weeks/months per exploit.

Toolkit#

Linux#

  • QEMU + GDB: emulate kernel, debug con gdb.
  • kgdb: in-kernel debugger.
  • crash utility: analyze crashes, dumps.
  • drgn: scripting debugger (Facebook).
  • pwntools: scripting framework exploits.
  • ROPgadget / ropper: find ROP gadgets en kernel binary.

Windows#

  • WinDbg: THE Windows kernel debugger.
  • KD + VBox/VMware: debug target VM.
  • Pykd: scripting WinDbg con Python.
  • HexRays IDA Pro: disassembler (comercial).
  • Ghidra: alternative free.

Common#

  • Fuzzers: syzkaller (Linux kernel), kAFL.
  • Static analysis: Coverity, CodeQL.

Linux CVEs recientes#

  • CVE-2022-0847 Dirty Pipe: pipe buffer bug, writes to read-only files.
  • CVE-2022-2588 (route4 UAF): network filter.
  • CVE-2023-0386 OverlayFS: SUID escalation.
  • CVE-2023-3269 StackRot: stack rotation bug.
  • CVE-2024-1086 (nf_tables): netfilter UAF, popular.
  • Various io_uring: subsystem con many bugs historically.

Many exploits publicados con detailed writeups por kernelCTF winners (Google challenge paying for n-day exploits).

Windows kernel bugs#

  • CVE-2022-24521 CLFS: common log file system LPE.
  • CVE-2023-28252 CLFS: another CLFS.
  • CVE-2024-30088 kernel: LPE.
  • Driver vulns: BYOVD (Bring Your Own Vulnerable Driver) technique sigue active.

Mitigation strategies#

Beyond individual bugs:

  • kernel hardening: KSPP (Kernel Self Protection Project) Linux.
  • grsecurity / PaX: commercial hardening.
  • Dedicated IOMMU: prevents DMA attacks.
  • Confidential computing: AMD SEV, Intel TDX encrypt kernel memory.

Para average sysadmin: keep kernel updated, enable all mitigations, monitor for anomalies.

syzkaller: el fuzzer que domina#

syzkaller (Google) es coverage-guided kernel fuzzer. Encuentra bugs automáticamente via systematic input exploration. Responsible for la mayoría de kernel bugs descubiertos 2018-2026.

Workflow:

# Setup syzkaller
git clone https://github.com/google/syzkaller
cd syzkaller && make
# Configure target kernel
./bin/syz-manager -config my.cfg
# Runs 24/7 fuzzing target kernel VM
# Reports crashes with reproducers

Para kernel researchers, syzkaller es essential. Public syzbot dashboard shows ongoing Linux kernel bugs discovered.

Grupos APT y kernel#

Múltiples state-sponsored groups invest heavily en kernel exploits:

  • Equation Group / NSA: historical custom kernel exploits in leaked tools (DoublePulsar, EternalBlue were kernel-level).
  • APT41: multiple Windows kernel 0-days.
  • Lazarus (North Korea): kernel component en multiple campaigns.
  • Pegasus (NSO Group): iOS kernel exploits comprehensive para zero-click.

Para most organizations, direct kernel exploitation menos common threat que supply chain / phishing. Pero worth understanding para threat modeling.

Bug bounties vs gray market#

Kernel 0-days tienen distintos mercados:

  • Legitimate bug bounties: ZDI (Trend Micro), vendor programs (Microsoft, Google).
  • Pwn2Own: competition paga 100k-500k por kernel exploits.
  • Gray market vendors: Zerodium, Zemethos, state buyers. Pay more pero controversial ethics.
  • Direct state sales: documented Pegasus/NSO case.

Prices for working Windows / Linux kernel LPE 0-day: 100k-500k USD legitimate, 500k-2M USD gray market.

Preguntas frecuentes#

¿Vale la pena carrera en kernel exploitation?#

High barrier entry, high reward. Vendors (Microsoft, Google, Apple) hire top talent. Independent researchers participate en Pwn2Own, kernelCTF.

¿Cuánto tiempo aprender kernel exploit dev?#

Full proficiency: 2-5 years dedicated study. Requires OS internals, assembly, debugger mastery. Not quick.

¿Linux vs Windows kernel?#

Both have active exploit development communities. Linux more academically studied, Windows targets corporate clients. Skills transfer con effort.

¿Bugs encontrados cómo report?#

  • Linux: linux-distros ML, kernel maintainers direct.
  • Windows: MSRC.
  • Vendor-specific per driver.

Typical 90-day embargo before public disclosure.

¿Pays para kernel 0-days?#

Yes, significant. ZDI (Zero Day Initiative) paga 100k+ USD typical. Grayer markets (Zerodium, etc.) pay more pero controversial.

¿Dónde practico?#

El laboratorio red-hat de whoami-labs incluye exploitable Linux kernel modules intencionales en VM aislada. Practica UAF exploitation, SMEP bypass, privilege escalation techniques.

¿Rust en kernel ayuda?#

Linux adopting Rust gradually (first Rust code 2022). Memory safety reduces UAF, OOB. Pero existing C codebase remains vulnerable. Transition multi-decade.

¿macOS/XNU kernel diferentes?#

Similar concepts, distinct architecture. XNU hybrid (Mach + BSD). Fewer researchers públicos; tighter code vía Apple. Market para exploits muy valuable.

¿Pwn2Own es realistic learning?#

Yes, prep for Pwn2Own es world-class training. Teams prep meses, publish findings post-event. Educational blog posts abundant.

¿Hypervisor escapes relacionados?#

Yes, cross-over especialización. Hypervisor bugs allow escape VM → host (often kernel-level). Highest difficulty + highest pays.

¿pwn.college worth learning?#

Excellent free resource. ASU course publicly available. Cubre basics a advanced kernel exploit.

¿Hardware para lab?#

Modest: laptop con 16GB RAM runs VMs comfortably. QEMU + kernel source + GDB. KASan enabled kernel para easier bug finding. Minimal cost.

Resumen#

  • Kernel exploitation desarrolla exploits ejecutando en Ring 0, bypassing user-mode protections.
  • Defensas 2026: SMEP, SMAP, KASLR, kPTI, CFI, HVCI, stack canaries, hardware features.
  • Vuln classes: UAF, races, type confusion, OOB, integer overflows.
  • Exploit chain: infoleak → control flow → SMEP bypass → SMAP bypass → privesc → cleanup.
  • Toolkit: QEMU+GDB, WinDbg, syzkaller, pwntools, ROPgadget.
  • CVEs activos 2022-2024: Dirty Pipe, netfilter bugs, CLFS Windows.
  • Carrera high-barrier, high-reward. Pays large en specialized vendor + bug bounty markets.

Entry paths para principiantes#

Kernel exploitation tiene barrier entry alto. Recommended progression:

Fase 1 - Fundamentos (6-12 meses):

  • C programming solid.
  • x86-64 assembly basics.
  • OS internals (CSAPP book, Operating Systems Three Easy Pieces).
  • Linux kernel basics: Robert Love's Linux Kernel Development.

Fase 2 - User-space exploitation (6-12 meses):

  • CTF challenges pwnable.kr, pwn.college.
  • ROP chains construction.
  • Heap exploitation.
  • Format strings, stack overflows.

Fase 3 - Kernel basics (6-12 meses):

  • Simple kernel modules.
  • QEMU/GDB kernel debugging.
  • Kernel CTF challenges (tcache_tyrant, etc).
  • First UAF exploit in intentional bug.

Fase 4 - Real bugs (12+ meses):

  • Follow syzbot reports.
  • Reproduce public kernel exploits.
  • Contribute upstream fixes.
  • Own research on subsystems.

Dedicated 2-3 years necessary to reach competitive level. Community (CTF teams, Discord servers) crucial.

Direction 2026-2030:

  • Rust kernel code: gradual adoption, Memory-safety mitigations.
  • Hardware security features: CET widely deployed, ARM MTE arriving.
  • Formal verification kernel components: seL4 established, more Linux components verified.
  • Confidential computing: encrypted kernel memory en TDX/SEV.
  • AI-driven fuzzing: ML identifying bug patterns faster.

Exploitation remains possible pero bar continues rising. Specialized expertise commands premium.

Es carrera que selecciona por dedicación extrema: pocos entran, pocos permanecen, pero los que lo hacen tienen job security para décadas en un campo donde la demanda constantemente supera la oferta de talento altamente cualificado con experiencia real demostrable en artefactos públicos publicados verificables por la comunidad técnica internacional especializada en seguridad ofensiva técnica de bajo nivel a nivel kernel y hypervisor en sistemas operativos modernos y maduros.

Fuentes y lecturas recomendadas#

Practícalo en estos laboratorios

Ver todos los laboratorios de esta categoría