OWASP ZAP Security Scanner
OWASP ZAP Zed Attack Proxy Web Security Scanner SQL Injection XSS CSRF Pentest CI/CD Open Source Automated Scanning API Testing Plugin Development Contribution
| Tool | License | ราคา | CI/CD | เหมาะกับ |
|---|---|---|---|---|
| OWASP ZAP | Apache 2.0 | ฟรี | ดีมาก | ทุกู้คืน |
| Burp Suite Pro | Commercial | $449/yr | ดี | Pentester |
| Nikto | GPL | ฟรี | พื้นฐาน | Quick Scan |
| Nuclei | MIT | ฟรี | ดีมาก | Template-based |
| w3af | GPL | ฟรี | พื้นฐาน | Framework |
ZAP Scanning
# === OWASP ZAP Setup & Scanning ===
# Docker
# docker run -u zap -p 8080:8080 -p 8090:8090 \
# -i ghcr.io/zaproxy/zaproxy:stable \
# zap-webswing.sh
# ZAP CLI — Automated Scan
# docker run -t ghcr.io/zaproxy/zaproxy:stable \
# zap-baseline.py -t https://target.example.com \
# -r report.html -J report.json
# ZAP Full Scan
# docker run -t ghcr.io/zaproxy/zaproxy:stable \
# zap-full-scan.py -t https://target.example.com \
# -r full-report.html
# ZAP API Scan (OpenAPI)
# docker run -t ghcr.io/zaproxy/zaproxy:stable \
# zap-api-scan.py -t https://target.example.com/openapi.json \
# -f openapi -r api-report.html
# Python ZAP API
# from zapv2 import ZAPv2
#
# zap = ZAPv2(apikey='your-api-key',
# proxies={'http': 'http://localhost:8080'})
#
# # Spider
# scan_id = zap.spider.scan('https://target.example.com')
# while int(zap.spider.status(scan_id)) < 100:
# time.sleep(5)
#
# # Active Scan
# scan_id = zap.ascan.scan('https://target.example.com')
# while int(zap.ascan.status(scan_id)) < 100:
# time.sleep(10)
#
# # Get Alerts
# alerts = zap.core.alerts()
# for alert in alerts:
# print(f"[{alert['risk']}] {alert['name']}: {alert['url']}")
from dataclasses import dataclass
from typing import List
@dataclass
class ScanResult:
vulnerability: str
risk: str
confidence: str
url: str
solution: str
results = [
ScanResult("SQL Injection", "High", "Medium", "/api/users?id=1", "ใช้ Parameterized Queries"),
ScanResult("XSS Reflected", "High", "High", "/search?q=test", "Encode Output HTML Entity"),
ScanResult("CSRF Token Missing", "Medium", "High", "/api/transfer", "เพิ่ม CSRF Token ทุก Form"),
ScanResult("Missing CSP Header", "Medium", "High", "/", "เพิ่ม Content-Security-Policy"),
ScanResult("Cookie No HttpOnly", "Low", "High", "/login", "Set HttpOnly Flag"),
ScanResult("Server Version Exposed", "Info", "High", "/", "ซ่อน Server Version Header"),
]
print("=== ZAP Scan Results ===")
high = sum(1 for r in results if r.risk == "High")
med = sum(1 for r in results if r.risk == "Medium")
for r in results:
print(f" [{r.risk}] {r.vulnerability}")
print(f" URL: {r.url} | Fix: {r.solution}")
print(f"\n Summary: {high} High, {med} Medium, {len(results)-high-med} Low/Info")
CI/CD Integration
# === CI/CD Pipeline Security Scanning ===
# GitHub Actions
# .github/workflows/security-scan.yml
# name: OWASP ZAP Security Scan
# on:
# push: { branches: [main] }
# schedule:
# - cron: '0 2 * * 1' # ทุกวันจันทร์ 02:00
#
# jobs:
# zap-scan:
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - name: Start Application
# run: docker-compose up -d
# - name: ZAP Baseline Scan
# uses: zaproxy/action-baseline@v0.12.0
# with:
# target: 'http://localhost:3000'
# rules_file_name: '.zap/rules.tsv'
# cmd_options: '-a -j'
# - name: Upload Report
# uses: actions/upload-artifact@v4
# with:
# name: zap-report
# path: report_html.html
# .zap/rules.tsv — Custom Rules
# 10015 IGNORE (Incomplete or No Cache-control)
# 10037 IGNORE (Server Leaks Information)
# 40012 FAIL (Cross Site Scripting Reflected)
# 40018 FAIL (SQL Injection)
# 40014 FAIL (Cross Site Scripting Persistent)
scan_types = {
"Baseline": {"duration": "1-5 min", "depth": "Passive only", "use": "ทุก PR"},
"API Scan": {"duration": "5-15 min", "depth": "API Endpoints", "use": "API Changes"},
"Full Scan": {"duration": "30-120 min", "depth": "Active + Passive", "use": "Weekly/Release"},
}
print("\nScan Types:")
for name, info in scan_types.items():
print(f" [{name}] Duration: {info['duration']}")
print(f" Depth: {info['depth']} | Use: {info['use']}")
Open Source Contribution
# === Contributing to OWASP ZAP ===
# 1. Fork & Clone
# git clone https://github.com/YOUR_USERNAME/zaproxy.git
# cd zaproxy
# git remote add upstream https://github.com/zaproxy/zaproxy.git
# 2. Setup Development Environment
# Java 11+ required
# ./gradlew assemble
# 3. Create Branch
# git checkout -b fix/sql-injection-false-positive
# 4. Make Changes & Test
# ./gradlew test
# ./gradlew check
# 5. Create Pull Request
# git push origin fix/sql-injection-false-positive
# -> Create PR on GitHub
# ZAP Add-on Development (Python Script)
# from org.zaproxy.zap.extension.script import ScriptVars
#
# def scan(ps, msg, src):
# url = msg.getRequestHeader().getURI().toString()
# body = msg.getResponseBody().toString()
#
# if 'password' in body.lower() and msg.getResponseHeader().getStatusCode() == 200:
# ps.raiseAlert(
# 1, 2, # pluginId, risk (HIGH)
# 'Password Exposed in Response',
# 'Response body contains password field',
# url, '', '', '',
# 'Remove passwords from API responses',
# '', msg
# )
contribution_guide = [
{"step": "Fork Repository", "difficulty": "ง่าย", "time": "5 min"},
{"step": "อ่าน CONTRIBUTING.md", "difficulty": "ง่าย", "time": "15 min"},
{"step": "เลือก good-first-issue", "difficulty": "ง่าย", "time": "10 min"},
{"step": "Setup Dev Environment", "difficulty": "ปานกลาง", "time": "30 min"},
{"step": "เขียน Code + Test", "difficulty": "ปานกลาง-สูง", "time": "1-8 hr"},
{"step": "สร้าง Pull Request", "difficulty": "ง่าย", "time": "15 min"},
{"step": "Address Review Feedback", "difficulty": "ปานกลาง", "time": "1-4 hr"},
]
print("Contribution Guide:")
for i, step in enumerate(contribution_guide, 1):
print(f" {i}. [{step['difficulty']}] {step['step']} ({step['time']})")
# Contribution Types
types = {
"Documentation": "เริ่มต้นง่ายสุด แก้ Typo เพิ่มตัวอย่าง",
"Bug Fix": "แก้ Bug ที่มี Issue อยู่แล้ว",
"Scan Rules": "เพิ่ม/แก้ไข Vulnerability Detection Rules",
"Add-on": "สร้าง Add-on ใหม่ (Python/Java)",
"Translation": "แปลภาษาไทย",
"Testing": "เขียน Test เพิ่ม ปรับปรุง Coverage",
}
print(f"\n\nContribution Types:")
for t, desc in types.items():
print(f" [{t}]: {desc}")
เคล็ดลับ
- Baseline: ใช้ Baseline Scan ใน CI ทุก PR เร็วและจับ Passive Issues
- API Scan: ใช้ API Scan กับ OpenAPI Spec ครอบคลุมทุก Endpoint
- Rules: ปรับ Rules ตัด False Positive ที่ไม่เกี่ยวข้อง
- Contribute: เริ่มจาก Documentation หรือ good-first-issue
- Auth: ตั้ง Authentication Context ให้ ZAP Scan หลัง Login ได้
แนวทางป้องกันภัยไซเบอร์สำหรับองค์กรไทย
ภัยคุกคามทางไซเบอร์ในปี 2026 มีความซับซ้อนมากขึ้น Ransomware ยังคงเป็นภัยอันดับหนึ่ง โดยผู้โจมตีใช้ AI ช่วยสร้าง Phishing Email ที่แนบเนียนขึ้น องค์กรควรมี Multi-Layered Security ตั้งแต่ Perimeter Defense ด้วย Next-Gen Firewall Endpoint Protection ด้วย EDR Solution และ Network Detection and Response
การฝึกอบรมพนักงานเป็นสิ่งสำคัญที่สุด เพราะ Human Error เป็นสาเหตุหลักของการรั่วไหลข้อมูล ควรจัด Security Awareness Training อย่างน้อยไตรมาสละครั้ง ทำ Phishing Simulation ทดสอบพนักงาน และมี Incident Response Plan ที่ชัดเจน ฝึกซ้อมเป็นประจำ
สำหรับกฎหมาย PDPA ของไทย องค์กรต้องมี Data Protection Officer แจ้งวัตถุประสงค์การเก็บข้อมูลอย่างชัดเจน ขอ Consent ก่อนใช้ข้อมูลส่วนบุคคล มีมาตรการรักษาความปลอดภัยที่เหมาะสม และแจ้งเหตุ Data Breach ภายใน 72 ชั่วโมง
OWASP ZAP คืออะไร
Open Source Web Security Scanner SQL Injection XSS CSRF GUI CLI API Testing Automated Passive Active Scanning ฟรี CI/CD
ZAP ใช้ทดสอบอะไรได้บ้าง
SQL Injection XSS CSRF SSRF Path Traversal Authentication Misconfiguration Data Exposure IDOR ช่องโหว่เว็บทั่วไป
จะ Contribute OWASP ZAP อย่างไร
Fork GitHub CONTRIBUTING.md good-first-issue Branch Code Test PR Review Documentation Bug Fix Add-on Translation
ZAP กับ Burp Suite ต่างกันอย่างไร
ZAP ฟรี Open Source CI/CD ดี Burp Pro $449/yr Feature มากกว่า Pentest มืออาชีพ ทั้งสอง Proxy Intercept Scan
สรุป
OWASP ZAP Web Security Scanner SQL Injection XSS CSRF Open Source CI/CD GitHub Actions Baseline API Full Scan Plugin Add-on Contribution Fork PR Review Burp Suite Nuclei
