ai

OWASP ZAP Batch Processing Pipeline — สร้างระบบ

owasp zap batch processing pipeline
OWASP ZAP Batch Processing Pipeline — สร้างระบบ

OWASP ZAP คืออะไรและใช้ทำอะไรใน Pipeline

OWASP ZAP Batch Processing Pipeline — สร้างระบบ

OWASP ZAP (Zed Attack Proxy) เป็น open source web application security scanner ที่พัฒนาโดย OWASP community ใช้สำหรับค้นหาช่องโหว่ด้านความปลอดภัยใน web applications เช่น SQL Injection, Cross-Site Scripting (XSS), CSRF, Insecure Headers และอีกมากมาย ZAP เป็นเครื่องมือ DAST (Dynamic Application Security Testing) ที่ทดสอบ application ขณะทำงานจริง

การใช้ ZAP ใน Batch Processing Pipeline หมายถึงการ scan หลาย targets พร้อมกันหรือต่อเนื่องแบบอัตโนมัติ เหมาะสำหรับองค์กรที่มี web applications หลายตัวและต้องการ scan ทั้งหมดเป็นประจำ หรือ scan ทุกครั้งที่มีการ deploy

ZAP รองรับ automation ผ่านหลายช่องทาง ได้แก่ ZAP API (REST) สำหรับควบคุม ZAP ผ่าน HTTP, ZAP Automation Framework สำหรับ YAML-based configuration, ZAP Docker image สำหรับ containerized scanning และ ZAP CLI สำหรับ command-line execution

ข้อดีของ ZAP เมื่อเทียบกับ commercial tools เช่น Burp Suite Enterprise คือ ฟรีและ open source, community ใหญ่, API ครบถ้วน, Docker support ดี และมี Marketplace สำหรับ add-ons

ติดตั้ง ZAP และตั้งค่าสำหรับ Automation

วิธีติดตั้งและเตรียม ZAP สำหรับ batch scanning

ติดตั้ง ZAP ด้วย Docker (แนะนำสำหรับ CI/CD)

docker pull ghcr.io/zaproxy/zaproxy:stable

รัน ZAP ในโหมด daemon (headless)

docker run -d --name zap \
-p 8080:8080 \
-v $(pwd)/zap-work:/zap/wrk \
ghcr.io/zaproxy/zaproxy:stable \
zap.sh -daemon -host 0.0.0.0 -port 8080 \
-config api.key=your-api-key-here \
-config api.addrs.addr.name=.* \

-config api.addrs.addr.regex=true

ตรวจสอบว่า ZAP ทำงาน

curl http://localhost:8080/JSON/core/view/version/?apikey=your-api-key-here

=== ZAP Automation Framework (YAML config) ===

automation.yaml

env:

contexts:

  • name: "target-app"

urls:

  • "https://target-app.example.com"

includePaths:

  • "https://target-app.example.com/.*"

excludePaths:

  • "https://target-app.example.com/logout.*"

authentication:

method: "form"

parameters:

loginUrl: "https://target-app.example.com/login"

loginRequestData: "username={%username%}&password={%password%}"

verification:

method: "response"

เนื้อหาเกี่ยวข้อง — บทความที่เกี่ยวข้อง: Tailscale Mesh สำหรับมือใหม่ Step by Step — คู่มือฉบับสมบูรณ์ 2026

loggedInRegex: "Welcome.*"

users:

  • name: "test-user"

credentials:

username: "testuser"

password: "testpass123"

jobs:

  • type: spider

parameters:

maxDuration: 5

maxDepth: 5

maxChildren: 10

  • type: spiderAjax

parameters:

maxDuration: 5

แนะนำเพิ่มเติม — แหล่งความรู้ Forex iCafeForex

maxCrawlDepth: 3

  • type: passiveScan-wait

parameters:

maxDuration: 10

  • type: activeScan

parameters:

maxRuleDurationInMins: 5

maxScanDurationInMins: 30

  • type: report

parameters:

template: "traditional-html"

reportDir: "/zap/wrk"

reportFile: "zap-report"

รัน Automation Framework

docker run --rm \
-v $(pwd):/zap/wrk:rw \
ghcr.io/zaproxy/zaproxy:stable \

zap.sh -cmd -autorun /zap/wrk/automation.yaml

Quick scans

Baseline scan (passive only, fast)

docker run --rm -v $(pwd):/zap/wrk ghcr.io/zaproxy/zaproxy:stable \

zap-baseline.py -t https://target.example.com -r baseline-report.html

Full scan (active + passive)

เนื้อหาเกี่ยวข้อง — อ่านต่อ: LocalAI Self-hosted RBAC ABAC Policy — คู่มือฉบับสมบูรณ์ 2026

