Skip to content

Commit 64321f8

Browse files
committed
latest changes to libray
solved #4
1 parent a52ef33 commit 64321f8

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ I created a few jupyter notebooks that I hope can help you get familiar with the
5353
* [Basic Functionality](https://github.com/Cyb3rWard0g/ATTACK-Python-Client/blob/master/notebooks/Usage_Basics.ipynb)
5454
* [Custom Filters](https://github.com/Cyb3rWard0g/ATTACK-Python-Client/blob/master/notebooks/Usage_Filters.ipynb)
5555

56-
Install **Jupyter Lab** and **Pandas==0.22.0** in order to use the Jupyter Notebooks on your own. You can do it by using the **requirements.txt** file in this repo
56+
Install **Jupyter Lab** and **Pandas** in order to use the Jupyter Notebooks on your own. You can do it by using the **requirements.txt** file in this repo
5757

5858
```
5959
pip install -r requirements.txt

attackcti/attack_api.py

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ def parse_stix_objects(self, stix_objects, stix_object_type):
3131
technique_dict = {
3232
'type': technique['type'],
3333
'id': technique['id'],
34-
'created_by_ref': technique['created_by_ref'],
34+
'created_by_ref': self.try_except(technique,'created_by_ref'),
3535
'created': str(technique['created']),
3636
'modified': str(technique['modified']),
37-
'object_marking_refs': technique['object_marking_refs'],
37+
'object_marking_refs': self.try_except(technique,'object_marking_refs'),
3838
'url': technique['external_references'][0]['url'],
3939
'matrix': technique['external_references'][0]['source_name'],
4040
'technique': technique['name'],
41-
'technique_description': technique['description'],
42-
'tactic': self.handle_list(technique,'kill_chain_phases'),
41+
'technique_description': self.try_except(technique, 'description'),
42+
#'tactic': self.handle_list(technique,'kill_chain_phases'),
43+
'tactic': self.try_except(technique,'kill_chain_phases'),
4344
'technique_id': technique['external_references'][0]['external_id'],
4445
'platform': self.try_except(technique,'x_mitre_platforms'),
4546
'data_sources': self.try_except(technique,'x_mitre_data_sources'),
@@ -417,8 +418,7 @@ def get_technique_by_name(self, name):
417418
mobile_stix_objects = self.TC_MOBILE_SOURCE.query(filter_objects)
418419
all_stix_objects = enterprise_stix_objects + pre_stix_objects + mobile_stix_objects
419420
all_stix_objects = self.parse_stix_objects(all_stix_objects, "techniques")
420-
for o in all_stix_objects:
421-
return o
421+
return all_stix_objects
422422

423423
def get_object_by_attack_id(self, object_type, attack_id):
424424
valid_objects = {'attack-pattern','course-of-action','intrusion-set','malware','tool'}
@@ -443,8 +443,7 @@ def get_object_by_attack_id(self, object_type, attack_id):
443443
mobile_stix_objects = self.TC_MOBILE_SOURCE.query(filter_objects)
444444
mobile_stix_objects = self.parse_stix_objects(mobile_stix_objects, dictionary[object_type])
445445
all_stix_objects = enterprise_stix_objects + pre_stix_objects + mobile_stix_objects
446-
for o in all_stix_objects:
447-
return o
446+
return all_stix_objects
448447

449448
def get_group_by_alias(self, group_alias):
450449
filter_objects = [
@@ -456,8 +455,7 @@ def get_group_by_alias(self, group_alias):
456455
mobile_stix_objects = self.TC_MOBILE_SOURCE.query(filter_objects)
457456
all_stix_objects = enterprise_stix_objects + pre_stix_objects + mobile_stix_objects
458457
all_stix_objects = self.parse_stix_objects(all_stix_objects, 'groups')
459-
for o in all_stix_objects:
460-
return o
458+
return all_stix_objects
461459

462460
def get_relationships_by_object(self, stix_object):
463461
valid_objects = {'groups','software','mitigations'}
@@ -691,4 +689,28 @@ def get_all_used_by_group(self, group_name=None):
691689
software = self.get_software_used_by_group(group_name)
692690
techniques = self.get_techniques_used_by_group(group_name)
693691
all_used = software + techniques
694-
return all_used
692+
return all_used
693+
694+
def get_techniques_by_datasources(self, data_sources):
695+
techniques_results = []
696+
techniques = self.get_all_techniques()
697+
if isinstance(data_sources, list):
698+
for d in [x.lower() for x in data_sources]:
699+
for t in techniques:
700+
if t['data_sources'] is not None and d in [x.lower() for x in t['data_sources']]:
701+
techniques_results.append(t)
702+
elif isinstance(data_sources, str):
703+
for t in techniques:
704+
if t['data_sources'] is not None and data_sources.lower() in [x.lower() for x in t['data_sources']]:
705+
techniques_results.append(t)
706+
else:
707+
raise Exception("Not a list or a string")
708+
# Remove Duplicates
709+
already_seen = set()
710+
results_dedup = []
711+
for d in techniques_results:
712+
i = str(d.items())
713+
if i not in already_seen:
714+
already_seen.add(i)
715+
results_dedup.append(d)
716+
return results_dedup

requirements.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
pandas==0.22.0
2-
jupyter
3-
jupyterlab
1+
pandas==0.23.4
2+
altair==2.2.2
3+
jupyter==1.0.0
4+
jupyterlab==0.34.1
45
ipykernel
56
pprint
67
altair

setup.py

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

1414
setuptools.setup(
1515
name="attackcti",
16-
version="0.1.4",
16+
version="0.1.6",
1717
author="Roberto Rodriguez",
1818
author_email="rrodriguezops@gmail.com",
1919
description="ATTACK CTI Libary",

0 commit comments

Comments
 (0)