Skip to content

Commit f11d123

Browse files
author
ekt0
authored
Merge pull request #1 from dfir-iris/upgrade_to_m1_1
Upgrade to interface v1.1
2 parents db4b6d2 + 60fc3d8 commit f11d123

5 files changed

Lines changed: 148 additions & 93 deletions

File tree

.gitignore

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
*.json
10+
11+
# Distribution / packaging
12+
.Python
13+
build/
14+
develop-eggs/
15+
dist/
16+
downloads/
17+
eggs/
18+
.eggs/
19+
lib/
20+
lib64/
21+
parts/
22+
sdist/
23+
var/
24+
wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
.hypothesis/
50+
.pytest_cache/
51+
52+
# Translations
53+
*.mo
54+
*.pot
55+
56+
# Django stuff:
57+
*.log
58+
local_settings.py
59+
db.sqlite3
60+
61+
# Flask stuff:
62+
instance/
63+
.webassets-cache
64+
65+
# Scrapy stuff:
66+
.scrapy
67+
68+
# Sphinx documentation
69+
docs/_build/
70+
71+
# PyBuilder
72+
target/
73+
74+
# Jupyter Notebook
75+
.ipynb_checkpoints
76+
77+
# pyenv
78+
.python-version
79+
80+
# celery beat schedule file
81+
celerybeat-schedule
82+
83+
# SageMath parsed files
84+
*.sage.py
85+
86+
# Environments
87+
.env
88+
.venv
89+
env/
90+
venv/
91+
ENV/
92+
env.bak/
93+
venv.bak/
94+
95+
# Spyder project settings
96+
.spyderproject
97+
.spyproject
98+
99+
# Rope project settings
100+
.ropeproject
101+
102+
# mkdocs documentation
103+
/site
104+
105+
# mypy
106+
.mypy_cache/
107+
.idea/

iris_evtx/EVTXImportDispatcher.py

Lines changed: 23 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
# IMPORTS ------------------------------------------------
2222
import hashlib
23-
import logging
2423
import os
2524
import shutil
2625
import tempfile
@@ -34,8 +33,6 @@
3433

3534
import iris_interface.IrisInterfaceStatus as InterfaceStatus
3635

37-
log = logging.getLogger('iris')
38-
3936

4037
# CONTENT ------------------------------------------------
4138
def decompress_7z(filename, output_dir):
@@ -50,7 +47,7 @@ def decompress_7z(filename, output_dir):
5047
a.extractall(directory=output_dir, auto_create_dir=True)
5148

5249
except Exception as e:
53-
log.warning(e)
50+
print(e)
5451
return False
5552

5653
return True
@@ -61,15 +58,11 @@ class ImportDispatcher(object):
6158
Allows to dispatch files to each related importers
6259
"""
6360

64-
def __init__(self, task_self, task_args=None, evidence_storage=None, configuration=None):
61+
def __init__(self, task_self, task_args=None, evidence_storage=None, configuration=None, log=None):
6562
self.task = task_self
6663
self.evidence_storage = evidence_storage
6764
self.configuration = configuration
68-
self.message_queue = []
69-
handler = InterfaceStatus.QueuingHandler(message_queue=self.message_queue,
70-
level=logging.INFO,
71-
celery_task=task_self)
72-
log.addHandler(handler)
65+
self.log = log
7366

7467
self.index = task_args['pipeline_args']['index_evtx']
7568
self.user = task_args['user']
@@ -85,34 +78,22 @@ def _ret_task_success(self):
8578
Return a task compatible success object to be passed to the next task
8679
:return:
8780
"""
88-
return InterfaceStatus.iit_report_task_success(
89-
user=self.user,
90-
initial=self.task.request.id,
91-
case_name=self.case_name,
92-
logs=list(self.message_queue),
93-
data={}
94-
)
81+
return InterfaceStatus.I2Success
9582

9683
def _ret_task_failure(self):
9784
"""
9885
Return a task compatible failure object to be passed to the next task
9986
:return:
10087
"""
101-
return InterfaceStatus.iit_report_task_failure(
102-
user=self.user,
103-
initial=self.task.request.id,
104-
case_name=self.case_name,
105-
logs=list(self.message_queue),
106-
data={}
107-
)
88+
return InterfaceStatus.I2Error
10889

10990
def import_files(self):
11091
"""
11192
Check every uploaded files and dispatch to handlers
11293
:return:
11394
"""
11495

115-
log.info("Received new evtx import signal for {}".format(self.case_name))
96+
self.log.info("Received new evtx import signal for {}".format(self.case_name))
11697

