Skip to content
RCE Write-up Advanced

Novel Arbitrary Write in SQLite

The sqlite_dbpage virtual table lets an attacker with SQL execution overwrite raw database pages, bypassing most of SQLite's fixed header bytes. By relocating the ELF program header table and writing a shared object into a module path, then crashing the process to force a restart, the author achieves remote code execution in Python and Ruby runtimes.

gabdevele.dev

Published on gabdevele.dev

Achieving arbitrary code execution through SQLite is notoriously difficult, particularly in default configurations where external extension loading is disabled. Historically, attackers have relied on ATTACH DATABASE to achieve a dirty arbitrary file write, targeting parsers such as PHP or cronjobs, that tolerate…

The author, on gabdevele.dev

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the sqlite_dbpage virtual table exposes raw page writes to any SQL user, and the few header bytes SQLite keeps fixed can be worked around by relocating the ELF program header table and crashing the process to reload a shadowed module.

Impact

An attacker with a stacked-query SQL injection sink could write a shared object and, if the process is restarted by a manager such as Gunicorn or Docker, achieve remote code execution; this depends on sqlite_dbpage being compiled in and defensive mode being off.

What the attacker needed

SQL injection allowing stacked queries; sqlite_dbpage compiled in; defensive mode disabled; process manager restarts the app

How it was found

  1. Attach a new database file as the write target and create a padding table.
  2. Insert a large zeroblob to make SQLite allocate enough pages on disk.
  3. Overwrite pages in descending order with the payload bytes via sqlite_dbpage updates.
  4. Relocate the shared object's program header table to the end of the file so the fixed header bytes do not corrupt it.
  5. Send the generated SQL to the vulnerable endpoint to write the module into the app directory.
  6. Crash the worker (Gunicorn timeout or memory exhaustion) so it restarts and loads the shadowed module.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

SQLite is a small database engine that stores everything in one file, split into fixed-size blocks called pages. A built-in feature called sqlite_dbpage lets SQL queries read and rewrite those raw pages directly, so an attacker who can run SQL can also write almost any bytes into a file on disk. If that file is a compiled module the application later loads, the attacker's code runs when the app restarts.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.