-
Notifications
You must be signed in to change notification settings - Fork 1
/
UFEDtoJSON.py
1806 lines (1617 loc) · 69.6 KB
/
UFEDtoJSON.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#--- class UFEDtoJSON.py
import uuid
import os
import re
import sys
#from UFED_case_generator import *
from dependencies.CASE_Mapping_Python.case_mapping import base, case, drafting, uco
from datetime import datetime, date
from typing import Dict, List, Optional, Union
class UFEDtoJSON():
'''
It represents all attributes and methods to process the traces extracted from XML reports to generate
the JSON-LD file complied with the last version of UCO/CASE ontologies.
'''
TAB = '\t'
# default value for string value not provided
#
NP = ''
# default value for integer value not provided
#
INT = '0'
# default value for date value not provided
#
DATE = '1900-01-01T08:00:00'
# default value for Hash Method value not provided
#
HASH_M = 'MD5'
# default value for Hash Method value not provided
#
HASH_V = '1' * 76
# default value for the property referrerUrl of the URLHistoryFacet class
#
REF_URL = 'http:www.empty.com/referrer_url'
# default value for the location where a forensic action was carried out
#
LOC = 'Unknown location'
def __init__(
self,
json_output=None,
app_name=None,
app_user_name=None,
app_user_account=None,
case_bundle=None):
'''
The main class to deal with the artifacts extracted from the XML report
and call the CASE-Mapping-Python library to convert them into the
UCO/CASE representation by the generation of a JSON-LD file
'''
self.bundle = case_bundle
self.FileOut = json_output
self.phone_number_list = []
self.phoneNameList = []
self.phone_uuid_list = []
self.appNameList = []
self.appObjectList = []
self.domain_name_list = []
self.domain_observable_list = []
self.appAccountUsernameList = []
self.appAccountNameList = []
self.accountName = []
self.uuidaccountName = []
self.chat_name_participants_list = []
self.chat_id_participants_list = []
self.chat_id_account_list = []
self.EMAILaccountObjectList = []
self.EMAILaddressList = []
self.phoneOwnerNumber = ''
self.object_phone_owner = ''
self.FILEuuid = {}
self.FILEpath = {}
self.FILEid = []
self.EXTRA_INFOdictPath = {}
self.EXTRA_INFOdictSize = {}
self.EXTRA_INFOdictTableName = {}
self.EXTRA_INFOdictOffset = {}
self.EXTRA_INFOdictNodeInfoId = {}
self.U_ACCOUNTapp = app_name
self.U_ACCOUNTappUserName = app_user_name
self.U_ACCOUNTappUserAccount = app_user_account
self.DEVICE_object = None
self.UrlList = {}
self.LocationList = []
self.LocationIDList = []
self.CELL_SITE_gsm ={}
self.WIRELESS_NET_ACCESS ={}
self.LOCATION_lat_long_coordinate = {}
self.SEARCHED_ITEMvalue = []
self.SYS_MSG_ID = ''
@staticmethod
def __createUUID():
'''
Observables in CASE have a unique identification number, based on Globally Unique Identifier.
Each time a Trace is generated this static method in invoked, it doen't depends on any object
'''
return str(uuid.uuid4())
def __check_application_name(self, name):
"""It stores all the application connected with any Trace, in order to avoid duplications.
:param name: Tte name of the application (string)
:return: observableApp.
"""
if name in self.appNameList:
idx = self.appNameList.index(name)
observable_app = self.appObjectList[idx]
else:
observable_app = self.__generateTraceAppName(name)
self.appNameList.append(name)
self.appObjectList.append(observable_app)
return observable_app
def __checkAccountName(self, account, name, uuidApp):
self.accountName = []
self.uuidaccountName = []
id = account + '###' + name
if id not in self.accountName:
uuid = self.__generate_application_account_facet(account, name, uuidApp)
self.accountName.append(id)
self.uuidaccountName.append(uuid)
def __checkGeoCoordinates(self, latitude, longitude, elevation, category):
latitude = latitude.strip()
longitude = longitude.strip()
observable_location = None
if latitude != '' and longitude != '':
id_geo_loc = latitude + '@' + longitude
if id_geo_loc in self.LOCATION_lat_long_coordinate.keys():
observable_location = self.LOCATION_lat_long_coordinate[id_geo_loc]
else:
observable_location = self.__generate_trace_geo_location(latitude,
longitude, elevation, category)
self.LOCATION_lat_long_coordinate[id_geo_loc] = observable_location
return observable_location
def __checkSearchedItems(self, value):
itemFound = True
if value not in self.SEARCHED_ITEMvalue:
self.SEARCHED_ITEMvalue.append(value)
itemFound = False
return itemFound
def __checkUrlAddress(self, address):
if address in self.UrlList.keys():
observable_url = self.UrlList.get(address)
else:
observable_url = self.__generateTraceURLFullValue(address)
self.UrlList[address] = observable_url
return observable_url
def __checkChatParticipant(self, chat_id, chat_name, chat_source, id_app):
if chat_id.strip() in self.chat_id_participants_list:
idx = self.chat_id_participants_list.index(chat_id.strip())
observable_chat_account = self.chat_id_account_list[idx]
else:
self.chat_name_participants_list.append(chat_name.strip())
observable_chat_account = self.__generate_application_account_facet(chat_id.strip(),
chat_name.strip(), id_app)
self.chat_id_participants_list.append(chat_id.strip())
self.chat_id_account_list.append(observable_chat_account)
return observable_chat_account
def __checkPhoneNumber(self, contact_phone_num, contact_name):
if contact_phone_num not in self.phone_number_list:
self.phone_number_list.append(contact_phone_num)
self.phoneNameList.append(contact_name)
mobileOperator = ""
uuid = self.__generate_phone_account_facet(mobileOperator,
contact_name, contact_phone_num)
self.phone_uuid_list.append(uuid)
def cleanDate(self, originalDate):
aMonths = {
'Jan': '01',
'Feb': '02',
'Mar': '03',
'Apr': '04',
'May': '05',
'Jun': '06',
'Jul': '07',
'Aug': '08',
'Sep': '09',
'Oct': '10',
'Nov': '11',
'Dec': '12'
}
if not originalDate:
return None
originalDate = originalDate.strip()
for k,v in aMonths.items():
if originalDate.find(k) > -1:
originalDate = originalDate.replace(k, v)
break
originalDate = originalDate.replace("/", "-")
originalDate = originalDate.replace("(", "-")
originalDate = originalDate.replace(")", "-")
originalDate = originalDate.replace(' ', 'T', 1)
originalDate = originalDate.replace('UTC', '')
originalDate = originalDate.replace('AM', '')
originalDate = originalDate.replace('PM', '')
if re.search('^[0-9]{4}', originalDate):
pass
else:
originalDate = re.sub('-([0-9][0-9])T', '-20\g<1>T', originalDate)
originalDate = str(originalDate[6:10]) + originalDate[2:6] + originalDate[0:2] + \
originalDate[10:]
startTZ = originalDate.find("+")
if startTZ > -1:
originalDate = originalDate[:startTZ]
firstChars = originalDate[:10]
firstChars = firstChars.replace(".", "-")
originalDate = firstChars + originalDate[10:]
originalDate = originalDate.strip()
if originalDate[-1] == '-':
originalDate = originalDate[0:-1]
originalDate = originalDate.replace('.000', '')
originalDate = originalDate.replace('.', ':')
if re.search('T\d{2}\.', originalDate):
originalDate = originalDate.replace('.', ':')
if re.search('(\d{2}:\d{2}:\d{2})$', originalDate):
pass
else:
originalDate = re.sub('(\d{2}:\d{2})$', '\g<1>:00', originalDate)
if re.search('T(\d):', originalDate):
originalDate = re.sub('T(\d):', 'T0\g<1>:', originalDate)
if re.search(':(\d):', originalDate):
originalDate = re.sub(':(\d):', ':0\g<1>:', originalDate)
if re.search(':(\d)$', originalDate):
originalDate = re.sub(':(\d)$', ':0\g<1>', originalDate)
if re.search('T\d{2}:\d{2}:\d{2}(.+)$', originalDate):
originalDate = re.sub('(T\d{2}:\d{2}:\d{2})(.+)$', '\g<1>', originalDate)
if originalDate.find('+') > -1:
originalDate = datetime.strptime(originalDate,
'%Y-%m-%dT%H:%M:%S.%f%z')
else:
originalDate = datetime.strptime(originalDate,
'%Y-%m-%dT%H:%M:%S')
return originalDate
def cleanJSONtext(self, originalText):
new_text = originalText.strip()
if new_text == '':
return ''
else:
new_text = new_text.replace('"', "").replace('\n', '').replace('\r', '')
new_text = new_text.replace('\t', " ").replace("\\'", "'").replace("\\", "")
return new_text
def __generateContextUfed(self, ufedVersion, deviceReportCreateTime,
deviceExtractionStartTime, deviceExtractionEndTime, examinerName,
imagePath, imageSize, imageMetadataHashSHA, imageMetadataHashMD5):
# generate Trace/Tool for the Acquisition and Extraction Actions
object_tool = self.__generateTraceTool('UFED PA', 'Acquisition',
'Cellebrite', ufedVersion, []);
# generate Trace/Identity for the Performer, D.F. Expert, of the Actions
object_identity = self.__generateTraceIdentity(examinerName, '', '')
# generate Trace/Role for the Performer, D.F. Expert, of the Actions
object_role = self.__generateTraceRole('Digital Forensic Expert')
# generate Trace/Relation between Role and Identity by using the core Relationship
self.__generateTraceRelationCore(object_identity, object_role, relation='Has_Role');
#--- The XML report contains the attribute DeviceInfoExtractionStartDateTime
# that is the Acquisition Start Date and similarly for the Acquisition
# End Date, The CreationReportDate is the Start and the End of the Extraction
# Forensic Action.
object_device_list = []
object_device_list.append(self.DEVICE_object)
object_provenance_device = self.__generateTraceProvencance(object_device_list,
'Mobile device', '', deviceExtractionStartTime)
# generate Trace/File for each file extracted by the Acuisition action
# idFileList contains the uuid of these files and it is used for
# creating the Provenance_Record of the Result/Output of the Acquisition
# action. 2021-08-02: actually the XML report doesn't include the Acquisition info
#
object_files_acquisition = []
for i, img_path in enumerate(imagePath):
if imageMetadataHashSHA[i].strip() == '':
object_file_acquisition = self.__generateTraceFile(img_path,
imageSize[i], 'MD5', imageMetadataHashMD5[i], 'Uncategorized', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '')
else:
object_file_acquisition = self.__generateTraceFile(img_path,
imageSize[i], 'SHA256', imageMetadataHashSHA[i], 'Uncategorized',
'', '', '', '', '', '', '', '', '', '', '', '', '', '', '')
object_files_acquisition.append(object_file_acquisition)
object_provenance_acquisition_files = \
self.__generateTraceProvencance(object_files_acquisition,
'Acquisition files', '', deviceExtractionStartTime)
object_provenance_acquisition_files_list = []
object_provenance_acquisition_files_list.append(object_provenance_acquisition_files)
object_provencance_acquisition_action = \
self.__generateTraceInvestigativeAction('acquisition',
'Forensic mobile device acquisition', deviceExtractionStartTime,
deviceExtractionEndTime, object_tool, '', object_identity,
object_provenance_device, object_provenance_acquisition_files_list);
object_files_extraction = []
for uuidFile in self.FILEuuid.values():
object_files_extraction.append(uuidFile)
object_provenance_extraction_files = \
self.__generateTraceProvencance(object_files_extraction, 'Extraction',
'', deviceReportCreateTime);
object_provenance_extraction_files_list = []
object_provenance_extraction_files_list.append(object_provenance_extraction_files)
self.__generateTraceInvestigativeAction('extraction',
'Forensic mobile device extraction', deviceReportCreateTime,
deviceReportCreateTime, object_tool, '', object_identity,
object_provenance_acquisition_files, object_provenance_extraction_files_list);
def __generate_chain_of_evidence(self, IdTrace, uuidTrace):
# Search traceId in EXTRA_INFOdictNodeInfo a dictionary whose keys are the id
# that represents the link between a Trace and its file(s)
#
table = self.EXTRA_INFOdictTableName.get(IdTrace, '_?TABLE')
offset = self.EXTRA_INFOdictOffset.get(IdTrace, '_?OFFSET')
#--- This is the case where the infoNode sub element of extraInfo contains the id
#--- reference to the file. More then one infoNode can exist, the value of the key
#--- contains the id file separated by @
if self.EXTRA_INFOdictNodeInfoId.get(IdTrace, '').strip() == '':
path = self.EXTRA_INFOdictPath.get(IdTrace, '_?PATH')
size = self.EXTRA_INFOdictSize.get(IdTrace, '_?SIZE')
if path != '_?PATH':
uuidFile = self.__generateTraceFile(path, size, '',
'', 'Uncategorized', '', '', '', '', '',
'', '', '', '', '', '', '', '', '', '')
self.FILEuuid[IdTrace] = uuidFile
self.__generateTraceRelation(uuidTrace, uuidFile, 'Contained_Within',
table, offset, None, None);
else:
nodeInfoIdList = self.EXTRA_INFOdictNodeInfoId.get(IdTrace, '@@@').split('@@@')
for node in nodeInfoIdList:
if node.strip() != '':
if node in self.FILEid:
uuidFile = self.FILEuuid.get(node, '_?UUID')
self.__generateTraceRelation(uuidTrace, uuidFile, 'Contained_Within',
table, offset, None, None);
# else:
# print ('nodeInfo ' + node + ' not found')
def write_device(self, deviceId, devicePhoneModel, deviceOsType, deviceOsVersion,
devicePhoneVendor, deviceMacAddress, deviceIccid, deviceImsi,
deviceImei, deviceBluetoothAddress, deviceBluetoothName):
'''
Generate Device Facet for the mobile phone
'''
self.DEVICE_object = self.__generateTraceDevice(
deviceMacAddress,
deviceId,
devicePhoneModel,
deviceOsType,
deviceOsVersion,
devicePhoneVendor,
deviceMacAddress,
deviceIccid,
deviceImsi,
deviceImei,
deviceBluetoothAddress,
deviceBluetoothName
)
def __generateTraceAppName(self, app_name):
'''
Generate Application Facet
'''
observable = uco.observable.ObservableObject()
facet_application = uco.observable.ApplicationFacet(
application_identifier=app_name
)
observable.append_facets(facet_application)
self.bundle.append_to_uco_object(observable)
return observable
def __get_max_len_call_element(self, call_roles_to, call_roles_from,
call_names_to, call_names_from, call_identifiers_to,
call_identifiers_from):
maxLen = len(call_roles_to)
if len(call_roles_from) > maxLen:
maxLen = len(call_roles_from)
if len(call_names_to) > maxLen:
maxLen = len(call_names_to)
if len(call_names_from) > maxLen:
maxLen = len(call_names_from)
if len(call_identifiers_to) > maxLen:
maxLen = len(call_identifiers_to)
if len(call_identifiers_from) > maxLen:
maxLen = len(call_identifiers_from)
return maxLen
def write_call(
self,
call_id: List[str],
call_status: List[str] = None,
call_source: List[str] = None,
call_start_time: List[datetime] = None,
call_direction: List[str] = None,
call_duration: List[int] = None,
call_roles_to: Union[List[str], None] = None,
call_role_from: List[str] = None,
call_names_to: Dict = None,
call_name_from: List[str] = None,
call_outcome: List[str] = None,
call_identifiers_to: Union[List[str], None] = None,
call_identifier_from: List[str] = None,
):
'''
Convert any kind of call, further the traditional phone call, is processed, so the
phone_regex_pattern is not necessary mandatory any more.
'''
phone_regex_pattern = '^\+?[0-9]+$'
for i, call_id in enumerate(call_id):
id_party_to = ''
id_party_from = ''
id_party = ''
maxLen = self.__get_max_len_call_element(call_roles_to[i], call_role_from[i],
call_names_to[i], call_name_from[i], call_identifiers_to[i],
call_identifier_from[i])
# All these arrays should have the same size, the check fill in the values.
# if this is not the case, the loops make the dimension of all arrays the same
for j in range(maxLen - len(call_roles_to[i])):
call_roles_to[i].append('')
for j in range(maxLen - len(call_role_from[i])):
call_role_from[i].append('')
for j in range(maxLen - len(call_names_to[i])):
call_names_to[i].append('')
for j in range(maxLen - len(call_name_from[i])):
call_name_from[i].append('')
for j in range(maxLen - len(call_identifiers_to[i])):
call_identifiers_to[i].append('')
for j in range(maxLen - len(call_identifier_from[i])):
call_identifier_from[i].append('')
if maxLen == 0:
call_roles_to[i].append('')
call_role_from[i].append('')
call_names_to[i].append('')
call_name_from[i].append('')
call_identifiers_to[i].append('')
call_identifier_from[i].append('')
if (len(call_role_from[i]) > 1):
if call_role_from[i][0].strip() == '':
id_party_from = call_identifier_from[i][1]
name_from = call_name_from[i][1]
id_party_to = call_identifiers_to[i][0]
name_to = call_names_to[i][0]
else:
id_party_from = call_identifier_from[i][0]
name_from = call_name_from[i][0]
id_party_to = call_identifiers_to[i][1]
name_to = call_names_to[i][1]
else:
if call_role_from[i][0].strip() == '':
id_party_from = self.phoneOwnerNumber
name_from = 'PHONE OWNER'
id_party_to = call_identifiers_to[i][0]
id_party = id_party_to
name_to = call_names_to[i][0]
else:
id_party_from = call_identifier_from[i][0]
id_party = id_party_from
id_party_to = self.phoneOwnerNumber
name_from = call_name_from[i][0]
name_to = 'PHONE OWNER'
resPattern = re.match(phone_regex_pattern, id_party.strip())
if resPattern:
if id_party_to in self.phone_number_list:
idx = self.phone_number_list.index(id_party_to)
uuid_party_to = self.phone_uuid_list[idx]
else:
# if the mobile operator is available in the XML report, an uco-identity:Identity
# will be defined as Organisation.
mobileOperator = "-"
uuid_party_to = self.__generate_phone_account_facet(mobileOperator,
name_to, id_party_to)
if id_party_from in self.phone_number_list:
idx = self.phone_number_list.index(id_party_from)
uuid_party_from = self.phone_uuid_list[idx]
else:
mobileOperator = "-"
uuid_party_from = self.__generate_phone_account_facet(mobileOperator,
name_from, id_party_from)
else:
idAppIdentity = self.__check_application_name(call_source[i].strip())
if id_party_from.strip() in self.chat_id_participants_list:
idx = self.chat_id_participants_list.index(id_party_from.strip())
uuid_party_from = self.chat_id_account_list[idx]
else:
self.chat_name_participants_list.append(name_from.strip())
uuid_party_from = self.__generate_application_account_facet(id_party_from.strip(),
name_from.strip(), idAppIdentity)
self.chat_id_participants_list.append(id_party_from.strip())
self.chat_id_account_list.append(uuid_party_from)
if id_party_to.strip() in self.chat_id_participants_list:
idx = self.chat_id_participants_list.index(id_party_to.strip())
uuid_party_to = self.chat_id_account_list[idx]
else:
self.chat_name_participants_list.append(name_to.strip())
uuid_party_to = self.__generate_application_account_facet(id_party_to.strip(),
name_to.strip(), idAppIdentity)
self.chat_id_participants_list.append(id_party_to.strip())
self.chat_id_account_list.append(uuid_party_to)
object_phone_call = self.__generate_call_facet(call_direction[i].lower(),
call_start_time[i], uuid_party_from, uuid_party_to, call_duration[i],
call_status[i], call_outcome[i])
self.__generate_chain_of_evidence(call_id, object_phone_call)
def __generateTraceWebBookmark(self, wb_id, wb_source, wb_timeStamp, wb_path, wb_url):
'''
It generates the uco-observable:BrowserBookmarkFacet objectt
'''
web_bookmark_object = uco.observable.ObservableObject()
#object_url = self.__checkUrlAddress(wb_url)
objet_app = self.__check_application_name(wb_source)
if wb_timeStamp.strip() == '':
wb_timeStamp = None
else:
wb_timeStamp = self.cleanDate(wb_timeStamp)
url_id = self.__generateTraceURLFullValue(wb_url)
facet_web_bookmark = uco.observable.BrowserBookmarkFacet(
application_id=objet_app,
urlTargeted_id=url_id,
bookmarkPath=wb_path,
accessedTime=wb_timeStamp
)
web_bookmark_object.append_facets(facet_web_bookmark)
self.bundle.append_to_uco_object(web_bookmark_object)
return web_bookmark_object
def __generateTraceBluetooth(self, bt_id, bt_status, bt_value):
if bt_value.strip() == '':
return None
bluetooth_object = uco.observable.ObservableObject()
facet_bluetooth = uco.observable.BluetoothAddressFacet(address=bt_value)
bluetooth_object.append_facets(facet_bluetooth)
self.bundle.append_to_uco_object(bluetooth_object)
return bluetooth_object
def __generateTraceCalendar(self, calendar_id, status, group, subject,
details, startDate, endDate, repeatUntil, repeatInterval, repeatRule):
startDate = self.cleanDate(startDate)
endDate = self.cleanDate(endDate)
subject = self.cleanJSONtext(subject)
details = self.cleanJSONtext(details)
calendar_object = uco.observable.ObservableObject()
# what are group and details?
#print(f"group={group}\ndetails={details}")
facet_calendary = uco.observable.CalendarEntryFacet(
subject=subject,
start_time=startDate,
end_time=endDate,
recurrence=repeatInterval,
)
calendar_object.append_facets(facet_calendary)
self.bundle.append_to_uco_object(calendar_object)
return calendar_object
def __generate_trace_cell_site(self, cell_id, cell_status,
cell_longitude, cell_latitude, cell_timeStamp, cell_mcc,
cell_mnc, cell_lac, cell_cid, cell_nid, cell_bid, cell_sid):
cell_timeStamp = self.cleanDate(cell_timeStamp)
observableLocation = self.__checkGeoCoordinates(cell_latitude, cell_longitude, '', 'Cell Tower')
cell_id = cell_mcc.strip() + '@' + cell_mnc.strip() +'@' + \
cell_lac.strip() + '@' + cell_cid.strip()
if cell_id == '@@@':
return None
if cell_id in self.CELL_SITE_gsm.keys():
return self.CELL_SITE_gsm.get(cell_id)
else:
cell_site_object = uco.observable.ObservableObject()
facet_cell_site = uco.observable.CellSiteFacet(
cell_site_country_code=cell_mcc,
cell_site_network_code=cell_mnc,
cell_site_location_area_code=cell_lac,
cell_site_identifier=cell_cid
)
cell_site_object.append_facets(facet_cell_site)
self.bundle.append_to_uco_object(cell_site_object)
self.CELL_SITE_gsm[cell_id] = cell_site_object
if observableLocation:
observable_relationship = uco.observable.ObservableRelationship(
source=cell_site_object,
target=observableLocation,
start_time=cell_timeStamp,
kind_of_relationship="Located_At",
directional=True)
self.bundle.append_to_uco_object(observable_relationship)
return cell_site_object
def __generate_application_account_facet(self, partyId, partyName, idApp):
partyName = self.cleanJSONtext(partyName)
partyId = self.cleanJSONtext(partyId)
observable = uco.observable.ObservableObject()
facet_account = uco.observable.AccountFacet(identifier=partyId)
facet_app_account = uco.observable.ApplicationAccountFacet(application=idApp)
facet_digital_account = uco.observable.DigitalAccountFacet(display_name=partyName)
observable.append_facets(facet_account, facet_app_account, facet_digital_account)
self.bundle.append_to_uco_object(observable)
return observable
def __generateTraceChat(self, body, idApplication, timeStamp, idFrom,
idToList, status, outcome, direction, attachmentNames, attachmentUrls):
TOlist = []
for item in idToList:
if item != idFrom:
TOlist.append(item)
if TOlist == []:
TOlist.append(idFrom)
body = self.cleanJSONtext(body)
observable_message = self.__generate_trace_message(body, idApplication,
idFrom, TOlist, timeStamp, status, 'CHAT Message')
# Each Message, within a specific Chat can have more than one attachment,
# both the Filenames and the Urls of the Attachment are separated by a triple hash tag #
listFileNames = attachmentNames.split('###');
listFileUrls = attachmentUrls.split('###');
nName = len(listFileNames)
nUrl = len(listFileUrls)
if nName > nUrl:
for i in range(nName - nUrl):
listFileUrls.append('')
if nName < nUrl:
for i in range(nUrl - nName):
listFileNames.append('')
for i, file_name in enumerate(listFileNames):
if (file_name.strip() != '') or \
(listFileUrls[i].strip() != ''):
fileUuid = self.__generateTraceFile(file_name,
'', '', '', 'Uncategorized', '', '', '', listFileUrls[i],
'', '', '', '', '', '', '', '', '', '', '')
if uuid != '':
self.__generateTraceRelation(fileUuid, observable_message,
'Connected_To', '', '', None, None)
return observable_message
def __generateTraceDevice(self, deviceMAC, deviceSN, deviceModel,
deviceOS, deviceOSVersion, deviceManufacturer, deviceWiFi, deviceICCID,
deviceIMSI, deviceIMEI, deviceBluetoothAddress, deviceBluetoothName):
device_object = uco.observable.ObservableObject()
facet_device = uco.observable.DeviceFacet(
device_type="Mobile phone",
model=deviceModel,
serial=deviceSN
)
sim_card_facet = uco.observable.SimCardFacet(
ICCID=deviceICCID,
IMSI=deviceIMSI)
if deviceManufacturer:
manufacturer_object = self.__generateTraceIdentity(None, deviceManufacturer, None)
facet_operating_system = uco.observable.OperatingSystemFacet(
os_version=deviceOSVersion, os_manufacturer=manufacturer_object)
else:
facet_operating_system = uco.observable.OperatingSystemFacet(
os_version=deviceOSVersion)
facet_bluetooth = uco.observable.BluetoothAddressFacet(address=deviceBluetoothAddress)
facet_wifi = uco.observable.WifiAddressFacet(wifi_mac_address=deviceWiFi)
device_object.append_facets(facet_device, sim_card_facet, facet_operating_system,
facet_bluetooth,facet_wifi)
self.bundle.append_to_uco_object(device_object)
return device_object
def __generate_trace_cookie(self, cookie_id, cookie_status,
cookie_source, cookie_name, cookie_path, cookie_domain,
cookie_creationTime, cookie_lastAccessedTime, cookie_expiry):
id_app = None
if cookie_source.strip() != "":
id_app = self.__check_application_name(cookie_source.strip())
cookie_creationTime = self.cleanDate(cookie_creationTime)
cookie_lastAccessedTime = self.cleanDate(cookie_lastAccessedTime)
cookie_expiry = self.cleanDate(cookie_expiry)
cookie_name = self.cleanJSONtext(cookie_name)
cookie_object = uco.observable.ObservableObject()
observable_source = self.__check_application_name(cookie_source)
observable_domain = self.__check_application_name(cookie_domain)
facet_cookie = uco.observable.BrowserCookieFacet(
application = id_app,
cookie_name=cookie_name,
cookie_path=cookie_path,
created_time=cookie_creationTime,
accessed_time=cookie_lastAccessedTime,
expiration_time=cookie_expiry
)
cookie_object.append_facets(facet_cookie)
self.bundle.append_to_uco_object(cookie_object)
return cookie_object
def __generateTraceDeviceEvent(self, event_id, event_status,
event_timeStamp, event_type, event_text):
event_timeStamp = self.cleanDate(event_timeStamp)
event_text = self.cleanJSONtext(event_text)
device_event_object = uco.observable.ObservableObject()
facet_event = uco.observable.EventRecordFacet(
event_type=event_type,
event_record_text=event_text,
observable_created_time=event_timeStamp
)
device_event_object.append_facets(facet_event)
self.bundle.append_to_uco_object(device_event_object)
return device_event_object
def __generateTraceInstalledApp(self, INSTALLED_APPid, INSTALLED_APPstatus, INSTALLED_APPname,
INSTALLED_APPversion, INSTALLED_APPidentifier, INSTALLED_APPpurchaseDate):
INSTALLED_APPtimeStamp = self.cleanDate(INSTALLED_APPpurchaseDate)
# If installed_app_purchase_date is not empy a complete ApplicationFacet and ans ApplicationVerions are generated,
# otherwise on a partial APplicatinFacet is generate and no Chain of Evidence is created (return None)
observable = uco.observable.ObservableObject()
if INSTALLED_APPtimeStamp:
object_app_version = uco.observable.ObservableApplicationVersion(
install_date=INSTALLED_APPtimeStamp)
#self.bundle.append_to_uco_object(object_app_version)
facet_application = uco.observable.ApplicationFacet(
application_identifier=INSTALLED_APPname,
installed_version_history=[object_app_version]
)
observable.append_facets(facet_application)
self.bundle.append_to_uco_object(observable)
return observable
else:
facet_application = uco.observable.ApplicationFacet(
application_identifier=INSTALLED_APPname)
observable.append_facets(facet_application)
self.bundle.append_to_uco_object(observable)
return None
def __generateTraceEmail(self, EMAILid, EMAILstatus, EMAILsource,
EMAILidentifierFROM, EMAILidentifiersTO, EMAILidentifiersCC,
EMAILidentifiersBCC, EMAILbody, EMAILsubject, EMAILtimeStamp,
EMAILattachmentsFilename):
#print(f'EMAILidentifierFROM={EMAILidentifierFROM}')
if EMAILidentifierFROM.strip() in self.EMAILaddressList:
idx = self.EMAILaddressList.index(EMAILidentifierFROM.strip())
idFROM = self.EMAILaccountObjectList[idx]
else:
self.EMAILaddressList.append(EMAILidentifierFROM.strip())
observable_email_account = self.__generateTraceEmailAccount(EMAILidentifierFROM.strip())
self.EMAILaccountObjectList.append(observable_email_account)
idFROM = observable_email_account
itemsTO = []
for i, email_identifier in enumerate(EMAILidentifiersTO):
if email_identifier.strip() != '':
if email_identifier.strip() in self.EMAILaddressList:
idx = self.EMAILaddressList.index(email_identifier.strip())
itemsTO.append(self.EMAILaccountObjectList[idx])
else:
self.EMAILaddressList.append(email_identifier.strip())
observable_email = \
self.__generateTraceEmailAccount(email_identifier.strip())
self.EMAILaccountObjectList.append(observable_email)
itemsTO.append(observable_email)
itemsCC = []
for i, email_identifier_cc in enumerate(EMAILidentifiersCC):
if email_identifier_cc.strip() != '':
if email_identifier_cc.strip() in self.EMAILaddressList:
idx = self.EMAILaddressList.index(email_identifier_cc.strip())
itemsCC.append(self.EMAILaccountObjectList[idx])
else:
self.EMAILaddressList.append(email_identifier_cc.strip())
observable_email = self.__generateTraceEmailAccount(email_identifier_cc.strip())
self.EMAILaccountObjectList.append(observable_email)
itemsCC.append(observable_email)
itemsBCC = []
for i, email_identifier_bcc in enumerate(EMAILidentifiersBCC):
if email_identifier_bcc.strip() != '':
if email_identifier_bcc.strip() in self.EMAILaddressList:
idx = self.EMAILaddressList.index(email_identifier_bcc.strip())
itemsBCC.append(self.EMAILaccountObjectList[idx])
else:
self.EMAILaddressList.append(email_identifier_bcc.strip())
observable_email = self.__generateTraceEmailAccount(email_identifier_bcc.strip())
self.EMAILaccountObjectList.append(observable_email)
itemsBCC.append(observable_email)
body = self.cleanJSONtext(EMAILbody)
subject = self.cleanJSONtext(EMAILsubject)
EMAILtimeStamp = self.cleanDate(EMAILtimeStamp)
email_object = uco.observable.ObservableObject()
application_object = self.__check_application_name(EMAILsource)
facet_email_message = uco.observable.EmailMessageFacet(
msg_to=itemsTO,
msg_from=idFROM,
cc=itemsCC,
bcc=itemsBCC,
subject=subject,
body=body,
sent_time=EMAILtimeStamp,
application=application_object
)
email_object.append_facets(facet_email_message)
self.bundle.append_to_uco_object(email_object)
self.__generate_chain_of_evidence(EMAILid, email_object)
for i, email_attachment in enumerate(EMAILattachmentsFilename):
if email_attachment.strip() != '':
fileUuid = self.__generateTraceFile(email_attachment,
'', '', '', 'Uncategorized', '', '', '', '',
'', '', '', '', '', '', '', '', '', '', '')
self.__generateTraceRelation(fileUuid, email_object, 'Attached_To',
'', '', None, None)
return email_object
def __generateTraceEmailAccount(self, address):
address = self.cleanJSONtext(address)
email_address_object = self.__generateTraceEmailAddress(address)
email_account_object = uco.observable.ObservableObject()
facet_email_account = uco.observable.EmailAccountFacet(email_address_object)
facet_account = uco.observable.AccountFacet(identifier="-")
email_account_object.append_facets(facet_account, facet_email_account)
self.bundle.append_to_uco_object(email_account_object)
return email_account_object
def __generateTraceEmailAddress(self, address):
address = self.cleanJSONtext(address)
email_address_object = uco.observable.ObservableObject()
facet_email_address = uco.observable.EmailAddressFacet(
email_address_value=address
)
email_address_object.append_facets(facet_email_address)
self.bundle.append_to_uco_object(email_address_object)
return email_address_object
def __generateTraceFile(self, FILEpath, FILEsize, FILEhashType,
FILEHashValue, FILETag, FILEtimeC, FILEtimeM, FILEtimeA, FILElocalPath,
FILEiNode, FILEiNodeTimeM, FILEgid, FILEuid, FILEexifLatitudeRef, FILEexifLatitude,
FILEexifLongitudeRef, FILEexifLongitude, FILEexifAltitude, FILEexifMake, FILEexifModel):
head, tail = os.path.split(FILEpath)
file_object = uco.observable.ObservableObject()
tail = self.cleanJSONtext(tail)
path = FILEpath.replace('"', "").replace('\n', '').replace('\r', '')
path = path.replace("\\", "/")
dotPos = tail.find('.')
if dotPos > -1:
sExt = tail[dotPos:]
else:
sExt = ''
if FILEHashValue.upper() == 'N/A':
FILEHashValue = UFEDtoJSON.HASH_V
if FILEHashValue.strip() == '':
FILEHashValue = UFEDtoJSON.HASH_V
if FILEhashType.strip() == '':
FILEhashType = UFEDtoJSON.HASH_M
if FILEhashType.upper() == '_NOT_PROVIDED_':
FILEhashType = UFEDtoJSON.HASH_M
if FILETag.upper() == '_NOT_PROVIDED_':
FILETag = 'Uncategorized';
FILEsize = re.sub('[^0-9]','', FILEsize)
if FILEsize.strip() == '':
FILEsize = int(UFEDtoJSON.INT)
else:
FILEsize = int(FILEsize)
if FILEHashValue != UFEDtoJSON.HASH_V:
facet_content = uco.observable.ContentDataFacet(hash_method=FILEhashType, hash_value=FILEHashValue)
file_object.append_facets(facet_content)
FILEtimeC = self.cleanDate(FILEtimeC)
FILEtimeM = self.cleanDate(FILEtimeM)
FILEtimeA = self.cleanDate(FILEtimeA)
FILEiNodeTimeM = self.cleanDate(FILEiNodeTimeM)
FILEiNode = FILEiNode.strip()
if FILEiNode.strip() == '':
FILEiNode = UFEDtoJSON.INT
if FILEiNode.find('0x') > - 1:
FILEiNode = int(FILEiNode, 16)
else:
FILEiNode = int(FILEiNode)
FILEuid = FILEuid.strip()
if FILEuid.strip() == '':
FILEuid = UFEDtoJSON.INT
if FILEuid.find('0x') > - 1:
FILEuid = int(FILEuid, 16)
else:
FILEuid = int(FILEuid)
FILEgid = FILEgid.strip()
if FILEgid.strip() == '':
FILEgid = UFEDtoJSON.INT
if FILEgid.find('0x') > - 1:
FILEgid = int(FILEgid, 16)
else:
FILEgid = int(FILEgid)
localPath = FILElocalPath.replace('"', "").replace('\n', '').replace('\r', '')
localPath = localPath.replace("\\", "/")
if FILEexifLatitude.strip() != '':
exif_data = {"Make":FILEexifMake,
"Model":FILEexifModel, "LatitudeRef":FILEexifLatitudeRef,
"Latitude":FILEexifLatitude, "LongitudeRef":FILEexifLongitudeRef,
"Longitude":FILEexifLongitude, "Altitude":FILEexifAltitude}
facet_exif = uco.observable.EXIFFacet(**exif_data)
file_object.append_facets(facet_exif)
facet_ext_inode = uco.observable.ExtInodeFacet(inode_change_time=FILEiNodeTimeM,
inode_id=FILEiNode, sgid=FILEgid, suid=FILEuid)
file_object.append_facets(facet_ext_inode)
facet_file = uco.observable.FileFacet(file_mime_type=FILETag, file_name=tail,
file_path=path, file_extension=sExt, file_size_bytes=FILEsize,
file_accessed_time=FILEtimeA, file_created_time=FILEtimeC,
file_modified_time=FILEtimeM)
file_object.append_facets(facet_file)
self.bundle.append_to_uco_object(file_object)
return file_object
def __generateTraceIdentity(self, name, family_name, birthDate):
birthDate = self.cleanDate(birthDate)
identity_object = uco.identity.Identity()
identity_facet = uco.identity.SimpleNameFacet(
given_name=name,
family_name=family_name
)
if birthDate:
identity_birth = uco.identity.BirthInformationFacet(
birthdate=birthDate
)
identity_object.append_facets(identity_birth, identity_facet)
else:
identity_object.append_facets(identity_facet)
self.bundle.append_to_uco_object(identity_object)
return identity_object
def __generateTraceLocationDevice(self, loc_id, loc_status,
loc_longitude, loc_latitude, loc_elevation,
loc_timeStamp, loc_category, item):
uuidLocation = self.__checkGeoCoordinates(loc_latitude, loc_longitude,
loc_elevation, loc_category)
return uuidLocation
def __generate_phone_account_facet(
self,
phone_num: str,
source: Optional[str] = None,
name: Optional[str] = None,
):
'''
Generate the PhoneAccountFacet and the associated Identity based on its name.
'''
identity = None
if source != "":
identity = uco.identity.Identity()
identity_name = uco.identity.SimpleNameFacet(
given_name=source
)
self.bundle.append_to_uco_object(identity)
observable = uco.observable.ObservableObject()
account_facet = uco.observable.AccountFacet(identifier=name, issuer_id=identity)
phone_account_facet = uco.observable.PhoneAccountFacet(phone_number=phone_num)
observable.append_facets(account_facet, phone_account_facet)
self.bundle.append_to_uco_object(observable)
return observable
def __generateTraceInvestigativeAction(self, name, description, start_time, end_time,
object_instrument, str_location, object_performer, object_input,
object_list_result):
start_time = self.cleanDate(start_time)
end_time = self.cleanDate(end_time)
object_location = self.__generateTraceLocation(str_location)
investigation = case.investigation.InvestigativeAction(