OWASP ZAP 網頁安全掃描工具

使用 OWASP ZAP 進行網頁應用程式安全測試,支援自動掃描、手動測試、API 整合

專案簡介

OWASP ZAP(Zed Attack Proxy)是世界上最受歡迎的免費網頁安全掃描工具。由 OWASP 維護,提供自動化掃描、手動滲透測試、API 測試等功能。

GitHub Stars: 14K+

主要功能

  • 被動掃描 - 自動分析流經的請求
  • 主動掃描 - 主動探測漏洞
  • Spider - 自動爬取網站結構
  • Fuzzer - 自訂 Payload 測試
  • API 整合 - 支援 CI/CD 自動化

安裝

官方安裝包

下載:https://www.zaproxy.org/download/

Docker

1
2
3
4
docker pull zaproxy/zap-stable

# 執行 GUI(需要 X11)
docker run -u zap -p 8080:8080 -p 8090:8090 zaproxy/zap-stable zap.sh -daemon -port 8090 -host 0.0.0.0

Kali Linux

1
sudo apt install zaproxy

基本操作

代理設定

  1. 啟動 ZAP
  2. 設定瀏覽器代理:localhost:8080
  3. 匯入 ZAP CA 憑證處理 HTTPS

自動掃描

  1. 輸入目標 URL
  2. 點擊「Attack」
  3. ZAP 會自動 Spider 並掃描

手動探索

  1. 設定瀏覽器代理
  2. 瀏覽目標網站
  3. ZAP 自動記錄並被動掃描

Spider 爬蟲

標準 Spider

1
2
# 透過 API
curl "http://localhost:8090/JSON/spider/action/scan/?url=https://target.com"

AJAX Spider

適用於 SPA(React、Vue):

1
curl "http://localhost:8090/JSON/ajaxSpider/action/scan/?url=https://target.com"

Spider 設定

  • Maximum Depth: 爬取深度
  • Thread Count: 並行數
  • Parse Comments: 解析註解中的 URL

主動掃描

開始掃描

1
2
# 取得 Spider 結果後掃描
curl "http://localhost:8090/JSON/ascan/action/scan/?url=https://target.com"

掃描策略

建立自訂掃描策略:

  1. Analyze → Scan Policy Manager
  2. 新增策略
  3. 調整各漏洞檢測的強度

掃描進度

1
curl "http://localhost:8090/JSON/ascan/view/status/?scanId=0"

常見漏洞檢測

SQL Injection

ZAP 會自動測試:

  • Error-based SQLi
  • Blind SQLi
  • Time-based SQLi

XSS

檢測類型:

  • Reflected XSS
  • Stored XSS
  • DOM-based XSS

其他漏洞

  • CSRF
  • Path Traversal
  • Remote File Inclusion
  • Command Injection
  • LDAP Injection

API 測試

匯入 OpenAPI

  1. Import → Import OpenAPI Definition
  2. 選擇 OpenAPI/Swagger 檔案
  3. ZAP 自動生成請求

匯入 GraphQL

1
2
# 透過 API
curl "http://localhost:8090/JSON/graphql/action/importUrl/?url=https://api.target.com/graphql"

自動化整合

CLI 掃描

1
2
3
4
5
6
7
8
# 基線掃描
docker run -t zaproxy/zap-stable zap-baseline.py -t https://target.com

# 完整掃描
docker run -t zaproxy/zap-stable zap-full-scan.py -t https://target.com

# API 掃描
docker run -t zaproxy/zap-stable zap-api-scan.py -t https://api.target.com/openapi.json -f openapi

GitHub Actions

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
name: OWASP ZAP Scan
on: [push]
jobs:
  zap_scan:
    runs-on: ubuntu-latest
    steps:
      - name: ZAP Baseline Scan
        uses: zaproxy/action-baseline@v0.12.0
        with:
          target: 'https://target.com'
          rules_file_name: '.zap/rules.tsv'

Jenkins 整合

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
pipeline {
    agent any
    stages {
        stage('ZAP Scan') {
            steps {
                script {
                    sh '''
                    docker run -t zaproxy/zap-stable \
                        zap-baseline.py -t https://target.com \
                        -r zap-report.html
                    '''
                }
            }
        }
    }
    post {
        always {
            publishHTML([
                reportDir: '.',
                reportFiles: 'zap-report.html',
                reportName: 'ZAP Report'
            ])
        }
    }
}

報告生成

HTML 報告

1
curl "http://localhost:8090/OTHER/core/other/htmlreport/"

JSON 報告

1
curl "http://localhost:8090/JSON/core/view/alerts/"

XML 報告

1
curl "http://localhost:8090/OTHER/core/other/xmlreport/"

擴充功能

常用 Add-ons

  • Active Scanner Rules - 額外掃描規則
  • Passive Scanner Rules - 額外被動規則
  • FuzzDB - Fuzzing 字典
  • Retire.js - 過時 JS 庫檢測
  • AJAX Spider - SPA 爬蟲

安裝 Add-on

1
curl "http://localhost:8090/JSON/autoupdate/action/installAddon/?id=retire"

相關連結

延伸閱讀

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy