chg: Simplify modules activation

pull/135/head
Raphaël Vinot 2020-12-03 12:33:35 +01:00
parent cebdbefccd
commit d353463548
4 changed files with 12 additions and 13 deletions

View File

@ -17,7 +17,7 @@ from .modules import SaneJavaScript
class Context(): class Context():
def __init__(self, sanejs: Optional[SaneJavaScript] = None): def __init__(self, sanejs: SaneJavaScript):
self.logger = logging.getLogger(f'{self.__class__.__name__}') self.logger = logging.getLogger(f'{self.__class__.__name__}')
self.logger.setLevel(get_config('generic', 'loglevel')) self.logger.setLevel(get_config('generic', 'loglevel'))
self.redis: Redis = Redis(unix_socket_path=get_socket_path('indexing'), db=1, decode_responses=True) self.redis: Redis = Redis(unix_socket_path=get_socket_path('indexing'), db=1, decode_responses=True)
@ -102,7 +102,7 @@ class Context():
if not to_lookup: if not to_lookup:
return known_content_table return known_content_table
if to_lookup and self.sanejs and self.sanejs.available: if to_lookup and self.sanejs.available:
# Query sanejs on the remaining ones # Query sanejs on the remaining ones
try: try:
for h, entry in self.sanejs.hashes_lookup(to_lookup).items(): for h, entry in self.sanejs.hashes_lookup(to_lookup).items():

View File

@ -70,10 +70,7 @@ class Lookyloo():
if not self.sanejs.available: if not self.sanejs.available:
self.logger.warning('Unable to setup the SaneJS module') self.logger.warning('Unable to setup the SaneJS module')
if hasattr(self, 'sanejs') and self.sanejs.available:
self.context = Context(self.sanejs) self.context = Context(self.sanejs)
else:
self.context = Context()
if not self.redis.exists('cache_loaded'): if not self.redis.exists('cache_loaded'):
self._init_existing_dumps() self._init_existing_dumps()
@ -329,14 +326,14 @@ class Lookyloo():
self.logger.warning(f'Unable to trigger the modules unless the tree ({capture_dir}) is cached.') self.logger.warning(f'Unable to trigger the modules unless the tree ({capture_dir}) is cached.')
return return
if hasattr(self, 'pi') and self.pi.available: if self.pi.available:
if ct.redirects: if ct.redirects:
for redirect in ct.redirects: for redirect in ct.redirects:
self.pi.url_lookup(redirect, force) self.pi.url_lookup(redirect, force)
else: else:
self.pi.url_lookup(ct.root_hartree.har.root_url, force) self.pi.url_lookup(ct.root_hartree.har.root_url, force)
if hasattr(self, 'vt') and self.vt.available: if self.vt.available:
if ct.redirects: if ct.redirects:
for redirect in ct.redirects: for redirect in ct.redirects:
self.vt.url_lookup(redirect, force) self.vt.url_lookup(redirect, force)
@ -352,14 +349,14 @@ class Lookyloo():
self.logger.warning(f'Unable to get the modules responses unless the tree ({capture_dir}) is cached.') self.logger.warning(f'Unable to get the modules responses unless the tree ({capture_dir}) is cached.')
return None return None
to_return: Dict[str, Any] = {} to_return: Dict[str, Any] = {}
if hasattr(self, 'vt') and self.vt.available: if self.vt.available:
to_return['vt'] = {} to_return['vt'] = {}
if ct.redirects: if ct.redirects:
for redirect in ct.redirects: for redirect in ct.redirects:
to_return['vt'][redirect] = self.vt.get_url_lookup(redirect) to_return['vt'][redirect] = self.vt.get_url_lookup(redirect)
else: else:
to_return['vt'][ct.root_hartree.har.root_url] = self.vt.get_url_lookup(ct.root_hartree.har.root_url) to_return['vt'][ct.root_hartree.har.root_url] = self.vt.get_url_lookup(ct.root_hartree.har.root_url)
if hasattr(self, 'pi') and self.pi.available: if self.pi.available:
to_return['pi'] = {} to_return['pi'] = {}
if ct.redirects: if ct.redirects:
for redirect in ct.redirects: for redirect in ct.redirects:

View File

@ -20,7 +20,7 @@ from pyeupi import PyEUPI
class SaneJavaScript(): class SaneJavaScript():
def __init__(self, config: Dict[str, Any]): def __init__(self, config: Dict[str, Any]):
if not ('enabled' in config or config['enabled']): if not config.get('enabled'):
self.available = False self.available = False
return return
self.client = SaneJS() self.client = SaneJS()
@ -85,7 +85,7 @@ class SaneJavaScript():
class PhishingInitiative(): class PhishingInitiative():
def __init__(self, config: Dict[str, Any]): def __init__(self, config: Dict[str, Any]):
if 'apikey' not in config or config['apikey'] is None: if not config.get('apikey'):
self.available = False self.available = False
return return
@ -158,7 +158,7 @@ class PhishingInitiative():
class VirusTotal(): class VirusTotal():
def __init__(self, config: Dict[str, Any]): def __init__(self, config: Dict[str, Any]):
if 'apikey' not in config or config['apikey'] is None: if not config.get('apikey'):
self.available = False self.available = False
return return

View File

@ -237,6 +237,8 @@ def modules(tree_uuid: str):
vt = modules_responses.pop('vt') vt = modules_responses.pop('vt')
# Get malicious entries # Get malicious entries
for url, full_report in vt.items(): for url, full_report in vt.items():
if not full_report:
continue
vt_short_result[url] = { vt_short_result[url] = {
'permaurl': f'https://www.virustotal.com/gui/url/{full_report["id"]}/detection', 'permaurl': f'https://www.virustotal.com/gui/url/{full_report["id"]}/detection',
'malicious': [] 'malicious': []