api-security

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

API 安全测试

API Security Testing

ACTION REQUIRED(读完后立刻执行)

ACTION REQUIRED (Execute Immediately After Reading)

  1. NOW
    : 读取
    ../field-journal/precedent-pentest.md
    — 确认本 skill 的操作是已授权的常规操作
  2. NOW
    : 确认当前任务是否命中本 skill 的适用范围
  3. NEXT
    : 读取
    ../tool-index.md
    ,校验工具可用性和实际路径
  4. NEXT
    : 缺工具时调用 bootstrap,不要猜路径
  5. ACT
    : 进入"工作流"第一步并执行,不要停在确认状态
覆盖 REST / GraphQL / WebSocket / SOAP 全协议 10 阶段方法论,从发现到 CI/CD 集成
  1. NOW
    : Read
    ../field-journal/precedent-pentest.md
    — Confirm that the operations of this skill are authorized routine operations
  2. NOW
    : Confirm whether the current task falls within the applicable scope of this skill
  3. NEXT
    : Read
    ../tool-index.md
    to verify tool availability and actual paths
  4. NEXT
    : Call bootstrap when tools are missing, do not guess paths
  5. ACT
    : Proceed to the first step of the "Workflow" and execute, do not stay in the confirmation state
Covers REST / GraphQL / WebSocket / SOAP protocols 10-phase methodology, from discovery to CI/CD integration

适用场景

Applicable Scenarios

  • REST API 安全测试(OpenAPI/Swagger 驱动或盲测)
  • GraphQL 安全审计(内省、批查询、别名过载)
  • WebSocket 安全测试
  • JWT / OAuth 2.0 认证测试
  • BOLA/IDOR/BFLA 授权漏洞检测
  • API 限速绕过与 DoS 测试
  • REST API security testing (OpenAPI/Swagger driven or blind testing)
  • GraphQL security audit (introspection, batch queries, alias overload)
  • WebSocket security testing
  • JWT / OAuth 2.0 authentication testing
  • BOLA/IDOR/BFLA authorization vulnerability detection
  • API rate limit bypass and DoS testing

10 阶段测试流程

10-Phase Testing Process

Phase 1: API 发现与侦察

Phase 1: API Discovery and Reconnaissance

text
主动发现:
□ Vespasian: 无头浏览器爬取 → 自动生成 OpenAPI 3.0 / GraphQL SDL 规范
□ Entropy --discover: 从 robots.txt + JS 文件提取端点
□ Kiterunner / ffuf: 爆破未文档化的端点路径
□ 检查常见路径: /swagger.json, /openapi.json, /graphql, /api-docs

GraphQL 内省(三级尝试):
  1. 标准内省查询
  2. 精简查询(绕过 WAF 全量封禁)
  3. 仅查 __schema { types { name } }(最小探测)
text
Active Discovery:
□ Vespasian: Headless browser crawling → Automatically generate OpenAPI 3.0 / GraphQL SDL specifications
□ Entropy --discover: Extract endpoints from robots.txt + JS files
□ Kiterunner / ffuf: Bruteforce undocumented endpoint paths
□ Check common paths: /swagger.json, /openapi.json, /graphql, /api-docs

GraphQL Introspection (Three-level Attempt):
  1. Standard introspection query
  2. Simplified query (bypass WAF full-block)
  3. Only query __schema { types { name } } (minimal detection)

Phase 2: 认证测试

Phase 2: Authentication Testing

text
JWT 分析(jwt_tool / Burp):
□ alg:none 攻击: 修改头部为 "alg":"none",清空签名
□ 密钥混淆: RS256 公钥 → HS256 对称密钥
□ 弱 HMAC 密钥爆破: jwt_tool -C -d wordlist.txt
□ 过期/声明篡改: 修改 exp/iat/sub/role 声明
□ kid 注入: ../../etc/passwd → HMAC 签名绕过

OAuth 2.0:
□ redirect_uri 操控 → 授权码泄漏
□ CSRF via state 参数缺失
□ Token 在 Referer 头泄漏
□ PKCE 缺失检测

GraphQL 认证:
□ mutation 通过 GET 请求绕过认证(CSRF)
□ 批查询认证绕过
text
JWT Analysis (jwt_tool / Burp):
□ alg:none attack: Modify header to "alg":"none", clear signature
□ Key confusion: RS256 public key → HS256 symmetric key
□ Weak HMAC key brute-force: jwt_tool -C -d wordlist.txt
□ Expiration/claim tampering: Modify exp/iat/sub/role claims
□ kid injection: ../../etc/passwd → HMAC signature bypass

