Skip to content

hypnguyen1209/offensive-claude / skills/browser-exploitation

browser-exploitation

Verified

Use when building a client-side browser exploit — V8/JSC JIT type confusion to renderer R/W, V8 heap-sandbox escape, renderer-to-browser sandbox escape (Mojo IPC, GPU/Dawn/ANGLE), Electron/webview IPC abuse, 1-click RCE chains

references/v8-sandbox-escape.md

View on GitHub
# V8 Heap-Sandbox Escape (Cage R/W → Native R/W → Code Execution)

Input: an in-cage arbitrary read/write from `v8-jit-typeconfusion.md`. Problem: that R/W is *cage-relative* — every JS-reachable pointer is a 32/35-bit offset into the V8 heap region, and the backing-store pointers you faked are sandboxed. You cannot read/write process memory yet. This cluster escapes the **V8 heap sandbox**.

## Theory / Mechanism

### What the sandbox is
The V8 sandbox (a.k.a. "heap cage") is software fault isolation, *not* a hardware boundary. Design (Samuel Groß, OffensiveCon 2024):
- **Pointer compression**: all on-heap pointers are 32-bit (35-bit on some Android builds) indices into a contiguous, base-aligned region (up to ~128 GB reservation with guard pages). Even a fully arbitrary in-cage write cannot name an address outside the cage by construction.
- **External Pointer Table (EPT)**: pointers to *out-of-cage* C++ objects (e.g. `ArrayBuffer` backing stores) are not stored inline; objects hold an index into the EPT, and the table holds the real 64-bit pointer with a type tag. A confused/forged inline value can't become an arbitrary native pointer — it can only pick an EPT slot.
- **Trusted Pointer Table (TPT) / trusted space**: introduced to hold security-sensitive objects (much WebAssembly metadata, bytecode/code references) outside the corruptible cage. Objects in the cage reference them via an index into the TPT.
- Because of pointer compression there is **no room for MTE tag bits**, so V8 explicitly does not rely on memory tagging here.

### How escapes actually happen
You don't "bypass pointer compression" head-on. You find a structure still holding a **raw 64-bit pointer** that an in-cage write can reach, or you abuse a **trusted-table** entry. WebAssembly is the perennial source because Wasm needs real code/function pointers:
- **Raw pointer in a Wasm object** (historically `WasmIndirectFunctionTable.targets`, Liftoff-compiled code references): a field that points *outside* the cage to executable/native memory. If your in-cage write reaches it, you forge a native pointer → arbitrary native write → code execution.
- **Trusted Pointer Table abuse**: overwrite a TPT entry (or fake an object that indexes one) to point at attacker-controlled trusted memory, e.g. fake a `WasmExportedFunctionData` so calling the exported function sets `rip` to a chosen 8-byte value; control the bytes via immediates of a bytecode instruction (`AddSmi.ExtraWide`).
- **Pivot to RWX Wasm code**: a JIT-compiled Wasm module owns an RWX (or W^X-toggled) code region with a stable, leakable address. Overwrite the start of that region with shellcode (encoded as Wasm `f64.const` immediates, then patched) and call the exported function → native execution.

### The escape ladder
1. In-cage R/W (have it). 2. Instantiate a small Wasm module → get a `WebAssembly.Instance`/exported function backed by an RWX code page. 3. Locate the trusted/raw pointer for that module via your cage R/W (walk the instance's fields; many are in trusted space, reached through the TPT index). 4. Either overwrite the raw code/target pointer to point at your shellcode buffer, or write shellcode into the RWX code page directly. 5. Call the exported Wasm function → native code execution **inside the renderer** (sandbox-escaped from V8's POV; OS sandbox is the next cluster).

## Modern 2024-2026 variants (verified)

- **In-the-wild `WasmIndirectFunctionTable` raw-pointer escape (Theori, 2025)** — analyzing CVE-2023-2033, Theori escaped the V8 sandbox via the raw `targets` pointer in `WasmIndirectFunctionTable`, which points outside the cage, yielding arbitrary write + code execution. The corresponding V8 patch "sandboxified" that pointer (turned it into an on-heap pointer-compressed pointer). The technique generalized an approach @zh1x1an1221 used to pop calc on CVE-2023-3079 (also in-the-wild). This is the canonical, documented modern escape primitive.
- **Liftoff assembly trust abuse (Chromium issue 41482162)** — after in-cage corruption, escape by abusing Liftoff's trust in V8 sandbox pointers to corrupt instructions and overwrite sanity checks, creating a native arbitrary R/W. Reported as an escape path.
- **Trusted Pointer Table / `WasmExportedFunctionData` (HITCON CTF 2024, mem2019)** — with the sandbox enabled and in bug bounty scope, the writeup demonstrates writing a 64-bit value into a TPT entry + a PIE base leak, then faking a `WasmExportedFunctionData` to set `rip`, controlling the target bytes via `AddSmi.ExtraWide` immediates.
- **Community catalog (xv0nfers/V8-sbx-bypass-collection)** — 2024-2025 escapes: dangling `ArrayBufferExtension` via `ArrayBufferSweeper` linked-list manipulation; `MemoryChunk` `metadata_pointer_table` OOB write; OOB write in `JsonStringifier::SerializeString`; `StringToBigIntHelper` stack overflow; control-flow hijack via corrupted `MessageTemplate` enum in a switch; `%TypedArray%.prototype.set` bounds-check integer overflow (wildcopy arbitrary write).

