> 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 для лабораторий PortSwigger Web Security Academy, включая рабочий процесс эксплуатации, тестирование полезных нагрузок, валидацию в Burp Suite и контекст устранения.

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

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

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

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

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

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-3f01ad6ba4e743f68a0330397a095378adf99cd2%2F%7BB28E1DCE-F5D2-44B8-8329-FE95EBD43134%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

**Выявление уязвимости**

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-a28baaf531db10e15e6175075ed0feef6c4ebc53%2F%7B18F37E07-0E38-462B-B0A8-401D5EE6FAC5%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

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

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

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-ca74f14bedf60858bd9c43b4699c62e8442094eb%2F%7BAECB5589-C050-4374-9143-82AA73B05DBC%7D.png?alt=media" alt=""><figcaption></figcaption></figure>

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

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

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

<figure><img src="https://4248209978-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fl4EVJpcOrsgjSGsLI7p2%2Fuploads%2Fgit-blob-574930b45d6ceee7a0b6db1eb383a86ebd976a00%2F%7B90BE3977-6929-43AB-82A1-425DB8A7C8DD%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/ru/web/nosql-injection/detection-of-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.
