Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /cli /examples /plugins /example_plugin.py
| """Example plugin for Kimi Pentest CLI. | |
| This plugin demonstrates how to create custom plugins for the Kimi Pentest framework. | |
| """ | |
| from kimi_pentest.plugins import Plugin, PluginContext, PluginHook | |
| class ExamplePlugin(Plugin): | |
| """Example plugin that logs scan activities.""" | |
| # Plugin metadata | |
| name = "example-plugin" | |
| version = "1.0.0" | |
| description = "Example plugin that logs scan activities" | |
| author = "Kimi Pentest Team" | |
| # Hooks this plugin listens to | |
| hooks = [ | |
| PluginHook.PRE_SCAN, | |
| PluginHook.POST_SCAN, | |
| PluginHook.VULNERABILITY_FOUND, | |
| ] | |
| def initialize(self) -> bool: | |
| """Initialize the plugin.""" | |
| print(f"[{self.name}] Plugin initialized") | |
| # Load configuration | |
| self.log_file = self.get_config("log_file", "/tmp/kimi-pentest-plugin.log") # nosec B108 | |
| self.verbose = self.get_config("verbose", False) | |
| return True | |
| def shutdown(self): | |
| """Shutdown the plugin.""" | |
| print(f"[{self.name}] Plugin shutting down") | |
| def on_pre_scan(self, context: PluginContext): | |
| """Called before a scan starts.""" | |
| target = context.get("target", "unknown") | |
| scan_type = context.get("scan_type", "unknown") | |
| self._log(f"Starting scan: {scan_type} on {target}") | |
| # Can modify context | |
| context.set("plugin_notified", True) | |
| def on_post_scan(self, context: PluginContext): | |
| """Called after a scan completes.""" | |
| scan_id = context.get("scan_id", "unknown") | |
| status = context.get("status", "unknown") | |
| vuln_count = context.get("vulnerability_count", 0) | |
| self._log(f"Scan {scan_id} completed with status: {status}") | |
| self._log(f"Vulnerabilities found: {vuln_count}") | |
| def on_vulnerability_found(self, context: PluginContext): | |
| """Called when a vulnerability is found.""" | |
| vuln = context.get("vulnerability", {}) | |
| name = vuln.get("name", "unknown") | |
| severity = vuln.get("severity", "unknown") | |
| self._log(f"Vulnerability found: {name} ({severity})") | |
| # Can add custom data to the vulnerability | |
| vuln["plugin_data"] = { | |
| "logged_by": self.name, | |
| "logged_at": "timestamp", | |
| } | |
| def _log(self, message: str): | |
| """Log a message.""" | |
| import datetime | |
| timestamp = datetime.datetime.now().isoformat() | |
| log_line = f"[{timestamp}] {message}\n" | |
| # Write to log file | |
| with open(self.log_file, "a") as f: | |
| f.write(log_line) | |
| if self.verbose: | |
| print(f"[{self.name}] {message}") | |
| class NotificationPlugin(Plugin): | |
| """Plugin that sends notifications on important events.""" | |
| name = "notification-plugin" | |
| version = "1.0.0" | |
| description = "Sends notifications on scan completion and critical vulnerabilities" | |
| author = "Kimi Pentest Team" | |
| hooks = [ | |
| PluginHook.POST_SCAN, | |
| PluginHook.VULNERABILITY_FOUND, | |
| ] | |
| def initialize(self) -> bool: | |
| """Initialize the plugin.""" | |
| self.webhook_url = self.get_config("webhook_url") | |
| self.notify_on_critical = self.get_config("notify_on_critical", True) | |
| self.notify_on_high = self.get_config("notify_on_high", True) | |
| return True | |
| def shutdown(self): | |
| """Shutdown the plugin.""" | |
| pass | |
| def on_post_scan(self, context: PluginContext): | |
| """Send notification when scan completes.""" | |
| if not self.webhook_url: | |
| return | |
| import requests | |
| scan_id = context.get("scan_id") | |
| status = context.get("status") | |
| try: | |
| requests.post( | |
| self.webhook_url, | |
| json={ | |
| "event": "scan_completed", | |
| "scan_id": scan_id, | |
| "status": status, | |
| }, | |
| timeout=10, | |
| ) | |
| except Exception as e: | |
| print(f"[{self.name}] Failed to send notification: {e}") | |
| def on_vulnerability_found(self, context: PluginContext): | |
| """Send notification for critical/high vulnerabilities.""" | |
| if not self.webhook_url: | |
| return | |
| vuln = context.get("vulnerability", {}) | |
| severity = vuln.get("severity", "") | |
| if severity == "critical" and self.notify_on_critical: | |
| self._send_notification("critical_vulnerability", vuln) | |
| elif severity == "high" and self.notify_on_high: | |
| self._send_notification("high_vulnerability", vuln) | |
| def _send_notification(self, event_type: str, data: dict): | |
| """Send a notification.""" | |
| import requests | |
| try: | |
| requests.post( | |
| self.webhook_url, | |
| json={ | |
| "event": event_type, | |
| "data": data, | |
| }, | |
| timeout=10, | |
| ) | |
| except Exception as e: | |
| print(f"[{self.name}] Failed to send notification: {e}") | |
Xet Storage Details
- Size:
- 5 kB
- Xet hash:
- ef1bc49950236b879a1d8006174781eae2f93904ac2cad394a284841e7d48034
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.