Geavanceerd
Zoeken inInstallatiegidsen
Zo zoek je
  • Plak een foutmelding tussen aanhalingstekens, bijv. "permission denied", om de oplossingstabel te vinden.
  • Kies een gebied en een deel van de gids (installeren, eerste instellingen, dagelijks gebruik, beveiliging, oplossingen) om direct naar de juiste stap te gaan.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

Gids 68OWASP ZAP · Security

Install and set up OWASP ZAP (web app scanner)

ZAP (Zed Attack Proxy, now "ZAP by Checkmarx", still free and open source) tests a running web app from the outside — DAST. It crawls the site, finds missing security headers, cookie problems, information leaks, and with an active scan tries real attacks like XSS and SQL injection. This guide runs ZAP with Docker (the easiest way on RHEL and Ubuntu), uses the baseline, API and full scans, tunes the rules, adds an authenticated scan with the Automation Framework, and puts ZAP in CI.

  • 10 Lessen
  • 5 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

68.1

Know it before you install

The spider finds pages. The passive scan only looks at requests and responses (safe for any environment). The active scan sends attacks (only on test systems you are allowed to attack). The Automation Framework describes a full scan as a YAML plan.

ItemValue
Imageghcr.io/zaproxy/zaproxy:stable (also weekly)
Scripts in the imagezap-baseline.py (spider + passive), zap-api-scan.py (OpenAPI/GraphQL/SOAP), zap-full-scan.py (+ active attacks)
Desktop appLinux installer from zaproxy.org (needs Java 17+)
Rules filea TSV file with IGNORE / WARN / FAIL per rule ID
ReportsHTML, JSON, Markdown, XML

Let op

Scan only systems you own or have written permission to test. An active scan is an attack — it can create data, send emails and slow down or break the app. Use a test environment.

Commando's in deze les

68.2

Install on RHEL and Ubuntu

Install Docker (or Podman) first (see the Docker guide), then:

docker pull ghcr.io/zaproxy/zaproxy:stable
mkdir -p ~/zap && cd ~/zap
chmod 777 ~/zap

ZAP writes reports into /zap/wrk in the container — mount a folder there (it must be writable by the container user).

68.3

First configuration: a baseline scan

The baseline scan is safe for production-like systems (no attacks), takes about 1–2 minutes, and is a good first CI gate:

docker run --rm -v "$PWD":/zap/wrk:rw -t ghcr.io/zaproxy/zaproxy:stable zap-baseline.py -t https://staging.shop.example.com -r baseline.html -J baseline.json -g zap-rules.tsv
WARN-NEW: Content Security Policy (CSP) Header Not Set [10038] x 4
WARN-NEW: Strict-Transport-Security Header Not Set [10035] x 4
FAIL-NEW: 0     FAIL-INPROG: 0  WARN-NEW: 6     WARN-INPROG: 0  INFO: 3 IGNORE: 0       PASS: 58

-g zap-rules.tsv writes a rules file with every rule. Edit it — decide which rules fail the build:

zap-rules.tsv
10035	FAIL	(Strict-Transport-Security Header Not Set)
10038	WARN	(Content Security Policy (CSP) Header Not Set)
10021	FAIL	(X-Content-Type-Options Header Missing)
10096	IGNORE	(Timestamp Disclosure - Unix)

Then use it with -c zap-rules.tsv. Exit codes: 0 = pass, 1 = at least one FAIL, 2 = only WARN.

OptionWhy
-t URLThe target (a test system you may scan).
-c rules.tsvYour FAIL/WARN/IGNORE decisions — the gate.
-r, -JHTML report for people, JSON for tools.
-m MINUTESHow long the spider may run.
-IDo not fail on warnings (only on FAIL rules).

68.4

API and full scans

Scan a REST API from its OpenAPI definition (active, so a test system):

docker run --rm -v "$PWD":/zap/wrk:rw -t ghcr.io/zaproxy/zaproxy:stable zap-api-scan.py -t https://staging-api.shop.example.com/openapi.json -f openapi -r api.html -c zap-rules.tsv
docker run --rm -v "$PWD":/zap/wrk:rw -t ghcr.io/zaproxy/zaproxy:stable zap-full-scan.py -t https://staging.shop.example.com -m 10 -r full.html

