Professional-grade web application vulnerability scanning API powered by Nuclei and OWASP ZAP
- π Quick Start
- π§ Installation
- π Complete API Reference
- π‘οΈ Security Engines
- π‘ Usage Examples
- π Advanced Features
- βοΈ Configuration
- π Troubleshooting
git clone <repository_url>
cd pentesting-api
docker-compose up -d# Quick Nuclei scan (safe for any target)
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://testphp.vulnweb.com",
"engine": "nuclei",
"options": {"type": "quick"}
}'
# Or try ZAP passive scan (also safe)
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://testphp.vulnweb.com",
"engine": "zap-passive",
"enhanced_passive": true
}'# Get scan status
curl http://localhost:5000/scan/{scan_id}/status
# View HTML report
open http://localhost:5000/report/{scan_id}/html- Docker & Docker Compose
- 4GB+ RAM recommended
- Network access to target systems
# Clone repository
git clone <repository_url>
cd pentesting-api
# Start services
docker-compose up -d
# Verify installation
curl http://localhost:5000/health| Service | Port | Description |
|---|---|---|
| API Server | 5000 | Main vulnerability scanner API |
| OWASP ZAP | 8080 | Web application security scanner |
http://localhost:5000
Currently no authentication required.
Check API status and available engines
GET /healthResponse:
{
"status": "healthy",
"service": "Internal Vulnerability Scanner",
"version": "1.1.0",
"engines_available": ["nuclei", "zap"]
}cURL Example:
curl http://localhost:5000/healthInitiate a new security scan
POST /scan
Content-Type: application/jsonRequest Body:
{
"url": "string (required)",
"engine": "string (required)",
"options": "object (optional)",
"auth": "object (optional, ZAP only)",
"enable_parallel": "boolean (optional, ZAP active only)",
"max_workers": "integer (optional, ZAP active only)",
"enhanced_passive": "boolean (optional, ZAP passive only)"
}Parameters:
url: Target URL to scan (must include http/https)engine: Scanner engine (nuclei,zap,zap-passive,zap-active)options: Engine-specific configurationauth: Authentication configuration (ZAP only)username: Username for form-based authenticationpassword: Password for authenticationlogin_url: Login form URL
enable_parallel: Enable parallel scanning (ZAP active only, default: true)max_workers: Number of parallel scan workers (ZAP active only, default: 3)enhanced_passive: Enable enhanced passive scanning features (ZAP passive only, default: true)
Response:
{
"message": "Scan started successfully",
"scan_id": "123e4567-e89b-12d3-a456-426614174000",
"target": "http://example.com",
"engine": "nuclei",
"status_url": "/scan/123e4567-e89b-12d3-a456-426614174000/status",
"report_url": "/report/123e4567-e89b-12d3-a456-426614174000",
"html_report_url": "/report/123e4567-e89b-12d3-a456-426614174000/html"
}cURL Examples:
Basic Nuclei Scan:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://example.com",
"engine": "nuclei",
"options": {"type": "quick"}
}'Custom Nuclei Scan:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://example.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["tech", "cve", "sqli", "xss"],
"severity": ["critical", "high"],
"intensity": "aggressive"
}
}'ZAP Enhanced Passive Scan:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://example.com",
"engine": "zap-passive",
"enhanced_passive": true
}'ZAP Advanced Active Scan with Authentication (FIXED):
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://testphp.vulnweb.com/login.php",
"engine": "zap-active",
"auth": {
"username": "test",
"password": "test",
"login_url": "http://testphp.vulnweb.com/login.php"
},
"enable_parallel": false,
"max_workers": 1
}'PowerShell Example (Windows):
$body = '{"url": "http://testphp.vulnweb.com", "engine": "zap-active", "enable_parallel": false, "max_workers": 1}'
Invoke-RestMethod -Uri "http://localhost:5000/scan" -Method POST -ContentType "application/json" -Body $bodyCheck scan progress and basic results
GET /scan/{scan_id}/statusResponse:
{
"status": "completed",
"target": "http://example.com",
"engine": "nuclei",
"duration": 45.23,
"result": {
"success": true,
"scan_id": "123e4567-e89b-12d3-a456-426614174000",
"vulnerabilities_found": 5
}
}Status Values:
in_progress: Scan is runningcompleted: Scan finished successfullyfailed: Scan encountered an error
cURL Example:
curl http://localhost:5000/scan/123e4567-e89b-12d3-a456-426614174000/statusRetrieve detailed scan results in JSON format
GET /report/{scan_id}Response:
{
"scan_id": "123e4567-e89b-12d3-a456-426614174000",
"target": "http://example.com",
"engine": "nuclei",
"engine_version": "v3.4.7",
"scan_date": "2025-07-25 17:30:41",
"scan_intensity": "comprehensive",
"status": "completed",
"summary": {
"total": 5,
"critical": 1,
"high": 2,
"medium": 1,
"low": 0,
"info": 1
},
"vulnerabilities": [
{
"title": "SQL Injection",
"severity": "critical",
"description": "SQL injection vulnerability detected",
"url": "http://example.com/login.php",
"template": "sql-injection",
"template_path": "/templates/sql-injection.yaml",
"cve": ["CVE-2021-1234"],
"reference": ["https://owasp.org/..."],
"type": "http",
"matcher_status": true,
"curl_command": "curl -X POST ...",
"host": "example.com",
"port": "80",
"scheme": "http",
"timestamp": "2025-07-25T17:30:20Z",
"extracted_results": []
}
],
"scan_statistics": {
"duration_seconds": 300,
"templates_used": ["tech", "cve", "sqli"],
"severity_filter": ["critical", "high", "medium", "info"],
"scan_command": "/usr/local/bin/nuclei ..."
},
"scan_warnings": []
}cURL Example:
curl http://localhost:5000/report/123e4567-e89b-12d3-a456-426614174000View formatted vulnerability report in browser
GET /report/{scan_id}/htmlReturns a styled HTML page with:
- Executive summary
- Vulnerability breakdown by severity
- Detailed findings with remediation steps
- Technical details and proof-of-concept
Browser Example:
http://localhost:5000/report/123e4567-e89b-12d3-a456-426614174000/html
cURL Example:
curl http://localhost:5000/report/123e4567-e89b-12d3-a456-426614174000/html > report.htmlGet overview of all performed scans
GET /scansResponse:
{
"scans": [
{
"scan_id": "123e4567-e89b-12d3-a456-426614174000",
"target": "http://example.com",
"engine": "nuclei",
"status": "completed"
},
{
"scan_id": "456e7890-e89b-12d3-a456-426614174001",
"target": "http://testsite.com",
"engine": "zap-active",
"status": "in_progress"
}
]
}cURL Example:
curl http://localhost:5000/scansGet scanner engines and their capabilities
GET /enginesResponse:
{
"engines": {
"nuclei": {
"name": "Nuclei",
"description": "Fast vulnerability scanner based on simple YAML-based DSL",
"capabilities": ["passive", "template-based"],
"scan_types": ["quick", "comprehensive"]
},
"zap": {
"name": "OWASP ZAP",
"description": "The OWASP Zed Attack Proxy",
"capabilities": ["passive", "active", "authentication", "parallel"],
"scan_types": ["passive", "active"]
}
}
}cURL Example:
curl http://localhost:5000/enginesGet API overview and example requests
GET /Response:
{
"service": "Internal Vulnerability Scanner API",
"version": "1.1.0",
"endpoints": {
"POST /scan": "Start vulnerability scan",
"GET /scan/<id>/status": "Get scan status",
"GET /report/<id>": "Get JSON report",
"GET /report/<id>/html": "Get HTML report",
"GET /scans": "List all scans",
"GET /engines": "List available engines",
"GET /health": "Health check"
},
"example_scan_requests": {
"quick_scan": {
"url": "http://example.com",
"engine": "nuclei",
"options": {"type": "quick"}
},
"comprehensive_scan": {
"url": "http://example.com",
"engine": "nuclei",
"options": {"type": "comprehensive"}
},
"deep_scan": {
"url": "http://example.com",
"engine": "nuclei",
"options": {"type": "deep"}
},
"custom_scan": {
"url": "http://example.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["tech", "cve", "sqli", "xss", "rce"],
"severity": ["critical", "high", "medium"],
"intensity": "aggressive"
}
},
"zap_advanced_scan": {
"url": "http://example.com",
"engine": "zap-active",
"auth": {
"username": "user",
"password": "pass",
"login_url": "http://example.com/login"
},
"enable_parallel": true,
"max_workers": 3
}
},
"scan_types": {
"quick": "Fast scan with basic templates (3 min)",
"comprehensive": "Thorough scan with many templates (10 min)",
"deep": "Maximum coverage scan (15 min)",
"custom": "User-defined scan parameters"
},
"available_intensities": ["light", "normal", "aggressive", "maximum"],
"common_tags": ["tech", "cve", "misconfig", "sqli", "xss", "rce", "file-upload", "lfi", "ssrf", "idor", "auth-bypass", "owasp-top-10", "exposure"]
}cURL Example:
curl http://localhost:5000/Fast, template-based vulnerability scanner
| Type | Duration | Rate Limit | Templates | Description |
|---|---|---|---|---|
quick |
4 min | 30/sec | tech, cve, misconfig | Light reconnaissance scan |
comprehensive |
12 min | 35/sec | 10+ categories | Aggressive vulnerability assessment |
deep |
20 min | 20/sec | All templates | Maximum template coverage |
custom |
Variable | User-defined | User-defined | Fully customizable scan |
Quick Scan:
{
"url": "http://example.com",
"engine": "nuclei",
"options": {
"type": "quick"
}
}Comprehensive Scan:
{
"url": "http://example.com",
"engine": "nuclei",
"options": {
"type": "comprehensive"
}
}Deep Scan:
{
"url": "http://example.com",
"engine": "nuclei",
"options": {
"type": "deep"
}
}Custom Scan with All Options:
{
"url": "http://example.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["tech", "cve", "sqli", "xss", "rce", "file-upload", "lfi", "ssrf", "idor", "auth-bypass", "owasp-top-10", "exposure", "misconfig"],
"severity": ["critical", "high", "medium", "low", "info"],
"intensity": "maximum"
}
}Vulnerability Categories:
tech- Technology detection and fingerprintingcve- CVE vulnerabilitiesmisconfig- Configuration issues and misconfigurationssqli- SQL injection vulnerabilitiesxss- Cross-site scriptingrce- Remote code executionfile-upload- File upload vulnerabilitieslfi- Local file inclusionssrf- Server-side request forgeryidor- Insecure direct object referenceauth-bypass- Authentication bypassowasp-top-10- OWASP Top 10 vulnerabilitiesexposure- Information exposure and leaks
critical- Critical vulnerabilities requiring immediate attentionhigh- High-impact vulnerabilitiesmedium- Medium-risk vulnerabilitieslow- Low-impact vulnerabilitiesinfo- Information gathering and fingerprinting
| Intensity | Rate Limit | Timeout | Retries | Use Case |
|---|---|---|---|---|
light |
30/sec | 8s | 0 | Fast reconnaissance |
normal |
50/sec | 12s | 0 | Balanced scanning |
aggressive |
35/sec | 18s | 2 | Thorough assessment |
maximum |
20/sec | 25s | 3 | Deep vulnerability hunting |
π Advanced web application security testing with enhanced features
Enhanced Passive Scan (Safe for Production):
{
"url": "http://example.com",
"engine": "zap-passive",
"enhanced_passive": true
}- Duration: 2-5 minutes (enhanced mode)
- Method: Advanced spider + AJAX spider + passive analysis
- Safety: β Safe for production systems
- Coverage: Comprehensive URL discovery with modern web app support
- Features:
- Enhanced spider configuration (depth: 8, children: 30)
- AJAX spider for SPA applications
- Robots.txt and sitemap parsing
- Comment and form parameter discovery
Advanced Active Scan (
{
"url": "http://example.com",
"engine": "zap-active",
"enable_parallel": true,
"max_workers": 3
}- Duration: 10-20 minutes (depending on site size)
- Method: Multi-phase comprehensive security testing
- Safety:
β οΈ Only for test environments - Coverage: Maximum vulnerability detection with actual exploits
- Features:
- Advanced scan policies with 20+ vulnerability rules
- Parallel scanning for performance
- Deep spider crawling (depth: 10, children: 50)
- AJAX spider for modern web applications
- Comprehensive attack simulation
π Advanced Active Scan with Authentication:
{
"url": "http://example.com",
"engine": "zap-active",
"auth": {
"username": "testuser",
"password": "testpass123",
"login_url": "http://example.com/login"
},
"enable_parallel": true,
"max_workers": 5
}- Authentication: Form-based authentication support
- Session Management: Maintains authenticated sessions
- Coverage: Tests authenticated areas of the application
- Security: Credentials handled securely and cleaned up after scan
- Form-based authentication configuration
- Session management for authenticated scanning
- Automatic credential cleanup after scan completion
- Support for complex login flows
- Configurable parallel workers (default: 3, max recommended: 5)
- Intelligent URL chunking for optimal performance
- Reduces scan time by 40-60% for large applications
- Automatic load balancing across scan workers
- Deep Crawling: Up to 10 levels deep
- Comprehensive Coverage: 50 URLs per page
- Smart Parsing: Robots.txt, sitemap.xml, comments
- Form Handling: Automatic form discovery and processing
- Parameter Detection: Advanced parameter identification
- SPA Applications: Full JavaScript rendering support
- Dynamic Content: Discovers AJAX-loaded content
- Modern Web Apps: React, Angular, Vue.js compatibility
- Complementary Discovery: Works alongside traditional spider
- 20+ Vulnerability Rules: Comprehensive coverage
- High Attack Strength: Maximum detection capability
- Low Alert Threshold: Catches subtle vulnerabilities
- Custom Payloads: Advanced injection techniques
- Specific Rules Include:
- SQL Injection (MySQL, PostgreSQL, Oracle, SQLite)
- Cross-Site Scripting (Reflected & Persistent)
- Remote Code Execution
- CRLF Injection
- Server-Side Includes
- Parameter Tampering
- Detailed Statistics: URL discovery metrics, scan phases
- Performance Metrics: Duration breakdown by phase
- Coverage Analysis: Forms, parameters, authentication status
- Enhanced Vulnerability Details: Evidence, payloads, confidence levels
- Scan Configuration Tracking: Authentication, parallel settings
π Enhanced Passive Scan Process:
- Advanced Spider Configuration (30 sec)
- Comprehensive Spider Crawling (2-3 min)
- AJAX Spider for Modern Content (1-2 min)
- Passive Security Analysis (30 sec)
- Report Generation with Statistics (15 sec)
π₯ Advanced Active Scan Process:
- π Authentication Setup (30 sec)
- π·οΈ Advanced Spider Configuration (30 sec)
- βοΈ Advanced Scan Policy Creation (45 sec)
- π Comprehensive Spider Crawling (3-5 min)
- π AJAX Spider for Modern Web Apps (2-3 min)
- π Passive Scan Processing (15 sec)
- π₯ Advanced Active Vulnerability Scanning (5-15 min)
- π Results Collection and Analysis (30 sec)
- π§Ή Resource Cleanup (15 sec)
π Performance by Site Size:
| Site Size | Enhanced Passive | Advanced Active | Advanced Active + Auth |
|---|---|---|---|
| Small (5-20 pages) | 1-2 min | 5-8 min | 6-10 min |
| Medium (20-100 pages) | 2-5 min | 10-20 min | 12-25 min |
| Large (100+ pages) | 5-10 min | 20-40 min | 25-45 min |
β‘ Parallel Scanning Benefits:
- 2 Workers: 30-40% faster than single scan
- 3 Workers: 40-50% faster (recommended)
- 4-5 Workers: 50-60% faster (for large sites only)
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://target.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["tech"],
"severity": ["info"],
"intensity": "light"
}
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://target.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["cve", "sqli", "xss", "rce", "auth-bypass"],
"severity": ["critical", "high"],
"intensity": "aggressive"
}
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://target.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["owasp-top-10", "sqli", "xss", "rce", "idor", "auth-bypass", "exposure"],
"intensity": "maximum"
}
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://target.com",
"engine": "nuclei",
"options": {
"type": "deep"
}
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://production-site.com",
"engine": "zap-passive",
"enhanced_passive": true
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://test-environment.com",
"engine": "zap-active",
"enable_parallel": true,
"max_workers": 3
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://webapp.test.com",
"engine": "zap-active",
"auth": {
"username": "testuser",
"password": "testpass123",
"login_url": "http://webapp.test.com/login"
},
"enable_parallel": true,
"max_workers": 4
}'curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://large-application.test.com",
"engine": "zap-active",
"enable_parallel": true,
"max_workers": 5
}'#!/bin/bash
targets=("http://site1.com" "http://site2.com" "http://site3.com")
scan_ids=()
echo "Starting batch scan of ${#targets[@]} targets..."
for target in "${targets[@]}"; do
echo "Scanning: $target"
response=$(curl -s -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d "{
\"url\": \"$target\",
\"engine\": \"nuclei\",
\"options\": {\"type\": \"comprehensive\"}
}")
scan_id=$(echo $response | jq -r '.scan_id')
scan_ids+=("$scan_id")
echo "Scan ID: $scan_id"
done
echo "Monitoring ${#scan_ids[@]} scans..."
for scan_id in "${scan_ids[@]}"; do
echo "Monitoring scan: $scan_id"
while true; do
status=$(curl -s http://localhost:5000/scan/$scan_id/status | jq -r '.status')
target=$(curl -s http://localhost:5000/scan/$scan_id/status | jq -r '.target')
echo "[$target] Status: $status"
if [[ "$status" == "completed" ]]; then
vulns=$(curl -s http://localhost:5000/report/$scan_id | jq '.summary.total')
echo "[$target] β
Completed - Found $vulns vulnerabilities"
echo "[$target] Report: http://localhost:5000/report/$scan_id/html"
break
elif [[ "$status" == "failed" ]]; then
echo "[$target] β Failed"
break
fi
sleep 30
done
done
echo "All scans completed!"#!/bin/bash
scan_id="$1"
if [ -z "$scan_id" ]; then
echo "Usage: $0 <scan_id>"
exit 1
fi
echo "Monitoring scan: $scan_id"
echo "Press Ctrl+C to stop monitoring"
while true; do
response=$(curl -s http://localhost:5000/scan/$scan_id/status)
status=$(echo $response | jq -r '.status')
target=$(echo $response | jq -r '.target')
duration=$(echo $response | jq -r '.duration')
timestamp=$(date '+%Y-%m-%d %H:%M:%S')
echo "[$timestamp] $target - Status: $status - Duration: ${duration}s"
if [[ "$status" == "completed" ]]; then
vulns=$(echo $response | jq -r '.result.vulnerabilities_found // 0')
echo "π Scan completed! Found $vulns vulnerabilities"
echo "π JSON Report: http://localhost:5000/report/$scan_id"
echo "π HTML Report: http://localhost:5000/report/$scan_id/html"
break
elif [[ "$status" == "failed" ]]; then
error=$(echo $response | jq -r '.error // "Unknown error"')
echo "β Scan failed: $error"
break
fi
sleep 10
doneEnterprise Application Authentication:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "https://enterprise-app.com",
"engine": "zap-active",
"auth": {
"username": "security_tester",
"password": "complex_password123!",
"login_url": "https://enterprise-app.com/auth/login"
},
"enable_parallel": true,
"max_workers": 3
}'Benefits:
- Tests authenticated functionality
- Discovers auth-protected vulnerabilities
- Session management for complex apps
- Automatic credential cleanup
Large Application Optimization:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "https://large-ecommerce-site.test",
"engine": "zap-active",
"enable_parallel": true,
"max_workers": 5
}'Performance Gains:
- 40-60% faster than sequential scanning
- Intelligent URL chunking
- Load-balanced worker distribution
- Optimized for large applications (100+ pages)
Targeted SQL Injection Testing:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://webapp.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["sqli"],
"severity": ["critical", "high", "medium"],
"intensity": "maximum"
}
}'XSS Vulnerability Assessment:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://webapp.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["xss"],
"severity": ["critical", "high", "medium"],
"intensity": "aggressive"
}
}'Configuration and Exposure Audit:
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://webapp.com",
"engine": "nuclei",
"options": {
"type": "custom",
"tags": ["misconfig", "exposure"],
"intensity": "normal"
}
}'Python SDK Example:
import requests
import json
import time
class VulnScanner:
def __init__(self, base_url="http://localhost:5000"):
self.base_url = base_url
def start_scan(self, url, engine="nuclei", options=None, **kwargs):
"""Start a vulnerability scan with advanced options."""
payload = {"url": url, "engine": engine}
if options:
payload["options"] = options
# Add ZAP-specific parameters
for key in ['auth', 'enable_parallel', 'max_workers', 'enhanced_passive']:
if key in kwargs:
payload[key] = kwargs[key]
response = requests.post(f"{self.base_url}/scan", json=payload)
if response.status_code == 202:
return response.json()
else:
raise Exception(f"Scan failed: {response.text}")
def start_authenticated_scan(self, url, username, password, login_url,
engine="zap-active", parallel=True, workers=3):
"""Start an authenticated ZAP scan."""
return self.start_scan(
url=url,
engine=engine,
auth={
"username": username,
"password": password,
"login_url": login_url
},
enable_parallel=parallel,
max_workers=workers
)
def wait_for_completion(self, scan_id, poll_interval=10, timeout=1800):
"""Wait for scan completion with timeout."""
start_time = time.time()
while time.time() - start_time < timeout:
status = self.get_status(scan_id)
if status["status"] == "completed":
return self.get_report(scan_id)
elif status["status"] == "failed":
raise Exception(f"Scan failed: {status.get('error', 'Unknown error')}")
print(f"Scan {scan_id[:8]}... - Status: {status['status']} - Duration: {status.get('duration', 0):.1f}s")
time.sleep(poll_interval)
raise Exception(f"Scan timeout after {timeout} seconds")
def get_status(self, scan_id):
"""Get scan status."""
response = requests.get(f"{self.base_url}/scan/{scan_id}/status")
return response.json()
def get_report(self, scan_id):
"""Get detailed JSON report."""
response = requests.get(f"{self.base_url}/report/{scan_id}")
return response.json()
def list_scans(self):
"""List all scans."""
response = requests.get(f"{self.base_url}/scans")
return response.json()
# π Advanced Usage Examples
scanner = VulnScanner()
# Enhanced passive scan
print("π Starting enhanced passive vulnerability scan...")
result = scanner.start_scan(
"http://testphp.vulnweb.com",
engine="zap-passive",
enhanced_passive=True
)
print(f"β
Scan started: {result['scan_id']}")
# Advanced authenticated scan
print("π Starting authenticated security assessment...")
auth_result = scanner.start_authenticated_scan(
url="http://webapp.test.com",
username="testuser",
password="testpass123",
login_url="http://webapp.test.com/login",
parallel=True,
workers=4
)
# Wait for completion and get results
report = scanner.wait_for_completion(auth_result["scan_id"])
print(f"π Authenticated scan completed! Found {report['summary']['total']} vulnerabilities")
print(f" Critical: {report['summary']['critical']}")
print(f" High: {report['summary']['high']}")
print(f" Medium: {report['summary']['medium']}")
# Enhanced vulnerability analysis
if 'statistics' in report:
stats = report['statistics']
print(f"\nπ Enhanced Statistics:")
if 'total_urls_discovered' in stats:
print(f" - Total URLs discovered: {stats['total_urls_discovered']}")
if 'authentication_enabled' in stats:
print(f" - Authentication used: {stats['authentication_enabled']}")
if 'parallel_scanning_enabled' in stats:
print(f" - Parallel scanning: {stats['parallel_scanning_enabled']}")
print(f" - Scan duration: {stats.get('total_scan_duration', 'N/A')}")
# Custom comprehensive scan
print("\nπ Starting comprehensive vulnerability scan...")
comprehensive_result = scanner.start_scan(
"http://testphp.vulnweb.com",
options={
"type": "custom",
"tags": ["tech", "cve", "sqli", "xss", "rce", "file-upload"],
"severity": ["critical", "high", "medium"],
"intensity": "aggressive"
}
)
comprehensive_report = scanner.wait_for_completion(comprehensive_result["scan_id"])
print(f"π Comprehensive scan completed! Found {comprehensive_report['summary']['total']} vulnerabilities")
# List all scans
all_scans = scanner.list_scans()
print(f"\nπ Total scans performed: {len(all_scans['scans'])}")JavaScript/Node.js Example:
const axios = require('axios');
class VulnScanner {
constructor(baseUrl = 'http://localhost:5000') {
this.baseUrl = baseUrl;
}
async startScan(url, engine = 'nuclei', options = null, extraParams = {}) {
const payload = { url, engine, ...extraParams };
if (options) payload.options = options;
try {
const response = await axios.post(`${this.baseUrl}/scan`, payload);
return response.data;
} catch (error) {
throw new Error(`Scan failed: ${error.response?.data || error.message}`);
}
}
// π Advanced authenticated scan method
async startAuthenticatedScan(url, username, password, loginUrl, options = {}) {
return this.startScan(url, 'zap-active', null, {
auth: { username, password, login_url: loginUrl },
enable_parallel: options.parallel !== false,
max_workers: options.workers || 3
});
}
// π Enhanced passive scan method
async startEnhancedPassiveScan(url) {
return this.startScan(url, 'zap-passive', null, {
enhanced_passive: true
});
}
async waitForCompletion(scanId, pollInterval = 10000, timeout = 1800000) {
const startTime = Date.now();
while (Date.now() - startTime < timeout) {
const status = await this.getStatus(scanId);
if (status.status === 'completed') {
return await this.getReport(scanId);
} else if (status.status === 'failed') {
throw new Error(`Scan failed: ${status.error || 'Unknown error'}`);
}
console.log(`Scan ${scanId.substring(0, 8)}... - Status: ${status.status} - Duration: ${status.duration || 0}s`);
await new Promise(resolve => setTimeout(resolve, pollInterval));
}
throw new Error(`Scan timeout after ${timeout / 1000} seconds`);
}
async getStatus(scanId) {
const response = await axios.get(`${this.baseUrl}/scan/${scanId}/status`);
return response.data;
}
async getReport(scanId) {
const response = await axios.get(`${this.baseUrl}/report/${scanId}`);
return response.data;
}
}
// π Advanced Usage Examples
async function runAdvancedScans() {
const scanner = new VulnScanner();
try {
// Enhanced passive scan
console.log('π Starting enhanced passive scan...');
const passiveResult = await scanner.startEnhancedPassiveScan('http://testphp.vulnweb.com');
console.log(`β
Enhanced passive scan started: ${passiveResult.scan_id}`);
// Authenticated active scan
console.log('π Starting authenticated active scan...');
const authResult = await scanner.startAuthenticatedScan(
'http://webapp.test.com',
'testuser',
'testpass123',
'http://webapp.test.com/login',
{ parallel: true, workers: 4 }
);
console.log(`β
Authenticated scan started: ${authResult.scan_id}`);
// Wait for authenticated scan completion
const report = await scanner.waitForCompletion(authResult.scan_id);
console.log(`π Scan completed! Found ${report.summary.total} vulnerabilities`);
console.log(` Critical: ${report.summary.critical}`);
console.log(` High: ${report.summary.high}`);
console.log(` Medium: ${report.summary.medium}`);
// π Enhanced statistics analysis
if (report.statistics) {
const stats = report.statistics;
console.log('\nπ Enhanced Statistics:');
console.log(` - URLs discovered: ${stats.total_urls_discovered || 'N/A'}`);
console.log(` - Authentication: ${stats.authentication_enabled ? 'Enabled' : 'Disabled'}`);
console.log(` - Parallel scanning: ${stats.parallel_scanning_enabled ? 'Enabled' : 'Disabled'}`);
console.log(` - Scan duration: ${stats.total_scan_duration || 'N/A'}`);
if (stats.scan_coverage) {
console.log(` - Forms found: ${stats.scan_coverage.forms_found || 0}`);
console.log(` - Parameters tested: ${stats.scan_coverage.parameters_tested || 0}`);
}
}
} catch (error) {
console.error('β Scan failed:', error.message);
}
}
runAdvancedScans();# Run Nuclei directly in container for custom workflows
docker exec pentesting-api-vuln-scanner-1 \
nuclei -target http://example.com \
-tags tech,cve \
-severity critical,high \
-rate-limit 30 \
-timeout 10 \
-jsonl -silentAccess ZAP UI at http://localhost:8080 for:
- Manual security testing
- Custom scan policies
- Authentication configuration
- Advanced reporting
# docker-compose.yml
environment:
- FLASK_ENV=development
- FLASK_DEBUG=1
- SECRET_KEY=your-secret-key-change-in-production
- ZAP_HOST=zap
- ZAP_PORT=8080
- NUCLEI_PATH=/usr/local/bin/nuclei
- REPORTS_DIR=reports
- MAX_SCAN_DURATION=300
- RATE_LIMIT_PER_MINUTE=10| Parameter | Default | Description |
|---|---|---|
ZAP_MAX_SPIDER_DEPTH |
10 | Maximum spider crawling depth |
ZAP_MAX_SPIDER_CHILDREN |
50 | Maximum URLs per page |
ZAP_SPIDER_TIMEOUT |
600 | Spider timeout in seconds |
ZAP_AJAX_TIMEOUT |
300 | AJAX spider timeout |
ZAP_MAX_PARALLEL_SCANS |
5 | Maximum parallel scan workers |
ZAP_SCAN_POLICY_STRENGTH |
High | Attack strength level |
ZAP_ALERT_THRESHOLD |
Low | Alert detection threshold |
volumes:
- ./app/reports:/app/reports # Scan reports storage
- ./app:/app # Application code
- nuclei_templates:/root/.nuclei # Nuclei templatesports:
- "5000:5000" # API Server
- "8080:8080" # ZAP Proxy UI# Increase memory for large scans
deploy:
resources:
limits:
memory: 4G
cpus: '2'
reservations:
memory: 2G
cpus: '1'- Add Authentication: Implement API key or OAuth
- Rate Limiting: Configure per-IP rate limits
- HTTPS Only: Use TLS encryption
- Network Isolation: Restrict scanner network access
- Input Validation: Whitelist target domains
- Logging: Enable comprehensive audit logging
- Monitoring: Set up alerting for scan activities
- π Credential Security: Secure handling of authentication data
- π Resource Limits: Configure parallel scan limits
- Get Permission: Only scan systems you own or have written permission to test
- Test Environment First: Always test on non-production systems
- Rate Limiting: Configure appropriate scan speeds to avoid DoS
- Monitoring: Monitor resource usage during scans
- ZAP Active Scans: Use only in dedicated test environments
- π Authentication Data: Use test credentials only, never production credentials
- π Parallel Scanning: Monitor server resources when using multiple workers
# production-docker-compose.yml
version: '3.8'
services:
vuln-scanner:
build: .
ports:
- "5000:5000"
environment:
- FLASK_ENV=production
- FLASK_DEBUG=0
- SECRET_KEY=${SECRET_KEY}
- RATE_LIMIT_PER_MINUTE=5
- MAX_SCAN_DURATION=600
# π Advanced ZAP security settings
- ZAP_MAX_PARALLEL_SCANS=2
- ZAP_SCAN_TIMEOUT=900
volumes:
- /secure/reports:/app/reports
restart: unless-stopped
zap:
image: owasp/zap:stable
command: zap.sh -daemon -host 0.0.0.0 -port 8080 -config api.disablekey=true
ports:
- "127.0.0.1:8080:8080" # Bind to localhost only
restart: unless-stopped# Check if scan ID is correct
curl http://localhost:5000/scans | jq '.scans[] | select(.scan_id | contains("partial-id"))'
# List all recent scans
curl http://localhost:5000/scans | jq '.scans | sort_by(.scan_id) | reverse'# Check ZAP container status
docker-compose ps zap
docker-compose logs zap
# Test ZAP API directly
curl http://localhost:8080/JSON/core/view/version/
# Restart ZAP if needed
docker-compose restart zap# Run comprehensive authentication debug script
python debug_zap_auth.py
# Check authentication configuration in logs
docker-compose logs vuln-scanner | grep "Authentication"
# Check for userid parameter errors (FIXED in v1.1.1)
docker-compose logs vuln-scanner | grep "userid"
# Verify ZAP forced user mode setup
docker-compose logs vuln-scanner | grep "forced user"
# Check authentication verification process
docker-compose logs vuln-scanner | grep "Verifying authentication"
# Verify login URL accessibility
curl -I http://your-app.com/login
# Test authentication manually
curl -X POST http://your-app.com/login \
-d "username=testuser&password=testpass123" \
-c cookies.txt -v
# Test with working examples
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://testphp.vulnweb.com",
"engine": "zap-active",
"enable_parallel": false,
"max_workers": 1
}'# Check system resources during parallel scans
docker stats
# Reduce parallel workers if needed
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://target.com",
"engine": "zap-active",
"enable_parallel": true,
"max_workers": 2
}'
# Monitor active scan progress
docker-compose logs vuln-scanner | grep "parallel"# Update Nuclei templates manually
docker exec pentesting-api-vuln-scanner-1 nuclei -update-templates
# Verify template update
docker exec pentesting-api-vuln-scanner-1 nuclei -stats# Check container resource usage
docker stats
# Monitor during scan
docker exec pentesting-api-vuln-scanner-1 top
# Increase memory limits in docker-compose.yml
deploy:
resources:
limits:
memory: 4G# Check scan configuration in logs
docker-compose logs vuln-scanner | grep "Enhanced"
# Adjust scan intensity for faster results
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://target.com",
"engine": "nuclei",
"options": {
"type": "custom",
"intensity": "light"
}
}'# Enable verbose logging
docker-compose logs -f vuln-scanner
# Check specific scan logs
docker-compose logs vuln-scanner | grep "scan_id_here"
# ZAP debug logs
docker-compose logs zap | grep ERROR
# π Advanced ZAP debugging
docker-compose logs vuln-scanner | grep "Phase"
docker-compose logs vuln-scanner | grep "Authentication"
docker-compose logs vuln-scanner | grep "parallel"New comprehensive debugging tool for authentication issues:
# Run the authentication debug script
python debug_zap_auth.pyThis script automatically tests:
- β API health and connectivity
- β ZAP service direct connection
- β Simple scan without authentication
- β Authentication scan (where issues typically occur)
Example output:
π ZAP AUTHENTICATION DEBUG SCRIPT
==================================================
β° Started at: 2025-07-30 14:30:00
==================== TEST 1: API HEALTH ====================
π₯ Testing API health...
β
API is healthy: {'status': 'healthy', 'service': 'Internal Vulnerability Scanner'}
==================== TEST 2: ZAP DIRECT ====================
π Testing ZAP service directly...
π‘ Testing ZAP at: http://localhost:8080/JSON/core/view/version/
β
ZAP is running! Version: {'version': '2.16.1'}
==================== TEST 3: SIMPLE SCAN ====================
π§ͺ Testing simple scan without auth...
β
Simple scan started: a15fb705-9aa7-4857-a3c0-030131abda80
==================== TEST 4: AUTH SCAN ====================
π Testing auth scan (the problematic one)...
β
Auth scan completed successfully!
==================== SUMMARY ====================
api_health : β
PASS
zap_direct : β
PASS
simple_scan : β
PASS
auth_scan : β
PASS
# Comprehensive system check
curl http://localhost:5000/health && echo "β
API healthy"
curl http://localhost:5000/engines && echo "β
Engines available"
curl http://localhost:8080/JSON/core/view/version/ && echo "β
ZAP healthy"
# Test basic scan functionality
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://httpbin.org/ip",
"engine": "nuclei",
"options": {"type": "quick"}
}' && echo "β
Scan endpoint working"
# π Test advanced ZAP features (FIXED)
curl -X POST http://localhost:5000/scan \
-H "Content-Type: application/json" \
-d '{
"url": "http://testphp.vulnweb.com",
"engine": "zap-active",
"enable_parallel": false,
"max_workers": 1
}' && echo "β
ZAP active scanning working"| Code | Status | Description | Example Response |
|---|---|---|---|
| 200 | OK | Request successful | {"status": "healthy"} |
| 202 | Accepted | Scan started (async operation) | {"scan_id": "123...", "message": "Scan started"} |
| 400 | Bad Request | Invalid request parameters | {"error": "URL is required"} |
| 404 | Not Found | Scan ID not found | {"error": "Scan not found"} |
| 500 | Internal Server Error | Server error occurred | {"error": "Scan engine failed"} |
- π Nuclei Templates - Official template repository
- π OWASP ZAP User Guide - Comprehensive ZAP documentation
- π ZAP API Documentation - ZAP API reference
- π Flask API Best Practices - Flask framework guide
- π¬ Nuclei Discord - ProjectDiscovery community
- π¬ OWASP ZAP User Group - ZAP community support
- π OWASP Testing Guide - Web security testing methodology
- π Web Application Security Testing - PortSwigger Web Security Academy
- π Vulnerability Assessment - SANS guidance
- π Ethical Hacking - EC-Council resources
- β
FIXED: ZAP Authentication Issues: Resolved
useridparameter errors in spider and active scans - β FIXED: Forced User Mode: Proper authentication context management for all scan types
- β FIXED: API Parameter Handling: Correct boolean and string parameter formatting for ZAP API
- β FIXED: Spider Authentication: Removed unsupported parameters, using forced user mode correctly
- β FIXED: Active Scan Authentication: Proper context and user management for authenticated scanning
- π Multi-Type Authentication: Basic, Digest, and Form-based authentication support
- π Authentication Verification: Advanced verification with multiple fallback methods
- β‘ Improved Error Handling: Better error messages and debugging information
- π Enhanced Logging: Detailed phase-by-phase scan progress tracking
- π§ͺ Debug Tools: New debug script for troubleshooting authentication issues
- debug_zap_auth.py: Comprehensive authentication debugging script
- test_scan_comparison.py: Compare passive vs active scan results
- test_auth_attacks.py: Authentication attack test cases and examples
{
"url": "http://testphp.vulnweb.com",
"engine": "zap-active",
"enable_parallel": false,
"max_workers": 1
}{
"url": "http://testphp.vulnweb.com/login.php",
"engine": "zap-active",
"auth": {
"username": "test",
"password": "test",
"login_url": "http://testphp.vulnweb.com/login.php"
},
"enable_parallel": false,
"max_workers": 1
}- π Authentication Support: Form-based authentication for ZAP scans
- β‘ Parallel Scanning: Multi-worker active scanning for improved performance
- π·οΈ Enhanced Spider: Advanced crawling with AJAX support for modern web apps
- π Detailed Statistics: Comprehensive scan metrics and performance data
- π SPA Support: AJAX spider for Single Page Applications
- βοΈ Advanced Policies: 20+ specific vulnerability detection rules
- π Enhanced Passive: Improved passive scanning with better coverage
- 40-60% faster scanning with parallel workers
- Better coverage for modern web applications
- Enhanced discovery with AJAX spider support
- Optimized resource usage with intelligent load balancing
- β Stable Authentication: Reliable authenticated scanning without API errors
- ZAP_ADVANCED_FEATURES.md - Detailed feature documentation
This project is licensed under the MIT License - see the LICENSE file for details.
We welcome contributions! Please see our contributing guidelines:
- Fork the repository
- Create feature branch:
git checkout -b feature/amazing-feature - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open Pull Request
# Clone for development
git clone <repository_url>
cd pentesting-api
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
python -m pytest tests/
# Start development server
python app/main.pyπ Happy Hunting! Stay ethical, scan responsibly.
Remember: Always obtain proper authorization before scanning any systems you don't own.