implementing-api-security-testing-with-42crunch
使用42Crunch平台实施全面的API安全测试,对OpenAPI规范执行静态审计(Static Audit)和动态合规扫描(Conformance Scanning)。
Best use case
implementing-api-security-testing-with-42crunch is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
使用42Crunch平台实施全面的API安全测试,对OpenAPI规范执行静态审计(Static Audit)和动态合规扫描(Conformance Scanning)。
Teams using implementing-api-security-testing-with-42crunch should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/implementing-api-security-testing-with-42crunch/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How implementing-api-security-testing-with-42crunch Compares
| Feature / Agent | implementing-api-security-testing-with-42crunch | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
使用42Crunch平台实施全面的API安全测试,对OpenAPI规范执行静态审计(Static Audit)和动态合规扫描(Conformance Scanning)。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 使用42Crunch实施API安全测试
## 概述
42Crunch是一个API安全平台,将安全左移(Shift-Left)测试与运行时防护(Shield-Right)相结合。它提供API Audit(API审计)用于OpenAPI定义的静态安全分析,API Conformance Scan(API合规扫描)用于动态漏洞检测,以及API Protect(API防护)用于实时威胁防护。该平台集成到CI/CD流水线和IDE中,在部署前后识别OWASP API安全Top 10漏洞。
## 前置条件
- 42Crunch平台账号(评估可用免费版)
- 目标API的OpenAPI规范(OAS)v2.0、v3.0或v3.1定义
- 带42Crunch扩展的IDE(VS Code、IntelliJ或Eclipse)
- CI/CD流水线(Jenkins、GitHub Actions、Azure DevOps或GitLab CI)
- 动态扫描(合规扫描)需要运行中的API实例
- CLI工具需要Node.js或Python环境
## 核心概念
### API Audit(静态分析)
API Audit无需运行中的API即可对OpenAPI定义执行静态安全分析。它按类别对规范进行300+项安全检查:
**安全评分类别:**
- **数据验证(Data Validation)**:Schema定义、参数约束、响应验证
- **认证(Authentication)**:安全方案定义、范围要求
- **传输安全(Transport Security)**:服务器URL scheme、TLS要求
- **错误处理(Error Handling)**:错误响应定义、信息泄露防护
**通过VS Code扩展运行API Audit:**
1. 从VS Code市场安装42Crunch扩展
2. 打开OpenAPI规范文件(YAML或JSON)
3. 点击编辑器工具栏中的安全审计图标
4. 查看安全分数(0-100)和各项发现
5. 使用内联修复指导处理问题
**带安全控制的OpenAPI定义示例:**
```yaml
openapi: 3.0.3
info:
title: Secure User API
version: 1.0.0
servers:
- url: https://api.example.com/v1
description: Production server (HTTPS only)
security:
- BearerAuth: []
paths:
/users/{userId}:
get:
operationId: getUserById
summary: Retrieve user by ID
parameters:
- name: userId
in: path
required: true
schema:
type: string
format: uuid
pattern: '^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$'
maxLength: 36
responses:
'200':
description: User details
content:
application/json:
schema:
$ref: '#/components/schemas/User'
'400':
description: Invalid request
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'401':
description: Unauthorized
'404':
description: User not found
components:
securitySchemes:
BearerAuth:
type: http
scheme: bearer
bearerFormat: JWT
schemas:
User:
type: object
required:
- id
- email
properties:
id:
type: string
format: uuid
readOnly: true
email:
type: string
format: email
maxLength: 254
name:
type: string
maxLength: 100
pattern: '^[a-zA-Z\s\-]+$'
additionalProperties: false
Error:
type: object
required:
- code
- message
properties:
code:
type: integer
format: int32
message:
type: string
maxLength: 256
additionalProperties: false
```
### API Conformance Scan(动态测试)
合规扫描对运行中的API进行动态测试,验证其是否符合OpenAPI契约,检测运行时漏洞(包括OWASP API安全Top 10问题):
**Scan v2配置:**
```yaml
# 42c-conf.yaml
version: "2.0"
scan:
target:
url: https://api.example.com/v1
authentication:
- type: bearer
token: "${API_TOKEN}"
in: header
name: Authorization
settings:
maxScanTime: 3600
requestsPerSecond: 10
followRedirects: false
tests:
owasp:
- bola
- bfla
- injection
- ssrf
- massAssignment
- excessiveDataExposure
```
**通过CLI运行合规扫描:**
```bash
# 安装42Crunch CLI
npm install -g @42crunch/cicd-cli
# 运行合规扫描
42crunch-cli scan \
--api-definition ./openapi.yaml \
--target-url https://api.example.com/v1 \
--token $CRUNCH_TOKEN \
--min-score 70 \
--report-format sarif \
--output scan-report.sarif
```
### CI/CD流水线集成
**GitHub Actions集成:**
```yaml
name: API Security Testing
on:
push:
paths:
- 'api/**'
- 'openapi/**'
jobs:
api-security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: 42Crunch API审计
uses: 42Crunch/api-security-audit-action@v3
with:
api-token: ${{ secrets.CRUNCH_API_TOKEN }}
collection-name: "my-api-collection"
min-score: 75
upload-to-code-scanning: true
- name: 42Crunch合规扫描
if: github.ref == 'refs/heads/main'
uses: 42Crunch/api-conformance-scan@v1
with:
api-token: ${{ secrets.CRUNCH_API_TOKEN }}
target-url: ${{ secrets.STAGING_API_URL }}
scan-config: ./42c-conf.yaml
```
**Jenkins流水线集成:**
```groovy
pipeline {
agent any
stages {
stage('API Security Audit') {
steps {
script {
def auditResult = sh(
script: '''
42crunch-cli audit \
--api-definition openapi.yaml \
--token ${CRUNCH_TOKEN} \
--min-score 75 \
--report-format json \
--output audit-report.json
''',
returnStatus: true
)
if (auditResult != 0) {
error("API安全审计失败 - 分数低于阈值")
}
}
}
}
stage('Conformance Scan') {
when { branch 'main' }
steps {
sh '''
42crunch-cli scan \
--api-definition openapi.yaml \
--target-url ${STAGING_URL} \
--token ${CRUNCH_TOKEN} \
--scan-config 42c-conf.yaml
'''
}
}
}
post {
always {
archiveArtifacts artifacts: '*-report.*'
publishHTML([
reportDir: '.',
reportFiles: 'audit-report.html',
reportName: 'API Security Report'
])
}
}
}
```
### API Protect(运行时防护)
API Protect作为微网关(Micro-Gateway)部署在API端点前端,在运行时强制执行OpenAPI契约:
```yaml
# api-protect-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: api-protect-config
data:
protection-config.json: |
{
"apiDefinition": "/config/openapi.yaml",
"enforcement": {
"validateRequests": true,
"validateResponses": true,
"blockOnFailure": true,
"logLevel": "warn"
},
"rateLimit": {
"enabled": true,
"requestsPerMinute": 100,
"burstSize": 20
},
"allowlist": {
"contentTypes": ["application/json"],
"methods": ["GET", "POST", "PUT", "DELETE"]
}
}
```
## 修复工作流
当42Crunch发现问题时,遵循以下修复流程:
1. **分类(Triage)**:按严重性(严重、高、中、低)排序查看发现
2. **分析(Analyze)**:理解OpenAPI定义中缺少的特定安全控制
3. **修复(Fix)**:对规范应用推荐的更改
4. **验证(Validate)**:重新运行审计确认分数提升
5. **部署(Deploy)**:通过CI/CD流水线推送更新的规范
**常见审计发现及修复:**
| 发现 | 严重性 | 修复方案 |
|------|--------|----------|
| 未定义认证 | 严重 | 添加securitySchemes和security要求 |
| 缺少输入验证 | 高 | 添加type、format、pattern、maxLength约束 |
| 服务器URL使用HTTP | 高 | 将服务器URL改为HTTPS |
| 未定义错误响应 | 中 | 添加4xx和5xx响应定义 |
| additionalProperties未限制 | 中 | 在对象Schema上设置additionalProperties: false |
| 缺少速率限制 | 中 | 添加x-rateLimit扩展或使用API Protect |
## 关键安全检查
42Crunch针对以下关键安全领域评估API:
- **BOLA防护**:验证是否定义了对象级授权模式
- **BFLA防护**:检查是否定义了功能级访问控制
- **注入防护**:确保输入参数有适当的type/format/pattern约束
- **数据暴露**:验证响应Schema限制返回的属性
- **安全配置错误**:检查认证方案、传输安全、CORS设置
- **批量赋值**:验证请求体使用显式属性白名单
## 参考资料
- 42Crunch API安全平台: https://42crunch.com/api-security-platform/
- 42Crunch文档: https://docs.42crunch.com/
- Microsoft Defender for Cloud 42Crunch集成: https://learn.microsoft.com/en-us/azure/defender-for-cloud/onboarding-guide-42crunch
- OWASP API安全Top 10 2023: https://owasp.org/API-Security/editions/2023/en/0x00-header/
- Jenkins 42Crunch插件: https://plugins.jenkins.io/42crunch-security-audit/Related Skills
triaging-security-incident
使用 NIST SP 800-61r3 和 SANS PICERL 框架对安全事件进行初始分类,确定严重性、范围和所需响应行动。 按类型对事件分类,根据业务影响分配优先级,并路由到相应的响应团队。适用于事件分类、 安全告警分类、严重性评估、事件优先级排序或初始事件分析等请求场景。
triaging-security-incident-with-ir-playbook
使用结构化 IR Playbook 对安全事件进行分类和优先排序,确定严重性、分配响应团队并启动适当的响应程序。
triaging-security-alerts-in-splunk
在 Splunk Enterprise Security 中对安全告警进行分类,通过 SPL 查询和事件审查(Incident Review) 仪表板对重要事件进行严重性分类、调查、关联相关遥测并做出升级或关闭决策。 适用于 SOC 分析师需要处理关联搜索产生的告警队列、确定调查优先级, 或需要为交接给二/三级分析师记录分类决策时。
testing-websocket-api-security
测试 WebSocket API 实现中的安全漏洞,包括 WebSocket 升级时缺少身份认证、跨站 WebSocket 劫持(Cross-Site WebSocket Hijacking,CSWSH)、通过 WebSocket 消息进行的注入攻击、输入校验不足、通过消息泛洪实施拒绝服务,以及通过 WebSocket 帧造成的信息泄露。测试人员使用 Burp Suite 拦截 WebSocket 握手和消息,构造恶意 payload,并测试 WebSocket 通道上的授权绕过。适用于 WebSocket 安全测试、WS 渗透测试、CSWSH 攻击或实时 API 安全评估相关请求。
testing-oauth2-implementation-flaws
测试 OAuth 2.0 和 OpenID Connect 实现中的安全缺陷,包括授权码拦截、重定向 URI 操控、OAuth 流程中的 CSRF、令牌泄露、权限范围(scope)提升以及 PKCE 绕过。测试人员对授权服务器、客户端应用及令牌处理进行评估,发现可导致账户接管或未授权访问的常见错误配置。适用于 OAuth 安全测试、OIDC 漏洞评估、OAuth2 重定向绕过或授权码流程测试相关请求。
testing-mobile-api-authentication
测试移动应用 API 的认证与授权机制,识别认证失效、不安全的令牌管理、会话固定、 权限提升和 IDOR 漏洞。适用于对移动应用后端进行 API 安全评估、测试 JWT 实现、 评估 OAuth 流程或评估会话管理的场景。适合涉及移动 API 认证测试、令牌安全评估、 OAuth 移动端流程测试或 API 授权绕过的相关请求。
testing-jwt-token-security
在安全测试活动中,评估 JSON Web Token(JWT)实现中的密码学弱点、算法混淆攻击和授权绕过漏洞。
testing-for-xxe-injection-vulnerabilities
在授权的渗透测试中发现和利用 XML 外部实体(XXE)注入漏洞,以读取服务器文件、执行 SSRF 并外泄数据。
testing-for-xss-vulnerabilities
通过向反射型、存储型和 DOM 型上下文注入 JavaScript 载荷,测试 Web 应用程序的跨站脚本(XSS)漏洞, 演示客户端代码执行、会话劫持和用户冒充。测试人员识别所有注入点和输出上下文,构造适合上下文的载荷, 并绕过净化和 CSP 保护。适用于 XSS 测试、跨站脚本评估、客户端注入测试或 JavaScript 注入漏洞测试等请求场景。
testing-for-xss-vulnerabilities-with-burpsuite
在授权的安全评估过程中,使用 Burp Suite 的扫描器、Intruder 和 Repeater 工具识别和验证跨站脚本(XSS)漏洞。适用于 Web 应用渗透测试中检测反射型、存储型和 DOM 型 XSS,验证自动化扫描器报告的 XSS 发现,以及评估 CSP 和 XSS 过滤器的有效性时使用。
testing-for-xml-injection-vulnerabilities
测试 Web 应用程序中的 XML 注入漏洞,包括 XXE(XML 外部实体注入)、XPath 注入和 XML 实体攻击,以识别数据泄露和服务器端请求伪造(SSRF)风险。
testing-for-sensitive-data-exposure
在安全评估中识别敏感数据暴露漏洞,包括 API 密钥泄露、响应中的 PII、不安全存储以及未受保护的数据传输。