World of SELECT-only PostgreSQL Injections: (Ab)using the filesystem
A web API built on Go's Gin framework passed a query parameter straight into a SQL string, giving a SELECT-only SQL injection because the PGX driver wraps queries in prepared statements that block stacked queries. The author then abused granted large-object functions to read and write server files, edited table filenodes on disk to make their user a superuser, and used the config file to reach code execution.
Published on phrack.org
Phrack Prophile on BSDaemon | Phrack Staff |
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
Impact
An attacker with only a SELECT injection could read and write server files, escalate to database superuser, and potentially achieve remote code execution, though the text notes the user was not a superuser and pg_reload_conf was blocked.
What the attacker needed
A reachable web API endpoint; database user with lo_import/lo_export grants; ability to read and write server files
The fix
The application should use parameterised queries instead of string formatting, and the database user should not be granted the large-object file functions.
How it was found
- Send a request with a crafted id value to confirm the injection returns all rows.
- Try a stacked query and observe the driver rejects it as a prepared statement.
- Call the large-object import and get functions through a nested SELECT to read a server file.
- Look up the target table's filenode path and read its metadata.
- Download the filenode, edit it offline to set the superuser flag, and upload it back.
- Overwrite the server configuration file and trigger a reload to execute a malicious library.
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.
The web page took a value from the URL and glued it into a database command without checking it, so a visitor could add their own database instructions. The database driver only allowed one read query at a time, so the author found other ways to read and write files on the server and eventually run their own code there.
What is SQL injection?
Input reaches a database query as code, letting an attacker read or change data the application never meant to expose.