Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /examples /exploit_validator_example.py
| #!/usr/bin/env python3 | |
| """ | |
| Exploit Validator Beispiel-Usage | |
| Demonstriert die Verwendung des Exploit Validators mit: | |
| - Sandboxed Execution (Docker-in-Docker / gVisor) | |
| - Evidence Collection (Screenshots, Video) | |
| - Remediation Generation | |
| - CVSS Score Update | |
| ⚠️ LEGAL WARNING: Only test against systems you own or have EXPLICIT | |
| written permission to test! | |
| """ | |
| import sys | |
| sys.path.insert(0, "/home/user/Zen-Ai-Pentest") | |
| from autonomous.exploit_validator import ( | |
| ExploitType, | |
| ExploitValidator, | |
| ExploitValidatorPool, | |
| SafetyLevel, | |
| ScopeConfig, | |
| validate_exploit, | |
| ) | |
| async def example_basic_usage(): | |
| """Beispiel: Grundlegende Verwendung des Exploit Validators.""" | |
| print("=" * 60) | |
| print("Beispiel 1: Grundlegende Validierung") | |
| print("=" * 60) | |
| # Validator mit erweiterter Sandbox initialisieren | |
| validator = ExploitValidator( | |
| safety_level=SafetyLevel.CONTROLLED, | |
| use_advanced_sandbox=True, | |
| sandbox_runtime="docker_dind", # Docker-in-Docker | |
| output_dir="/tmp/evidence", # nosec B108 | |
| ) | |
| await validator.initialize() | |
| # Exploit-Code (Beispiel: SQL Injection Test) | |
| exploit_code = """ | |
| import requests | |
| import sys | |
| # Teste SQL Injection | |
| test_payload = "' OR '1'='1" | |
| response = requests.get( | |
| "http://testphp.vulnweb.com/listproducts.php", | |
| params={"cat": test_payload}, | |
| timeout=10 | |
| ) | |
| # Prüfe auf SQL Error in Response | |
| if "mysql" in response.text.lower() or "syntax" in response.text.lower(): | |
| print("SQL Injection vulnerability detected!") | |
| sys.exit(0) | |
| else: | |
| print("No SQL injection detected") | |
| sys.exit(1) | |
| """ | |
| try: | |
| result = await validator.validate( | |
| cve_id="CVE-2024-TEST-001", | |
| target="http://testphp.vulnweb.com/listproducts.php", | |
| exploit_code=exploit_code, | |
| exploit_type=ExploitType.WEB_SQLI, | |
| timeout=30, | |
| cvss_score=7.5, | |
| capture_video=False, | |
| auto_remediate=True, | |
| ) | |
| print(f"\n✅ Exploit Status: {result.status.name}") | |
| print(f"✅ Exploited: {result.success}") | |
| print(f"✅ Execution Time: {result.execution_time:.2f}s") | |
| print(f"✅ CVSS Score: {result.cvss_score}") | |
| if result.cvss_score_after_fix: | |
| print(f"✅ CVSS After Fix: {result.cvss_score_after_fix}") | |
| if result.remediation: | |
| print("\n📝 Remediation Code Generated:") | |
| print("-" * 40) | |
| print(result.remediation[:500] + "..." if len(result.remediation) > 500 else result.remediation) | |
| if result.evidence.screenshots: | |
| print(f"\n📸 Screenshots: {len(result.evidence.screenshots)}") | |
| for screenshot in result.evidence.screenshots: | |
| print(f" - {screenshot}") | |
| finally: | |
| await validator.sandbox.cleanup_all() | |
| async def example_with_pool(): | |
| """Beispiel: Verwendung mit Validator Pool für parallele Ausführung.""" | |
| print("\n" + "=" * 60) | |
| print("Beispiel 2: Parallele Validierung mit Pool") | |
| print("=" * 60) | |
| # Pool mit 3 Validatoren | |
| pool = ExploitValidatorPool( | |
| pool_size=3, | |
| safety_level=SafetyLevel.CONTROLLED, | |
| scope_config=ScopeConfig(allowed_hosts=["scanme.nmap.org", "testphp.vulnweb.com"]), | |
| use_advanced_sandbox=True, | |
| ) | |
| await pool.initialize() | |
| # Mehrere Exploits definieren | |
| exploits = [ | |
| { | |
| "code": """ | |
| import requests | |
| response = requests.get("http://scanme.nmap.org", timeout=10) | |
| print(f"Status: {response.status_code}") | |
| """, | |
| "target": "http://scanme.nmap.org", | |
| "type": "service", | |
| "parameters": {}, | |
| }, | |
| { | |
| "code": """ | |
| import requests | |
| response = requests.get("http://testphp.vulnweb.com", timeout=10) | |
| print(f"Status: {response.status_code}") | |
| """, | |
| "target": "http://testphp.vulnweb.com", | |
| "type": "web_xss", | |
| "parameters": {}, | |
| }, | |
| ] | |
| # Parallele Ausführung | |
| results = await pool.submit_batch(exploits, auto_remediate=False) | |
| for i, result in enumerate(results): | |
| print(f"\n Exploit {i + 1}:") | |
| print(f" Status: {result.status.name}") | |
| print(f" Success: {result.success}") | |
| print(f" Target: {result.target}") | |
| stats = pool.get_stats() | |
| print(f"\n📊 Pool Statistics: {stats}") | |
| async def example_convenience_function(): | |
| """Beispiel: Verwendung der Convenience-Funktion.""" | |
| print("\n" + "=" * 60) | |
| print("Beispiel 3: Convenience-Funktion validate_exploit()") | |
| print("=" * 60) | |
| # Einfache Einzeiler-Validierung | |
| result = await validate_exploit( | |
| cve_id="CVE-2024-1234", | |
| target="http://scanme.nmap.org", | |
| exploit_code=""" | |
| import requests | |
| response = requests.get("http://scanme.nmap.org", timeout=10) | |
| print(f"Scan successful: {response.status_code}") | |
| """, | |
| timeout=30, | |
| sandbox=True, | |
| auto_remediate=True, | |
| ) | |
| print("\n✅ Result:") | |
| print(f" Status: {result.status.name}") | |
| print(f" Exploited: {result.success}") | |
| print(f" CVSS: {result.cvss_score}") | |
| if result.remediation_result: | |
| rr = result.remediation_result | |
| print("\n🛠️ Remediation:") | |
| print(f" Original CVSS: {rr.original_cvss}") | |
| print(f" Remediated CVSS: {rr.remediated_cvss}") | |
| print(f" Risk Before: {rr.risk_level_before}") | |
| print(f" Risk After: {rr.risk_level_after}") | |
| print(f" Effort: {rr.estimated_effort}") | |
| print(f" Priority: {rr.priority}") | |
| async def example_gvisor_sandbox(): | |
| """Beispiel: Verwendung von gVisor für maximale Isolation.""" | |
| print("\n" + "=" * 60) | |
| print("Beispiel 4: gVisor Sandbox (maximale Isolation)") | |
| print("=" * 60) | |
| from guardrails.sandbox import SandboxRuntime | |
| validator = ExploitValidator( | |
| safety_level=SafetyLevel.CONTROLLED, | |
| use_advanced_sandbox=True, | |
| sandbox_runtime=SandboxRuntime.GVISOR, # gVisor Runtime | |
| ) | |
| await validator.initialize() | |
| result = await validator.validate( | |
| cve_id="CVE-2024-TEST-002", | |
| target="http://scanme.nmap.org", | |
| exploit_code=""" | |
| import os | |
| print(f"Running in isolated environment") | |
| print(f"Process ID: {os.getpid()}") | |
| """, | |
| exploit_type=ExploitType.SERVICE, | |
| timeout=30, | |
| ) | |
| print("\n✅ gVisor Execution:") | |
| print(f" Status: {result.status.name}") | |
| print(f" Success: {result.success}") | |
| if result.sandbox_result: | |
| print("\n📦 Sandbox Details:") | |
| print(f" Execution Time: {result.sandbox_result.execution_time:.2f}s") | |
| print(f" Resource Usage: {result.sandbox_result.resource_usage}") | |
| await validator.sandbox.cleanup_all() | |
| async def main(): | |
| """Hauptfunktion mit allen Beispielen.""" | |
| print(""" | |
| ╔══════════════════════════════════════════════════════════════╗ | |
| ║ Zen AI Pentest - Exploit Validator Demo ║ | |
| ╚══════════════════════════════════════════════════════════════╝ | |
| ⚠️ WARNUNG: Diese Beispiele verwenden nur autorisierte Test-Ziele | |
| (scanme.nmap.org, testphp.vulnweb.com) | |
| """) | |
| try: | |
| # Beispiel 1: Grundlegende Verwendung | |
| # await example_basic_usage() | |
| # Beispiel 2: Pool | |
| # await example_with_pool() | |
| # Beispiel 3: Convenience-Funktion | |
| await example_convenience_function() | |
| # Beispiel 4: gVisor | |
| # await example_gvisor_sandbox() | |
| except Exception as e: | |
| print(f"\n❌ Fehler: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| print("\n" + "=" * 60) | |
| print("Demo abgeschlossen!") | |
| print("=" * 60) | |
| if __name__ == "__main__": | |
| # Nur Syntax-Check durchführen | |
| print("Syntax-Check erfolgreich!") | |
| print("\nDateien erstellt:") | |
| print(" - guardrails/sandbox.py") | |
| print(" - autonomous/evidence_collector.py") | |
| print(" - autonomous/exploit_validator.py (erweitert)") | |
| print(" - examples/exploit_validator_example.py") | |
| # Für tatsächliche Ausführung (benötigt Docker): | |
| # asyncio.run(main()) | |
Xet Storage Details
- Size:
- 8.35 kB
- Xet hash:
- 431d9c45d75bd36e34c0f96a115f4e59056769c2c82018fd22736bed1925b4a1
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.