11798
temp_zippath = tempfile.TemporaryDirectory()
11899
shutil.move(str(self.path), temp_zippath.name)
@@ -121,41 +102,25 @@ def import_files(self):
121102

122103
import_list = self._create_import_list(path=self.path)
123104

124-
ret = self._ret_task_success()
105+
ret = None
125106
if import_list:
126107

127108
for data_type in import_list:
128109

129110
ret_t = self.inner_import_files(import_list[data_type], data_type)
130111

131112
# Merge the result with the current caller
132-
ret.merge_task_results(ret_t, is_update=self.is_update)
113+
ret = InterfaceStatus.merge_status(ret, ret_t)
133114

134115
else:
135116

136-
log.error("Import list was empty. Please check previous errors.")
137-
log.error("Either internal error, either the files could not be uploaded successfully.")
138-
log.error("Nothing to import")
117+
self.log.error("Import list was empty. Please check previous errors.")
118+
self.log.error("Either internal error, either the files could not be uploaded successfully.")
119+
self.log.error("Nothing to import")
139120
ret = self._ret_task_failure()
140121

141122
return ret
142123

143-
def _merge_task_results(self, base_ret, new_ret, type):
144-
"""
145-
Merge the result of multiple tasks
146-
:param base_ret: Task return to merge
147-
:return:
148-
"""
149-
# Set the overall task success at false if any of the task failed
150-
base_ret['success'] = new_ret['success'] and base_ret['success']
151-
152-
# Concatenate the tasks logs to display everything at the end
153-
base_ret['logs'] += new_ret['logs']
154-
155-
base_ret['data']['is_update'] = self.is_update
156-
157-
return base_ret
158-
159124
def _create_import_list(self, path=None):
160125
"""
161126
Create the list for every files
@@ -165,8 +130,8 @@ def _create_import_list(self, path=None):
165130
import_list = {
166131
}
167132

168-
log.info("Checking input files")
169-
log.info("Path is {}".format(path))
133+
self.log.info("Checking input files")
134+
self.log.info("Path is {}".format(path))
170135

171136
if path.is_dir():
172137
for entry in path.iterdir():
@@ -209,20 +174,20 @@ def _create_import_list(self, path=None):
209174
if not is_valid:
210175
try:
211176
entry.unlink()
212-
log.debug(entry)
177+
self.log.debug(entry)
213178
except Exception:
214179
pass
215-
log.info("File has been deleted from the server")
180+
self.log.info("File has been deleted from the server")
216181

217182
else:
218183
entry.unlink()
219-
log.warning("{} was already imported".format(entry))
184+
self.log.warning("{} was already imported".format(entry))
220185

221186
# log.info("Detected {} valid files".format(len(import_list)))
222187
return import_list
223188

224189
else:
225-
log.error("Internal error. Provided path is not a path")
190+
self.log.error("Internal error. Provided path is not a path")
226191
return None
227192

228193
def inner_import_files(self, import_list: list, files_type):
@@ -233,10 +198,10 @@ def inner_import_files(self, import_list: list, files_type):
233198
:return: True if imported, false if not + list of errors
234199
"""
235200

236-
log.info("New imports for {} on behalf of {}".format(self.case_name, self.user))
237-
log.info("{} files of type {} to import into {}".format(len(import_list), files_type, self.index))
201+
self.log.info("New imports for {} on behalf of {}".format(self.case_name, self.user))
202+
self.log.info("{} files of type {} to import into {}".format(len(import_list), files_type, self.index))
238203

239-
log.info("Starting processing of files")
204+
self.log.info("Starting processing of files")
240205

241206
in_path = import_list[0].parent
242207
# Temporary files are placed in the same directory, not in tmp as there is a
@@ -253,12 +218,13 @@ def inner_import_files(self, import_list: list, files_type):
253218
elif files_type == "evtx":
254219
in_path_evtx = in_path
255220
else:
256-
log.error("Unexpected file type, aborting...")
221+
self.log.error("Unexpected file type, aborting...")
257222
return self._ret_task_failure()
258223

259224
start_time = time.time()
260225

261226
e2s = Evtx2Splunk()
227+
262228
# We could just pass on self.configuration, but we prefer to format the dict in such way that
263229
# field names in evtx2splunk will not depend on IrisEVTXModule
264230
proxies = {
@@ -288,7 +254,7 @@ def inner_import_files(self, import_list: list, files_type):
288254

289255
end_time = time.time()
290256

291-
log.info("Finished in {time}".format(time=end_time - start_time))
257+
self.log.info("Finished in {time}".format(time=end_time - start_time))
292258

293259
if ret_t is False:
294260
return self._ret_task_failure()

0 commit comments

Comments
 (0)