OWASP ZAP Scanning Options
Detailed configuration of scanning features in OWASP ZAP for effective vulnerability discovery
This guide provides detailed information on configuring and optimizing OWASP ZAP's scanning capabilities. Understanding these options will help you tailor scans to your specific needs, improve accuracy, and maximize effectiveness.
Scanning Types Overview
ZAP offers several scanning mechanisms, each with different purposes and configuration options:
Passive Scanning
Passive scanning analyzes HTTP messages without sending additional requests:
- Automatic: Runs automatically on all traffic passing through ZAP
- Non-intrusive: Doesn't generate additional traffic
- Safe: Cannot modify application state
Key capabilities:
- Identifying information disclosure
- Detecting insecure headers
- Finding cookie issues
- Discovering content security policy problems
- Detecting outdated libraries
Passive Scan Configuration
Passive scanning happens automatically but can be fine-tuned for optimal performance and results.
Global Passive Scan Settings
Access Passive Scan Options
- Go to Tools > Options > Passive Scanner
- This opens the passive scanner configuration panel
Configure General Settings
- Scan Only in Scope: When enabled, only scans requests that are in scope
- Scan Headers of All Requests: When enabled, scans the headers of all requests (not just HTML responses)
- Scan All Tags: When enabled, scans all tags (not just those considered useful)
- Max Alerts per Rule: Limits the number of alerts each rule can raise (useful to prevent alert flooding)
Manage Scan Rules
- Click on the Rules tab
- For each rule, you can:
- Enable/disable the rule
- Set the threshold (Off, Low, Medium, High)
- Configure rule-specific parameters
- Use the Filter field to find specific rules
Passive Scan Rule Configuration
Information Gathering Rules
These rules identify information disclosure issues:
Rule | Description | Configuration |
---|---|---|
Application Error | Detects application error messages | Threshold: Adjust to reduce false positives |
Private IP Disclosure | Finds private IP addresses in responses | None |
Server Leaks Information | Detects server information leakage | None |
Timestamp Disclosure | Finds timestamps in responses | Threshold: Adjust based on application |
Username Disclosure | Detects potential usernames | Pattern: Add custom username patterns |
Active Scan Configuration
Active scanning is highly configurable to balance thoroughness with performance and impact.
Scan Policies
Access Scan Policies
- Go to Tools > Options > Active Scan
- This opens the active scan policy configuration panel
Manage Existing Policies
- The default policy is always available
- Select a policy to view or edit its settings
- Click Add to create a new policy
- Click Remove to delete a custom policy
Create a Custom Policy
- Click Add to create a new policy
- Enter a name for the policy
- Configure general settings:
- Default Strength: Overall strength of the scan
- Default Threshold: Overall threshold for raising alerts
- Configure individual rules in the categories tabs
Rule Categories
Injection Rules
These rules test for various injection vulnerabilities:
Rule | Description | Strength | Threshold |
---|---|---|---|
SQL Injection | Tests for SQL injection flaws | High: More test cases Medium: Balanced Low: Fewer tests | High: Fewer false positives Medium: Balanced Low: More alerts |
Command Injection | Tests for OS command injection | High: More payloads Medium: Standard payloads Low: Basic checks | High: Requires clear evidence Medium: Standard evidence Low: More suspicious patterns |
LDAP Injection | Tests for LDAP injection flaws | High: Comprehensive Medium: Standard Low: Basic | High: Strict matching Medium: Standard matching Low: Loose matching |
XPath Injection | Tests for XPath injection | Similar to above | Similar to above |
NoSQL Injection | Tests for NoSQL injection | Similar to above | Similar to above |
Active Scan Options
When starting an active scan, you can configure various options:
Access Scan Dialog
- Right-click on a target in the Sites tree
- Select Attack > Active Scan
- The Active Scan dialog appears
Configure Scan Scope
- Starting Point: The URL to start scanning from
- Recurse: When checked, scans all nodes under the starting point
- Context: Select a context to use its configuration
- User: Select a user for authenticated scanning
Configure Technology
- Click on the Technology tab
- Select the technologies used by the target:
- Operating Systems: Windows, Linux, macOS, etc.
- Databases: MySQL, PostgreSQL, Oracle, etc.
- Web Servers: Apache, IIS, Nginx, etc.
- Languages: PHP, Java, .NET, etc.
- Frameworks: Spring, Django, Laravel, etc.
- This helps ZAP focus on relevant tests
Configure Input Vectors
- Click on the Input Vectors tab
- Select which elements to test:
- URL Query String: Parameters in the URL
- POST Data: Form parameters
- HTTP Headers: Request headers
- Cookie Data: Cookies
- URL Path: Path components
- Configure how to handle specific input types
Advanced Options
- Click on the Custom Vectors tab to define custom input vectors
- Click on the DOM tab to configure DOM-specific options
- Click on the Options tab to set:
- Inject plugin ID in header: Helps identify which rule generated a request
- Thread per host: Number of threads per target host
- Delay in milliseconds: Delay between requests
- Max rule duration: Maximum time a rule can run
Spider Configuration
Traditional Spider Options
Access Spider Options
- Go to Tools > Options > Spider
- This opens the spider configuration panel
Configure General Settings
- Max Depth: Maximum depth to crawl (default: 5)
- Thread Count: Number of concurrent threads (default: 2)
- Max Duration: Maximum running time in minutes (0 for unlimited)
- Max Children: Maximum number of child nodes per node (0 for unlimited)
Configure Processing Options
- Process Forms: When enabled, submits forms with default values
- POST Forms: When enabled, submits POST forms (potentially modifying data)
- Parse Comments: When enabled, looks for URLs in HTML comments
- Parse robots.txt: When enabled, processes robots.txt for URLs
- Parse sitemap.xml: When enabled, processes sitemap.xml for URLs
- Parse SVN metadata: When enabled, processes SVN metadata for URLs
- Parse Git metadata: When enabled, processes Git metadata for URLs
Configure Scope Options
- Skip URL regex: URLs matching these patterns will be skipped
- Handle OData-specific parameters: When enabled, handles OData parameters
- Domain whitelist: Only follow links to these domains
- Domain blacklist: Don't follow links to these domains
AJAX Spider Options
Access AJAX Spider Options
- Go to Tools > Options > AJAX Spider
- This opens the AJAX Spider configuration panel
Configure Browser Settings
- Browser: Select which browser to use (Chrome, Firefox, HtmlUnit)
- Browser arguments: Additional arguments to pass to the browser
Configure Crawling Settings
- Number of browsers: Number of concurrent browser instances
- Max crawl depth: Maximum depth to crawl
- Max crawl states: Maximum number of states to crawl
- Max duration: Maximum running time in minutes
- Event wait time: Time to wait after an event is fired
- Reload wait time: Time to wait after a page is reloaded
Configure Advanced Options
- Click elements once: When enabled, clicks each element only once
- Click default elements only: When enabled, only clicks on default elements
- Random inputs: When enabled, uses random values for form inputs
- Element wait time: Time to wait for elements to appear
Advanced Scanning Techniques
Scan Hooks
Scan hooks allow you to customize the scanning process programmatically:
// Example scan hook script
function scannerHook(helper, msg) {
// Add a custom header to all active scan requests
msg.getRequestHeader().setHeader('X-Scanner', 'ZAP');
return true;
}
function alertFilter(helper, alertList) {
// Filter out certain alerts
var filteredAlerts = [];
for (var i = 0; i < alertList.length; i++) {
var alert = alertList[i];
if (alert.getRisk() >= Alert.RISK_MEDIUM) {
filteredAlerts.push(alert);
}
}
return filteredAlerts;
}
To use scan hooks:
- Go to Tools > Options > Scripts
- Add a new script in the Scan Rules category
- Implement the required functions
- Enable the script
Custom Scan Rules
You can create custom scan rules to test for specific vulnerabilities:
Custom Passive Rules
// Example passive scan rule
function scan(helper, msg) {
// Check if response contains sensitive information
var body = msg.getResponseBody().toString();
var url = msg.getRequestHeader().getURI().toString();
if (/password|credential|token/i.test(body)) {
helper.newAlert()
.setRisk(Alert.RISK_MEDIUM)
.setConfidence(Alert.CONFIDENCE_MEDIUM)
.setName('Potential Sensitive Information Disclosure')
.setDescription('The response contains potentially sensitive information.')
.setUri(url)
.setEvidence(body.match(/password|credential|token/i)[0])
.raise();
}
}
To add a custom passive rule:
- Go to Tools > Options > Scripts
- Add a new script in the Passive Rules category
- Implement the
scan
function - Enable the script
Context-Specific Scanning
Create a Targeted Context
- Create a new context for your target
- Define include/exclude patterns precisely
- Configure authentication if needed
- Set up users for authenticated scanning
- Define technology scope to focus testing
Configure Input Vector Context
- Right-click on the context in the Sites tree
- Select Attack > Active Scan
- Go to the Input Vectors tab
- Select only the relevant input vectors
- This focuses testing on specific input types
Use Custom Scan Policy
- Create a custom scan policy for the context
- Enable only relevant rules
- Set appropriate strength and threshold
- This ensures efficient and targeted scanning
Execute Context-Specific Scan
- Start the active scan with the context selected
- Select a specific user if testing authenticated functionality
- Monitor the scan progress
- Review results in the context of the application
Performance Optimization
Optimizing Scan Speed
Active Scan Performance Tips
-
Adjust Thread Count:
- Increase thread count for faster scanning (Tools > Options > Active Scan)
- Start with 5 threads per host and adjust based on performance
- Too many threads may overwhelm the target or your system
-
Focus Rule Selection:
- Disable unnecessary rules for your environment
- Create custom policies for different testing phases
- Use technology filters to skip irrelevant tests
-
Optimize Scan Strength:
- Use lower strength for initial scans
- Increase strength for targeted, in-depth testing
- Balance between speed and thoroughness
-
Target Input Vectors:
- Disable testing of unnecessary input vectors
- Focus on the most relevant attack surfaces
- Use custom input vectors for specific tests
Resource Management
Memory Allocation
- Increase memory allocation for ZAP:
- Edit
zap.bat
(Windows) orzap.sh
(Linux/macOS) - Modify the
-Xmx
parameter (e.g.,-Xmx2g
for 2GB) - Restart ZAP for changes to take effect
- Edit
- Monitor memory usage in the status bar
- Clear history periodically for long testing sessions
Database Management
- Go to Tools > Options > Database
- Configure database settings:
- Compact database on shutdown: Reduces database size
- Recovery log: Controls transaction logging
- Maximum request body size: Limits stored request size
- Maximum response body size: Limits stored response size
- These settings affect performance and disk usage
History Management
- Periodically clean history for long-running tests:
- Right-click on History tab and select Purge History
- Use Analysis > Clear Passive Scan Results to clear alerts
- Export important findings before clearing
- Consider using separate ZAP sessions for different testing phases
Scan Strategies
Risk-Based Scanning
Initial Reconnaissance
- Run passive scanning on the entire application
- Use the traditional and AJAX spiders to discover content
- Review the application structure and functionality
- Identify high-value targets and sensitive functionality
Risk Assessment
- Prioritize targets based on:
- Business criticality
- Exposure (public vs. internal)
- Data sensitivity
- User privileges required
- Create a risk-based testing plan
Tiered Scanning
-
Tier 1: Quick scan of all discovered content
- Use a lightweight scan policy
- Focus on high-risk, low-false-positive rules
- Identify obvious vulnerabilities
-
Tier 2: Detailed scan of high-risk areas
- Use a more comprehensive scan policy
- Include medium-risk rules
- Test all input vectors
-
Tier 3: In-depth scan of critical functionality
- Use maximum strength settings
- Enable all relevant rules
- Perform manual testing alongside automated scanning
Incremental Scanning
Baseline Scan
- Perform an initial scan of the entire application
- Document findings as a baseline
- Address critical vulnerabilities
Change-Based Scanning
- For new features or changes:
- Spider the affected areas
- Run targeted active scans
- Compare with baseline results
- Focus testing efforts on modified functionality
- Verify that previous issues haven't been reintroduced
Regression Testing
- Periodically scan the entire application
- Compare with previous baseline
- Identify new vulnerabilities
- Update the baseline after each cycle
Integration with Development Workflow
Continuous Integration
Set Up ZAP in CI/CD
- Use ZAP's automation framework or Docker container
- Create a baseline scan configuration
- Define thresholds for build failure
Configure CI Pipeline
# Example CI script using ZAP Docker
docker run -t owasp/zap2docker-stable zap-baseline.py \
-t https://example.com \
-c zap-baseline.conf \
-r testreport.html
The configuration file (zap-baseline.conf
) can specify:
- Rules to include/exclude
- Alert levels that cause build failure
- Scan options and parameters
Review and Triage
- Generate reports in a format suitable for your workflow
- Integrate results with issue tracking system
- Implement a triage process for findings
- Track vulnerability trends over time
API Testing
Import API Definition
- Go to Tools > Import > OpenAPI Definition
- Import your OpenAPI/Swagger specification
- ZAP will create Sites tree entries for all endpoints
Configure Authentication
- Set up appropriate authentication for the API
- Create a context with the API endpoints
- Configure users and authentication method
Create API-Specific Scan Policy
- Create a custom scan policy for API testing
- Enable relevant rules for API vulnerabilities:
- Injection flaws
- Authorization issues
- Information disclosure
- Rate limiting
- Disable irrelevant rules (e.g., browser-specific issues)
Execute API Scan
- Run the active scan with the API-specific policy
- Monitor for false positives
- Review findings in the context of API functionality
Next Steps
Now that you understand the scanning options in OWASP ZAP, explore these topics:
- Reporting - Generating and customizing security reports
- Advanced Techniques - Advanced usage scenarios and features
- Best Practices - Best practices for effective and ethical use of ZAP