Closed16

Docker ベースで Zed Attack Proxy (ZAP) を 使ってみる

snakasnaka

Baseline Scan

コンテナで zap-baseline.py を実行する。

docker run \
-v $(pwd):/zap/wrk/:rw \
-t ghcr.io/zaproxy/zaproxy:stable \
zap-baseline.py \
-t https://(対象のドメイン名) \
-z "-configfile option.prop"

zap-basline.py のソースコードは以下

https://github.com/zaproxy/zaproxy/blob/main/docker/zap-baseline.py

snakasnaka

ZAP ログの出力場所

Home は /home/zap

ログは /home/zap/.ZAP/zap.log に出力されている。

snakasnaka

以下のコマンドでもログは参照できる

docker cp (container):/home/zap/.ZAP/zap.log - | less

前述のスクショの例だと以下のようになる

docker cp laughing_noether:/home/zap/.ZAP/zap.log - | less
snakasnaka

Full Scan

コンテナで zap-full-scan.py を実行する。

docker run \
-v $(pwd):/zap/wrk/:rw \
-t ghcr.io/zaproxy/zaproxy:stable \
zap-full-scan.py \
-t https://(対象のドメイン) \
-z "-configfile option.prop"

zap-full-scan.py のソースコードは以下

https://github.com/zaproxy/zaproxy/blob/main/docker/zap-full-scan.py

snakasnaka

結果を XML と HTML で出力する

  • HTML
    • -r results-full.html
  • XML
    • -x results-full.xml

例)

docker run \
-v $(pwd):/zap/wrk/:rw \
-t ghcr.io/zaproxy/zaproxy:stable \
zap-full-scan.py \
-t https://(対象のドメイン) \
-z "-configfile option.prop" \
-x results-full.xml \
-r results-full.html
snakasnaka

その他のオプション

$ docker run -v $(pwd):/zap/wrk/:rw -t owasp/zap2docker-stable zap-full-scan.py -h
Usage: zap-full-scan.py -t <target> [options]
    -t target         target URL including the protocol, e.g. https://www.example.com
Options:
    -h                print this help message
    -c config_file    config file to use to INFO, IGNORE or FAIL warnings
    -u config_url     URL of config file to use to INFO, IGNORE or FAIL warnings
    -g gen_file       generate default config file(all rules set to WARN)
    -m mins           the number of minutes to spider for (defaults to no limit)
    -r report_html    file to write the full ZAP HTML report
    -w report_md      file to write the full ZAP Wiki(Markdown) report
    -x report_xml     file to write the full ZAP XML report
    -J report_json    file to write the full ZAP JSON document
    -a                include the alpha active and passive scan rules as well
    -d                show debug messages
    -P                specify listen port
    -D                delay in seconds to wait for passive scanning 
    -i                default rules not in the config file to INFO
    -I                do not return failure on warning
    -j                use the Ajax spider in addition to the traditional one
    -l level          minimum level to show: PASS, IGNORE, INFO, WARN or FAIL, use with -s to hide example URLs
    -n context_file   context file which will be loaded prior to scanning the target
    -p progress_file  progress file which specifies issues that are being addressed
    -s                short output format - dont show PASSes or example URLs
    -T                max time in minutes to wait for ZAP to start and the passive scan to run
    -U user           username to use for authenticated scans - must be defined in the given context file
    -z zap_options    ZAP command line options e.g. -z "-config aaa=bbb -config ccc=ddd"
    --hook            path to python file that define your custom hooks
snakasnaka

レポートで指摘された内容について調べる

レポートは以下のような感じで指摘が上がってくる

Evidence にはその指摘の根拠となる値 ( その指摘内容に応じたヘッダーやHTTPステータスなど ) がセットされている。

snakasnaka

CWE

CWE id のリンク先に飛ぶと、脆弱性に関する詳細な内容が確認できる。

snakasnaka

Alert

Plugin Id のリンク先に飛ぶと、その Alert についての概要(Summary)と対応方法(Solution) が記載されたページが開く。

Code のリンクからは、その Alert の実装コード (Java) を参照することができる。

上記のスクショの例だと以下のコードで Alert が実装されている。

https://github.com/zaproxy/zap-extensions/blob/main/addOns/pscanrules/src/main/java/org/zaproxy/zap/extension/pscanrules/UserControlledHTMLAttributesScanRule.java

snakasnaka

localhost:3000 をターゲットとして実行する

そのままだと、コンテナ内からホスト側の localhost:3000 は見れないので、 --network host オプションを利用する。

docker run \
-v $(pwd):/zap/wrk/:rw \
--network host \
-t ghcr.io/zaproxy/zaproxy:stable \
zap-full-scan.py \
-t http://localhost:3000 \
-x results-full.xml \
-r results-full.html

https://docs.docker.com/network/drivers/host/

snakasnaka

config file を利用する

-c config_file オプションで、 Rule に対してて WARN, IGNORE, FAIL のように動作を指定できるらしい。
元となる file は -g オプションで作成できる。

例えばconfigのファイル名が rules.txt だったとして、以下のように実行する。

docker run \
-v $(pwd):/zap/wrk/:rw \
--network host \
-t ghcr.io/zaproxy/zaproxy:stable \
zap-full-scan.py \
-t http://localhost:3000 \
-x results-full.xml \
-r results-full.html \
-c rules.txt
このスクラップは4ヶ月前にクローズされました