@@ -295,19 +295,21 @@ def extract_embedded_relationships(self, stix_object, types=None):
295
295
# Extract date
296
296
try :
297
297
if "description" in external_reference :
298
- matches = list (
299
- datefinder . find_dates ( external_reference ["description" ])
298
+ matches = datefinder . find_dates (
299
+ external_reference ["description" ]
300
300
)
301
301
else :
302
- matches = list ( datefinder .find_dates (source_name ) )
302
+ matches = datefinder .find_dates (source_name )
303
303
except :
304
- matches = []
305
- if len (matches ) > 0 :
306
- published = list (matches )[0 ].strftime ("%Y-%m-%dT%H:%M:%SZ" )
307
- else :
308
- published = datetime .datetime .today ().strftime (
309
- "%Y-%m-%dT%H:%M:%SZ"
310
- )
304
+ matches = None
305
+ published = None
306
+ today = datetime .datetime .today ()
307
+ if matches is not None :
308
+ for match in matches :
309
+ if match < today :
310
+ published = match .strftime ("%Y-%m-%dT%H:%M:%SZ" )
311
+ if published is None :
312
+ published = today .strftime ("%Y-%m-%dT%H:%M:%SZ" )
311
313
312
314
if "mitre" in source_name and "name" in stix_object :
313
315
title = "[MITRE ATT&CK] " + stix_object ["name" ]
@@ -595,25 +597,23 @@ def import_relationship(self, stix_relation, update=False, types=None):
595
597
for external_reference in stix_relation ["external_references" ]:
596
598
try :
597
599
if "description" in external_reference :
598
- matches = list (
599
- datefinder . find_dates ( external_reference ["description" ])
600
+ matches = datefinder . find_dates (
601
+ external_reference ["description" ]
600
602
)
601
603
else :
602
- matches = list (
603
- datefinder . find_dates ( external_reference ["source_name" ])
604
+ matches = datefinder . find_dates (
605
+ external_reference ["source_name" ]
604
606
)
605
607
except :
606
- matches = []
607
- if len (matches ) > 0 :
608
- date = matches [0 ].strftime ("%Y-%m-%dT%H:%M:%SZ" )
609
- else :
610
- date = datetime .datetime .today ().strftime ("%Y-%m-%dT%H:%M:%SZ" )
608
+ matches = None
609
+ date = None
610
+ today = datetime .datetime .today ()
611
+ if matches is not None :
612
+ for match in matches :
613
+ if match < today :
614
+ date = match .strftime ("%Y-%m-%dT%H:%M:%SZ" )
611
615
if date is None :
612
- date = (
613
- datetime .datetime .utcnow ()
614
- .replace (microsecond = 0 , tzinfo = datetime .timezone .utc )
615
- .isoformat ()
616
- )
616
+ date = datetime .datetime .today ().strftime ("%Y-%m-%dT%H:%M:%SZ" )
617
617
618
618
stix_relation_result = None
619
619
if StixObservableRelationTypes .has_value (stix_relation ["relationship_type" ]):
@@ -1284,11 +1284,15 @@ def prepare_export(
1284
1284
observables_stix_ids = (
1285
1285
observables_stix_ids + observable_object_data ["stixIds" ]
1286
1286
)
1287
- if stix_object ['type' ] == 'report' :
1288
- if 'object_refs' in stix_object :
1289
- stix_object ['object_refs' ].append (observable_object_data ['observedData' ]['id' ])
1287
+ if stix_object ["type" ] == "report" :
1288
+ if "object_refs" in stix_object :
1289
+ stix_object ["object_refs" ].append (
1290
+ observable_object_data ["observedData" ]["id" ]
1291
+ )
1290
1292
else :
1291
- stix_object ['object_refs' ] = [observable_object_data ['observedData' ]['id' ]]
1293
+ stix_object ["object_refs" ] = [
1294
+ observable_object_data ["observedData" ]["id" ]
1295
+ ]
1292
1296
result .append (stix_object )
1293
1297
1294
1298
if mode == "simple" :
@@ -1387,7 +1391,7 @@ def prepare_export(
1387
1391
final_result = []
1388
1392
for entity in result :
1389
1393
if entity ["type" ] == "report" :
1390
- if ' object_refs' in entity :
1394
+ if " object_refs" in entity :
1391
1395
entity ["object_refs" ] = [
1392
1396
k for k in entity ["object_refs" ] if k in uuids
1393
1397
]
0 commit comments