-
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.
- Loading branch information
1 parent
a3b13fe
commit c16257c
Showing
41 changed files
with
615 additions
and
428 deletions.
There are no files selected for viewing
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
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
53 changes: 2 additions & 51 deletions
53
stix_shifter/stix_translation/src/modules/aws_cloud_watch_logs/data_mapping.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,61 +1,12 @@ | ||
from os import path | ||
import glob | ||
import json | ||
from stix_shifter.stix_translation.src.modules.base.base_data_mapper import BaseDataMapper | ||
|
||
|
||
class DataMapper(BaseDataMapper): | ||
|
||
def __init__(self, options): | ||
mapping_json = options['mapping'] if 'mapping' in options else {} | ||
basepath = path.dirname(__file__) | ||
self.from_stix_files_cnt = self.json_files_to_fetch(path.abspath( | ||
path.join(basepath, "json", "from_*.json"))) | ||
self.map_data = mapping_json or self.fetch_mapping() | ||
self.dialect = options.get('dialect') or 'guardduty' | ||
self.map_data = self.fetch_mapping(basepath) | ||
|
||
@staticmethod | ||
def json_files_to_fetch(file_path): | ||
return glob.glob(file_path) | ||
|
||
def fetch_mapping(self): | ||
""" | ||
Fetches STIX-to-datasource mapping JSON from the module's from_stix_map.json file | ||
:param basepath: path of data source translation module | ||
:type basepath: str | ||
""" | ||
map_data = {} | ||
try: | ||
for each_file in self.from_stix_files_cnt: | ||
map_file = open(each_file).read() | ||
map_data[path.basename(each_file)] = json.loads(map_file) | ||
return map_data | ||
except Exception as ex: | ||
print('exception in main():', ex) | ||
return {} | ||
|
||
def map_field(self, stix_object_name, stix_property_name): | ||
""" | ||
:param stix_object_name: str, stix object | ||
:param stix_property_name: str, stix field | ||
:return: list | ||
""" | ||
mapped_field_lst = [] | ||
for each_model_mapper in self.map_data.values(): | ||
if stix_object_name in each_model_mapper and stix_property_name in \ | ||
each_model_mapper[stix_object_name]["fields"]: | ||
mapped_field_lst.append(each_model_mapper[stix_object_name]["fields"][stix_property_name]) | ||
return mapped_field_lst | ||
|
||
def map_field_json(self, stix_object_name, stix_property_name, json_file): | ||
""" | ||
Return mapped fields from json file | ||
:param stix_object_name:str, stix object | ||
:param stix_property_name:str, stix field | ||
:param json_file:str, json file name | ||
:return: list | ||
""" | ||
if stix_object_name in self.map_data.get(json_file) and stix_property_name in \ | ||
self.map_data.get(json_file)[stix_object_name]["fields"]: | ||
return self.map_data.get(json_file)[stix_object_name]["fields"][stix_property_name] | ||
else: | ||
return [] |
1 change: 0 additions & 1 deletion
1
...ch_logs/json/from_stix_guardduty_map.json → ...ch_logs/json/guardduty_from_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
1 change: 0 additions & 1 deletion
1
...atch_logs/json/from_stix_vpcflow_map.json → ...atch_logs/json/vpcflow_from_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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
{ | ||
"log-type": "vpcflow", | ||
"ipv4-addr": { | ||
"fields": { | ||
"value": ["srcAddr", "dstAddr"], | ||
|
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
File renamed without changes.
File renamed without changes.
Oops, something went wrong.