mirror of
https://github.com/infinition/Bjorn.git
synced 2026-03-19 10:10:24 +00:00
feat: Add login page with dynamic RGB effects and password toggle functionality
feat: Implement package management utilities with JSON endpoints for listing and uninstalling packages feat: Create plugin management utilities with endpoints for listing, configuring, and installing plugins feat: Develop schedule and trigger management utilities with CRUD operations for schedules and triggers
This commit is contained in:
69
plugins/example_notifier/example_notifier.py
Normal file
69
plugins/example_notifier/example_notifier.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""example_notifier.py - Example Bjorn plugin that logs events to the console.
|
||||
|
||||
This plugin demonstrates how to:
|
||||
- Extend BjornPlugin
|
||||
- Use config values from plugin.json config_schema
|
||||
- Subscribe to hooks (on_credential_found, on_vulnerability_found, etc.)
|
||||
- Use the PluginLogger for namespaced logging
|
||||
- Access the database via self.db
|
||||
|
||||
Copy this directory as a starting point for your own plugin!
|
||||
"""
|
||||
|
||||
from bjorn_plugin import BjornPlugin
|
||||
|
||||
|
||||
class ExampleNotifier(BjornPlugin):
|
||||
"""Logs security events to the Bjorn console."""
|
||||
|
||||
def setup(self):
|
||||
"""Called once when the plugin is loaded."""
|
||||
self.prefix = self.config.get("custom_prefix", "ALERT")
|
||||
self.log.info(f"Example Notifier ready (prefix={self.prefix})")
|
||||
|
||||
def teardown(self):
|
||||
"""Called when the plugin is unloaded."""
|
||||
self.log.info("Example Notifier stopped")
|
||||
|
||||
# ── Hook implementations ─────────────────────────────────────────
|
||||
|
||||
def on_host_discovered(self, host):
|
||||
"""Fired when a new host appears on the network."""
|
||||
mac = host.get("mac_address", "?")
|
||||
ips = host.get("ips", "?")
|
||||
self.log.info(f"[{self.prefix}] New host: {mac} ({ips})")
|
||||
|
||||
def on_credential_found(self, cred):
|
||||
"""Fired when a new credential is stored in the DB."""
|
||||
if not self.config.get("log_credentials", True):
|
||||
return
|
||||
|
||||
service = cred.get("service", "?")
|
||||
user = cred.get("user", "?")
|
||||
ip = cred.get("ip", "?")
|
||||
self.log.success(
|
||||
f"[{self.prefix}] Credential found! {service}://{user}@{ip}"
|
||||
)
|
||||
|
||||
def on_vulnerability_found(self, vuln):
|
||||
"""Fired when a new vulnerability is recorded."""
|
||||
if not self.config.get("log_vulnerabilities", True):
|
||||
return
|
||||
|
||||
cve = vuln.get("cve_id", "?")
|
||||
ip = vuln.get("ip", "?")
|
||||
severity = vuln.get("severity", "?")
|
||||
self.log.warning(
|
||||
f"[{self.prefix}] Vulnerability: {cve} on {ip} (severity={severity})"
|
||||
)
|
||||
|
||||
def on_action_complete(self, action_name, success, target):
|
||||
"""Fired after any orchestrated action finishes."""
|
||||
if not self.config.get("log_actions", False):
|
||||
return
|
||||
|
||||
status = "SUCCESS" if success else "FAILED"
|
||||
ip = target.get("ip", "?")
|
||||
self.log.info(
|
||||
f"[{self.prefix}] Action {action_name} {status} on {ip}"
|
||||
)
|
||||
52
plugins/example_notifier/plugin.json
Normal file
52
plugins/example_notifier/plugin.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"id": "example_notifier",
|
||||
"name": "Example Notifier",
|
||||
"description": "Logs events to console when credentials or vulnerabilities are found. Use as a template for building your own plugins.",
|
||||
"author": "Bjorn Team",
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"type": "notifier",
|
||||
"main": "example_notifier.py",
|
||||
"class": "ExampleNotifier",
|
||||
"tags": ["example", "template", "notifier"],
|
||||
|
||||
"config_schema": {
|
||||
"log_credentials": {
|
||||
"type": "boolean",
|
||||
"label": "Log new credentials",
|
||||
"default": true,
|
||||
"help": "Log to console when new credentials are discovered"
|
||||
},
|
||||
"log_vulnerabilities": {
|
||||
"type": "boolean",
|
||||
"label": "Log new vulnerabilities",
|
||||
"default": true,
|
||||
"help": "Log to console when new vulnerabilities are found"
|
||||
},
|
||||
"log_actions": {
|
||||
"type": "boolean",
|
||||
"label": "Log action completions",
|
||||
"default": false,
|
||||
"help": "Log every action result (can be noisy)"
|
||||
},
|
||||
"custom_prefix": {
|
||||
"type": "string",
|
||||
"label": "Log prefix",
|
||||
"default": "ALERT",
|
||||
"help": "Custom prefix for log messages"
|
||||
}
|
||||
},
|
||||
|
||||
"hooks": [
|
||||
"on_credential_found",
|
||||
"on_vulnerability_found",
|
||||
"on_action_complete",
|
||||
"on_host_discovered"
|
||||
],
|
||||
|
||||
"requires": {
|
||||
"pip": [],
|
||||
"system": [],
|
||||
"bjorn_min_version": "1.0.0"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user