API安全渗透测试
conducting-api-security-testing
对 REST、GraphQL 和 gRPC API 进行安全测试,识别身份验证、授权、速率限制、输入验证和业务逻辑中的漏洞。测试人员使用 OWASP API Security Top 10 作为测试框架,结合 Burp Suite 拦截、Postman 集合和自定义脚本,在每个权限级别测试端点安全性。适用于涉及 API 安全测试、REST API 渗透测试、GraphQL 安全评估或 API 漏洞测试的请求。
- License 许可
- Apache-2.0
- 最近更新
- 2026-08-31
- Stars
- ★ 3.6w
- Forks
- 4.4k
01 前言 Front Matter
- name
- conducting-api-security-testing
- tags
- [ "API-security", "OWASP-API-Top10", "REST", "GraphQL", "authorization-testing" ]
- author
- mahipal
- domain
- cybersecurity
- license
- Apache-2.0
- version
- 1.0.0
- nist_csf
- [ "ID.RA-01", "ID.RA-06", "GV.OV-02", "DE.AE-07" ]
- subdomain
- penetration-testing
- description
- Conducts security testing of REST, GraphQL, and gRPC APIs to identify vulnerabilities in authentication, authorization, rate limiting, input validation, and business logic. The tester uses the OWASP API Security Top 10 as the testing framework, combining Burp Suite interception with Postman collections and custom scripts to test endpoint security at every privilege level. Activates for requests involving API security testing, REST API pentest, GraphQL security assessment, or API vulnerability testing.
- mitre_attack
- [ "T1190", "T1213", "T1552.001", "T1078", "T1071.001" ]
02 资源文件 3
- 许可证LICENSE11.0 KB
- 参考文档references/api-reference.md2.5 KB
- 脚本scripts/agent.py8.2 KB
03 SKILL.md 正文
Conducting API Security Testing
When to Use
- Testing API endpoints for authorization flaws, injection vulnerabilities, and business logic bypasses
- Assessing the security of microservices architecture where APIs are the primary communication method
- Validating that API gateway protections (rate limiting, authentication, input validation) are properly enforced
- Testing third-party API integrations for data exposure and insecure configurations
- Evaluating GraphQL APIs for introspection disclosure, query complexity attacks, and authorization bypasses
Do not use against APIs without written authorization, for load testing or denial-of-service testing unless explicitly scoped, or for testing production APIs that process real financial transactions without safeguards.
Prerequisites
- API documentation (OpenAPI/Swagger, GraphQL schema, Postman collection) or application access to reverse-engineer the API
- Burp Suite Professional configured to intercept API traffic with JSON/XML content type handling
- Postman or Insomnia for organizing and replaying API requests across different authentication contexts
- Valid API tokens or credentials at multiple privilege levels (unauthenticated, standard user, admin)
- Target API base URL and version information
Workflow
Step 1: API Discovery and Documentation
Map the complete API attack surface:
- Import API documentation: Load OpenAPI/Swagger specs into Postman or Burp Suite to catalog all endpoints, methods, parameters, and authentication requirements
- Reverse-engineer undocumented APIs: Proxy the mobile app or web frontend through Burp Suite and exercise all features to capture API calls. Export the Burp sitemap as the baseline endpoint inventory.
- GraphQL introspection: Send an introspection query to discover the full schema:
{"query": "{__schema{types{name,fields{name,args{name,type{name}}}}}}"} - Endpoint enumeration: Fuzz for hidden API versions (
/api/v1/,/api/v2/,/api/internal/), debug endpoints (/api/debug,/api/health,/api/metrics), and administrative endpoints - Document authentication mechanisms: Identify if the API uses API keys, OAuth 2.0 Bearer tokens, JWT, session cookies, or mutual TLS
Step 2: Authentication and Token Testing
Test authentication mechanisms for weaknesses:
- JWT analysis: Decode the JWT and inspect claims (sub, exp, iss, aud, role). Test:
- Algorithm confusion: Change
algtononeand remove the signature - Key confusion: Change
algfrom RS256 to HS256 and sign with the public key - Weak secret: Brute-force the HMAC secret with
hashcat -m 16500 jwt.txt wordlist.txt - Token expiration: Verify tokens expire and cannot be used after expiration
- Claim tampering: Modify role, userId, or permission claims and re-sign
- Algorithm confusion: Change
- OAuth 2.0 testing: Check for redirect_uri manipulation, authorization code reuse, token leakage in Referer headers, and missing state parameter (CSRF)
- API key security: Test if API keys are validated per-endpoint, if revoked keys are immediately rejected, and if keys in query strings appear in access logs or analytics
Step 3: Authorization Testing (BOLA/BFLA)
Test for Broken Object Level Authorization (BOLA) and Broken Function Level Authorization (BFLA):
- BOLA (IDOR) testing: For every endpoint that returns user-specific data, replace the object identifier with another user's identifier:
GET /api/users/123/orders->GET /api/users/456/orders- Test with numeric IDs, UUIDs, usernames, and email addresses
- Automate with Burp Autorize extension: configure it with two sessions (attacker and victim) and replay all requests
- BFLA testing: Using a low-privilege token, attempt to access administrative endpoints:
DELETE /api/users/456(admin-only delete)PUT /api/users/456/role(role modification)GET /api/admin/dashboard(admin panel data)
- Mass assignment: Send additional JSON properties not shown in the documentation:
PUT /api/users/123 {"name": "Test", "role": "admin", "isVerified": true, "balance": 99999} - HTTP method testing: If GET works on an endpoint, try PUT, PATCH, DELETE, and OPTIONS to discover unprotected methods
Step 4: Input Validation and Injection Testing
Test API inputs for injection and validation flaws:
- SQL injection in API parameters: Test all parameters (path, query, body, headers) with SQL injection payloads. JSON APIs are often overlooked:
{"username": "admin' OR 1=1--", "password": "test"} - NoSQL injection: For MongoDB backends, test with operator injection:
{"username": {"$gt": ""}, "password": {"$gt": ""}} - SSRF via API: Test any parameter that accepts URLs (webhook URLs, avatar URLs, import endpoints) with internal addresses and cloud metadata endpoints
- GraphQL-specific injection: Test for query depth attacks, alias-based batching for brute force, and field suggestion enumeration
- XXE in XML APIs: Submit XML content with external entity declarations to API endpoints that accept XML
- Rate limiting validation: Send 100+ rapid requests to authentication endpoints, password reset, and OTP verification to test for brute force protection
Step 5: Data Exposure and Response Analysis
Check for excessive data exposure in API responses:
- Verbose responses: Compare the data returned in API responses with what the UI displays. APIs often return more fields than needed (internal IDs, creation timestamps, email addresses of other users, role information).
- Error message analysis: Trigger errors by sending malformed input, invalid tokens, and non-existent resources. Check if error messages reveal stack traces, database queries, internal paths, or technology details.
- Pagination and enumeration: Test if enumeration is possible by iterating through paginated responses (
/api/users?page=1,page=2, etc.) to extract all records - GraphQL data exposure: Query for fields not intended for the current user's role. Test nested queries that traverse relationships to access unauthorized data.
- Debug endpoints: Check
/api/debug,/api/status,/metrics,/health,/.env,/api/swagger.jsonfor exposed internal information
Key Concepts
| Term | Definition |
|---|---|
| BOLA | Broken Object Level Authorization (OWASP API #1); failure to verify that the requesting user is authorized to access a specific object, enabling IDOR attacks |
| BFLA | Broken Function Level Authorization (OWASP API #5); failure to restrict administrative or privileged API functions from being accessed by lower-privilege users |
| Mass Assignment | A vulnerability where the API binds client-provided data to internal object properties without filtering, allowing attackers to modify fields they should not have access to |
| GraphQL Introspection | A built-in GraphQL feature that exposes the complete API schema including all types, fields, and relationships; should be disabled in production |
| JWT | JSON Web Token; a self-contained token format used for API authentication containing claims signed with a secret or key pair |
| Rate Limiting | Controls that restrict the number of API requests a client can make within a time window, preventing brute force, enumeration, and abuse |
Tools & Systems
- Burp Suite Professional: HTTP proxy for intercepting, modifying, and replaying API requests with extensions like Autorize for automated authorization testing
- Postman: API development platform used for organizing endpoint collections, scripting tests, and comparing responses across authentication contexts
- GraphQL Voyager: Visual tool for exploring GraphQL schemas obtained through introspection queries
- jwt.io / jwt_tool: Tools for decoding, analyzing, and tampering with JWT tokens to test authentication bypasses
- Nuclei: Template-based scanner with API-specific templates for detecting common misconfigurations and known vulnerabilities
Common Scenarios
Scenario: API Security Assessment for a Fintech Mobile Application
Context: A fintech startup has a mobile banking application with a REST API backend. The API handles account management, fund transfers, bill payments, and transaction history. The tester has Swagger documentation and accounts at user and admin levels.
Approach:
- Import Swagger spec into Postman, generating 87 endpoint collections across 12 controllers
- Discover BOLA on
/api/v1/accounts/{accountId}/transactionsallowing any authenticated user to view any account's transaction history - Find mass assignment on the user update endpoint where adding
"dailyTransferLimit": 999999bypasses the configured transfer limit - Identify that the fund transfer endpoint lacks rate limiting, allowing unlimited transfer attempts without throttling
- Discover that JWT tokens have a 30-day expiration with no refresh token rotation, enabling long-lived session hijacking
- Find that the admin endpoint
/api/v1/admin/usersis accessible with a standard user token (BFLA) - Report all findings with CVSS scores and specific API code-level remediation guidance
Pitfalls:
- Testing only the endpoints documented in Swagger and missing undocumented or deprecated API versions
- Not testing the same endpoint with tokens from every privilege level to detect authorization bypasses
- Ignoring response body analysis for excessive data exposure when the UI only shows a subset of returned fields
- Failing to test for mass assignment by only sending fields shown in the documentation
Output Format
## Finding: Broken Object Level Authorization in Transaction History API
**ID**: API-001
**Severity**: Critical (CVSS 9.1)
**Affected Endpoint**: GET /api/v1/accounts/{accountId}/transactions
**OWASP API Category**: API1:2023 - Broken Object Level Authorization
**Description**:
The transaction history endpoint returns all transactions for the specified
account without verifying that the authenticated user owns the account. Any
authenticated user can view the complete transaction history of any account
by substituting the accountId path parameter.
**Proof of Concept**:
1. Authenticate as User A (account ID: ACC-10045)
2. Request: GET /api/v1/accounts/ACC-10046/transactions
Authorization: Bearer <User_A_token>
3. Response: 200 OK with User B's full transaction history
**Impact**:
Any authenticated user can view the complete financial transaction history of
all 45,000 customer accounts, including amounts, dates, recipients, and
transaction descriptions.
**Remediation**:
Implement server-side authorization check that verifies the authenticated user
owns the requested account before returning data:
const account = await Account.findById(accountId);
if (account.userId !== req.user.id) return res.status(403).json({error: "Forbidden"});
04 同仓库更多 Skills
SLSA 构建来源验证
verifying-build-provenance-with-slsa-sigstore
使用 Sigstore 的 cosign(verify、verify-attestation、verify-blob-attestation)和 slsa-verifier(verify-artifact)验证工件签名和 SLSA 来源(provenance),强制校验 keyless OIDC 构建者身份和源仓库是否符合 SLSA Build 级别。适用于 CI/CD 中部署工件前、消费第三方证明时、建立 SLSA Build L3 管道,或在事件响应或准入控制期间确认来源的场景。
TPM 测量启动验证
validating-tpm-measured-boot-attestation
使用 tpm2-tools 验证 TPM 2.0 测量启动(measured boot)的完整性和远程证明:读取 PCR(tpm2_pcrread)、重放启动事件日志、生成并检查签名报价(tpm2_quote/tpm2_checkquote),以及将机密封印(seal)到 PCR 策略。适用于确认系统已启动可信固件/内核以实现零信任(Zero Trust)设备状态、通过 PCR 漂移检测启动链篡改,或构建黄金值基线用于机群(fleet)证明。
备份完整性验证
validating-backup-integrity-for-recovery
通过加密哈希验证、自动化恢复测试、损坏检测和可恢复性检查来验证备份完整性,确认备份对于灾难恢复和勒索软件响应是可靠的。适用于在依赖备份进行恢复之前、构建备份后验证管道、审计备份基础设施以满足合规要求,或检查不可变/air-gapped(气隙)备份是否存在静默损坏或篡改的场景。
KAPE Windows 取证收集
triaging-windows-with-kape
运行 KAPE(Kroll Artifact Parser and Extractor),通过 Targets 收集目标取证工件(注册表配置单元、$MFT、事件日志、prefetch、浏览器数据),并使用封装 Eric Zimmerman 的 EZ Tools(PECmd、MFTECmd、RECmd)的 Modules 进行解析。适用于事件遏制/分诊早期阶段——此时完整磁盘镜像不切实际,但需要快速获得可采信、可解析的 Windows 工件集,包括大规模远程收集。
SSVC 漏洞优先级分诊
triaging-vulnerabilities-with-ssvc-framework
使用 CISA 的 Stakeholder-Specific Vulnerability Categorization(SSVC,利益相关方特定漏洞分类)决策树对漏洞进行分诊和优先级排序,权衡利用状态(通过 CISA KEV 目录和 FIRST EPSS API)、技术影响、自动化程度和任务普遍性,输出 Track/Track*/Attend/Act 决策。适用于对漏洞扫描结果(OpenVAS、Nessus、Qualys)进行优先级排序以制定修复计划,而不局限于原始 CVSS 分数的场景。
安全事件初步分诊
triaging-security-incident
使用 NIST SP 800-61r3 和 SANS PICERL 框架对安全事件进行初步分诊,分类事件类型、按业务影响分配优先级,并路由到相应的响应团队。适用于 SIEM/EDR 告警需要人工分类、并发告警必须确定优先级,或用户报告或威胁情报 IOC 匹配需要初步事件分类的场景。