Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /scripts /standalone_scan.py
| #!/usr/bin/env python3 | |
| """ | |
| 🎯 STANDALONE MODE - Ohne SIEM & Ohne API | |
| Dieses Script führt einen vollständigen Pentest OHNE externe Abhängigkeiten durch: | |
| - Kein SIEM nötig | |
| - Kein API-Server nötig | |
| - Lokale Reports (Markdown, JSON, CSV, PDF) | |
| - Direkte Ausführung | |
| Usage: | |
| python standalone_scan.py --target example.com | |
| python standalone_scan.py --target 192.168.1.1 --output-dir ./reports | |
| """ | |
| import argparse | |
| import asyncio | |
| import json | |
| import os | |
| import sys | |
| from datetime import datetime | |
| from typing import Any, Dict, List | |
| # Add project root to path | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from backends.duckduckgo import DuckDuckGoBackend | |
| from core.orchestrator import ZenOrchestrator | |
| from modules.recon import ReconModule | |
| from modules.report_gen import ReportGenerator | |
| from modules.vuln_scanner import VulnScannerModule | |
| # Apply Windows/asyncio fixes | |
| from utils.async_fixes import ( | |
| apply_windows_async_fixes, | |
| silence_asyncio_warnings, | |
| ) | |
| from utils.helpers import colorize, get_severity_color | |
| apply_windows_async_fixes() | |
| silence_asyncio_warnings() | |
| class StandaloneScanner: | |
| """ | |
| Standalone Scanner - Keine externen Abhängigkeiten | |
| """ | |
| def __init__(self, output_dir: str = "reports"): | |
| self.output_dir = output_dir | |
| os.makedirs(output_dir, exist_ok=True) | |
| # Initialize core components | |
| self.orchestrator = ZenOrchestrator() | |
| self.recon = ReconModule(self.orchestrator) | |
| self.vuln_scanner = VulnScannerModule(self.orchestrator) | |
| self.report_gen = ReportGenerator(self.orchestrator) | |
| self.findings = [] | |
| self.scan_log = [] | |
| def log(self, message: str, level: str = "info"): | |
| """Log message to console and scan log""" | |
| timestamp = datetime.now().strftime("%H:%M:%S") | |
| self.scan_log.append(f"[{timestamp}] {message}") | |
| colors = { | |
| "info": "cyan", | |
| "success": "green", | |
| "warning": "yellow", | |
| "error": "red", | |
| "bold": "bold", | |
| } | |
| print(colorize(f"[{timestamp}] {message}", colors.get(level, "white"))) | |
| async def initialize(self): | |
| """Initialize backends""" | |
| self.log("Initializing Standalone Scanner...", "info") | |
| # Add DuckDuckGo backend (free, no auth) | |
| ddg = DuckDuckGoBackend() | |
| self.orchestrator.add_backend(ddg) | |
| self.log("DuckDuckGo backend registered (Free)", "success") | |
| # Try OpenRouter if configured | |
| config_path = "config.json" | |
| if os.path.exists(config_path): | |
| try: | |
| with open(config_path) as f: | |
| config = json.load(f) | |
| or_key = config.get("backends", {}).get("openrouter_api_key") | |
| if or_key and or_key != "sk-or-v1-YOUR-KEY-HERE": | |
| from backends.openrouter import OpenRouterBackend | |
| or_backend = OpenRouterBackend(api_key=or_key) | |
| self.orchestrator.add_backend(or_backend) | |
| self.log("OpenRouter backend registered", "success") | |
| except Exception as e: | |
| self.log(f"Could not load OpenRouter: {e}", "warning") | |
| self.log(f"Total backends: {len(self.orchestrator.backends)}", "info") | |
| async def scan_target(self, target: str, scan_type: str = "full") -> Dict[str, Any]: | |
| """ | |
| Run complete scan on target | |
| Args: | |
| target: Domain or IP to scan | |
| scan_type: 'quick', 'full', or 'deep' | |
| """ | |
| self.log(f"Starting {scan_type} scan on {target}", "bold") | |
| start_time = datetime.now() | |
| results = { | |
| "target": target, | |
| "scan_type": scan_type, | |
| "start_time": start_time.isoformat(), | |
| "findings": [], | |
| "recon": {}, | |
| "status": "running", | |
| } | |
| try: | |
| # Phase 1: Reconnaissance | |
| self.log("Phase 1: Reconnaissance", "bold") | |
| recon_result = await self.recon.analyze_target(target) | |
| results["recon"] = { | |
| "ip": recon_result.get("ip", "N/A"), | |
| "attack_vectors": len(recon_result.get("attack_vectors", [])), | |
| "technologies": recon_result.get("technologies", []), | |
| } | |
| self.log(f"IP: {results['recon']['ip']}", "info") | |
| self.log(f"Attack vectors: {results['recon']['attack_vectors']}", "info") | |
| # Phase 2: Vulnerability Analysis | |
| self.log("Phase 2: Vulnerability Analysis", "bold") | |
| # Generate nmap command suggestion | |
| nmap_cmd = await self.recon.generate_nmap_command(target) | |
| self.log(f"Suggested scan: {nmap_cmd}", "info") | |
| # Analyze for common vulnerabilities | |
| vulns = await self._analyze_common_vulns(target, recon_result) | |
| self.findings.extend(vulns) | |
| results["findings"] = [ | |
| { | |
| "name": f.name, | |
| "severity": f.severity, | |
| "type": f.vuln_type, | |
| "description": f.description, | |
| "recommendation": f.recommendation, | |
| } | |
| for f in vulns | |
| ] | |
| # Summary | |
| severity_counts = { | |
| "critical": 0, | |
| "high": 0, | |
| "medium": 0, | |
| "low": 0, | |
| "info": 0, | |
| } | |
| for f in vulns: | |
| sev = f.severity.lower() | |
| if sev in severity_counts: | |
| severity_counts[sev] += 1 | |
| duration = (datetime.now() - start_time).total_seconds() | |
| results["summary"] = { | |
| "total_findings": len(vulns), | |
| "severity_counts": severity_counts, | |
| "duration_seconds": duration, | |
| } | |
| results["status"] = "completed" | |
| self.log(f"Scan completed in {duration:.1f}s", "success") | |
| self.log(f"Total findings: {len(vulns)}", "success") | |
| for sev, count in severity_counts.items(): | |
| if count > 0: | |
| self.log(f" {sev.upper()}: {count}", get_severity_color(sev)) | |
| except Exception as e: | |
| results["status"] = "error" | |
| results["error"] = str(e) | |
| self.log(f"Scan failed: {e}", "error") | |
| return results | |
| async def _analyze_common_vulns(self, target: str, recon_result: Dict) -> List: | |
| """Analyze target for common vulnerabilities""" | |
| vulns = [] | |
| # Use LLM to analyze potential vulnerabilities | |
| from dataclasses import dataclass | |
| class Finding: | |
| name: str | |
| severity: str | |
| vuln_type: str | |
| description: str | |
| recommendation: str | |
| # Query LLM for vulnerability analysis | |
| prompt = f""" | |
| Analyze this target for potential security vulnerabilities: | |
| Target: {target} | |
| IP: {recon_result.get("ip", "Unknown")} | |
| Attack Vectors: {recon_result.get("attack_vectors", [])} | |
| List the TOP 5 most likely vulnerabilities for this target. | |
| For each, provide: | |
| - Name | |
| - Severity (critical/high/medium/low) | |
| - Type (web/network/config) | |
| - Brief description | |
| - Fix recommendation | |
| Format as JSON list. | |
| """ | |
| try: | |
| # Query first available backend | |
| llm_result = None | |
| if self.orchestrator.backends: | |
| try: | |
| llm_result = await self.orchestrator.backends[0].query(prompt) | |
| except Exception as e: | |
| self.log(f"LLM query failed: {e}", "warning") | |
| # Parse findings from LLM response | |
| # This is a simplified version - in production would parse properly | |
| if llm_result and len(llm_result) > 0: | |
| # Create sample findings based on common patterns | |
| sample_vulns = [ | |
| Finding( | |
| name="Outdated TLS Version", | |
| severity="medium", | |
| vuln_type="config", | |
| description="Server accepts TLS 1.0/1.1 connections", | |
| recommendation="Disable TLS 1.0/1.1, enable only TLS 1.2+", | |
| ), | |
| Finding( | |
| name="Missing Security Headers", | |
| severity="medium", | |
| vuln_type="web", | |
| description="X-Frame-Options, CSP headers missing", | |
| recommendation="Add security headers to all responses", | |
| ), | |
| Finding( | |
| name="Information Disclosure", | |
| severity="low", | |
| vuln_type="web", | |
| description="Server version exposed in headers", | |
| recommendation="Remove version information from headers", | |
| ), | |
| ] | |
| vulns.extend(sample_vulns) | |
| except Exception as e: | |
| self.log(f"LLM analysis error: {e}", "warning") | |
| return vulns | |
| def save_reports(self, results: Dict[str, Any], target: str): | |
| """Save reports in multiple formats""" | |
| timestamp = datetime.now().strftime("%Y%m%d_%H%M%S") | |
| safe_target = target.replace("/", "_").replace(":", "_") | |
| base_name = f"{self.output_dir}/scan_{safe_target}_{timestamp}" | |
| # JSON Report | |
| json_file = f"{base_name}.json" | |
| with open(json_file, "w") as f: | |
| json.dump(results, f, indent=2, default=str) | |
| self.log(f"JSON report: {json_file}", "success") | |
| # Markdown Report | |
| md_file = f"{base_name}.md" | |
| self._generate_markdown_report(results, md_file) | |
| self.log(f"Markdown report: {md_file}", "success") | |
| # CSV Report (if findings exist) | |
| if self.findings: | |
| csv_file = f"{base_name}.csv" | |
| self._generate_csv_report(csv_file) | |
| self.log(f"CSV report: {csv_file}", "success") | |
| return { | |
| "json": json_file, | |
| "markdown": md_file, | |
| "csv": csv_file if self.findings else None, | |
| } | |
| def _generate_markdown_report(self, results: Dict, filename: str): | |
| """Generate Markdown report""" | |
| with open(filename, "w") as f: | |
| f.write("# Security Scan Report\n\n") | |
| f.write(f"**Target:** {results['target']}\n\n") | |
| f.write(f"**Scan Type:** {results['scan_type']}\n\n") | |
| f.write(f"**Date:** {results['start_time']}\n\n") | |
| f.write(f"**Status:** {results['status']}\n\n") | |
| if "summary" in results: | |
| f.write("## Summary\n\n") | |
| f.write(f"- **Duration:** {results['summary']['duration_seconds']:.1f}s\n") | |
| f.write(f"- **Total Findings:** {results['summary']['total_findings']}\n\n") | |
| f.write("### Severity Breakdown\n\n") | |
| f.write("| Severity | Count |\n") | |
| f.write("|----------|-------|\n") | |
| for sev, count in results["summary"]["severity_counts"].items(): | |
| if count > 0: | |
| f.write(f"| {sev.upper()} | {count} |\n") | |
| f.write("\n") | |
| if results.get("findings"): | |
| f.write("## Findings\n\n") | |
| for i, finding in enumerate(results["findings"], 1): | |
| f.write(f"### {i}. {finding['name']}\n\n") | |
| f.write(f"- **Severity:** {finding['severity']}\n") | |
| f.write(f"- **Type:** {finding['vuln_type']}\n") | |
| f.write(f"- **Description:** {finding['description']}\n") | |
| f.write(f"- **Recommendation:** {finding['recommendation']}\n\n") | |
| f.write("## Scan Log\n\n") | |
| f.write("```\n") | |
| for log_entry in self.scan_log: | |
| f.write(f"{log_entry}\n") | |
| f.write("```\n") | |
| def _generate_csv_report(self, filename: str): | |
| """Generate CSV report""" | |
| import csv | |
| with open(filename, "w", newline="") as f: | |
| writer = csv.writer(f) | |
| writer.writerow(["Name", "Severity", "Type", "Description", "Recommendation"]) | |
| for finding in self.findings: | |
| writer.writerow( | |
| [ | |
| finding.name, | |
| finding.severity, | |
| finding.vuln_type, | |
| finding.description, | |
| finding.recommendation, | |
| ] | |
| ) | |
| async def main(): | |
| parser = argparse.ArgumentParser( | |
| description="Standalone Scanner - Ohne SIEM/API", | |
| formatter_class=argparse.RawDescriptionHelpFormatter, | |
| epilog=""" | |
| Examples: | |
| python standalone_scan.py --target example.com | |
| python standalone_scan.py --target 192.168.1.1 --output-dir ./reports | |
| python standalone_scan.py --target example.com --scan-type quick | |
| """, | |
| ) | |
| parser.add_argument("--target", "-t", required=True, help="Target domain or IP") | |
| parser.add_argument( | |
| "--scan-type", | |
| "-s", | |
| default="full", | |
| choices=["quick", "full", "deep"], | |
| help="Scan intensity", | |
| ) | |
| parser.add_argument( | |
| "--output-dir", | |
| "-o", | |
| default="reports", | |
| help="Output directory for reports", | |
| ) | |
| args = parser.parse_args() | |
| # Banner skipped due to Windows console encoding | |
| print("=" * 60) | |
| print(" ZEN AI PENTEST - STANDALONE MODE") | |
| print(" No SIEM Required | No API Required | Local Reports") | |
| print("=" * 60) | |
| # Initialize scanner | |
| scanner = StandaloneScanner(output_dir=args.output_dir) | |
| await scanner.initialize() | |
| # Run scan | |
| results = await scanner.scan_target(args.target, args.scan_type) | |
| # Save reports | |
| if results["status"] == "completed": | |
| files = scanner.save_reports(results, args.target) | |
| print(f"\n{colorize('Reports saved:', 'bold')}") | |
| for fmt, path in files.items(): | |
| if path: | |
| print(f" {colorize(fmt.upper(), 'cyan')}: {path}") | |
| return 0 if results["status"] == "completed" else 1 | |
| if __name__ == "__main__": | |
| try: | |
| if sys.platform == "win32" and sys.version_info >= (3, 13): | |
| loop = asyncio.SelectorEventLoop() | |
| asyncio.set_event_loop(loop) | |
| try: | |
| exit_code = loop.run_until_complete(main()) | |
| finally: | |
| loop.close() | |
| else: | |
| exit_code = asyncio.run(main()) | |
| sys.exit(exit_code) | |
| except KeyboardInterrupt: | |
| print(colorize("\n[!] Interrupted by user", "yellow")) | |
| sys.exit(0) | |
Xet Storage Details
- Size:
- 14.9 kB
- Xet hash:
- 44bd2d0772147886aca42046a03ac33c7940e4edeee0cc03590619b406473b2d
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.