-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BigFIx module update for translations (#81)
- Loading branch information
1 parent
f895492
commit ae113a0
Showing
11 changed files
with
510 additions
and
429 deletions.
There are no files selected for viewing
354 changes: 143 additions & 211 deletions
354
stix_shifter/stix_translation/src/modules/bigfix/README.md
Large diffs are not rendered by default.
Oops, something went wrong.
52 changes: 0 additions & 52 deletions
52
stix_shifter/stix_translation/src/modules/bigfix/bigfix_data_mapping.py
This file was deleted.
Oops, something went wrong.
197 changes: 93 additions & 104 deletions
197
stix_shifter/stix_translation/src/modules/bigfix/bigfix_query_constructor.py
Large diffs are not rendered by default.
Oops, something went wrong.
10 changes: 8 additions & 2 deletions
10
stix_shifter/stix_translation/src/modules/bigfix/bigfix_translator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
from ..base.base_translator import BaseTranslator | ||
from .stix_to_bigfix import StixToRelevanceQuery | ||
from .bigfix_result_translator import BigfixResultTranslator | ||
from ...json_to_stix.json_to_stix import JSONToStix | ||
|
||
from os import path | ||
|
||
class Translator(BaseTranslator): | ||
|
||
def __init__(self): | ||
self.result_translator = BigfixResultTranslator() | ||
basepath = path.dirname(__file__) | ||
filepath = path.abspath( | ||
path.join(basepath, "json", "to_stix_map.json")) | ||
|
||
self.mapping_filepath = filepath | ||
self.result_translator = JSONToStix(filepath) | ||
self.query_translator = StixToRelevanceQuery() |
7 changes: 0 additions & 7 deletions
7
stix_shifter/stix_translation/src/modules/bigfix/json/from_stix_map.json
This file was deleted.
Oops, something went wrong.
81 changes: 81 additions & 0 deletions
81
stix_shifter/stix_translation/src/modules/bigfix/json/to_stix_map.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
{ | ||
"file_name": { | ||
"key": "file.name", | ||
"object": "file" | ||
}, | ||
"file_path": [ | ||
{ | ||
"key": "directory.path", | ||
"object": "directory" | ||
}, | ||
{ | ||
"key": "file.parent_directory_ref", | ||
"object": "file", | ||
"references": "directory" | ||
}, | ||
{ | ||
"key": "process.binary_ref", | ||
"object": "process", | ||
"references": "file" | ||
} | ||
], | ||
"sha256hash": { | ||
"key": "file.hashes.SHA-256", | ||
"object": "file" | ||
}, | ||
"sha1hash": { | ||
"key": "file.hashes.SHA-1", | ||
"object": "file" | ||
}, | ||
"md5hash": { | ||
"key": "file.hashes.MD5", | ||
"object": "file" | ||
}, | ||
"process_name": { | ||
"key": "process.name", | ||
"object": "process" | ||
}, | ||
"process_id": { | ||
"key": "process.pid", | ||
"object": "process" | ||
}, | ||
"start_time": [ | ||
{ | ||
"key": "created", | ||
"transformer": "EpochSecondsToTimestamp", | ||
"cybox": false | ||
}, | ||
{ | ||
"key": "first_observed", | ||
"transformer": "EpochSecondsToTimestamp", | ||
"cybox": false | ||
}, | ||
{ | ||
"key": "last_observed", | ||
"transformer": "EpochSecondsToTimestamp", | ||
"cybox": false | ||
} | ||
], | ||
"modified_time": [ | ||
{ | ||
"key": "modified", | ||
"transformer": "EpochSecondsToTimestamp", | ||
"cybox": false | ||
}, | ||
{ | ||
"key": "first_observed", | ||
"transformer": "EpochSecondsToTimestamp", | ||
"cybox": false | ||
}, | ||
{ | ||
"key": "last_observed", | ||
"transformer": "EpochSecondsToTimestamp", | ||
"cybox": false | ||
} | ||
], | ||
"computer_identity": | ||
{ | ||
"key": "name", | ||
"cybox": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,95 @@ | ||
from stix_shifter.stix_translation import stix_translation | ||
import unittest | ||
import json | ||
from stix_shifter.stix_translation.src import transformers | ||
from stix_shifter.stix_translation.src.json_to_stix import json_to_stix_translator | ||
from stix_shifter.stix_translation.src.modules.bigfix import bigfix_translator | ||
|
||
translation = stix_translation.StixTranslation() | ||
interface = bigfix_translator.Translator() | ||
map_file = open(interface.mapping_filepath).read() | ||
map_data = json.loads(map_file) | ||
data_source = { | ||
"type": "identity", | ||
"id": "identity--3532c56d-ea72-48be-a2ad-1a53f4c9c6d3", | ||
"name": "BigFix", | ||
"identity_class": "events" | ||
} | ||
options = {} | ||
|
||
class TestBigFixResultsToStix(object): | ||
@staticmethod | ||
def get_first(itr, constraint): | ||
return next( | ||
(obj for obj in itr if constraint(obj)), | ||
None | ||
) | ||
|
||
class TestBigFixResultsToStix(unittest.TestCase, object): | ||
@staticmethod | ||
def get_first_of_type(itr, typ): | ||
return TestBigFixResultsToStix.get_first(itr, lambda o: type(o) == dict and o.get('type') == typ) | ||
|
||
def test_ipv4_query(self): | ||
# bf_results = "[{'computerID': 12369754, 'computerName': 'bigdata4545.canlab.ibm.com', 'subQueryID': 1," \ | ||
# " 'isFailure': False, 'result': '.err, d41d8cd98f00b204e9800998ecf8427e, /.err'," \ | ||
# " 'ResponseTime': 1000}, " \ | ||
# "{'computerID': 14821900, 'computerName': 'DESKTOP-C30V1JF', 'subQueryID': 1, 'isFailure': True," \ | ||
# " 'result': '12520437.cpx, 0a0feb9eb28bde8cd835716343b03b14, C:\\Windows\\system32\\12520437.cpx'," \ | ||
# " 'ResponseTime': 63000}]" | ||
# query = translation.translate('bigfix', 'results', '{}', bf_results) | ||
# assert query == bf_results | ||
assert "query" == "query" | ||
|
||
def test_common_prop(self): | ||
data = {"computer_identity": "12369754-bigdata4545.canlab.ibm.com", "subQueryID": 1, "start_time": "1541424881", "type": "process", "process_name": "systemd", "process_id": "1", "sha256hash": "9c74c625b2aba7a2e8d8a42e2e94715c355367f7cbfa9bd5404ba52b726792a6", "sha1hash": "916933045c5c91ebcaa325e7f8302f3a732a0a3d", "md5hash": "28a9beb86c4d4c31ba572805bea8494f", "file_path": "/usr/lib/systemd/systemd"} | ||
result_bundle = json_to_stix_translator.convert_to_stix( | ||
data_source, map_data, [data], transformers.get_all_transformers(), options) | ||
print(json.dumps(result_bundle, indent=2)) | ||
assert(result_bundle['type'] == 'bundle') | ||
result_bundle_objects = result_bundle['objects'] | ||
|
||
result_bundle_identity = result_bundle_objects[0] | ||
assert(result_bundle_identity['type'] == data_source['type']) | ||
assert(result_bundle_identity['id'] == data_source['id']) | ||
assert(result_bundle_identity['name'] == data_source['name']) | ||
assert(result_bundle_identity['identity_class'] | ||
== data_source['identity_class']) | ||
|
||
observed_data = result_bundle_objects[1] | ||
print(observed_data) | ||
assert(observed_data['id'] is not None) | ||
assert(observed_data['type'] == "observed-data") | ||
assert(observed_data['created_by_ref'] == result_bundle_identity['id']) | ||
|
||
assert(observed_data['created'] is not None) | ||
assert(observed_data['first_observed'] is not None) | ||
assert(observed_data['last_observed'] is not None) | ||
|
||
def test_file_results_to_stix(self): | ||
file_name = '.X0-lock' | ||
data = {"computer_identity": "12369754-bigdata4545.canlab.ibm.com", "subQueryID": 1, "type": "file", "file_name": ".X0-lock", "sha256hash": "7236f966f07259a1de3ee0d48a3ef0ee47c4a551af7f0d76dcabbbb9d6e00940", "sha1hash": "8b5e953be1db90172af66631132f6f27dda402d2", "md5hash": "e5307d27f0eb9a27af8597a1ddc51e89", "file_path": "/tmp/.X0-lock", "modified_time": "1541424894"} | ||
result_bundle = json_to_stix_translator.convert_to_stix( | ||
data_source, map_data, [data], transformers.get_all_transformers(), options) | ||
|
||
result_bundle_objects = result_bundle['objects'] | ||
|
||
result_bundle_identity = result_bundle_objects[0] | ||
assert(result_bundle_identity['type'] == data_source['type']) | ||
|
||
observed_data = result_bundle_objects[1] | ||
|
||
assert('objects' in observed_data) | ||
objects = observed_data['objects'] | ||
|
||
file_obj = TestBigFixResultsToStix.get_first_of_type(objects.values(), 'file') | ||
assert(file_obj is not None), 'file object type not found' | ||
assert(file_obj.keys() == {'type', 'name', 'hashes', 'parent_directory_ref'}) | ||
assert(file_obj['name'] == file_name) | ||
|
||
def test_process_results_to_stix(self): | ||
process_name = 'systemd' | ||
data = {"computer_identity": "12369754-bigdata4545.canlab.ibm.com", "subQueryID": 1, "start_time": "1541424881", "type": "process", "process_name": "systemd", "process_id": "1", "sha256hash": "9c74c625b2aba7a2e8d8a42e2e94715c355367f7cbfa9bd5404ba52b726792a6", "sha1hash": "916933045c5c91ebcaa325e7f8302f3a732a0a3d", "md5hash": "28a9beb86c4d4c31ba572805bea8494f", "file_path": "/usr/lib/systemd/systemd"} | ||
result_bundle = json_to_stix_translator.convert_to_stix( | ||
data_source, map_data, [data], transformers.get_all_transformers(), options) | ||
print(json.dumps(result_bundle, indent=2)) | ||
result_bundle_objects = result_bundle['objects'] | ||
|
||
result_bundle_identity = result_bundle_objects[0] | ||
assert(result_bundle_identity['type'] == data_source['type']) | ||
|
||
observed_data = result_bundle_objects[1] | ||
|
||
assert('objects' in observed_data) | ||
objects = observed_data['objects'] | ||
|
||
process_obj = TestBigFixResultsToStix.get_first_of_type(objects.values(), 'process') | ||
assert(process_obj is not None), 'process object type not found' | ||
assert(process_obj.keys() == {'type', 'name', 'pid', 'binary_ref'}) | ||
assert(process_obj['name'] == process_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.