Skip to content

fix: Extract TTP from the platform #3888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions internal-import-file/import-document-ai/src/reportimporter/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def _download_import_file(self, data: Dict) -> Tuple[str, BytesIO]:

def _process_parsing_results(
self, parsed: List[Dict], context_entity: Dict
) -> (List[Dict], List[str]):
) -> List[Dict] | List[str]:
observables = []
entities = []
observables = []
Expand All @@ -171,6 +171,34 @@ def _process_parsing_results(
"created_by_ref": author,
},
)
if match[RESULT_FORMAT_CATEGORY] == "Attack-Pattern.x_mitre_id":
ttp_object = self.helper.api.attack_pattern.read(
filters={
"mode": "and",
"filters": [
{
"key": "x_mitre_id",
"values": [match[RESULT_FORMAT_MATCH]],
}
],
"filterGroups": [],
}
)
ttp_stix_bundle = (
self.helper.api.stix2.get_stix_bundle_or_object_from_entity_id(
entity_type=ttp_object["entity_type"],
entity_id=ttp_object["id"],
)
)
stix_ttp = [
object
for object in ttp_stix_bundle["objects"]
if "x_opencti_id" in object
and object["x_opencti_id"] == ttp_object["id"]
][0]
stix_object = (
stix_ttp or stix_object
) # Handle the case where the Attack pattern is not in the platform
entities.append(stix_object)
if match[RESULT_FORMAT_TYPE] == "observable":
stix_object = create_stix_object(
Expand Down Expand Up @@ -358,7 +386,7 @@ def _process_parsed_objects(
now = datetime.now(timezone.utc)
report = stix2.Report(
id=Report.generate_id(file_name, now),
name="nlp-importdoc-" + file_name,
name="import-document-ai" + file_name,
description="Automatic import",
published=now,
report_types=["threat-report"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def create_stix_object(
allow_custom=True,
),
"Attack-Pattern.x_mitre_id": lambda value, object_markings, custom_properties: stix2.AttackPattern(
id=AttackPattern.generate_id(value),
id=AttackPattern.generate_id(name=value, x_mitre_id=value),
name=value,
object_markings=object_markings,
custom_properties=custom_properties,
Expand Down