> 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/detection-of-nosql-injection.md).

# Обнаружение NoSQL-инъекции

### Обнаружение NoSQL-инъекции

**Цель лабораторной работы**

В этой лабораторной работе есть приложение электронной коммерции, чей фильтр категорий основан на базе данных **MongoDB (NoSQL)**. / Уязвимость NoSQL-инъекции позволяет отображать **неопубликованные товары**.

Цель — эксплуатировать эту уязвимость, чтобы заставить приложение вернуть все товары, включая те, которые не должны быть видны.

**Контекст приложения**

* Страница электронной коммерции с одним фильтром по категории.
* Пример обычного запроса

```bash
filter?category=Accessories
```

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

**Идентификация уязвимости**

При добавлении **апострофа** в конце `category` параметра сервер возвращает внутреннюю ошибку:

```bash
Внутренняя ошибка сервера
Сбой команды с ошибкой 139 (JSInterpreterFailure):
SyntaxError: незавершённый строковый литерал....
```

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

Эта ошибка раскрывает несколько важных элементов:

* Бэкенд использует **MongoDB**.
* Пользовательские данные интерпретируются в **JavaScript** контексте на стороне базы данных.
* Приложение уязвимо к \*\*NoSQL\*\*-инъекции.

**Эксплуатация NoSQL-инъекции**

Цель — изменить условие, используемое в запросе MongoDB, чтобы оно всегда было истинным.

Примеры протестированных полезных нагрузок:

```sql
' || 1==1 || '
' || true || '
' && 0 && '
```

Эти выражения заставляют условие быть истинным, что приводит к отображению \*\*всех товаров\*\* включая непубликованные

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

#### Нефункциональные полезные нагрузки (для сравнения)

```sql
' && 0 && '
' || 1==2 || '
```

Эти условия оцениваются как ложные и не возвращают никаких товаров

<figure><img src="/files/d2323baacf40ba15651ccd987322848eb3ae064b" 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/detection-of-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.
