Skip to content
RCE Write-up Beginner

Hackviser — PostgreSQL COPY TO/FROM PROGRAM Authenticated Remot

The lab targets a PostgreSQL instance where the COPY TO/FROM PROGRAM feature allows a highly privileged database user to run operating system commands as the database server's OS user. The author uses a Metasploit module for CVE-2019-9193 to gain a shell and read a secret file.

Dogukan İSPİRLİ Follow

Published on medium.com

Bu laboratuvar, PostgreSQL 9.3 ila 11.7 sürümlerinde bulunan CVE-2019–9193 güvenlik açığını barındırmaktadır. Bu açık, “COPY TO/FROM PROGRAM” fonksiyonunun kötüye kullanılmasıyla, süper kullanıcılar ve ‘pgexecuteserverprogram’ grubundaki kullanıcıların veritabanı sunucusunun işletim sistemi kullanıcısı bağlamında…

Dogukan İSPİRLİ, 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 COPY TO/FROM PROGRAM feature is enabled by default and can be used by superusers or members of the pg_execute_server_program role to execute arbitrary OS commands.

Impact

An attacker with a highly privileged database account could run arbitrary OS commands as the database server user and read files such as the secret file.

What the attacker needed

Access to a privileged database account; default credentials postgres/postgres; network access to the database

The fix

The text does not state a fix; it notes that some consider this intended behaviour, so mitigation would be to restrict the COPY PROGRAM feature and avoid default credentials.

How it was found

  1. Start msfconsole and select the CVE-2019-9193 module.
  2. Set RHOSTS, LHOST and other required options, then run exploit.
  3. After gaining a shell, list files with ls -la.
  4. Search the filesystem for secret.txt using find.
  5. Read the file with less /secret.txt.

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 program. Normally a database user should only be able to read and write data, not run commands on the computer that hosts the database. Here, a built-in feature lets a very powerful database user run operating system commands, so someone who gets that account can take over the machine.

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 Dogukan İSPİRLİ

View all

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