Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

zap

ZAP (Zed Attack Proxy): dynamic application security testing (DAST) — scan a running web app or API from the outside.

Level
DevSecOps service
Group
Security scanning and hardening
Needs root
No
Package
zaproxy
Also called
zap-baseline.py, zaproxy

What it does

ZAP (now under Checkmarx, still open source) crawls a web app (spider, AJAX spider), watches the traffic (passive scan: missing headers, cookies without flags, info leaks) and can attack it (active scan: XSS, SQL injection, path traversal). For CI there are ready scripts in the Docker image: baseline (passive, safe, fast), full (active, long, only on test systems) and api (OpenAPI/GraphQL).

Only scan systems you own or have written permission to test.

How to write it

docker run -t zaproxy/zap-stable zap-baseline.py -t URL [OPTIONS]
zap-full-scan.py | zap-api-scan.py -t URL ...

Main parts

Scan scripts

zap-baseline.py
Spider + passive scan; safe for production.
zap-full-scan.py
Spider + active attacks; test systems only.
zap-api-scan.py -f openapi|graphql|soap
Scan an API from its definition.
zap.sh -daemon
Run ZAP headless with its API.

Options 8

Most used

Script flags

-t URL
Target.
-r FILE.html / -J FILE.json / -x FILE.xml / -w FILE.md
Reports.
-c FILE
Rule config (IGNORE / WARN / FAIL per rule ID).
-g FILE
Generate a default rule config file.
-m MINUTES
Spider time.
-a
Also the AJAX spider.
-I
Do not fail on warnings.
-z "OPTIONS"
Extra ZAP options (auth headers, etc.).

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Baseline scan of a test site

    docker run --rm -v "$PWD:/zap/wrk:rw" -t zaproxy/zap-stable zap-baseline.py -t https://staging.example.com -r baseline.html
  2. 2Read the summary

    docker run --rm -t zaproxy/zap-stable zap-baseline.py -t https://staging.example.com | tail -5
    FAIL-NEW: 0  FAIL-INPROG: 0  WARN-NEW: 6  WARN-INPROG: 0  INFO: 0  IGNORE: 0  PASS: 58
  3. 3Make your own rule config

    docker run --rm -v "$PWD:/zap/wrk:rw" -t zaproxy/zap-stable zap-baseline.py -t https://staging.example.com -g zap-rules.tsv
    grep 10038 zap-rules.tsv
    10038	FAIL	(Content Security Policy (CSP) Header Not Set)
  4. 4Use the rules in CI

    docker run --rm -v "$PWD:/zap/wrk:rw" -t zaproxy/zap-stable zap-baseline.py -t https://staging.example.com -c zap-rules.tsv -J zap.json
  5. 5Scan an API from OpenAPI

    docker run --rm -v "$PWD:/zap/wrk:rw" -t zaproxy/zap-stable zap-api-scan.py -t https://staging.example.com/openapi.json -f openapi -r api.html
  6. 6Full active scan of a test environment

    docker run --rm -v "$PWD:/zap/wrk:rw" -t zaproxy/zap-stable zap-full-scan.py -t https://test.lab.local -m 10 -r full.html
  7. 7Scan with a login token

    docker run --rm -t zaproxy/zap-stable zap-api-scan.py -t https://staging.example.com/openapi.json -f openapi -z "-config replacer.full_list(0).matchtype=REQ_HEADER -config replacer.full_list(0).matchstr=Authorization -config replacer.full_list(0).replacement='Bearer TEST_TOKEN'"
  8. 8GitHub Actions

    cat .github/workflows/dast.yml
          - uses: zaproxy/action-baseline@v0.14.0
            with: { target: "https://staging.example.com", rules_file_name: "zap-rules.tsv" }
  9. 9Count findings by risk from JSON

    jq -r '.site[].alerts[] | .riskdesc' zap.json | cut -d' ' -f1 | sort | uniq -c
  10. 10Check the headers ZAP complains about

    curl -sI https://staging.example.com | grep -iE "content-security-policy|strict-transport|x-content-type"

Watch out

  • Never run the full/active scan against production or third-party sites without written permission.
  • Active scans submit forms and can create junk data or send e-mails.

Files

/zap/wrk
Mounted folder for reports and configs (Docker).
zap-rules.tsv
Rule config (ID, action, name).

Tips to remember

  • Start with the baseline scan in every PR deployment; run the full scan nightly on staging.

Exit codes

0Success (no FAIL / WARN).
1At least one FAIL.
2At least one WARN (no FAIL).
3Other error.