Anonymous Walkthrough - TryHackMe [EN][ES]

Write-up of the room Anonymous - TryHackMe. Difficulty: Medium 🟠

Anonymous Walkthrough [EN]

[Task 1] Pwn

Deploy the machine and wait 5 minutes:

ping

My initial Nmap scan:

nmap
nmap

Enumerate Samba (SMB) shares:

smb

Enumerate File Transfer Protocol (FTP) and the shares with the anonymous login:

ftp
ftp
ftp

The file “clean.sh” seems to be a script which runs automatically at regular intervals (cronjob), printing the output to “removed_files.log” file. We have writing permissions in the file, so lets try to change it, putting our script in the FTP Server.

ftp
ftp

Now that we know the script works, we could change again the script to obtain a reverse shell.

ftp

Get the reverse shell with the netcat listener:

ReverseShell

The first step is to get a fulltty to make our life easier. Then, we could read the user flag:

UserFlag

In my case, I used the LinEnum.sh script for the privilege escalation but we can do it manually (Searching listening ports, “sudo -l”, kernel and sudo versions, processes, SUID…). We found a SUID binary in the path /usr/bin/path using the LinEnum. To search SUID Binaries manually find / -perm -u=s -type f 2>/dev/null.

LinEnum
LinEnum

If we find a SUID, it is a must to think of GTFOBins. In this case, if we search for our binary env, we just need to copy the command /usr/bin/env /bin/sh -p to get root:

root
root


Anonymous Walkthrough [ES]

[Task 1] Pwn

Desplegamos la máquina y esperamos 5 minutos a que se configure:

ping

Mi escaneo inicial con Nmap:

nmap
nmap

Enumeramos los recursos compartidos de Samba (SMB):

smb

Enumeramos los ficheros del File Transfer Protocol (FTP) con las credenciales anonimas:

ftp
ftp
ftp

El fichero “clean.sh” parece ser un script que se ejecuta cada cierto tiempo (cronjob), enviando el output al fichero “removed_files.log”. Dado que tenemos permisos de escritura, podemos cambiar el script y subirlo al servidor para comprobar si estamos en lo correcto. Para ello, envíemos un whoami al fichero nombrado antes.

ftp
ftp

Como observamos en la imagen, el script funciona y se ha ejecutado, por lo tanto, cambiaremos el añadido para darnos una reverse shell:

ftp

Hemos obtenido la reverse shell con el netcat:

ReverseShell

El primer paso, es el de convertir nuestra shell a una fulltty para facilitarnos la vida. Posteriormente, podemos leer la flag del usuario:

UserFlag

En mi caso, he hecho uso del script LinEnum.sh para la escalación de privilegios, aunque lo podriamos hacer de forma manual (Buscar puertos escuchando, “sudo -l”, versiones de kernel y sudo, procesos, SUID…). Esta maquina contiene un binario SUID en la path /usr/bin/env que nos ha reportado el fichero comentado. Para realizarlo de forma manual, podríamos hacerlo con el siguiente comando find / -perm -u=s -type f 2>/dev/null.

LinEnum
LinEnum

Siempre que encontremos un SUID, debe venir a nuestra mente GTFOBins. En este caso, buscando nuestro binario env en la web, solamente deberíamos de copiar el comando /usr/bin/env /bin/sh -p para obtener root:

root
root

Esta máquina, aunque esta categorizada como Medium en la plataforma TryHackMe, es bastante sencilla de reventar, lo único de lo que te tienes que dar cuenta es de que el script “clean.sh” se ejecuta periódicamente y tenemos acceso de escritura pudiendo cambiarlo. Respecto a la escalada de privilegios, es una de las escaladas más típicas en las máquinas, que es haciendo uso de un SUID y de GTFOBins.

Alberto Fernandez-de-Retana
Alberto Fernandez-de-Retana
PhD Student

Kaixo! PhD Student at University of Deusto under supervision of Igor Santos-Grueiro and Pablo G. Bringas. My research interests include web security & privacy. In my free time I love to be pizzaiolo.