Skip to content

Commit 9c3b725

Browse files
committed
Update the get_software_used_by_group() method to have a batch_size parameter which will batch the queries to TAXII. This fixes an issue where the URI becomes too long and returns a HTTP 414.
1 parent cc2f015 commit 9c3b725

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

attackcti/attack_api.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,12 +1721,14 @@ def get_techniques_used_by_all_groups(self, stix_format=True):
17211721
groups_use_techniques = self.translate_stix_objects(groups_use_techniques)
17221722
return groups_use_techniques
17231723

1724-
def get_software_used_by_group(self, stix_object, stix_format=True):
1724+
def get_software_used_by_group(self, stix_object, stix_format=True, batch_size=10):
17251725
""" Extracts software STIX objects used by one group accross all ATT&CK matrices
17261726
17271727
Args:
17281728
stix_object (stix object) : STIX Object group to extract software from
17291729
stix_format (bool): Returns results in original STIX format or friendly syntax (e.g. 'attack-pattern' or 'technique')
1730+
batch_size (int): The batch size to use when querying the TAXII datastore. Use a lower batch size if the
1731+
URI becomes too long and you get HTTP 414 errors.
17301732
17311733
Returns:
17321734
List of STIX objects
@@ -1739,11 +1741,17 @@ def get_software_used_by_group(self, stix_object, stix_format=True):
17391741
software_relationships.append(relation)
17401742
if len(software_relationships) == 0:
17411743
return software_relationships
1742-
filter_objects = [
1743-
Filter('type', 'in', ['malware', 'tool']),
1744-
Filter('id', '=', [r.target_ref for r in software_relationships])
1745-
]
1746-
all_software = self.COMPOSITE_DS.query(filter_objects)
1744+
1745+
all_software = []
1746+
1747+
for software_relation_batch in [software_relationships[i:i+batch_size] for i in range(0, len(software_relationships), batch_size)]:
1748+
filter_objects = [
1749+
Filter('type', 'in', ['malware', 'tool']),
1750+
Filter('id', '=', [r.target_ref for r in software_relation_batch])
1751+
]
1752+
1753+
search_results = self.COMPOSITE_DS.query(filter_objects)
1754+
all_software.extend(search_results)
17471755

17481756
if not stix_format:
17491757
all_software = self.translate_stix_objects(all_software)

0 commit comments

Comments
 (0)