Kuboid
Open Luck·Kuboid.in
Black Hat2024
Open in YouTube ↗

Achilles' Heel of JS Engines: Exploiting Modern Browsers During WASM Execution

Black Hat1,715 views37:00about 1 year ago

This talk demonstrates novel exploitation techniques targeting WebAssembly (WASM) execution within modern browser JavaScript engines, specifically focusing on vulnerabilities in the runtime build, bytecode execution, and external interaction phases. The researchers detail how new WASM proposals and optimizations introduce complex attack surfaces, leading to type confusion and use-after-free vulnerabilities. They present a targeted fuzzing methodology that improves code coverage by distinguishing between compilation and execution errors, enabling the discovery of multiple exploitable bugs. The presentation concludes with a case study on achieving arbitrary read/write and remote code execution (RCE) in Chromium and Firefox by leveraging these WASM-specific flaws.

Exploiting Modern Browser Engines Through WebAssembly Runtime Flaws

TLDR: Researchers at Black Hat 2024 revealed how new WebAssembly (WASM) features and optimizations in V8 and SpiderMonkey introduce critical attack surfaces. By targeting the runtime build, bytecode execution, and external interaction phases, they demonstrated how to achieve arbitrary read/write and RCE. Pentesters should prioritize auditing WASM-to-JS wrappers and garbage collection implementations in browser-based applications to identify similar type-confusion vulnerabilities.

WebAssembly was supposed to be the safe, sandboxed alternative to native code execution in the browser. For years, the security community treated WASM as a black box that was largely impenetrable compared to the messy, JIT-heavy world of JavaScript. That assumption is now officially dead. The research presented at Black Hat 2024 proves that as browsers add support for complex features like garbage collection and tail-calls, they are inadvertently opening massive, under-tested attack surfaces in the very engines that power the modern web.

The Shift in Attack Surface

Modern browser engines like V8 and SpiderMonkey are no longer just executing JavaScript. They are managing a complex, low-level execution environment for WASM that interacts directly with the host browser. The researchers identified that the most dangerous bugs are not in the core WASM logic, but in the "glue" code—the wrappers that handle the translation between WASM and JavaScript types.

When a WASM module calls a JavaScript function, or vice versa, the browser must perform type conversion. This is where the logic breaks. Because WASM is a low-level language that operates on raw memory, and JavaScript is a high-level, dynamic language, the translation layer is prone to type confusion. If the engine fails to correctly validate the signature of an imported function, it can lead to a state where the engine treats a raw memory pointer as a high-level JavaScript object.

Mechanically Exploiting Type Confusion

The researchers demonstrated a clear path to exploitation using CVE-2024-1939. The root cause was a failure in the function signature check within the WASM-to-JS wrapper. By crafting a specific WASM module that triggers this signature mismatch, an attacker can force the engine to misinterpret data on the stack.

In a 32-bit environment, the exploit flow is straightforward:

  1. Allocate a large ArrayBuffer to gain a predictable memory layout.
  2. Use the type confusion bug to create a "fake" JavaScript object at a controlled address.
  3. Leverage this fake object to gain arbitrary read/write primitives within the browser's memory space.

The demo showed this technique being used to pop the calculator on an Android device, proving that these vulnerabilities are not just theoretical. The lack of rigorous checks in the runtime build phase—specifically during the "glue" code generation—means that even minor changes to the WASM specification can introduce exploitable flaws.

Fuzzing for Execution Errors

One of the most valuable takeaways for researchers is the methodology used to find these bugs. Standard fuzzing often fails here because it treats compilation errors and execution errors as the same thing. The researchers built a targeted fuzzing loop that distinguishes between the two.

By using Fuzzilli, they were able to generate WASM samples that specifically target the interaction between the WASM compiler and the runtime. They found that by monitoring the engine's output logs, they could identify when a sample successfully passed the compilation phase but triggered a crash during execution. This distinction is critical. If your fuzzer stops at the first sign of a "compile error," you are missing the entire class of vulnerabilities that occur during the actual execution of the generated machine code.

Real-World Impact for Pentesters

If you are performing a web application penetration test or hunting for bugs in browser-based platforms, stop ignoring the WASM components. Look for applications that use WASM for performance-critical tasks, such as image processing, cryptography, or game engines. These are the areas where developers are most likely to implement custom WASM-to-JS wrappers.

Focus your efforts on the WebAssembly.instantiate calls. Analyze how the application imports and exports functions. If you see complex data structures being passed back and forth between the WASM memory and the JavaScript heap, you have found a high-value target. Use the OWASP A06:2021 – Vulnerable and Outdated Components guidance to frame the risk, but remember that the vulnerability is often in the custom implementation, not just the library version.

Defensive Considerations

For blue teams, the defense is difficult because these bugs exist in the browser engine itself. However, you can reduce the risk by enforcing strict Content Security Policy (CSP) headers that restrict the execution of WASM modules to only trusted sources. If your application does not require WASM, disable it entirely via CSP.

The research highlights that we are entering a new era of browser exploitation where the boundary between high-level JS and low-level WASM is the primary battleground. As these engines continue to optimize for performance, the complexity of the translation layer will only grow. Keep an eye on the V8 security advisories and the Mozilla security advisories for updates on how these engines are patching the "Achilles' heel" of their WASM implementations. The next big browser exploit is likely hiding in the code that connects these two worlds.

Talk Type
research presentation
Difficulty
expert
Category
web security
Has Demo Has Code Tool Released


Black Hat USA 2024

121 talks · 2024
Browse conference →
Premium Security Audit

We break your app before they do.

Professional penetration testing and vulnerability assessments by the Kuboid Secure Layer team. Securing your infrastructure at every layer.

Get in Touch
Official Security Partner
kuboid.in