68.5

Authenticated scans with the Automation Framework

Most pages are behind a login. Describe the scan as a plan:

zap-plan.yaml
env:
  contexts:
    - name: shop
      urls: ["https://staging.shop.example.com"]
      includePaths: ["https://staging.shop.example.com.*"]
      excludePaths: ["https://staging.shop.example.com/logout.*"]
      authentication:
        method: browser
        parameters:
          loginPageUrl: https://staging.shop.example.com/login
      users:
        - name: tester
          credentials:
            username: zap-tester@example.com
            password: ${ZAP_TEST_PASSWORD}
jobs:
  - type: spider
    parameters: { context: shop, user: tester, maxDuration: 5 }
  - type: passiveScan-wait
  - type: activeScan
    parameters: { context: shop, user: tester, maxScanDurationInMins: 20 }
  - type: report
    parameters:
      template: traditional-html
      reportDir: /zap/wrk
      reportFile: auth-scan
docker run --rm -e ZAP_TEST_PASSWORD -v "$PWD":/zap/wrk:rw -t ghcr.io/zaproxy/zaproxy:stable zap.sh -cmd -autorun /zap/wrk/zap-plan.yaml

Use a test user with test data only; exclude logout and dangerous paths (delete account, payments).

68.6

Daily use: CI and the real uses

A GitLab CI job after the deploy to staging:

.gitlab-ci.yml
dast-baseline:
  stage: dast
  image: ghcr.io/zaproxy/zaproxy:stable
  script:
    - mkdir -p /zap/wrk && cp zap-rules.tsv /zap/wrk/
    - zap-baseline.py -t "$STAGING_URL" -c zap-rules.tsv -r baseline.html -J baseline.json -I
    - cp /zap/wrk/baseline.* .
  artifacts:
    when: always
    paths: [baseline.html, baseline.json]

(GitHub has ready actions: zaproxy/action-baseline, action-api-scan, action-full-scan.)

Real uses at work:

  • Baseline scan after every staging deploy (headers, cookies, leaks).
  • Nightly authenticated active scan of the test environment.
  • API scans from the OpenAPI file; manual testing with the desktop proxy.

68.7

Make it safe

Security checklist:

  • Written permission and a test environment for active scans; never attack production by accident.
  • Test accounts and test data only; exclude logout, delete and payment paths.
  • Credentials from CI secrets (${ZAP_TEST_PASSWORD}), never in the plan file.
  • Keep reports private — they describe your weaknesses.
  • Tune rules (FAIL/WARN/IGNORE) with reasons; pin the image tag for stable gates.
  • DAST complements SAST (Semgrep) and dependency scans (Trivy) — it does not replace them.

68.8

Update and remove

docker pull ghcr.io/zaproxy/zaproxy:stable
docker image rm ghcr.io/zaproxy/zaproxy:stable

68.9

Fix common problems

ProblemCauseFix
Permission denied: '/zap/wrk/…'The mounted folder is not writable by the container user.chmod 777 the folder (or run with a matching user ID).
Target unreachable from the containerlocalhost means the container itself.Use the real host name, or --network host for a local app.
Only the login page is scannedNo authentication.Use the Automation Framework with a context, user and auth method.
Active scan takes hoursBig site, no limits.maxScanDurationInMins, include/exclude paths, scan per area.
WAF blocks ZAPThe firewall sees attacks.Allow-list the scanner IP in the test environment.
Too many low findingsAll rules on.Tune zap-rules.tsv; fail only on what matters.

Commando's in deze les

68.10

Next steps

1Which ZAP scan is safe to run against a production-like system?

The baseline scan — spider plus passive checks, no attacks.

2What decides if a ZAP CI job fails?

The rules file: rules marked FAIL that are found make the exit code 1.

Commando's in deze les

Alle commando's in dit hoofdstuk