Currency note: many older "fake ArrayBuffer backing store" escapes are dead on builds with the sandbox enabled (default since ~2023). On current builds you **must** target trusted/raw-pointer structures (mostly Wasm) or a non-sandboxed table OOB.

## Complete working code/commands

`scripts/sandbox_escape.js` is a complete, annotated template that (given `read64`/`write64` from `v8_typer.js`) builds a Wasm RWX page, locates it, and patches in shellcode. Core flow:

```javascript
// 1) Build a tiny wasm module so V8 allocates an RWX code page we can target.
const wasmCode = new Uint8Array([
  0x00,0x61,0x73,0x6d, 0x01,0x00,0x00,0x00,            // \0asm, version 1
  0x01,0x05,0x01, 0x60,0x00,0x01,0x7f,                  // type: () -> i32
  0x03,0x02,0x01,0x00,                                  // func 0 uses type 0
  0x07,0x08,0x01, 0x04,'m','a','i','n'.charCodeAt?0:0,  // export "main" (see script for bytes)
  0x00,0x00,
  0x0a,0x06,0x01, 0x04,0x00, 0x41,0x2a, 0x0b,           // body: i32.const 42; end
]);
const instance = new WebAssembly.Instance(new WebAssembly.Module(wasmCode), {});
const main = instance.exports.main;             // calling this runs the RWX code page

// 2) Using cage R/W, walk the JSFunction -> SharedFunctionInfo -> WasmExportedFunctionData
//    (trusted space; reached via its TPT index) to recover the native code entry pointer.
// 3) Write x64 shellcode bytes into the RWX code page (see scripts/sandbox_escape.js for the
//    full pointer-chasing + the prebuilt execve/WinExec shellcode blob).
// 4) main();  // -> native code execution
```

Local sandbox-internals testing:
```bash
# d8 builds expose flags to test sandbox behavior locally:
d8 --sandbox-testing-mode ./scripts/sandbox_escape.js     # validate cage boundaries
d8 --no-sandbox-testing-mode ./scripts/sandbox_escape.js  # run the real escape path
# Confirm the sandbox is even on in your target build:
d8 -e 'console.log(typeof Sandbox)'   # in testing builds
```

## Detection
- The escape itself produces **RWX memory activity**: a real shellcode write into a Wasm code page and a subsequent indirect call.
```yaml
# Sigma (Windows ETW / EDR): renderer creating/modifying RWX regions atypically
title: Chromium Renderer RWX Region Write (possible V8 sandbox escape)
logsource: { product: windows, category: image_load }   # pair with EDR mem-protect telemetry
detection:
  proc:
    Image|endswith: ['\chrome.exe','\msedge.exe']
    CommandLine|contains: '--type=renderer'
  mem:
    Protection: 'PAGE_EXECUTE_READWRITE'
  condition: proc and mem
level: high
```
- EDR/ETW: `VirtualProtect`/`mprotect` toggling a Wasm region to executable then immediate execution; unexpected native call from a JIT region; renderer making syscalls unusual for sandboxed renderers (file/registry/process) — those typically only succeed *after* the OS-sandbox escape, but the attempt is logged.
- IOCs: shellcode byte patterns inside Wasm code pages in a renderer minidump; an exported Wasm function whose code prologue doesn't match V8's codegen.

## OPSEC
- **Touches**: renderer-process RWX Wasm pages and trusted-space/TPT entries. No disk yet.
- **Reuse, don't allocate**: write shellcode into the *existing* RWX Wasm page rather than `VirtualAlloc(RWX)`/`mmap(PROT_EXEC)` — fresh RWX allocations are a louder EDR signal than overwriting an already-RWX JIT page.
- **Restore trusted state**: if you overwrote a TPT entry / raw code pointer to bootstrap, write it back to the original value before continuing so GC / later Wasm calls don't crash the renderer.
- **Stay in-process**: do all subsequent work (OS-sandbox escape staging) from this native exec context without spawning a child — child processes are the loudest IOC and most are blocked by the renderer sandbox anyway.
- Keep the Wasm module minimal; large or oddly-shaped modules increase crash risk and telemetry.

## References
- Theori, "A Deep Dive into V8 Sandbox Escape Technique Used in In-The-Wild Exploit" — https://theori.io/blog/a-deep-dive-into-v8-sandbox-escape-technique-used-in-in-the-wild-exploit
- Samuel Groß, "The V8 Heap Sandbox" (OffensiveCon 2024) — https://saelo.github.io/presentations/offensivecon_24_the_v8_heap_sandbox.pdf
- V8 team, "The V8 Sandbox" — https://v8.dev/blog/sandbox
- mem2019, "Breaking V8 Sandbox with Trusted Pointer Table" (HITCON CTF 2024) — https://mem2019.github.io/jekyll/update/2024/07/14/HITCON.html
- Chromium issue 41482162, "V8 sandbox escape abusing Liftoff assembly" — https://issues.chromium.org/issues/41482162
- xv0nfers/V8-sbx-bypass-collection — https://github.com/xv0nfers/V8-sbx-bypass-collection
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: 198kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
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: 194kUpdated Claude CodeCodexVerifiedInstall