Apiscan/secforge

GitHub: Apiscan/secforge

CLI 原生 API 安全扫描器,基于证据检测 OWASP API Top 10 漏洞并自动关联生成攻击链分析。

Stars: 0 | Forks: 0

# ApiScan CLI — API 安全扫描器

在攻击者发现之前,先一步发现漏洞。
CLI 原生 API 安全扫描器,配备 16 个插件和 AI 攻击链关联分析。

Web App · 文档 · 定价 · 博客

## ApiScan 的独特之处 大多数安全扫描器只会告诉你 *"CORS 配置错误。"* ApiScan 会告诉你:*"你的 CORS 配置错误 + JWT 签名绕过 = 攻击者可以通过恶意网页在 3 个 HTTP 请求内冒充任何用户。"* 这就是“漏洞列表”与**攻击链**的区别 —— 即漏洞如何组合成真实攻击的故事。这是一名资深渗透测试人员在项目结束后会产出内容。ApiScan 能自动完成这项工作。 ``` $ secforge scan --profile target.yaml --yes [tls] ✓ PASS [headers] ⚠ 2 missing headers (HSTS, CSP) [cors] ✗ ARBITRARY ORIGIN REFLECTION [auth] ✓ PASS [jwt] ✗ ALG:NONE ACCEPTED [rate_limit] ✓ PASS [bola] ✓ PASS [oauth2] ✓ PASS [apikey] ✓ PASS [graphql] ✓ PASS [ssrf] ✓ PASS [injection] ✓ PASS [mass_assignment] ✓ PASS [misconfiguration]✓ PASS [bfla] ✓ PASS [sensitive_data] ✓ PASS ────────────────────────────────────────────── ⚡ CRITICAL ATTACK CHAIN DETECTED CORS Reflection + JWT Algorithm None → Account Takeover Step 1: Attacker hosts malicious page at https://evil.com Step 2: CORS allows evil.com to make credentialed requests Step 3: JWT endpoint accepts alg:none — no signature required Step 4: Forge token for any user_id, read response via CORS Result: Full authenticated API access as any user PoC: curl -H "Origin: https://evil.com" \ -H "Authorization: Bearer eyJhbGciOiJub25lIn0..." \ https://api.target.com/v1/users/profile ────────────────────────────────────────────── Scan complete: 2 findings (1 critical chain, 1 medium) Time: 11.3s ``` ## 安装 ``` pip install secforge ``` **或者从源码安装:** ``` git clone https://github.com/Apiscan/secforge cd secforge pip install -e ".[dev]" ``` **系统要求:** Python 3.10+,无外部运行时依赖。 ## 快速开始 **1. 创建目标配置文件:** ``` # target.yaml target: base_url: https://api.yourapp.com auth_header: Authorization: Bearer YOUR_TOKEN_HERE plugins: all scope_acknowledged: true # required — confirms you have authorization ``` **2. 运行扫描:** ``` secforge scan --profile target.yaml --yes ``` **3. 导出报告:** ``` # JSON secforge scan --profile target.yaml --yes --output report.json # Markdown secforge scan --profile target.yaml --yes --output report.md --format markdown ``` ## CI/CD 集成 ``` # .github/workflows/security.yml - name: API Security Scan run: | pip install secforge secforge scan --profile .secforge/target.yaml --yes --output security-report.json env: API_TOKEN: ${{ secrets.API_TOKEN }} ``` ## 插件 所有 16 个插件并行运行。每个发现都需要真实的 HTTP 证据 —— 拒绝理论推测。 | 插件 | OWASP API | 测试内容 | |--------|-----------|---------------| | `tls` | API8 | 协议降级、证书过期、自签名、主机名不匹配、弱加密套件 | | `headers` | API8 | HSTS, CSP, X-Frame-Options, CORP, COEP — 6 个必需 Header + 3 项泄露检查 | | `cors` | API8 | 任意源反射、null 源绕过、子域名前缀攻击 | | `bola` | API1 | 通过顺序 ID 探测绕过对象级授权 | | `auth` | API2 | 敏感路由缺失认证、JWT alg:none、URL 中包含 API Key | | `rate_limit` | API4 | 针对根路径和认证端点的突发测试、429 检测、Header 验证 | | `jwt` | API2 | alg:none, RS256→HS256 混淆、弱密钥爆破、kid 注入、声明分析 | | `oauth2` | API2 | redirect_uri 绕过、危险的授权类型、PKCE 强制执行、Token 端点信息泄露 | | `apikey` | API2 | 熵分析、厂商特征检测、测试 Key 标记、响应扫描 | | `graphql` | API8 | 内省、批量攻击、深度限制、字段建议、GET mutation CSRF | | `ssrf` | API7 | 云元数据探测 (AWS/GCP/DO)、本地主机注入、开放重定向链 | | `injection` | API3 | SQL 注入、NoSQL 注入、通过 API 参数进行的 OS 命令注入 | | `mass_assignment` | API3 | 接受额外字段、通过请求体中的 role/admin 标志进行提权 | | `misconfiguration` | API8 | 调试端点、版本泄露、堆栈跟踪、默认凭据 | | `bfla` | API5 | 功能级授权绕过 —— 水平和垂直提权 | | `sensitive_data` | API3 | API 响应体中的 PII、机密信息、Token 和密钥材料 | ## 严重级别 | 级别 | 含义 | |-------|---------| | `CRITICAL` | 可直接利用,对数据或系统完整性构成直接威胁 | | `HIGH` | 可通过中等努力利用,风险较大 | | `MEDIUM` | 在特定条件下可被利用 | | `LOW` | 纵深防御问题,直接风险较低 | | `INFO` | 最佳实践建议 | ## 目标配置文件参考 ``` target: base_url: https://api.yourapp.com # required auth_header: # optional — adds auth to all requests Authorization: Bearer TOKEN plugins: all # all | [tls, cors, jwt] | comma-separated rate_limit_rps: 10 # requests per second (default: 10) timeout_s: 30 # request timeout (default: 30) scope_acknowledged: true # REQUIRED — confirms you have authorization ``` ## 输出格式 JSON 报告结构: ``` { "target": "https://api.yourapp.com", "scan_time_s": 11.3, "findings": [ { "plugin": "cors", "title": "Arbitrary Origin Reflection", "severity": "HIGH", "status": "CONFIRMED", "description": "The API reflects arbitrary origins with credentials.", "evidence": [ { "request": "GET /api/v1/users HTTP/1.1\nOrigin: https://attacker.com", "response_status": 200, "response_headers": { "Access-Control-Allow-Origin": "https://attacker.com", "Access-Control-Allow-Credentials": "true" } } ], "remediation": "Implement an allowlist of trusted origins. Never reflect the Origin header directly." } ], "summary": { "CRITICAL": 0, "HIGH": 1, "MEDIUM": 2, "LOW": 0, "INFO": 0 } } ``` ## 编写自定义插件 ``` from secforge.plugins.base import BasePlugin, Finding, Severity, Status, Evidence class MyPlugin(BasePlugin): name = "my_plugin" description = "Tests for something specific" async def run(self) -> list[Finding]: findings = [] resp = await self.client.get("/api/sensitive") if resp.status_code == 200 and not self.client.headers.get("Authorization"): findings.append(Finding( plugin=self.name, title="Unauthenticated Access to Sensitive Endpoint", severity=Severity.HIGH, status=Status.CONFIRMED, description="The endpoint returned 200 without authentication.", evidence=[Evidence( request=str(resp.request), response_status=resp.status_code, )], remediation="Add authentication middleware to this route." )) return findings ``` 将文件放在 `secforge/plugins/my_plugin.py` 中,它将被自动发现。 ## 道德与法律 **您只能扫描自己拥有或拥有明确书面授权测试的系统。** ApiScan 通过目标配置文件中的 `scope_acknowledged: true` 标志和 `--yes` CLI 标志来强制执行此要求。在大多数司法管辖区,未经授权的扫描根据计算机犯罪法属于非法行为。 作者不对滥用行为承担责任。 ## AI 链分析 位于 [app.apiscan.ai](https://app.apiscan.ai) 的 SaaS 版本增加了一个多阶段 AI 分析管道: - 移除误报并根据上下文重新分类严重性 - 以 95%+ 的置信度通过真实 HTTP 证据验证可利用性 - 将发现关联为多步骤攻击链 - 生成包含业务影响和修复代码的执行报告 | 计划 | 每月扫描次数 | 插件 | AI 链 | |------|----------|---------|----------| | Free | 5 | 3 (TLS, Headers, CORS) | — | | Pro ($39/mo) | 50 | 全部 16 个 | ✓ 完整链 + PDF | | Enterprise ($299/mo) | 不限 | 全部 16 个 | ✓ + AI 渗透测试员 | ## 许可证 MIT — CLI 和所有插件均为免费开源。 AI 链分析管道为专有内容,可通过 [app.apiscan.ai](https://app.apiscan.ai) 使用。

ApiScan 构建 · 免费扫描 · 博客 · 定价

标签:API 安全, API 网关, BFLA, BOLA, CI/CD 安全, CISA项目, CLI 工具, CORS, DevSecOps, DNS枚举, GraphQL 安全, JWT 安全, LNA, OWASP Top 10, PE 加载器, Python, SSRF, Web 安全, 上游代理, 云安全监控, 安全合规, 攻击链分析, 敏感数据泄露, 数据投毒防御, 文档结构分析, 无后门, 注入攻击, 网络代理, 网络安全工具, 自动化渗透测试, 静态分析