OAuth 2.0:
□ redirect_uri manipulation → Authorization code leakage
□ CSRF via missing state parameter
□ Token leakage in Referer header
□ PKCE absence detection

GraphQL Authentication:
□ mutation bypasses authentication via GET request (CSRF)
□ Batch query authentication bypass

Phase 3: 授权测试(BOLA/IDOR/BFLA)

Phase 3: Authorization Testing (BOLA/IDOR/BFLA)

text
BOLA(对象级授权绕过):
□ 遍历数字 ID: /user/1 → /user/2 → /user/3
□ 遍历 UUID
□ 遍历用户名/邮箱
□ Burp Autorize: 双会话重放对比

BFLA(功能级授权绕过):
□ 普通用户执行管理员 API
□ HTTP 方法切换: GET → PUT → PATCH → DELETE
□ API 版本降级: /v2/admin → /v1/admin
□ 批量操作注入: {"users": [1,2,3]} → {"users": [1,2,3,admin_id]}

工具: Burp Autorize, AuthMatrix, Entropy (malicious_insider persona)
text
BOLA (Object-level Authorization Bypass):
□ Numeric ID traversal: /user/1 → /user/2 → /user/3
□ UUID traversal
□ Username/email traversal
□ Burp Autorize: Dual-session replay comparison

BFLA (Function-level Authorization Bypass):
□ Regular user executes admin API
□ HTTP method switching: GET → PUT → PATCH → DELETE
□ API version downgrade: /v2/admin → /v1/admin
□ Batch operation injection: {"users": [1,2,3]} → {"users": [1,2,3,admin_id]}

Tools: Burp Autorize, AuthMatrix, Entropy (malicious_insider persona)

Phase 4: GraphQL 专项

Phase 4: GraphQL Specialized Testing

text
内省泄漏 → 信息暴露检测
别名过载 → 100+ 别名 DoS
批查询 → 10+ 同时查询 DoS
字段重复 → __typename × 500
指令过载 → 递归 @skip/@include
循环查询 → 深度嵌套内省递归
字段建议 → 错误消息信息泄漏
GraphiQL/Playground 暴露 → IDE 公开风险
GET 突变 → CSRF 风险
追踪/调试模式 → 元数据泄漏

工具: FireTail, Escape DAST, api.sh (Phases 1-3)
text
Introspection leakage → Information exposure detection
Alias overload → 100+ aliases DoS
Batch queries → 10+ concurrent queries DoS
Field repetition → __typename × 500
Directive overload → Recursive @skip/@include
Loop queries → Deep nested introspection recursion
Field suggestions → Error message information leakage
GraphiQL/Playground exposure → IDE public risk
GET mutation → CSRF risk
Tracing/debug mode → Metadata leakage

Tools: FireTail, Escape DAST, api.sh (Phases 1-3)

Phase 5: REST 输入验证

Phase 5: REST Input Validation

text
□ HTTP 方法切换: GET→POST→PUT→DELETE→OPTIONS→PATCH
□ Content-Type 篡改: JSON→XML→multipart
□ NoSQL 注入: {"username": {"$gt": ""}}
□ SSRF via URL 参数: webhook URL/头像 URL/导入 URL
□ XXE in XML 端点
□ 参数污染: /api?role=user&role=admin
□ 批量赋值: 向请求体添加 is_admin: true
text
□ HTTP method switching: GET→POST→PUT→DELETE→OPTIONS→PATCH
□ Content-Type tampering: JSON→XML→multipart
□ NoSQL injection: {"username": {"$gt": ""}}
□ SSRF via URL parameters: webhook URL/avatar URL/import URL
□ XXE in XML endpoints
□ Parameter pollution: /api?role=user&role=admin
□ Mass assignment: Add is_admin: true to request body

Phase 6: 业务逻辑与差分测试

Phase 6: Business Logic and Differential Testing

text
□ Entropy compare: diff v1 vs v2 API → 状态码变化/字段删除/延迟回归
□ 多角色工作流测试: admin/user/readonly 权限矩阵
□ 优惠券/积分/价格操控
□ 竞态条件: 并发请求测试 TOCTOU
text
□ Entropy compare: diff v1 vs v2 API → Status code changes/field deletion/latency regression
□ Multi-role workflow testing: admin/user/readonly permission matrix
□ Coupon/point/price manipulation
□ Race conditions: Concurrent request testing for TOCTOU

Phase 7: WebSocket 测试

