Skip to content

Commit 561f7ff

Browse files
committed
Merge branch 'release/2.2.0'
2 parents 586a906 + 2882aa6 commit 561f7ff

File tree

5 files changed

+77
-35
lines changed

5 files changed

+77
-35
lines changed

CHANGELOG.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Change Log
2+
3+
## [2.1.0](https://github.com/TheHive-Project/cortexutils/tree/2.1.0) (2021-02-25)
4+
[Full Changelog](https://github.com/TheHive-Project/cortexutils/compare/2.0.0...2.1.0)
5+
6+
**Implemented enhancements:**
7+
8+
- API secret logging in Cortex analyzers [\#10](https://github.com/TheHive-Project/cortexutils/issues/10)
9+
10+
**Fixed bugs:**
11+
12+
- Various errors in unittests [\#17](https://github.com/TheHive-Project/cortexutils/issues/17)
13+
- \[Bug\] manage files in artifacts [\#16](https://github.com/TheHive-Project/cortexutils/issues/16)
14+
- The tests fail for the Worker Class: io.UnsupportedOperation: fileno [\#7](https://github.com/TheHive-Project/cortexutils/issues/7)
15+
16+
**Closed issues:**
17+
18+
- Trying to add a binary file as observable from analyzer returns error [\#14](https://github.com/TheHive-Project/cortexutils/issues/14)
19+
- diagnostic output is not valid JSON [\#6](https://github.com/TheHive-Project/cortexutils/issues/6)
20+
21+
**Merged pull requests:**
22+
23+
- file attachment must be managed as binary [\#15](https://github.com/TheHive-Project/cortexutils/pull/15) ([dadokkio](https://github.com/dadokkio))
24+
25+
## [2.0.0](https://github.com/TheHive-Project/cortexutils/tree/2.0.0) (2019-04-04)
26+
**Implemented enhancements:**
27+
28+
- Deduplicate extracted artifacts from a job report [\#3](https://github.com/TheHive-Project/cortexutils/issues/3)
29+
30+
31+
32+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*

cortexutils/analyzer.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
class Analyzer(Worker):
1616

17-
def __init__(self, job_directory=None):
18-
Worker.__init__(self, job_directory)
17+
def __init__(self, job_directory=None, secret_phrases=None):
18+
Worker.__init__(self, job_directory, secret_phrases)
1919

2020
# Not breaking compatibility
2121
self.artifact = self._input
@@ -102,11 +102,16 @@ def report(self, full_report, ensure_ascii=False):
102102
summary = self.summary(full_report)
103103
except Exception:
104104
pass
105-
105+
operation_list = []
106+
try:
107+
operation_list = self.operations(full_report)
108+
except Exception:
109+
pass
106110
super(Analyzer, self).report({
107111
'success': True,
108112
'summary': summary,
109113
'artifacts': self.artifacts(full_report),
114+
'operations': operation_list,
110115
'full': full_report
111116
}, ensure_ascii)
112117

cortexutils/responder.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
class Responder(Worker):
1010

11-
def __init__(self, job_directory=None):
12-
Worker.__init__(self, job_directory)
11+
def __init__(self, job_directory=None, secret_phrases=None):
12+
Worker.__init__(self, job_directory, secret_phrases)
1313

1414
# Not breaking compatibility
1515
self.artifact = self._input
@@ -20,26 +20,6 @@ def get_data(self):
2020
:return: Data (observable value) given through Cortex"""
2121
return self.get_param('data', None, 'Missing data field')
2222

23-
@staticmethod
24-
def build_operation(op_type, **parameters):
25-
"""
26-
:param op_type: an operation type as a string
27-
:param parameters: a dict including the operation's params
28-
:return: dict
29-
"""
30-
operation = {
31-
'type': op_type
32-
}
33-
operation.update(parameters)
34-
35-
return operation
36-
37-
def operations(self, raw):
38-
"""Returns the list of operations to be executed after the job completes
39-
40-
:returns: by default return an empty array"""
41-
return []
42-
4323
def report(self, full_report, ensure_ascii=False):
4424
"""Returns a json dict via stdout.
4525

cortexutils/worker.py

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
#!/usr/bin/env python
22
# encoding: utf-8
33

4-
import os
5-
import sys
64
import codecs
75
import json
6+
import os
87
import select
8+
import sys
99

10+
DEFAULT_SECRET_PHRASES = ("key", "password", "secret")
1011

1112
class Worker(object):
1213
READ_TIMEOUT = 3 # seconds
1314

14-
def __init__(self, job_directory):
15+
def __init__(self, job_directory, secret_phrases):
1516
if job_directory is None:
1617
if len(sys.argv) > 1:
1718
job_directory = sys.argv[1]
1819
else:
1920
job_directory = '/job'
2021
self.job_directory = job_directory
22+
if secret_phrases is None:
23+
self.secret_phrases = DEFAULT_SECRET_PHRASES
24+
else:
25+
self.secret_phrases = secret_phrases
2126
# Load input
2227
self._input = {}
2328
if os.path.isfile('%s/input/input.json' % self.job_directory):
@@ -127,6 +132,26 @@ def get_data(self):
127132
:return: Data (observable value) given through Cortex"""
128133
return self.get_param('data', None, 'Missing data field')
129134

135+
@staticmethod
136+
def build_operation(op_type, **parameters):
137+
"""
138+
:param op_type: an operation type as a string
139+
:param parameters: a dict including the operation's params
140+
:return: dict
141+
"""
142+
operation = {
143+
'type': op_type
144+
}
145+
operation.update(parameters)
146+
147+
return operation
148+
149+
def operations(self, raw):
150+
"""Returns the list of operations to be executed after the job completes
151+
152+
:returns: by default return an empty array"""
153+
return []
154+
130155
def get_param(self, name, default=None, message=None):
131156
"""Just a wrapper for Analyzer.__get_param.
132157
:param name: Name of the parameter to get. JSON-like syntax, e.g. `config.username`
@@ -144,13 +169,13 @@ def error(self, message, ensure_ascii=False):
144169
# Get analyzer input
145170
analyzer_input = self._input
146171

147-
# Define sensitive key values
148-
secrets = ['password', 'key', 'secret']
149-
150172
# Loop over all the sensitive config names and clean them
151-
for config_key, v in analyzer_input.get('config', {}).items():
152-
if any(secret in config_key.lower() for secret in secrets):
153-
analyzer_input.get('config', {})[config_key] = 'REMOVED'
173+
for config_key in analyzer_input.get('config', {}).keys():
174+
if any(
175+
secret_phrase in config_key.lower()
176+
for secret_phrase in self.secret_phrases
177+
):
178+
analyzer_input['config'][config_key] = 'REMOVED'
154179

155180
self.__write_output({'success': False,
156181
'input': analyzer_input,

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='cortexutils',
5-
version='2.1.0',
5+
version='2.2.0',
66
description='A Python library for including utility classes for Cortex analyzers and responders',
77
long_description=open('README').read(),
88
author='TheHive-Project',

0 commit comments

Comments
 (0)