Skip to content
RCE Write-up Intermediate

The 12-Year Hole in PostgreSQL’s Replication Layer

A privilege boundary in PostgreSQL's logical replication allowed a user with only the REPLICATION role to supply a plugin name containing a path, which was passed to the OS library loader without the restriction check used by LOAD. This let an attacker execute arbitrary native code inside the server process and escalate to superuser.

medium.com

Published on medium.com

I’ve spent two articles making the case that PostgreSQL deserves more trust than most engineers give it — that it can enforce rules, eliminate race conditions, and absorb logic that would otherwise sprawl across the application layer. Then a vulnerability called PostGREShell showed up, and it forced me to sit with an…

Bhavyansh, 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 a missing call to the library-name restriction check in the logical replication plugin-loading path, so a user-supplied plugin name was passed directly to the OS loader.

Impact

An attacker with only the REPLICATION role could execute arbitrary code as the postgres OS user and escalate to database superuser, potentially persisting via configuration changes; on Linux and macOS exploitation typically required a library already on disk, while Windows with outbound SMB allowed remote delivery.

What the attacker needed

REPLICATION role on target; ability to create replication slot; attacker-controlled library on disk or SMB share

The fix

The text implies a patch was released; it should be fixed by applying the security release and auditing REPLICATION grants and network egress.

How it was found

  1. Obtain the REPLICATION role on the target instance.
  2. Issue a CREATE_REPLICATION_SLOT command with a plugin name that resolves to an attacker-controlled library via path traversal or absolute path.
  3. On Windows with outbound SMB, host the malicious DLL on a network share and use a UNC path.
  4. The OS loader maps the library into the postgres process and runs its initialisation routine.
  5. Use the code execution to access shared memory and catalog structures to escalate to superuser.

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.

PostgreSQL is a database. It has a feature called logical replication that lets other systems read changes. To format those changes, it loads a plugin, which is native code. A security check existed for one way of loading plugins but not for the replication way. So someone with a limited replication role could point the database at a malicious library and get it to run, taking over the database.

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.