docker run --rm -v $(pwd):/zap/wrk ghcr.io/zaproxy/zaproxy:stable \

zap-full-scan.py -t https://target.example.com -r full-report.html

API scan

docker run --rm -v $(pwd):/zap/wrk ghcr.io/zaproxy/zaproxy:stable \

zap-api-scan.py -t https://target.example.com/openapi.json -f openapi -r api-report.html

สร้าง Batch Scanning Pipeline ด้วย Python

OWASP ZAP Batch Processing Pipeline — สร้างระบบ

Python script สำหรับ scan หลาย targets

รวม ZAP กับ CI/CD Pipeline

GitHub Actions workflow สำหรับ automated DAST

# .github/workflows/dast-scan.yml
name: DAST Security Scan

on:
  push:
    branches: [main]
  schedule:
    - cron: '0 2 * * 1'  # ทุกวันจันทร์ 02:00 UTC

jobs:
  dast-baseline:
    runs-on: ubuntu-latest
    services:
      app:
        image: }:latest
        ports: ["8080:8080"]
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Wait for app
        run: |
          for i in $(seq 1 30); do
            curl -s http://localhost:8080/health && break || sleep 2
          done
      
      - name: ZAP Baseline Scan
        uses: zaproxy/action-baseline@v0.12.0
        with:
          target: 'http://localhost:8080'
          rules_file_name: '.zap/rules.tsv'
          cmd_options: '-a -j'
      
      - name: Upload Report
        if: always()
        uses: actions/upload-artifact@v4
        with:
          name: zap-baseline-report
          path: report_html.html

  dast-full:
    runs-on: ubuntu-latest
    if: github.event_name == 'schedule'
    
    steps:
      - uses: actions/checkout@v4
      
      - name: Deploy to staging
        run: |
          echo "Deploy app to staging environment"
      
      - name: ZAP Full Scan
        uses: zaproxy/action-full-scan@v0.10.0
        with:
          target: 'https://staging.example.com'
          rules_file_name: '.zap/rules.tsv'
          cmd_options: '-a -j -m 30'
      
      - name: Check Results
        if: always()
        run: |
          if grep -q '"risk": "High"' zap-report.json 2>/dev/null; then
            echo "HIGH vulnerabilities found!"
            exit 1
          fi
      
      - name: Notify Security Team
        if: failure()
        uses: slackapi/slack-github-action@v1
        with:
          payload: |
            {"text": "DAST Scan FAILED: High vulnerabilities detected in staging"}

  dast-api:
    runs-on: ubuntu-latest
    if: github.event_name == 'schedule'
    
    steps:
      - uses: actions/checkout@v4
      
      - name: ZAP API Scan
        uses: zaproxy/action-api-scan@v0.7.0
        with:
          target: 'https://staging.example.com/openapi.json'
          format: openapi
          rules_file_name: '.zap/api-rules.tsv'

# .zap/rules.tsv — Customize alert handling
# ID	Action	Description
# 10015	IGNORE	Incomplete or No Cache-control Header Set
# 10037	IGNORE	Server Leaks Information via X-Powered-By
# 10096	WARN	Timestamp Disclosure
# 40012	FAIL	Cross Site Scripting (Reflected)
# 40014	FAIL	Cross Site Scripting (Persistent)
# 40018	FAIL	SQL Injection
# 90033	FAIL	Loosely Scoped Cookie

วิเคราะห์ผลลัพธ์และสร้าง Reports

สร้าง custom reports จากผลการ scan

Advanced Configuration และ Custom Scan Policies

ตั้งค่า scan policies และ custom scripts

=== Custom Scan Policy ===

สร้างผ่าน ZAP API

Python script สำหรับสร้าง custom policy

import requests

แนะนำเพิ่มเติม — อีบุ๊กการลงทุน SiamCafeBook

ZAP_URL = "http://localhost:8080"

API_KEY = "your-api-key"

def zap_api(endpoint, params=None):

params = params or {}

params["apikey"] = API_KEY

return requests.get(f"{ZAP_URL}{endpoint}", params=params).json()

สร้าง scan policy

zap_api("/JSON/ascan/action/addScanPolicy/", {"scanPolicyName": "production-policy"})

ปิด scanners ที่ไม่ต้องการ (ลด scan time)

Buffer Overflow (ไม่เกี่ยวกับ web apps ส่วนใหญ่)

zap_api("/JSON/ascan/action/disableScanners/", {

"ids": "30001,30002",

เนื้อหาเกี่ยวข้อง — แนะนำให้อ่าน MLOps Pipeline Post-mortem Analysis —

"scanPolicyName": "production-policy"

})

