PreAuth RCE with CodeQL in Under 20 Minutes
The pgAdmin web interface in server mode had an unauthenticated endpoint that passed a user-controlled path to a subprocess call, allowing an attacker to execute arbitrary code by pointing to a remote SMB share containing a malicious executable. An attacker could achieve pre-authentication remote code execution on Windows installations.
Published on frycos.github.io
This write-up won’t be an intense discussion on security code review techniques this time. We’ll simply let do all the hard work by a third party: CodeQL.
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 endpoint lacked authentication and passed a user-supplied path to subprocess.getoutput without validating that the path was local and safe.
What the attacker needed
PgAdmin server mode on Windows; attacker-controlled SMB share; network access to the endpoint
The fix
The pgAdmin team fixed the vulnerability in version 6.17 by adding authentication to the endpoint.
How it was found
- Set up an SMB server on the attacker machine.
- Create a malicious executable named after one of the expected utilities.
- Send a POST request to the validate_binary_path endpoint with a utility_path pointing to the SMB share.
- The server retrieves and executes the file from the SMB share.
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.
pgAdmin is a tool for managing PostgreSQL databases, and it can run as a web server. A part of that web server let anyone, without logging in, tell it where to look for certain helper programs. Because the server would run whatever program it found at that location, an attacker could host a malicious program on their own computer and make the server run it, taking control of the server.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.