Integrates OWASP ZAP for DAST scans in GitHub Actions and GitLab CI pipelines, configuring baseline, full, and API scans on running web apps with rule tuning and quality gates.
npx claudepluginhub killvxk/cybersecurity-skills-zhThis skill uses the workspace's default tool permissions.
- 测试运行中的 Web 应用程序以发现 XSS、SQLi、CSRF 和配置错误等漏洞时
Integrates OWASP ZAP for baseline, full, and API DAST scans in GitHub Actions and GitLab CI pipelines. Covers policy tuning, findings analysis, and quality gates for web apps.
Integrates OWASP ZAP for DAST scans in CI/CD pipelines. Configures baseline, full, and API scans against running web apps/APIs, tunes policies, sets quality gates in GitHub Actions/GitLab CI.
Performs DAST with OWASP ZAP on web apps and APIs via passive/active scans, OWASP Top 10 detection, authenticated testing, and Docker-based CI/CD scans. Generates reports with OWASP/CWE mappings.
Share bugs, ideas, or general feedback.
不适用于扫描源代码(使用 SAST)、扫描依赖项(使用 SCA)或基础设施配置扫描(使用 IaC 扫描工具)。
# .github/workflows/dast-scan.yml
name: DAST Security Scan
on:
deployment_status:
workflow_dispatch:
inputs:
target_url:
description: 'Target URL to scan'
required: true
jobs:
zap-baseline:
name: ZAP Baseline Scan
runs-on: ubuntu-latest
services:
webapp:
image: ${{ github.repository }}:${{ github.sha }}
ports:
- 8080:8080
options: --health-cmd="curl -f http://localhost:8080/health" --health-interval=10s --health-timeout=5s --health-retries=5
steps:
- uses: actions/checkout@v4
- name: ZAP Baseline Scan
uses: zaproxy/action-baseline@v0.12.0
with:
target: 'http://webapp:8080'
rules_file_name: '.zap/rules.tsv'
cmd_options: '-a -j'
allow_issue_writing: false
- name: Upload ZAP Report
if: always()
uses: actions/upload-artifact@v4
with:
name: zap-baseline-report
path: report_html.html
zap-full-scan:
name: ZAP Full Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: ZAP Full Scan
uses: zaproxy/action-full-scan@v0.12.0
with:
target: ${{ github.event.inputs.target_url || 'https://staging.example.com' }}
rules_file_name: '.zap/rules.tsv'
cmd_options: '-a -j -T 60'
- name: Upload Reports
if: always()
uses: actions/upload-artifact@v4
with:
name: zap-full-report
path: |
report_html.html
report_json.json
zap-api-scan:
name: ZAP API Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: ZAP API Scan
uses: zaproxy/action-api-scan@v0.12.0
with:
target: 'https://staging.example.com/api/openapi.json'
format: openapi
rules_file_name: '.zap/api-rules.tsv'
cmd_options: '-a -j'
# .zap/rules.tsv
# 规则 ID 操作 (IGNORE/WARN/FAIL) 描述
10003 IGNORE # 易受攻击的 JS 库(由 SCA 处理)
10015 WARN # 缓存控制头不完整或缺失
10021 FAIL # 缺少 X-Content-Type-Options
10035 FAIL # 缺少 Strict-Transport-Security
10038 FAIL # 缺少内容安全策略
10098 IGNORE # 跨域配置错误(CDN)
40012 FAIL # 跨站脚本攻击(反射型)
40014 FAIL # 跨站脚本攻击(持久型)
40018 FAIL # SQL 注入
40019 FAIL # SQL 注入(MySQL)
40032 FAIL # .htaccess 信息泄露
90033 FAIL # Cookie 范围过宽
# docker-compose.zap.yml
version: '3.8'
services:
webapp:
build: .
ports:
- "8080:8080"
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:8080/health"]
interval: 10s
retries: 5
zap:
image: zaproxy/zap-stable:latest
depends_on:
webapp:
condition: service_healthy
command: >
zap-baseline.py
-t http://webapp:8080
-r /zap/wrk/report.html
-J /zap/wrk/report.json
-c /zap/wrk/rules.tsv
-I
volumes:
- ./zap-reports:/zap/wrk
- ./.zap/rules.tsv:/zap/wrk/rules.tsv
| 术语 | 定义 |
|---|---|
| DAST | 动态应用安全测试 — 通过发送请求并分析响应来测试运行中的应用程序 |
| 基线扫描 | 快速被动扫描,爬取应用程序而不进行主动攻击,适合 CI/CD |
| 完整扫描 | 包括 XSS、SQLi 和其他注入漏洞攻击载荷的主动扫描 |
| API 扫描 | 使用 OpenAPI/Swagger 规范测试所有已记录 API 端点的针对性扫描 |
| 爬虫 | ZAP 通过跟踪链接发现应用程序页面和端点的爬取器 |
| 主动扫描 | ZAP 向已发现端点发送攻击载荷以查找可利用漏洞的阶段 |
| 被动扫描 | 分析 HTTP 响应中的安全头、Cookie 和信息泄露,无需发送攻击 |
| 扫描策略 | 定义启用哪些攻击类型及其强度级别的配置 |
背景:团队在生产前部署到预发布环境,需要在阶段之间自动化 DAST 扫描以捕获运行时漏洞。
方法:
注意事项:ZAP 完整扫描可能需要 30+ 分钟,并可能以攻击流量淹没预发布服务器。在 CI 中使用基线扫描,按计划进行完整扫描。在未协调的情况下对生产运行 DAST 可能触发 WAF 阻止和事件告警。
ZAP DAST 扫描报告
======================
目标:https://staging.example.com
扫描类型:基线 + API
日期:2026-02-23
时长:4m 32s
发现:
FAIL: 3
WARN: 7
INFO: 12
PASS: 45
失败告警:
[高危] 40012 - 跨站脚本攻击(反射型)
URL:https://staging.example.com/search?q=<script>
方法:GET
证据:<script>alert(1)</script>
[中危] 10021 - 缺少 X-Content-Type-Options
URL:https://staging.example.com/api/v1/*
证据:响应头缺失
[中危] 10035 - 缺少 Strict-Transport-Security
URL:https://staging.example.com/
证据:HSTS 头不存在
质量门禁:失败(1 个高危,2 个中危发现)