From 43c87ecab95b18ba99207561a5580f750de261d4 Mon Sep 17 00:00:00 2001 From: Martin Carpenter Date: Fri, 11 Feb 2022 07:32:38 +0100 Subject: [PATCH 1/5] Permit file read exceptions to propagate --- pyattck/configuration.py | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/pyattck/configuration.py b/pyattck/configuration.py index a994954f..ab7824ac 100644 --- a/pyattck/configuration.py +++ b/pyattck/configuration.py @@ -61,18 +61,13 @@ def __write_to_disk(cls, path, data): raise UknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) def __read_from_disk(cls, path): - if os.path.exists(path) and os.path.isfile(path): - try: - with open(path) as f: - if path.endswith('.json'): - return json.load(f) - elif path.endswith('.yml') or path.endswith('.yaml'): - return yaml.load(f, Loader=yaml.FullLoader) - else: - raise UknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) - except: - pass - return None + with open(path) as f: + if path.endswith('.json'): + return json.load(f) + elif path.endswith('.yml') or path.endswith('.yaml'): + return yaml.load(f, Loader=yaml.FullLoader) + else: + raise UknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) def _save_json_data(cls, force: bool=False) -> None: if not os.path.exists(cls.data_path): From fc100115ad6f06cabf1fd93db13d52ffc92c2b6e Mon Sep 17 00:00:00 2001 From: MSAdministrator Date: Fri, 11 Feb 2022 10:35:35 -0600 Subject: [PATCH 2/5] Bumped minor version --- pyattck/utils/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyattck/utils/version.py b/pyattck/utils/version.py index 8134fded..dd5233c0 100644 --- a/pyattck/utils/version.py +++ b/pyattck/utils/version.py @@ -1,2 +1,2 @@ -__version_info__ = (5, 2, 2) +__version_info__ = (5, 3, 0) __version__ = ".".join(map(str, __version_info__)) \ No newline at end of file From 76abae0deee90634a736e98d7132339706669ed8 Mon Sep 17 00:00:00 2001 From: MSAdministrator Date: Fri, 11 Feb 2022 10:36:59 -0600 Subject: [PATCH 3/5] Adding access to tools from techniques --- pyattck/enterprise/technique.py | 22 ++++++++++++++++++++++ pyattck/mobile/technique.py | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/pyattck/enterprise/technique.py b/pyattck/enterprise/technique.py index b0f19bb9..b72a9ba1 100644 --- a/pyattck/enterprise/technique.py +++ b/pyattck/enterprise/technique.py @@ -283,3 +283,25 @@ def actors(self): if item in item_dict: return_list.append(AttckActor(attck_obj=self.__attck_obj, **item_dict[item])) return return_list + + @property + def tools(self): + """ + Returns all tool objects that are used in a technique + + Returns: + [list] -- A list of tool objects defined within the + Enterprise MITRE ATT&CK Framework + """ + from .tools import AttckTools + return_list = [] + item_dict = {} + for item in self.__attck_obj['objects']: + if 'type' in item: + if item['type'] == 'tool': + item_dict[item['id']] = item + if self._RELATIONSHIPS.get(self.stix): + for item in self._RELATIONSHIPS.get(self.stix): + if item in item_dict: + return_list.append(AttckTools(attck_obj=self.__attck_obj, **item_dict[item])) + return return_list diff --git a/pyattck/mobile/technique.py b/pyattck/mobile/technique.py index c01f5db9..8fb7e10b 100644 --- a/pyattck/mobile/technique.py +++ b/pyattck/mobile/technique.py @@ -191,3 +191,25 @@ def actors(self): except: pass return return_list + + @property + def tools(self): + """ + Returns all tool objects that are used in a technique + + Returns: + [list] -- A list of tool objects defined within the + Mobile MITRE ATT&CK Framework + """ + from .tools import MobileAttckTools + return_list = [] + item_dict = {} + for item in self.__attck_obj['objects']: + if 'type' in item: + if item['type'] == 'tool': + item_dict[item['id']] = item + if self._RELATIONSHIPS.get(self.stix): + for item in self._RELATIONSHIPS.get(self.stix): + if item in item_dict: + return_list.append(MobileAttckTools(attck_obj=self.__attck_obj, **item_dict[item])) + return return_list From cdf0b020b54618248a3816917210be2413579bbc Mon Sep 17 00:00:00 2001 From: MSAdministrator Date: Mon, 14 Feb 2022 11:40:06 -0600 Subject: [PATCH 4/5] Updating exception name and changes to read config files --- pyattck/configuration.py | 24 +++++++++++++++--------- pyattck/utils/exceptions.py | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/pyattck/configuration.py b/pyattck/configuration.py index ab7824ac..5dbfd39a 100644 --- a/pyattck/configuration.py +++ b/pyattck/configuration.py @@ -5,7 +5,7 @@ from pathlib import Path import yaml from requests.api import request -from .utils.exceptions import UknownFileError +from .utils.exceptions import UnknownFileError class ConfigurationProperties(type): @@ -58,16 +58,22 @@ def __write_to_disk(cls, path, data): elif path.endswith('.yml') or path.endswith('.yaml'): yaml.dump(data, f) else: - raise UknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) + raise UnknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) def __read_from_disk(cls, path): - with open(path) as f: - if path.endswith('.json'): - return json.load(f) - elif path.endswith('.yml') or path.endswith('.yaml'): - return yaml.load(f, Loader=yaml.FullLoader) - else: - raise UknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) + if os.path.exists(path) and os.path.isfile(path): + try: + with open(path) as f: + if path.endswith('.json'): + return json.load(f) + elif path.endswith('.yml') or path.endswith('.yaml'): + return yaml.load(f, Loader=yaml.FullLoader) + else: + raise UnknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) + except: + warnings.WarningMessage(message=f"The provided config file {path} is not in the correct format. Using default values instead.") + pass + return None def _save_json_data(cls, force: bool=False) -> None: if not os.path.exists(cls.data_path): diff --git a/pyattck/utils/exceptions.py b/pyattck/utils/exceptions.py index 2a38d82c..fb450e7c 100644 --- a/pyattck/utils/exceptions.py +++ b/pyattck/utils/exceptions.py @@ -11,7 +11,7 @@ class ConfigurationException(Exception): """ pass -class UknownFileError(ValueError): +class UnknownFileError(ValueError): """Raised when the provided file extension is unkown or is not json, yml or yaml """ def __init__(self, provided_value=None, known_values=None): From 406a4ab844cf33fa96def1a3e8cd4781e88f4f59 Mon Sep 17 00:00:00 2001 From: MSAdministrator Date: Mon, 14 Feb 2022 11:44:49 -0600 Subject: [PATCH 5/5] Updating warning --- pyattck/configuration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyattck/configuration.py b/pyattck/configuration.py index 5dbfd39a..83afb933 100644 --- a/pyattck/configuration.py +++ b/pyattck/configuration.py @@ -71,7 +71,7 @@ def __read_from_disk(cls, path): else: raise UnknownFileError(provided_value=path, known_values=['.json', '.yml', '.yaml']) except: - warnings.WarningMessage(message=f"The provided config file {path} is not in the correct format. Using default values instead.") + warnings.warn(message=f"The provided config file {path} is not in the correct format. Using default values instead.") pass return None