maogouste/api-security-checker

GitHub: maogouste/api-security-checker

一款基于 OWASP API Top 10 的 CLI 工具,用于自动化扫描 REST 和 GraphQL API 中的安全漏洞并生成多种格式的报告。

Stars: 0 | Forks: 0

# API Security Checker 一款快速、现代的 CLI 工具,用于扫描 REST 和 GraphQL API 的安全漏洞。 ``` $ apisec scan http://localhost:8000 -u john -p password123 ╭──────────────────────────────────────────────────────────────────────────────╮ │ API Security Scan Results │ │ http://localhost:8000 │ ╰──────────────────────────────────────────────────────────────────────────────╯ Summary CRITICAL 2 SQL Injection, Command Injection HIGH 3 CORS, BOLA, Mass Assignment MEDIUM 5 Rate limiting, Headers, Logging ``` ## 功能 **API 漏洞扫描器 (OWASP API Top 10)** - V01: 失效的对象级别授权 (BOLA/IDOR) - V02: 身份验证缺陷(用户枚举、弱 JWT、无速率限制) - V03: 过度数据暴露(敏感字段泄露) - V05: 大规模赋值(权限提升、隐藏字段) - V06: SQL 注入(针对特定数据库的检测) - V07: 命令注入(带输出模式匹配) - V09: 旧版 API 版本检测 - V10: 日志记录不足分析 - GraphQL 专项(自省、深度攻击、批量请求、绕过认证) **信息侦察** - 50+ 敏感文件(.env, .git, 备份文件、配置文件) - 60+ 常见 endpoint(admin, debug, actuator, metrics) - 安全头分析(CORS, CSP, HSTS) - 结合 OpenAPI 规范解析的 endpoint 模糊测试 **输出格式** - 带有颜色和表格的富文本控制台 - 用于自动化的 JSON 导出 - 独立 HTML 报告 - 用于 GitHub Code Scanning 的 SARIF 2.1.0 ## 安装 ``` git clone https://github.com/maogouste/api-security-checker.git cd api-security-checker python3 -m venv venv source venv/bin/activate pip install -e . ``` ## 快速开始 ``` # 扫描任何 API apisec scan https://api.example.com # 使用凭据进行 auth 测试 apisec scan https://api.example.com -u admin -p secret # 特定扫描类型 apisec scan https://api.example.com --type injection # 导出报告 apisec scan https://api.example.com -o report.json # JSON apisec scan https://api.example.com --html report.html # HTML apisec scan https://api.example.com --sarif report.sarif # SARIF ``` ## 扫描类型 | 类型 | 扫描器 | |------|----------| | `all` | 所有内容(默认) | | `api` | 认证, BOLA, 注入, GraphQL | | `recon` | 文件, Endpoint, 请求头 | | `auth` | 仅身份验证 | | `injection` | SQLi, 命令注入 | | `graphql` | GraphQL 专项 | | `headers` | 安全请求头 | | `files` | 敏感文件 | | `endpoints` | 常见路径 | ## 扫描器 | 扫描器 | 检测内容 | OWASP | |---------|---------|-------| | BOLAScanner | 访问其他用户的数据 | API1 | | AuthScanner | 用户枚举、弱 JWT、无速率限制 | API2, API4 | | ExposureScanner | 响应中的敏感数据(SSN, CC, 密钥) | API3 | | MassAssignmentScanner | 权限提升、修改隐藏字段 | API6 | | InjectionScanner | SQL 注入、命令注入 | API8 | | LegacyScanner | 已弃用的 API 版本 (/v1/, /v2/) | API9 | | LoggingScanner | 缺少安全事件日志记录 | API10 | | GraphQLScanner | 自省、深度攻击、批量请求 | API1-4 | | HeadersScanner | 缺失的安全请求头、CORS 问题 | API7 | | KnownFilesScanner | .env, .git, .sql, 暴露的配置文件 | - | | EndpointsScanner | /admin, /debug, /actuator, /metrics | - | | FuzzerScanner | 通过 OpenAPI + 模糊测试发现的隐藏 endpoint | - | ## 配置 为你经常扫描的目标创建一个 YAML 配置文件: ``` # config/myapi.yaml name: My Production API base_url: https://api.mycompany.com valid_username: testuser valid_password: testpass login_endpoint: /auth/login graphql_endpoint: /graphql ``` ``` apisec scan https://api.mycompany.com -c config/myapi.yaml ``` ## 退出代码 | 代码 | 含义 | |------|---------| | 0 | 无漏洞 | | 1 | 低/中危发现 | | 2 | 严重/高危发现 | 适用于 CI/CD: ``` apisec scan $API_URL || exit 1 ``` ## 配合 API Security Dojo 使用 此工具与 [API Security Dojo](https://github.com/maogouste/api-security-dojo) 完美搭配,这是一个用于学习的包含故意漏洞的 API。 ``` # Terminal 1: 启动 API Security Dojo cd api-security-dojo/implementations/python-fastapi hatch run serve # http://localhost:8000 # Terminal 2: 扫描它 apisec scan http://localhost:8000 -u john -p password123 # 其他后端 # Go: http://localhost:3002 # PHP: http://localhost:3003 # Java: http://localhost:3004 # Node: http://localhost:3005 # Rust: http://localhost:3006 ``` ## CI/CD 集成 使用 SARIF 输出进行 GitHub Code Scanning: ``` # .github/workflows/api-security.yml - name: Run API Security Scan run: apisec scan ${{ secrets.API_URL }} --sarif results.sarif - name: Upload SARIF uses: github/codeql-action/upload-sarif@v3 with: sarif_file: results.sarif ``` 查看 `.github/workflows/api-security-scan.yml` 获取完整示例。 ## License MIT
标签:API安全, CISA项目, JSON输出, Web安全, 密码管理, 文档结构分析, 蓝队分析, 逆向工具