diff --git a/lookyloo/context.py b/lookyloo/context.py index 5fb12dfd..2a03a4b8 100644 --- a/lookyloo/context.py +++ b/lookyloo/context.py @@ -17,7 +17,7 @@ from .modules import SaneJavaScript class Context(): - def __init__(self, sanejs: Optional[SaneJavaScript] = None): + def __init__(self, sanejs: SaneJavaScript): self.logger = logging.getLogger(f'{self.__class__.__name__}') self.logger.setLevel(get_config('generic', 'loglevel')) 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: 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 try: for h, entry in self.sanejs.hashes_lookup(to_lookup).items(): diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index 56852c28..ed1d64f6 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -70,10 +70,7 @@ class Lookyloo(): if not self.sanejs.available: self.logger.warning('Unable to setup the SaneJS module') - if hasattr(self, 'sanejs') and self.sanejs.available: - self.context = Context(self.sanejs) - else: - self.context = Context() + self.context = Context(self.sanejs) if not self.redis.exists('cache_loaded'): 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.') return - if hasattr(self, 'pi') and self.pi.available: + if self.pi.available: if ct.redirects: for redirect in ct.redirects: self.pi.url_lookup(redirect, force) else: 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: for redirect in ct.redirects: 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.') return None to_return: Dict[str, Any] = {} - if hasattr(self, 'vt') and self.vt.available: + if self.vt.available: to_return['vt'] = {} if ct.redirects: for redirect in ct.redirects: to_return['vt'][redirect] = self.vt.get_url_lookup(redirect) else: 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'] = {} if ct.redirects: for redirect in ct.redirects: diff --git a/lookyloo/modules.py b/lookyloo/modules.py index d4ecf28d..78969a70 100644 --- a/lookyloo/modules.py +++ b/lookyloo/modules.py @@ -20,7 +20,7 @@ from pyeupi import PyEUPI class SaneJavaScript(): def __init__(self, config: Dict[str, Any]): - if not ('enabled' in config or config['enabled']): + if not config.get('enabled'): self.available = False return self.client = SaneJS() @@ -85,7 +85,7 @@ class SaneJavaScript(): class PhishingInitiative(): 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 return @@ -158,7 +158,7 @@ class PhishingInitiative(): class VirusTotal(): 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 return diff --git a/website/web/__init__.py b/website/web/__init__.py index 03275d6c..29db86eb 100644 --- a/website/web/__init__.py +++ b/website/web/__init__.py @@ -237,6 +237,8 @@ def modules(tree_uuid: str): vt = modules_responses.pop('vt') # Get malicious entries for url, full_report in vt.items(): + if not full_report: + continue vt_short_result[url] = { 'permaurl': f'https://www.virustotal.com/gui/url/{full_report["id"]}/detection', 'malicious': []