chiragjaiswar0814/SchemaFuzzer
GitHub: chiragjaiswar0814/SchemaFuzzer
SchemaFuzzer 是一个用于检测 GraphQL 和 REST API 中 Mass Assignment 漏洞的 CLI 自动化扫描工具。
Stars: 0 | Forks: 0
# SchemaFuzzer — 任意赋值漏洞扫描器
一个用于检测 GraphQL 和 REST API 中 **Mass Assignment(越权赋值)** 漏洞的 CLI 自动化 QA 工具。SchemaFuzzer 以编程方式将禁止/特权键注入 API 载荷,并标记任何将其反射回来的端点——这明显表明缺少服务器端字段剥离。
## 什么是 Mass Assignment 漏洞?
当 API 盲目接受并持久化请求载荷中的所有字段(包括客户端绝不应被允许设置的字段,例如 `isAdmin`、`role`、`account_balance`)时,就会发生 Mass Assignment。加固良好的后端必须显式白名单允许的字段,并剥离其余所有字段。
SchemaFuzzer 会针对一组可配置的禁止键自动执行此检查。
## 注入的诊断键(默认探测集)
| Key | Injected Value | Risk |
|--------------------|-----------------------------------------|-------------------------------|
| `isAdmin` | `true` | Privilege escalation |
| `role` | `"admin"` | Role hijacking |
| `account_balance` | `999999` | Financial data manipulation |
| `is_superuser` | `true` | Superuser escalation |
| `permissions` | `["read","write","delete","admin"]` | Capability injection |
| `privilege_level` | `99` | Privilege tier escalation |
## 前置条件
- **Node.js** >= 18.x
- **npm** >= 9.x
## 安装
克隆仓库并安装所有依赖:
```
npm install
```
这将安装:
- `axios` — 用于发送 POST 请求的 HTTP 客户端
- `commander` — CLI 参数解析
- `chalk` — 彩色终端输出
- `ts-node` + `typescript` + `@types/node` — TypeScript 执行环境
## 用法
使用 `ts-node` 直接运行扫描器:
```
npx ts-node index.ts -e -t
```
### 参数
| Flag | Description | Required |
|-------------------|------------------------------------------|----------|
| `-e, --endpoint` | 目标 API 端点的完整 URL | Yes |
| `-t, --token` | Authorization 头部的 Bearer Token | Yes |
## 示例
### 测试 REST API 端点
```
npx ts-node index.ts \
-e https://api.internal.example.com/v1/users/update \
-t eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
```
### 测试本地开发服务器
```
npx ts-node index.ts \
-e http://localhost:3000/api/profile \
-t dev-static-token-abc123
```
## 理解输出
```
╔══════════════════════════════════════════════╗
║ SchemaFuzzer — Mass Assignment ║
║ Vulnerability Scanner ║
╚══════════════════════════════════════════════╝
Target : https://api.example.com/v1/users/update
Token : eyJhbG*******************************
Probes : 6 forbidden key injection(s)
▶ Sending baseline request...
✔ Baseline response received.
──────────────────────────────────────────────────
⚡ Injecting key: isAdmin = true
Response: {"id":"u_123","username":"testuser","isAdmin":true}
!! COMPLIANCE FAILURE: Mass Assignment Detected !!
The server reflected the forbidden key "isAdmin" in its response.
Injected Value : true
Server Echoed : true
──────────────────────────────────────────────────
⚡ Injecting key: role = "admin"
Response: {"id":"u_123","username":"testuser","role":"user"}
✔ PASS — Key "role" was not reflected. Backend appears to strip it correctly.
══════════════ SCAN SUMMARY ══════════════
Total Probes : 6
Passed : 5
Failed : 1
RESULT: 1 Mass Assignment vulnerability(s) detected! Immediate remediation required.
```
### 退出代码
| Code | Meaning |
|------|------------------------------------------------------|
| `0` | All probes passed — no vulnerabilities detected |
| `1` | One or more Mass Assignment vulnerabilities detected |
非零退出码使 SchemaFuzzer 能够轻松集成到 CI/CD 流水线(如 GitHub Actions、Jenkins 等)中,以在安全扫描通过时才允许部署。
## CI/CD 集成示例(GitHub Actions)
```
- name: Run SchemaFuzzer
run: |
npm install
npx ts-node index.ts -e ${{ secrets.API_ENDPOINT }} -t ${{ secrets.API_TOKEN }}
```
非零退出将自动使流水线步骤失败。
## 修复指导
如果 SchemaFuzzer 报告失败,后端必须实现 **显式字段白名单**:
- **REST(Node.js/Express):** 使用 `pick()`(lodash)或仅从 `req.body` 解构已知字段。
- **GraphQL:** 定义严格的输入类型;永远不要直接将原始对象传递给 resolver。
- **ORM(Prisma、TypeORM):** 避免将原始请求体展开到 `create()`/`update()` 调用中;始终映射到 DTO。
## 项目结构
```
SchemaFuzzer/
├── index.ts # Main scanner — CLI, fuzzing logic, response comparison
├── package.json # Dependency manifest
└── README.md # This file
```
标签:axios, GNU通用公共许可证, GraphQL, LNA, Mass Assignment, MITM代理, Node.js, REST API, SchemaFuzzer, TypeScript, 前端安全, 协议分析, 后端安全, 字段注入, 安全插件, 安全测试, 开发安全, 探针注入, 攻击性安全, 敏感字段, 权限提升, 自动化攻击, 质量保证, 防护绕过