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.
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…
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
- Start msfconsole and select the CVE-2019-9193 module.
- Set RHOSTS, LHOST and other required options, then run exploit.
- After gaining a shell, list files with ls -la.
- Search the filesystem for secret.txt using find.
- 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.