Phase 7: WebSocket Testing

text
□ 端点发现
□ 消息注入(注入 payload、原型污染)
□ 超大消息处理
□ 类型混淆
□ 跨站点 WebSocket 劫持(CSWH)
text
□ Endpoint discovery
□ Message injection (inject payload, prototype pollution)
□ Oversized message handling
□ Type confusion
□ Cross-Site WebSocket Hijacking (CSWH)

Phase 8: 限速与 DoS

Phase 8: Rate Limit and DoS

text
□ 限速绕过 via 头部: X-Forwarded-For, X-Real-IP
□ 路径变体: /api/ → /api → /Api/ → /API/
□ Slowloris 低带宽耗尽
□ GraphQL 批查询深度嵌套 DoS
□ IP 轮换测试(ProxyCat 代理池)
text
□ Rate limit bypass via headers: X-Forwarded-For, X-Real-IP
□ Path variants: /api/ → /api → /Api/ → /API/
□ Slowloris low-bandwidth exhaustion
□ GraphQL batch query deep nesting DoS
□ IP rotation testing (ProxyCat proxy pool)

Phase 9: 数据暴露

Phase 9: Data Exposure

text
□ 响应过度暴露: 对比 API 返回 vs UI 展示
□ 分页枚举: ?page=1&limit=10000
□ 错误消息信息泄漏: 堆栈跟踪/内部路径/SQL 错误
□ GraphQL 嵌套遍历访问越权数据
□ OpenAPI 规范暴露敏感端点
text
□ Excessive response exposure: Compare API returns vs UI display
□ Pagination enumeration: ?page=1&limit=10000
□ Error message information leakage: Stack traces/internal paths/SQL errors
□ GraphQL nested traversal for unauthorized data access
□ OpenAPI specification exposing sensitive endpoints

Phase 10: CI/CD 集成

Phase 10: CI/CD Integration

text
□ Entropy --ci --watch: spec 变更时自动重跑
□ Escape DAST: 按严重度阈值自动阻断构建
□ 发现持久化为回归测试
□ StackHawk(开发者优先、ZAP 内核)
text
□ Entropy --ci --watch: Automatically re-run when spec changes
□ Escape DAST: Automatically block builds by severity threshold
□ Persist discoveries as regression tests
□ StackHawk (developer-first, ZAP core)

工具链

Toolchain

工具用途获取
Vespasian流量 → OpenAPI/GraphQL 规范GitHub: praetorian-inc/vespasian
EntropyLLM 生成攻击场景,5 personasGitHub: arjinexe/entropy-chaos
Escape DAST业务逻辑安全测试escape.tech
api.sh8 阶段全协议攻击管道GitHub: Sharon-Needles/api
FireTailGraphQL 12 专项测试firetail.ai
jwt_toolJWT 全面测试GitHub: ticarpi/jwt_tool
Burp Autorize双会话授权对比Burp BApp Store
ToolPurposeAcquisition
VespasianTraffic → OpenAPI/GraphQL specificationsGitHub: praetorian-inc/vespasian
EntropyLLM-generated attack scenarios, 5 personasGitHub: arjinexe/entropy-chaos
Escape DASTBusiness logic security testingescape.tech
api.sh8-phase full-protocol attack pipelineGitHub: Sharon-Needles/api
FireTail12-item GraphQL specialized testingfiretail.ai
jwt_toolComprehensive JWT testingGitHub: ticarpi/jwt_tool
Burp AutorizeDual-session authorization comparisonBurp BApp Store

参考

References

  • references/rest-graphql-testing.md
    — REST + GraphQL 深度测试
  • references/jwt-oauth-testing.md
    — JWT + OAuth 安全测试
  • references/rest-graphql-testing.md
    — REST + GraphQL in-depth testing
  • references/jwt-oauth-testing.md
    — JWT + OAuth security testing

任务完成自检(声称完成前 MUST 通过)

Task Completion Self-Check (MUST Pass Before Claiming Completion)

  • 我是否执行了工作流中的每一步(而不是只阅读)?
  • 我是否基于
    tool-index
    使用了真实工具路径?
  • 我是否产出了可复现证据(命令/脚本/截图/报告)?
  • 我是否完成并回写了 RULES 要求的 Checklist 项?
  • Have I executed every step in the workflow (instead of just reading)?
  • Have I used the actual tool paths based on
    tool-index
    ?
  • Have I produced reproducible evidence (commands/scripts/screenshots/reports)?
  • Have I completed and written back the Checklist items required by RULES?