Skip to content
RCE Write-up Advanced

pgAdmin 4 Meta-Command Filter Bypass — RCE

pgAdmin's regex-based filter for blocking dangerous psql meta-commands could be bypassed by alternative whitespace characters or a UTF-8 BOM in a crafted PLAIN-format SQL dump. When a restore was performed, psql would interpret the meta-command and execute shell commands on the pgAdmin host.

cybersecplayground Follow

Published on medium.com

Attackers can craft a malicious PLAIN-format SQL dump that bypasses pgAdmin’s meta-command filter, resulting in command execution on the server when a restore operation is performed.

Cybersecplayground, on medium.com

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 filter used a regex to detect meta-commands, but psql's parser accepted the same commands with different whitespace or a leading BOM, so the filter and the interpreter disagreed.

Impact

Successful exploitation could allow pre-auth or user-assisted remote command execution, full compromise of the pgAdmin host, lateral movement, and database access.

What the attacker needed

PgAdmin 4 version 9.10 or earlier; Ability to supply a PLAIN-format SQL dump for restore; A restore operation is performed

The fix

pgAdmin 4 v9.11 was fixed by invoking psql with the \restrict flag during restore operations, disabling dangerous meta-commands at the interpreter level instead of relying on regex filtering.

How it was found

  1. Craft a PLAIN-format SQL dump containing a dangerous psql meta-command.
  2. Obfuscate the meta-command using carriage return, vertical tab, or a leading UTF-8 BOM to evade the regex filter.
  3. Perform a restore operation in pgAdmin with the crafted file.
  4. psql interprets the meta-command and executes the shell command on the pgAdmin host.

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. It tried to block certain special commands in uploaded SQL files using a pattern-matching filter, but the filter could be fooled by unusual whitespace or a hidden marker at the start of the file. When an administrator restored such a file, the database tool ran the hidden command on the server, letting an attacker run their own programs.

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 cybersecplayground

View all

2 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.