diff --git a/cortexutils/analyzer.py b/cortexutils/analyzer.py index 3ed4283..ec639c1 100644 --- a/cortexutils/analyzer.py +++ b/cortexutils/analyzer.py @@ -14,8 +14,8 @@ class Analyzer(Worker): - def __init__(self, job_directory=None): - Worker.__init__(self, job_directory) + def __init__(self, job_directory=None, secret_phrases=None): + Worker.__init__(self, job_directory, secret_phrases) # Not breaking compatibility self.artifact = self._input diff --git a/cortexutils/responder.py b/cortexutils/responder.py index 84b0fb8..21f74b9 100644 --- a/cortexutils/responder.py +++ b/cortexutils/responder.py @@ -8,8 +8,8 @@ class Responder(Worker): - def __init__(self, job_directory=None): - Worker.__init__(self, job_directory) + def __init__(self, job_directory=None, secret_phrases=None): + Worker.__init__(self, job_directory, secret_phrases) # Not breaking compatibility self.artifact = self._input diff --git a/cortexutils/worker.py b/cortexutils/worker.py index 15bf151..c5aab6a 100644 --- a/cortexutils/worker.py +++ b/cortexutils/worker.py @@ -1,23 +1,28 @@ #!/usr/bin/env python # encoding: utf-8 -import os -import sys import codecs import json +import os import select +import sys +DEFAULT_SECRET_PHRASES = ("key", "password", "secret") class Worker(object): READ_TIMEOUT = 3 # seconds - def __init__(self, job_directory): + def __init__(self, job_directory, secret_phrases): if job_directory is None: if len(sys.argv) > 1: job_directory = sys.argv[1] else: job_directory = '/job' self.job_directory = job_directory + if secret_phrases is None: + self.secret_phrases = DEFAULT_SECRET_PHRASES + else: + self.secret_phrases = secret_phrases # Load input self._input = {} if os.path.isfile('%s/input/input.json' % self.job_directory): @@ -164,13 +169,13 @@ def error(self, message, ensure_ascii=False): # Get analyzer input analyzer_input = self._input - # Define sensitive key values - secrets = ['password', 'key', 'secret'] - # Loop over all the sensitive config names and clean them - for config_key, v in analyzer_input.get('config', {}).items(): - if any(secret in config_key.lower() for secret in secrets): - analyzer_input.get('config', {})[config_key] = 'REMOVED' + for config_key in analyzer_input.get('config', {}).keys(): + if any( + secret_phrase in config_key.lower() + for secret_phrase in self.secret_phrases + ): + analyzer_input['config'][config_key] = 'REMOVED' self.__write_output({'success': False, 'input': analyzer_input, diff --git a/setup.py b/setup.py index d159def..814cf3f 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ setup( name='cortexutils', - version='2.1.0', + version='2.2.0', description='A Python library for including utility classes for Cortex analyzers and responders', long_description=open('README').read(), author='TheHive-Project',