Skip to content

Commit

Permalink
#19 Manual merge of PR#19
Browse files Browse the repository at this point in the history
  • Loading branch information
nadouani committed Nov 7, 2022
1 parent e2c98a8 commit e85738b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions cortexutils/analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions cortexutils/responder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 14 additions & 9 deletions cortexutils/worker.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit e85738b

Please sign in to comment.