เปิด scanners ที่สำคัญ

SQL Injection, XSS, CSRF, Path Traversal

zap_api("/JSON/ascan/action/enableScanners/", {

"ids": "40018,40012,40014,6,40003",

"scanPolicyName": "production-policy"

})

ตั้ง threshold และ strength

Threshold: OFF, DEFAULT, LOW, MEDIUM, HIGH

Strength: DEFAULT, LOW, MEDIUM, HIGH, INSANE

zap_api("/JSON/ascan/action/setScannerAlertThreshold/", {

"id": "40018", # SQL Injection

"alertThreshold": "LOW",

"scanPolicyName": "production-policy"

})

zap_api("/JSON/ascan/action/setScannerAttackStrength/", {

"id": "40018",

"attackStrength": "HIGH",

"scanPolicyName": "production-policy"

})

=== ZAP Script สำหรับ Custom Authentication ===

authentication_script.js (Zest/JS)

สำหรับ JWT-based authentication

เนื้อหาเกี่ยวข้อง — แนะนำให้อ่าน Tailscale Mesh Domain Driven Design DDD

=== Docker Compose สำหรับ Production ===

docker-compose.yml:

services:

zap:

image: ghcr.io/zaproxy/zaproxy:stable

command: >

zap.sh -daemon -host 0.0.0.0 -port 8080

-config api.key=

-config api.addrs.addr.name=.*

-config api.addrs.addr.regex=true

-config connection.timeoutInSecs=120

ports: ["8080:8080"]

volumes:

  • zap-data:/zap/wrk
  • ./policies:/home/zap/.ZAP/policies
  • ./scripts:/home/zap/.ZAP/scripts

deploy:

resources:

limits:

cpus: '2.0'

memory: 4G

scanner:

build: ./scanner

depends_on: [zap]

environment:

ZAP_URL: http://zap:8080

ZAP_API_KEY:

volumes:

  • ./reports:/app/reports

volumes:

zap-data:

FAQ คำถามที่พบบ่อย

Q: Baseline scan กับ Full scan ต่างกันอย่างไร?

A: Baseline scan ทำเฉพาะ passive scanning ที่วิเคราะห์ HTTP responses โดยไม่ส่ง attack payloads ใช้เวลา 1-5 นาที เหมาะสำหรับ CI/CD pipeline ทุก commit Full scan ทำทั้ง passive และ active scanning ที่ส่ง attack payloads จริง ใช้เวลา 30 นาทีถึงหลายชั่วโมง เหมาะสำหรับ scheduled weekly/monthly scans

Q: ZAP scan ทำให้ production ล่มได้ไหม?

A: Active scan ส่ง malicious payloads จริง อาจทำให้ application crash หรือ data corruption ได้ ไม่ควรรัน active scan กับ production โดยตรง ใช้ staging/testing environment แทน Baseline scan (passive only) ปลอดภัยกว่าแต่ก็อาจเพิ่ม load ได้ ควรจำกัด concurrent requests และ scan speed

Q: ZAP กับ Burp Suite เลือกอันไหน?

A: ZAP เป็น open source ฟรี เหมาะสำหรับ CI/CD automation มี Docker support ดี API ครบ Burp Suite Pro มี scanner ที่แม่นยำกว่า UI ดีกว่าสำหรับ manual testing มี extensions มากกว่า แต่มีค่าลิขสิทธิ์ สำหรับ automated pipeline scanning ZAP เพียงพอ สำหรับ penetration testing แบบ manual Burp Suite ดีกว่า หลายทีมใช้ทั้งสอง

Q: ลด false positives ของ ZAP ได้อย่างไร?

A: ใช้ rules.tsv file กำหนด IGNORE สำหรับ alerts ที่ไม่เกี่ยวข้อง ตั้ง alert threshold เป็น MEDIUM หรือ HIGH สร้าง context ที่กำหนด scope ชัดเจน exclude URLs ที่ไม่ต้อง scan (logout, static files) ใช้ custom scan policy ที่ปิด scanners ที่ไม่เกี่ยวข้องกับ tech stack และ review alerts เป็นประจำเพื่อ tune configuration

XM Legend · เทรดเดอร์ & ผู้สอน Forex 13 ปี

ผู้ก่อตั้ง SiamCafe ตั้งแต่ปี 1997 · เทรดเดอร์สาย Forex มากกว่า 13 ปี ได้รับการยกย่องเป็น XM Legend · แบ่งปันความรู้ Forex, ไอที, AI และการเทรด จากประสบการณ์จริงในตลาดจริง