Amarkumr/BOLA-IDOR-vulnerability-scanner
GitHub: Amarkumr/BOLA-IDOR-vulnerability-scanner
一款基于流量拦截与 JSON 响应差异比对的 BOLA/IDOR 授权漏洞自动化扫描与风险评估工具。
Stars: 0 | Forks: 0
# BOLA/IDOR 漏洞扫描器
一个全面的安全扫描器,通过分析不同用户角色的 API 响应来识别 **Broken Object Level Authorization (BOLA)** 和 **Insecure Direct Object Reference (IDOR)** 漏洞。
## 功能
✅ **mitmproxy 流量拦截** - 捕获来自两个不同用户会话的 HTTP 流量
✅ **JSON 结构扁平化** - 将复杂的嵌套 JSON 转换为扁平的键值对
✅ **结构对比** - 识别不同用户角色响应之间的差异
✅ **AI 驱动分析** - 使用 Claude 识别可疑参数和漏洞
✅ **BOLA/IDOR 检测** - 自动检测授权绕过模式
✅ **综合报告** - 生成包含风险评估的详细漏洞报告
## 架构
```
┌─────────────────────────────────────────────────────────────┐
│ BOLA/IDOR Scanner │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ mitmproxy │ │ Traffic JSON │ │
│ │ Interceptor │─────▶│ Capture File │ │
│ └──────────────────┘ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ JSON Flattener │ │
│ │ Converts nested JSON to flat pairs │ │
│ └──────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────────────┐ │
│ │ Structure Differencer │ │
│ │ Compares User A vs User B responses │ │
│ └──────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ BOLA Detector │ │ Vulnerability │ │
│ │ Pattern Match │ │ Analyzer │ │
│ └──────────────────┘ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌──────────────────┐ │
│ │ Claude AI │ │
│ │ Risk Analysis │ │
│ └──────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────┐ │
│ │ Vulnerability │ │
│ │ Report & Fixes │ │
│ └─────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
```
## 安装说明
1. **克隆/下载扫描器**
```
cd BOLA_IDOR_Scanner
```
2. **安装依赖**
```
pip install -r requirements.txt
```
3. **设置 Anthropic API key**
```
# Linux/macOS
export ANTHROPIC_API_KEY='sk-ant-...'
# Windows PowerShell
$env:ANTHROPIC_API_KEY='sk-ant-...'
```
## 使用方法
### 方法 1:使用 mitmproxy 捕获流量
**步骤 1:设置 mitmproxy**
```
# 使用 addon 启动 mitmproxy
mitmproxy -s traffic_interceptor.py --listen-host 127.0.0.1 --listen-port 8080
```
**步骤 2:配置你的测试客户端**
```
# 对于 curl
curl -x 127.0.0.1:8080 \
-H "X-Test-User-Role: user_a" \
https://api.example.com/api/profile
# 对于 Python requests
import requests
session = requests.Session()
session.proxies = {'https': 'http://127.0.0.1:8080'}
session.headers['X-Test-User-Role'] = 'user_a'
response = session.get('https://api.example.com/api/profile')
```
**步骤 3:对捕获的流量运行扫描**
```
python bola_scanner.py --traffic traffic_capture.json
```
### 方法 2:直接 JSON 比较
**创建示例 JSON 文件:**
`user_a.json` (普通用户):
```
{
"user": {
"id": 123,
"name": "Alice",
"is_admin": false,
"permissions": ["read", "write"]
},
"tenant_id": "tenant_001"
}
```
`user_b.json` (管理员用户):
```
{
"user": {
"id": 456,
"name": "Bob",
"is_admin": true,
"permissions": ["read", "write", "delete"],
"api_key": "sk-secret-key-12345"
},
"tenant_id": "tenant_001",
"debug_mode": true
}
```
**运行扫描:**
```
python bola_scanner.py \
--user-a user_a.json \
--user-b user_b.json \
--endpoint /api/profile \
--output-dir ./reports
```
### 方法 3:编程式 API
```
from bola_scanner import BOLAIDORScanner
import json
# 创建 scanner
scanner = BOLAIDORScanner(output_dir='reports')
# 加载 responses
with open('user_a.json') as f:
user_a_data = json.load(f)
with open('user_b.json') as f:
user_b_data = json.load(f)
# 运行 scan
results = scanner.scan_json_pair(user_a_data, user_b_data, '/api/profile')
# 生成 report
report_path = scanner.generate_report(results)
print(f"Report: {report_path}")
```
## 输出示例
```
================================================================================
BOLA/IDOR VULNERABILITY SCAN REPORT
================================================================================
SUMMARY
----------------------------------------
Overall Risk Level: Critical
Total Vulnerabilities: 5
Critical Issues: 2
High Issues: 3
ENDPOINT FINDINGS
----------------------------------------
/api/profile:
[Critical] BOLA - Permission Mismatch
Parameter: user_is_admin
Description: Different user_is_admin values between users
[High] BOLA - Privilege Escalation
Parameter: user_api_key
Description: Parameter user_api_key present in elevated role but not in standard user
[Critical] BOLA - Sensitive Parameter
Parameter: debug_mode
Description: Sensitive debug parameter detected
```
## 工作原理
### 1. 流量拦截
mitmproxy 插件捕获 HTTP 请求/响应并筛选 JSON 内容。每个请求都会被标记上用户角色 header (`X-Test-User-Role`)。
### 2. JSON 扁平化
复杂的嵌套结构会被扁平化为简单的键值对:
```
// Before
{
"user": {
"profile": {
"name": "Alice"
}
}
}
// After
{
"user_profile_name": "Alice"
}
```
### 3. 结构对比
扫描器会比较两个用户的扁平化响应:
- 仅 User A 拥有的键
- 仅 User B 拥有的键
- 相同键的不同值
- 相同的键和值
### 4. 可疑参数检测
识别常见的 BOLA/IDOR 指标:
- `is_admin`, `admin_flag`, `role`, `permission`
- `tenant_id`, `org_id`, `company_id`
- `debug`, `test_mode`, `bypass`
- `token`, `api_key`, `password`
### 5. AI 驱动分析
将发现的结果发送给 Claude 进行智能评估:
- 风险等级分类 (Critical/High/Medium/Low)
- 利用场景
- 测试建议
- 修复建议
## 检测到的漏洞类型
| 类型 | 指标 | 示例 |
|------|-----------|---------|
| **权限不匹配** | 权限字段的不同值 | User A: `is_admin=false`, User B: `is_admin=true` |
| **权限提升** | 仅在管理员响应中包含的敏感字段 | User B 收到了 User A 没有的 `api_key` |
| **对象 ID 暴露** | 不同角色可见不同的对象 ID | User A 只能看到自己的 `user_id` |
| **Debug 信息泄露** | 高权限响应中包含 debug 参数 | `debug_mode=true` 仅出现在管理员响应中 |
| **租户/组织绕过** | 不同组织之间具有相同的 tenant ID | 不应该共享的两个用户却共享了相同的 `tenant_id` |
## 常见攻击场景
### 场景 1:管理员标志修改
```
User A Response: is_admin: false
User B Response: is_admin: true
Attack: Attacker modifies request to set is_admin=true
Risk: Unauthorized admin access
```
### 场景 2:对象 ID 替换
```
User A can access: /api/documents/123
User B can access: /api/documents/456
Attack: User A changes URL to /api/documents/456
Risk: Access to other user's documents
```
### 场景 3:通过隐藏字段进行权限提升
```
User A Response: (no api_key)
User B Response: api_key: "secret-token"
Attack: Attacker adds api_key to their request
Risk: Bypassing authentication/authorization
```
## 测试最佳实践
1. **捕获多个 Endpoint**
- Profile endpoint
- 文档/资源访问
- 仅限管理员的 endpoint
- 账单/支付 endpoint
2. **测试不同的用户角色**
- 普通用户 vs. 管理员
- User A vs. User B(相同角色)
- 免费版 vs. 高级版
3. **自动化测试**
for endpoint in /api/profile /api/documents /api/settings /api/billing; do
python bola_scanner.py --user-a "user_a_${endpoint}.json" \
--user-b "user_b_${endpoint}.json" \
--endpoint "$endpoint"
done
4. **验证发现**
- 使用 Burp Suite 手动测试发现的结果
- 尝试修改参数和 header
- 检查限制是否仅存在于客户端
## 报告产出物
扫描器会生成:
- **JSON 报告**:完整的技术细节和原始分析
- **摘要文件**:人类可读的发现和建议
- **日志文件**:用于调试的详细执行日志
## 故障排除
**问题**:找不到 API key
```
Solution: export ANTHROPIC_API_KEY='sk-ant-...'
```
**问题**:mitmproxy 证书错误
```
Solution: Visit http://mitm.it in browser and install certificate
```
**问题**:未捕获到流量
```
Solution: Ensure X-Test-User-Role header is set in requests
```
## 安全注意事项
⚠️ **警告**:此工具仅供授权的安全测试使用。请务必:
- 在测试前获取书面授权
- 对你自己的应用进行测试
- 未经授权绝不测试第三方系统
- 遵循负责任的漏洞披露实践
- 负责任地记录所有发现
## 许可证
MIT 许可证 - 仅用于授权的安全测试,请负责任地使用。
## 支持
如有问题或疑问:
1. 检查 `bola_reports/` 中的日志文件
2. 查看示例 JSON 文件
3. 首先使用简单的 API 响应进行测试
4. 验证 API key 是否配置正确
**切记**:目标是识别并修复*你*自己系统中的漏洞,而不是 compromising 他人。请合乎道德地使用!
标签:API安全, Claude, CVE检测, IDOR检测, JSON输出, mitmproxy, 加密, 漏洞扫描器, 逆向工具, 防御绕过