mirror of
https://github.com/ziirish/burp-ui.git
synced 2026-05-21 06:45:24 -06:00
add: new audit logging system (see #260 for details)
This commit is contained in:
parent
bb5ddcf2d9
commit
8dcc431a91
12 changed files with 368 additions and 15 deletions
70
burpui/misc/audit/handler.py
Normal file
70
burpui/misc/audit/handler.py
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
# -*- coding: utf8 -*-
|
||||
import os
|
||||
|
||||
from .interface import BUIaudit, BUIauditLogger as BUIauditLoggerInterface
|
||||
|
||||
from importlib import import_module
|
||||
from collections import OrderedDict
|
||||
|
||||
|
||||
class BUIauditLoader(BUIaudit):
|
||||
"""See :class:`burpui.misc.audit.interface.BUIaudit`"""
|
||||
def __init__(self, app=None):
|
||||
"""See :func:`burpui.misc.audit.interface.BUIaudit.__init__`
|
||||
|
||||
:param app: Instance of the app we are running in
|
||||
:type app: :class:`burpui.engines.server.BUIServer`
|
||||
"""
|
||||
self.app = app
|
||||
backends = []
|
||||
self.errors = {}
|
||||
if self.app.audit_backends and 'none' not in self.app.audit_backends:
|
||||
me, _ = os.path.splitext(os.path.basename(__file__))
|
||||
back = self.app.audit_backends
|
||||
for au in back:
|
||||
if au == me:
|
||||
self.app.logger.critical('Recursive import not permitted!')
|
||||
continue
|
||||
try:
|
||||
(modpath, _) = __name__.rsplit('.', 1)
|
||||
mod = import_module('.' + au, modpath)
|
||||
obj = mod.BUIauditLoader(self.app)
|
||||
backends.append(obj)
|
||||
except:
|
||||
import traceback
|
||||
self.errors[au] = traceback.format_exc()
|
||||
for name, plugin in self.app.plugin_manager.get_plugins_by_type('audit').items():
|
||||
try:
|
||||
obj = plugin.BUIauditLoader(self.app)
|
||||
backends.append(obj)
|
||||
except:
|
||||
import traceback
|
||||
self.errors[name] = traceback.format_exc()
|
||||
backends.sort(key=lambda x: getattr(x, 'priority', -1), reverse=True)
|
||||
if not backends and self.app.audit_backends and 'none' not in self.app.audit_backends:
|
||||
raise ImportError(
|
||||
'No backend found for \'{}\':\n{}'.format(self.app.audit_backends,
|
||||
self.errors)
|
||||
)
|
||||
for name, err in self.errors.items():
|
||||
self.app.logger.error(
|
||||
'Unable to load module {}:\n{}'.format(repr(name), err)
|
||||
)
|
||||
self.backends = OrderedDict()
|
||||
for obj in backends:
|
||||
self.backends[obj.name] = obj
|
||||
self._logger = BUIauditLogger(self)
|
||||
|
||||
@property
|
||||
def logger(self):
|
||||
return self._logger
|
||||
|
||||
|
||||
class BUIauditLogger(BUIauditLoggerInterface):
|
||||
|
||||
def __init__(self, loader):
|
||||
self.loader = loader
|
||||
|
||||
def log(self, level, message, *args, **kwargs):
|
||||
for back in self.loader.backends.values():
|
||||
back.logger.log(level, message, *args, **kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue