Priyansh-01/APIStrike

GitHub: Priyansh-01/APIStrike

一款用于测试 REST 与 GraphQL API 常见安全漏洞的 CLI 工具,自动化发现并报告越权、认证绕过等问题。

Stars: 0 | Forks: 0

# APIStrike 一个用于测试 REST 和 GraphQL API 常见安全漏洞的 CLI 工具。它通过 Swagger/OpenAPI 规范或爬取 JS 文件来发现端点,运行自动化测试,并生成详细的 HTML 或 JSON 报告。 ## 测试执行 | 测试 | 检查内容 | |------|---------| | BOLA/IDOR | 跨用户资源访问与 ID 枚举 | | Auth Bypass | 无需令牌即可访问的端点,或使用过期/篡改/alg:none JWT 的绕过 | | Mass Assignment | POST/PUT 是否接受敏感字段(如 `role`、`isAdmin`、`balance` 等) | | Rate Limiting | 登录/OTP 端点在 100 次请求后未被限制 | | Sensitive Data Exposure | 响应中暴露的邮箱、JWT、AWS 密钥、密码等 | | GraphQL | 开放查询、批量请求、认证绕过、字段建议、IDOR | ## 安装 ``` pip install -r requirements.txt playwright install chromium # optional — enables browser-based crawling ``` ## 用法 ``` # 使用 Swagger/OpenAPI 文件 python main.py --url https://api.example.com --swagger openapi.json --token1 "Bearer eyJ..." # 不使用 Swagger — 爬取 JS 文件以发现端点 python main.py --url https://api.example.com --token1 "Bearer eyJ..." # 自动登录(无需手动粘贴令牌) python main.py --url https://api.example.com --login-url https://api.example.com/auth/login --username john@example.com --password secret123 # 双用户 BOLA 测试(检测跨用户数据访问) python main.py --url https://api.example.com --token1 "Bearer eyJ..." --token2 "Bearer eyJ..." # 双用户自动登录 python main.py --url https://api.example.com \ --login-url https://api.example.com/auth/login --username user1@example.com --password pass1 \ --login-url2 https://api.example.com/auth/login --username2 user2@example.com --password2 pass2 # 输出为 JSON 而非 HTML(适用于 CI/CD 流水线) python main.py --url https://api.example.com --token1 "Bearer eyJ..." --format json --output results.json # 按最低严重性过滤 python main.py --url https://api.example.com --token1 "Bearer eyJ..." --min-severity high # 跳过特定测试 python main.py --url https://api.example.com --token1 "Bearer eyJ..." --skip rate graphql ``` ## 参数 | 参数 | 必填 | 描述 | |------|------|------| | `--url` | 是 | API 基础 URL | | `--token1` | 否* | 用户 1 的 JWT 令牌(格式:`Bearer eyJ...`) | | `--token2` | 否 | 用户 2 的 JWT 令牌(启用跨用户 BOLA 检查) | | `--login-url` | 否* | 用于自动获取 token1 的登录端点 | | `--username` | 否* | 用户名/邮箱(用于自动登录,获取 token1) | | `--password` | 否* | 密码(用于自动登录,获取 token1) | | `--login-url2` | 否 | 用于自动获取 token2 的登录端点 | | `--username2` | 否 | 用户名/邮箱(用于自动登录,获取 token2) | | `--password2` | 否 | 密码(用于自动登录,获取 token2) | | `--swagger` | 否 | Swagger/OpenAPI v2 或 v3 文件路径 | | `--output` | 否 | 输出文件路径(默认:`report.html`) | | `--format` | 否 | 输出格式:`html` 或 `json`(默认:`html`) | | `--min-severity` | 否 | 最低严重级别:`low`、`medium`、`high`、`critical`(默认:`low`) | | `--skip` | 否 | 跳过的测试:`bola auth mass rate exposure graphql` | *必须提供 `--token1`,或同时提供 `--login-url`、`--username` 和 `--password`。 ## 示例输出 ``` [*] Target: https://api.example.com [*] Logging in via https://api.example.com/auth/login ... [*] Token1 acquired: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6... [*] Loaded 24 endpoints [*] BOLA/IDOR: 3 issue(s) found [*] Auth Bypass: 2 issue(s) found [*] Mass Assignment: 1 issue(s) found [*] Rate Limiting: 1 issue(s) found [*] Data Exposure: 0 issue(s) found [*] GraphQL: 2 issue(s) found [+] Total findings: 9 [!] 5 HIGH/CRITICAL issue(s) found — exiting with code 1 [+] Report saved → report.html ``` ## CI/CD 集成 当检测到 HIGH 或 CRITICAL 级别问题时,APIStrike 会以退出码 `1` 退出,便于在流水线中自动失败。 ``` # 示例 GitHub Actions 步骤 - name: Run API Security Tests run: python main.py --url ${{ secrets.API_URL }} --token1 ${{ secrets.API_TOKEN }} --min-severity high ``` ## 项目结构 ``` api-security-tester/ ├── main.py # Entry point ├── config.py # Shared constants and patterns ├── auth/ │ └── handler.py # JWT manipulation (alg:none, expired, admin escalation) ├── parser/ │ ├── swagger.py # OpenAPI v2/v3 parser │ └── crawler.py # Browser + regex + path-probe endpoint discovery ├── tests/ │ ├── bola.py # BOLA/IDOR tests │ ├── auth_bypass.py # Auth bypass tests │ ├── mass_assign.py # Mass assignment tests │ ├── rate_limit.py # Rate limit tests │ ├── data_exposure.py # Sensitive data exposure tests │ └── graphql.py # GraphQL-specific tests └── reporter/ └── report.py # HTML/JSON report generator ``` ## 输出 HTML 报告包含严重级别分类的发现结果、通俗易懂的解释、可点击的测试 URL 以及供开发者查看的原始请求/响应详情。也支持 JSON 格式输出以供程序化处理。
标签:API安全, GraphQL, HTML报告, IDOR, JavaScript爬虫, JSON报告, JSON输出, JWT, Mass Assignment, OpenAPI, Playwright, REST API, Swagger, Web安全, 令牌测试, 字段建议, 字段注入, 安全测试, 安全漏洞扫描, 批处理, 接口测试, 攻击性安全, 权限绕过, 枚举, 特征检测, 登录绕过, 蓝队分析, 认证绕过, 越权, 跨用户资源访问, 逆向工具