Skip to content
RCE Write-up Intermediate

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.

Florian Hauser Follow

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.

Florian Hauser (@frycos), on frycos.github.io

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

  1. Set up an SMB server on the attacker machine.
  2. Create a malicious executable named after one of the expected utilities.
  3. Send a POST request to the validate_binary_path endpoint with a utility_path pointing to the SMB share.
  4. 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.

More by Florian Hauser

View all

12 more disclosed reports, best first.

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.