Buckets:

download
raw
8.92 kB
#!/usr/bin/env python3
"""
Exploit Validator Demo
Demonstrates the usage of the ExploitValidator system for:
- Validating SQL injection vulnerabilities
- Validating XSS vulnerabilities
- Capturing evidence (screenshots, HTTP responses)
- Using the validator pool for concurrent validation
FOR AUTHORIZED SECURITY TESTING ONLY
"""
import asyncio
import json
# Import the ExploitValidator system
import sys
sys.path.insert(0, "C:\\Users\\Ataka\\zen-ai-pentest")
from autonomous import (
ExploitType,
ExploitValidator,
ExploitValidatorPool,
SafetyLevel,
ScopeConfig,
)
async def demo_basic_validation():
"""Demo: Basic exploit validation."""
print("=" * 60)
print("Demo 1: Basic Exploit Validation")
print("=" * 60)
# Create validator with controlled safety level
validator = ExploitValidator(
safety_level=SafetyLevel.CONTROLLED,
enable_playwright=False, # Disable for demo
)
# Define a simple test exploit
exploit_code = """
import requests
import sys
url = target + "/test"
try:
response = requests.get(url, timeout=10)
print(f"Status: {response.status_code}")
sys.exit(0)
except Exception as e:
print(f"Error: {e}")
sys.exit(1)
"""
# Validate against a target (will be blocked by scope by default)
result = await validator.validate(
exploit_code=exploit_code,
target="https://example.com",
exploit_type=ExploitType.WEB_SQLI,
)
print(f"Success: {result.success}")
print(f"Status: {result.status.name}")
print(f"Target: {result.target}")
print(f"Execution Time: {result.execution_time:.2f}s")
print(f"Validator ID: {result.validator_id}")
print()
async def demo_scope_configuration():
"""Demo: Configuring allowed scope."""
print("=" * 60)
print("Demo 2: Scope Configuration")
print("=" * 60)
# Create scope config with allowed hosts
scope_config = ScopeConfig(
allowed_hosts=["httpbin.org", "*.httpbin.org"],
allowed_ports=[80, 443],
blocked_hosts=["localhost", "127.0.0.1"],
)
# Create validator with custom scope
_ = ExploitValidator(
safety_level=SafetyLevel.CONTROLLED,
scope_config=scope_config,
enable_playwright=False,
)
# Test various targets
test_targets = [
"https://httpbin.org/get", # Should be allowed
"http://localhost:8080", # Should be blocked
"https://example.com", # Not in allowed list
]
for target in test_targets:
is_valid, error = scope_config.validate_target(target)
status = "[OK] ALLOWED" if is_valid else "[X] BLOCKED"
print(f"{status}: {target}")
if error:
print(f" Reason: {error}")
print()
async def demo_safety_levels():
"""Demo: Different safety levels."""
print("=" * 60)
print("Demo 3: Safety Levels")
print("=" * 60)
safety_levels = [
(SafetyLevel.READ_ONLY, "No exploits allowed"),
(SafetyLevel.VALIDATE_ONLY, "Validation only, no execution"),
(SafetyLevel.CONTROLLED, "Controlled execution"),
(SafetyLevel.FULL, "Full exploitation"),
]
for level, description in safety_levels:
validator = ExploitValidator(safety_level=level)
# Check which exploit types are allowed
web_sqli_allowed = validator._is_safety_compatible(ExploitType.WEB_SQLI)
privesc_allowed = validator._is_safety_compatible(ExploitType.PRIVESC)
print(f"{level.name}:")
print(f" Description: {description}")
print(f" Web SQLi: {'[OK]' if web_sqli_allowed else '[NO]'}")
print(f" Privilege Escalation: {'[OK]' if privesc_allowed else '[NO]'}")
print()
async def demo_evidence_collection():
"""Demo: Evidence collection capabilities."""
print("=" * 60)
print("Demo 4: Evidence Collection")
print("=" * 60)
validator = ExploitValidator(
safety_level=SafetyLevel.CONTROLLED,
enable_playwright=False, # Would require browser installation
)
# Capture evidence for a web target
evidence = await validator.capture_evidence(
target="https://httpbin.org/get",
exploit_type=ExploitType.WEB_SQLI,
capture_screenshot=False, # Disable for demo
capture_http=True,
capture_pcap=False,
)
print(f"Screenshots: {len(evidence.screenshots)}")
print(f"HTTP Responses: {len(evidence.http_responses)}")
print(f"PCAP File: {evidence.pcap_file}")
print(f"Metadata: {json.dumps(evidence.metadata, indent=2, default=str)[:200]}...")
print()
async def demo_remediation_generation():
"""Demo: Generating remediation advice."""
print("=" * 60)
print("Demo 5: Remediation Generation")
print("=" * 60)
validator = ExploitValidator()
vulnerabilities = [
{"type": "web_sqli", "severity": "high"},
{"type": "web_xss", "severity": "medium"},
{"type": "web_rce", "severity": "critical"},
{"type": "unknown_vuln", "severity": "low"}, # Default template
]
for vuln in vulnerabilities:
remediation = validator.generate_remediation(vuln)
print(f"\n{vuln['type'].upper()} ({vuln['severity']}):")
print("-" * 40)
print(remediation[:300] + "...")
print()
async def demo_validator_pool():
"""Demo: Using validator pool for concurrent execution."""
print("=" * 60)
print("Demo 6: Validator Pool")
print("=" * 60)
# Create pool with 2 validators
pool = ExploitValidatorPool(
pool_size=2,
safety_level=SafetyLevel.CONTROLLED,
scope_config=ScopeConfig(allowed_hosts=["httpbin.org"]),
)
await pool.initialize()
# Create multiple exploit tasks
exploits = [
{
"code": 'print("Exploit 1")',
"target": "https://httpbin.org/get",
"type": "web_sqli",
},
{
"code": 'print("Exploit 2")',
"target": "https://httpbin.org/post",
"type": "web_xss",
},
{
"code": 'print("Exploit 3")',
"target": "https://httpbin.org/headers",
"type": "web_rce",
},
]
print(f"Submitting {len(exploits)} exploits to pool...")
results = await pool.submit_batch(exploits)
print(f"Completed: {len(results)} validations")
print(f"Pool Stats: {pool.get_stats()}")
print()
async def demo_helper_functions():
"""Demo: Using helper functions for common exploits."""
print("=" * 60)
print("Demo 7: Helper Functions")
print("=" * 60)
# Note: These would actually run against a target in real usage
# For demo, we just show the generated exploit code structure
print("SQL Injection Validator:")
print(" - Generates payloads for SQLi detection")
print(" - Checks for SQL error messages")
print(" - Validates time-based injection")
print()
print("XSS Validator:")
print(" - Tests payload reflection")
print(" - Supports various contexts (HTML, JS, URL)")
print(" - Can capture screenshots of execution")
print()
print("Command Injection Validator:")
print(" - Tests command execution")
print(" - Supports blind injection detection")
print(" - Uses timing-based validation")
print()
async def demo_chain_of_custody():
"""Demo: Chain of custody for evidence."""
print("=" * 60)
print("Demo 8: Chain of Custody")
print("=" * 60)
validator = ExploitValidator(safety_level=SafetyLevel.CONTROLLED, enable_playwright=False)
# Execute an exploit
result = await validator.validate(
exploit_code="print('test')",
target="https://example.com",
exploit_type=ExploitType.WEB_SQLI,
)
print(f"Validator ID: {result.validator_id}")
print(f"Timestamp: {result.timestamp.isoformat()}")
print("\nChain of Custody:")
for entry in result.chain_of_custody:
print(f" - {entry['action']} at {entry.get('timestamp', 'N/A')}")
if "hash" in entry:
print(f" Hash: {entry['hash']}")
print()
async def main():
"""Run all demos."""
print("\n" + "=" * 60)
print("ZEN AI PENTEST - Exploit Validator Demo")
print("FOR AUTHORIZED SECURITY TESTING ONLY")
print("=" * 60 + "\n")
try:
await demo_basic_validation()
await demo_scope_configuration()
await demo_safety_levels()
await demo_evidence_collection()
await demo_remediation_generation()
await demo_validator_pool()
await demo_helper_functions()
await demo_chain_of_custody()
except Exception as e:
print(f"Demo error: {e}")
import traceback
traceback.print_exc()
print("=" * 60)
print("Demo completed!")
print("=" * 60)
if __name__ == "__main__":
asyncio.run(main())

Xet Storage Details

Size:
8.92 kB
·
Xet hash:
c94aaafc981ff7cfac6d8b97b39e0512b9314ca01bb6b615fc34fa1935cab632

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.