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

New Wine in an Old Bottle: Attacking Chrome WebSQL

Black Hat709 views31:11over 2 years ago

This talk demonstrates novel fuzzing techniques, specifically BNF-based and AST-based fuzzing, to discover memory corruption vulnerabilities in the Chrome WebSQL implementation. The research focuses on the SQLite engine integrated within the browser, identifying critical flaws in how SQL statements are parsed and optimized. The presenters successfully leverage these techniques to uncover multiple use-after-free vulnerabilities, including a seven-year-old bug. The session provides a detailed methodology for improving fuzzer effectiveness through context-aware grammar templates and heap spraying.

Exploiting Chrome WebSQL: How Modern Fuzzing Uncovered a Seven-Year-Old UAF

TLDR: Researchers at Black Hat 2023 demonstrated that Chrome’s legacy WebSQL implementation remains a fertile ground for memory corruption, specifically through the SQLite engine. By using context-aware BNF and AST-based fuzzing, they uncovered multiple use-after-free vulnerabilities, including a critical bug that had persisted for seven years. Pentesters should prioritize testing browser-based database interactions, as these legacy components often lack the modern hardening applied to core browser features.

WebSQL is effectively dead, yet it lingers in the codebase of major browsers like Chrome, creating a massive, often overlooked attack surface. While the industry has largely moved toward IndexedDB, the underlying SQLite engine powering WebSQL remains a critical component. If you are still auditing browser-based applications or looking for high-impact bugs in Chromium-based environments, this is where you should be looking. The recent research presented at Black Hat 2023 proves that even well-trodden code paths in SQLite can hide deep-seated memory corruption issues that bypass standard security mitigations.

The Power of Context-Aware Fuzzing

Standard black-box fuzzing often fails against complex SQL engines because the fuzzer generates syntactically invalid queries that are rejected by the parser before they ever reach the interesting memory-handling logic. To find deep bugs, you need to speak the language of the target. The researchers moved beyond simple mutation-based fuzzing by implementing two specific strategies: BNF-based fuzzing and AST-based fuzzing.

By defining a grammar template that mirrors the structure of valid SQL statements, they ensured that the fuzzer spent its time exploring the execution logic rather than getting stuck on syntax errors. The OWASP SQL Injection page covers the basics of injection, but this research goes much further, targeting the memory management of the engine itself. When you combine this grammar-based approach with a custom AST parser, you can generate complex, nested queries that trigger edge cases in the SQLite query optimizer.

Anatomy of the Vulnerability

The most significant finding was a use-after-free (UAF) vulnerability, tracked as CVE-2022-3041. This bug existed in the wild for seven years, hidden by the complexity of the SQLite query optimization phase. The vulnerability occurs when the query optimizer attempts to trim the syntax tree during semantic analysis.

In certain scenarios involving complex SELECT statements with GROUP BY and HAVING clauses, the optimizer incorrectly releases memory associated with specific nodes while the engine still holds pointers to them. The researchers used a heap-spraying technique to gain control over the freed memory, effectively turning a crash into a reliable exploit.

The following simplified logic illustrates the trigger condition:

SELECT * FROM (
  SELECT count(DISTINCT id) FROM users GROUP BY name HAVING count(id) > 1
) WHERE id IN (SELECT id FROM other_table);

When the engine processes this, the HAVING clause triggers a recursive call to the sqlite3Select function. If the optimizer decides that the ORDER BY or HAVING nodes are redundant, it frees the memory. However, if the pointer is still referenced in the pAggInfo structure, the engine later attempts to access that freed memory, leading to the UAF.

Real-World Impact for Researchers

For those of us conducting red team engagements or hunting for bugs, this research highlights a critical shift: stop focusing solely on the application layer and start looking at the browser's internal libraries. WebSQL is a third-party dependency that Google has to maintain, and as the researchers noted, third-party libraries are almost always the weakest link.

If you are testing an application that uses WebSQL, you are essentially testing the browser's implementation of SQLite. A successful exploit here doesn't just compromise the web application; it can lead to a full sandbox escape. During your next engagement, look for applications that perform heavy data processing in the browser. If you can influence the structure of the SQL queries being executed, you have a direct path to the engine's optimizer.

Hardening the Browser

Defenders and browser vendors have a difficult task here. The primary mitigation is to continue the deprecation of legacy features like WebSQL. If you are managing a fleet of browsers, ensure that you are running the latest versions of Chrome, as these patches are often backported to address long-standing issues in the underlying SQLite engine.

For developers, the best defense is to avoid legacy storage APIs entirely. If you must use client-side storage, stick to modern, well-maintained APIs like IndexedDB or the Cache API. These are built with modern security models in mind and are subject to much more rigorous testing than the legacy code paths that have been accumulating technical debt for nearly a decade.

The takeaway for any serious researcher is clear: the most dangerous bugs aren't always in the newest features. They are often hiding in the "old bottles" of legacy code that everyone assumes is too simple to be broken. Keep digging into the dependencies, keep refining your grammars, and don't assume that a seven-year-old codebase is secure just because it hasn't been in the headlines.

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


Black Hat Asia 2023

45 talks · 2023
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