OWASP ZAP
π° 1. What is OWASP ZAP?¶
OWASP ZAP (Zed Attack Proxy) is a free, open-source tool maintained by OWASP to find vulnerabilities in web applications.
β Features:¶
-
Manual & automated testing
-
Active & passive scanning
-
Browser proxy
-
Authentication-based scanning
-
API & CLI support
-
Powerful scripting
π§ 2. Installation¶
Option A: GUI (Windows/macOS/Linux)¶
-
Download: https://www.zaproxy.org/download/
-
Run and launch ZAP
-
Start in Standard Mode
Option B: Docker (Recommended for Automation)¶
Option C: Headless CLI (for automation)¶
ποΈ 3. ZAP Modes of Operation¶
| Mode | Use Case |
|---|---|
| Manual | Security research, exploring targets |
| Automated | Passive/active scan with minimal input |
| Headless | Automation scripts and cron jobs |
| API Mode | Interact via REST APIs |
| Scripting | Custom scan rules and logic |
π§ͺ 4. Manual Testing with ZAP GUI¶
4.1. Setup Proxy¶
-
Go to ZAP > Tools > Options > Local Proxy: Port
8080 -
In your browser, set proxy to
127.0.0.1:8080 -
For HTTPS:
-
Download ZAP's Root CA: Tools > Options > Dynamic SSL Certificates
-
Import it into browser trusted authorities
-
4.2. Explore the Target Website¶
-
Open your target site in browser
-
It will show up under Sites in ZAP
-
ZAP passively scans as traffic flows
4.3. Spider (Crawl) the Website¶
-
Right-click on the site > Attack > Spider
-
It follows links and builds a structure
-
Can be unauthenticated or authenticated (with login session in place)
4.4. Active Scan (Attack Mode)¶
-
Right-click on the target site > Attack > Active Scan
-
ZAP will inject payloads to detect:
-
SQLi
-
XSS
-
CSRF
-
Broken Auth
-
Insecure Headers
-
4.5. View Alerts¶
-
Go to Alerts tab:
-
Filter by Risk (High, Medium, Low, Info)
-
Click each alert for details, evidence, and remediation
-
4.6. Forced Browse (Directory Brute-Force)¶
-
Use
Forced Browsetab -
Choose a wordlist (e.g.,
/usr/share/wordlists/dirbuster) -
Run to discover hidden files/folders (e.g.,
/admin,/backup)
π 5. Authenticated Scanning (Manual or Automated)¶
Step-by-step for Form-based login:¶
-
Create Context: Right-click site > Include in Context > New Context
-
Define Authentication:
-
Tools > Options > Authentication
-
Choose βForm-basedβ > Enter Login URL & parameters (
username={%username%}&password={%password%})
-
-
Add Users:
- Context > Users > Add > Enter credentials
-
Start scan with the context & user selected
β Tip: Use ZAP HUD (Heads Up Display) to record login sequences.
π€ 6. Automated Scanning with GUI¶
-
Go to Quick Start tab
-
Enter target URL
-
Click Automated Scan
-
ZAP performs spidering + active scan
-
View results in Alerts
βοΈ 7. Automated Testing (Headless CLI Mode)¶
ZAP provides Python-based scripts for automation:
-
zap-baseline.py: Passive scan only -
zap-full-scan.py: Spider + active scan -
zap-api-scan.py: For OpenAPI (Swagger) definitions
7.1. Passive Scan Example (zap-baseline)¶
docker run -v $(pwd):/zap/wrk/:rw -t owasp/zap2docker-stable zap-baseline.py \
-t https://example.com -r baseline_report.html
7.2. Full Scan Example (zap-full-scan)¶
docker run -v $(pwd):/zap/wrk/:rw -t owasp/zap2docker-stable zap-full-scan.py \
-t https://example.com -r full_report.html
7.3. API Scan for Swagger (zap-api-scan)¶
docker run -v $(pwd):/zap/wrk/:rw owasp/zap2docker-stable zap-api-scan.py \
-f openapi -t https://example.com/swagger.json -r apiscan_report.html
π‘ 8. Using ZAP REST API¶
Start ZAP in daemon mode¶
Sample API Request¶
Common API Endpoints:¶
| API Call | Purpose |
|---|---|
/spider/action/scan/ |
Start spidering |
/ascan/action/scan/ |
Start active scan |
/core/view/alerts/ |
Get alerts |
/core/action/shutdown/ |
Stop ZAP |
π¬ 9. Scripting in ZAP¶
ZAP scripting adds custom behavior.
Script Types:¶
| Type | Purpose |
|---|---|
| Active Rules | Custom attack payloads |
| Passive Rules | Custom passive detectors |
| Auth Scripts | Handle JavaScript or token-based login |
| HTTP Sender | Modify request/response |
Example: Passive Script (Log Headers)¶
Create: Scripts > New > Passive Rule
π 10. Exporting Reports¶
ZAP supports exporting to:
-
HTML
-
JSON
-
XML
-
Markdown
GUI:¶
- File > Export Report > Choose format
CLI:¶
π§ͺ 11. Test Applications (Practice Targets)¶
DVWA (Damn Vulnerable Web App)¶
Juice Shop (OWASP)¶
β 12. Best Practices¶
| Practice | Why it matters |
|---|---|
| Use Contexts | Manage authentication/scope easily |
| Only scan authorized targets | Legal & ethical considerations |
| Perform passive scan first | Safe scan to start with |
| Include login & logout detection | Detect session handling bugs |
| Periodically update add-ons | New attack vectors added often |
| Review all High-Risk alerts | Focus on top-priority fixes |
| Always confirm with manual tests | Avoid false positives |
π 13. Resources to Learn More¶
-
π ZAP Docs
-
π₯ OWASP ZAP YouTube
-
π ZAP Cheat Sheet
-
π§ͺ ZAP in Action Labs