-
Notifications
You must be signed in to change notification settings - Fork 13
/
ufade.py
1258 lines (1166 loc) · 56.2 KB
/
ufade.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
#!/usr/bin/env python3
# UFADE - Universal Forensic Apple Device Extractor (c) C.Peter 2024
# Licensed under GPLv3 License
from pymobiledevice3 import usbmux, exceptions, lockdown
from pymobiledevice3.services.mobile_image_mounter import DeveloperDiskImageMounter, MobileImageMounterService, PersonalizedImageMounter
from pymobiledevice3.lockdown import create_using_usbmux, create_using_remote
from pymobiledevice3.lockdown import LockdownClient
from pymobiledevice3.services.companion import CompanionProxyService
from pymobiledevice3.services import installation_proxy
from pymobiledevice3.services.mobilebackup2 import Mobilebackup2Service
from pymobiledevice3.services.springboard import SpringBoardServicesService
from pymobiledevice3.services.afc import AfcService
from pymobiledevice3.services.house_arrest import HouseArrestService
from pymobiledevice3.services.crash_reports import CrashReportsManager
from pymobiledevice3.services.os_trace import OsTraceService
from pymobiledevice3.services.dvt.instruments.device_info import DeviceInfo
from pymobiledevice3.services.dvt.instruments.screenshot import Screenshot
from pymobiledevice3.services.screenshot import ScreenshotService
from pymobiledevice3.services.dvt.dvt_secure_socket_proxy import DvtSecureSocketProxyService
from pymobiledevice3.services.accessibilityaudit import AccessibilityAudit, Direction
from pymobiledevice3.services.amfi import AmfiService
from pymobiledevice3.tcp_forwarder import UsbmuxTcpForwarder
from pymobiledevice3.services.pcapd import PcapdService
from pymobiledevice3.tunneld import TUNNELD_DEFAULT_ADDRESS, TunneldRunner, get_tunneld_devices, get_rsds
from pymobiledevice3.services.os_trace import OsTraceService
from paramiko import SSHClient, AutoAddPolicy, Transport
from pathlib import Path
from dialog import Dialog
from iOSbackup import iOSbackup
from pyiosbackup import Backup
from datetime import datetime, timedelta, timezone, date
from subprocess import Popen, PIPE, check_call, run
from curses import wrapper
import posixpath
import pathlib
from playsound import playsound
import contextlib
import getpass
import pandas as pd
import numpy as np
import tarfile
import zipfile
import locale
import shutil
import os
import sys
import re
import string
import plistlib
import hashlib
import threading
import curses
import time
locale.setlocale(locale.LC_ALL, '')
d = Dialog(dialog="dialog")
d.set_background_title("Universal Forensic Apple Device Extractor (UFADE) by Prosch")
main_screen = curses.initscr()
pw = '12345'
app_name = None
developer = False
# Check for Apple device #
def check_device():
try:
lockdown = create_using_usbmux()
except:
code = d.yesno("No Apple device found! Check again?")
if code == d.OK:
#LockdownClient.pair()
check_device()
else:
os.system('clear')
raise SystemExit
finally:
try:
lockdown = create_using_usbmux()
return(lockdown)
except:
pass
#Menu options
def select_menu(main_screen):
code, tag = d.menu("Choose:",
choices=[("(1)", "Save device information to text", "Save device information and a list of user-installed apps to a textfile"),
("(2)", "Backup Options", "Data acquisition menu."),
("(3)", "Collect Unified Logs", "Collects the AUL from the device and saves them as a logarchive."),
("(4)", "Developer Options", "Access developer mode for further options."),
("(5)", "Advanced Options", "More specific options for data handling.")],
item_help=True, title=(dev_name + ", iOS " + version))
if code == d.OK:
if tag == "(1)":
save_info_menu()
elif tag == "(2)":
bu_menu()
elif tag == "(3)":
time=None
collect_ul(time)
elif tag == "(4)":
developer_options()
elif tag == "(5)":
advanced_menu()
else:
raise SystemExit
else:
os.system('clear')
raise SystemExit
def bu_menu():
code, tag = d.menu("Choose:",
choices=[("(1)", "Logical (iTunes-Style) Backup", "Perform a backup as iTunes would do it."),
("(2)", "Logical+ Backup", "Perform and decrypt an iTunes backup, gather AFC-media files, shared App folders and crash reports."),
("(3)", "Logical+ Backup (UFED-Style)", "Creates an advanced Logical Backup as ZIP with an UFD File for PA."),
("(4)", "Filesystem Backup (jailbroken)", "Creates a FFS Backup of an already jailbroken Device")],
item_help=True, title=(dev_name + ", iOS " + version))
if code == d.OK:
if tag == "(1)":
perf_itunes()
elif tag == "(2)":
perf_logical_plus(None)
elif tag == "(3)":
perf_logical_plus("UFED")
elif tag == "(4)":
perf_jailbreak_ssh_dump()
else:
bu_menu()
else:
select_menu(main_screen)
def advanced_menu():
code, tag = d.menu("Choose:",
choices=[("(1)", "Collect Unified Logs (with start time)", "Collects the AUL from the device from a given start-time and saves them as a logarchive."),
("(2)", "Extract crash reports", "Pull the crash report folder from the device"),
("(3)", "Initiate Sysdiagnose", "Create a Sysdiagnose archive on the device and pull it to the disk afterwards."),
("(4)", "Generate WhatsApp export (PuMA)", "Perform an iTunes-style Backup and extract the ChatStorage.sqlite alongside the Media-folder."),
("(5)", "Sniff device traffic", "Captures the device network traffic as a pcap file.")],
item_help=True, title=(dev_name + ", iOS " + version))
if code == d.OK:
if tag == "(1)":
code, da = d.calendar("Set the start time for the log-collection:")
if code == d.OK:
start = datetime(da[2],da[1],da[0])
time = int(datetime.timestamp(start))
collect_ul(time)
else:
advanced_menu()
elif tag == "(2)":
crash_report("Crash_Report")
d.msgbox("Extraction of crash reports completed!")
advanced_menu()
elif tag == "(3)":
sysdiagnose()
elif tag == "(4)":
backup_tess()
elif tag == "(5)":
network_capture()
else:
advanced_menu()
else:
select_menu(main_screen)
def watch_menu(main_screen):
code, tag = d.menu("Choose:",
choices=[("(1)", "Save device information to text", "Save device information and a list of user-installed apps to a textfile"),
("(2)", "Collect Unified Logs", "Collects the AUL from the device and saves them as a logarchive."),
("(3)", "Extract crash reports", "Pull the crash report folder from the device"),
("(4)", "Extract Media folder","Pull AFC-files (pictures, videos, recordings)")],
item_help=True, title=(dev_name + ", WatchOS " + version))
if code == d.OK:
if tag == "(1)":
save_info_menu()
elif tag == "(2)":
time=None
collect_ul(time)
elif tag == "(3)":
crash_report("Crash_Report")
d.msgbox("Extraction of crash reports completed!")
watch_menu(main_screen)
elif tag == "(4)":
folder = ("Media_" + udid)
os.mkdir(folder)
media_export(l_type="folder", dest=folder)
d.msgbox("AFC extraction complete!")
watch_menu(main_screen)
else:
raise SystemExit
else:
os.system('clear')
raise SystemExit
#Set directory
def chdir():
dir = os.getcwd()
code = d.yesno("Current working directory is: " + dir + "\n\nChange directory?")
if code == d.OK:
code, user_input = d.inputbox("Enter the name of the new directory:", title="New Path")
if code == d.OK:
try:
if user_input == '':
user_input = '.'
os.chdir(user_input)
dir = os.getcwd()
d.msgbox("New working directory is: " + dir)
pass
except:
os.mkdir(user_input)
os.chdir(user_input)
dir = os.getcwd()
d.msgbox("New working directory is: " + dir)
else:
d.msgbox("Working directory hasn't changed")
pass
else:
pass
return(dir)
# Check if a device is connected and print info
def show_device():
d.msgbox("Device found: \n\n" +
"Model-Nr: " + dev_name +
"\nDev-Name: " + name +
"\nHardware: " + hardware + ", " + mnr +
"\nProduct : " + product +
"\nSoftware: " + version +
"\nBuild-Nr: " + build +
"\nLanguage: " + language +
"\nSerialnr: " + snr +
"\nMLB-snr : " + mlbsnr +
"\nWifi MAC: " + w_mac +
"\nBT - MAC: " + b_mac +
"\nDisk Use: " + graph_progress +
"\nCapacity: " + disk + "0 GB" +
"\nUsed Cap: " + used + " GB" +
"\nFree Cap: " + free + " GB" +
"\nUDID : " + udid +
"\nECID : " + ecid +
"\nIMEI : " + imei +
"\nIMEI2: " + imei2, height=26, width=52)
#Play a notfication sound:
def notify():
playsound(os.path.join(os.path.dirname(__file__), "assets", "notification.mp3"))
curses.flash()
time.sleep(1)
#Save device information to txt File
def save_info():
file = open("device_" + udid + ".txt", "w")
file.write("## DEVICE ##\n\n" + "Model-Nr: " + dev_name + "\nDev-Name: " + name + "\nHardware: " + hardware + ", " + mnr + "\nProduct: " + product +
"\nSoftware: " + version + "\nBuild-Nr: " + build + "\nLanguage: " + language + "\nSerialnr: " + snr + "\nMLB-snr: " + mlbsnr +
"\nWifi MAC: " + w_mac + "\nBT-MAC: " + b_mac + "\nCapacity: " + disk + "0 GB" + "\nFree Space: " + free + " GB" +
"\nUDID : " + udid + "\nECID : " + ecid + "\nIMEI : " + imei + "\nIMEI2: " + imei2)
try:
number = lockdown.get_value(key="PhoneNumber")
if number == None:
number = ""
except: number = ""
if number != "":
file.write("\n\nLast Number: " + number)
if comp != []:
file.write("\n\n## COMPANION DEVICES (e.g. Watches) ##")
try:
for entry in comp:
file.write("\nUDID: " + entry)
except:
pass
#SIM-Info
try:
all = lockdown.all_values.get("CarrierBundleInfoArray")
if all == None:
all = ""
except:
all = ""
if all != "":
for entry in all:
if entry["Slot"] == "kOne":
stype = "SIM"
else:
stype = "eSIM"
try: file.write("\n\n## SIM-Info ##\n\nICCID: " + entry["IntegratedCircuitCardIdentity"] +
"\nIMSI: " + entry["InternationalMobileSubscriberIdentity"] +
"\nMCC: " + entry["MCC"] +
"\nMNC: " + entry["MNC"] +
"\nType: " + stype)
except: pass
#Save user-installed Apps to txt
try: l = str(len(max(app_id_list, key=len)))
except: l = 40
file.write("\n\n" + "## Installed Apps (by user) [App, shared documents] ## \n")
for app in app_id_list:
try:
apps.get(app)['UIFileSharingEnabled']
sharing = 'yes'
except:
sharing = 'no'
file.write("\n" + '{:{l}}'.format(app, l=l) + "\t [" + sharing + "]")
file.close()
#Create the info-file as txt
def save_info_menu():
save_info()
d.msgbox("Info written to device_" + udid + ".txt")
if d_class == "Watch":
watch_menu(main_screen)
else:
select_menu(main_screen)
#Stop the beep-timer for the PIN promt and show the backup process
def process_beep(x,m, beep_timer):
beep_timer.cancel()
d.gauge_update(int(x),"Performing " + m + " Backup: ",update_text=True)
#Perform iTunes Backup
def iTunes_bu(mode):
m = mode
pw_found = 0
#Check for active Encryption and activate
try:
beep_timer = threading.Timer(13.0,notify)
beep_timer.start()
curses.noecho()
d.infobox("Checking Backup Encryption.\n\nUnlock device with PIN/PW if prompted")
curses.echo()
c1 = str(Mobilebackup2Service(lockdown).change_password(new="12345")) #Try to activate backup encryption with password "12345"
if c1 == "None":
beep_timer.cancel()
d.infobox("New Backup password: \"12345\" \n\nStarting Backup...\n\nUnlock device with PIN/PW")
pw_found = 1
except:
beep_timer.cancel()
code = d.yesno("Backup Encryption is activated with password. Is the password known?")
if code == d.OK:
code, user_input = d.inputbox("Enter the password:", title="Backup password: ") #Get the password from user input
if code == d.OK:
pw = user_input
try:
Mobilebackup2Service(lockdown).change_password(old=pw) #Try to deactivate backup encryption with the given password
pw_found = 1
except:
d.msgbox("Wrong password.")
pass
else:
code = d.yesno("Do you want to attemt a password bruteforce? (Disable PIN/PW on Device beforehand)")
if code == d.OK:
code = d.yesno("Do you want to use the provided dictionary?")
if code == d.OK:
with open(os.path.dirname(__file__) + "/bu_pw.txt") as pwds:
pw_list = pwds.read().splitlines()
pw_count = len(pw_list)
else:
code, user_input = d.inputbox("Enter the path to your file:", title="Password File: ")
if code == d.OK:
try:
with open(user_input) as pwds:
pw_list = pwds.read().splitlines()
pw_count = len(pw_list)
except:
d.msgbox("Error loading file!")
pass
else:
select_menu(main_screen)
pw_num = 0
pw_pro = 0
d.gauge_start("Bruteforcing backup password on device: ")
for pw in pw_list:
d.gauge_update(pw_pro)
try:
Mobilebackup2Service(lockdown).change_password(old=pw)
d.msgbox("Password found: " + pw)
pw_found = 1
break
except:
pass
pw_num += 1
pw_pro = int(100*(pw_num/pw_count))
if pw_found == 0:
code_reset = d.yesno("Dictionary exhausted. Do you want to reset the password on the device?")
if code_reset == d.OK:
icons = SpringBoardServicesService(lockdown).get_icon_state()
d.msgbox("Unlock the device. \nOpen the \"Settings\"-app \n--> \"General\" \n--> \"Reset\" (bottom) \n--> \"Reset all Settings\"\n\n"
+ "You will loose known networks, user settings and dictionary. App and User-Data will remain.\n\nWait for the device to reboot and press \"OK\"", height=18, width=52)
try:
beep_timer = threading.Timer(13.0,notify)
beep_timer.start()
d.infobox("Trying to activate Backup Encryption again. \n\nUnlock device with PIN/PW if prompted")
c = str(Mobilebackup2Service(lockdown).change_password(new="12345"))
if c == 'None':
beep_timer.cancel()
pw_found = 1
SpringBoardServicesService(lockdown).set_icon_state(icons)
except:
beep_timer.cancel()
d.msgbox("Uh-Oh ... An error was raised ... try again.")
pass
else:
pass
else:
d.msgbox("You are still able to create a backup: \nUnlock the device. \nOpen the \"Settings\"-app \n--> \"General\" \n--> \"Reset\" (bottom) \n--> \"Reset all Settings\"\n\n"
+ "You will loose known networks, user settings and dictionary. App and User-Data will remain.\n\nWait for the device to reboot and start the extraction again.", height=18, width=52)
if pw_found == 1:
curses.noecho()
d.infobox("Encryption has to be reactivated\n\nNew Password is: \"12345\" \n\nUnlock device with PIN/PW if prompted")
curses.echo()
try:
beep_timer = threading.Timer(13.0,notify)
beep_timer.start()
c2 = str(Mobilebackup2Service(lockdown).change_password(new="12345"))
if c2 == "None":
beep_timer.cancel()
except:
beep_timer.cancel()
pass
d.infobox("Starting Backup...")
finally:
if pw_found == 1:
d.gauge_start("Performing " + m + " Backup - Unlock device with PIN/PW if prompted")
beep_timer = threading.Timer(13.0,notify)
beep_timer.start()
stderr_old = sys.stderr
sys.stderr = None
curses.noecho()
Mobilebackup2Service(lockdown).backup(full=True, progress_callback=lambda x: (process_beep(x,m,beep_timer)))
curses.echo()
sys.stderr = stderr_old
d.gauge_stop()
save_info()
beep_timer = threading.Timer(13.0,notify)
beep_timer.start()
curses.noecho()
d.infobox("iTunes Backup complete! Trying to deactivate Backup Encryption again. \n\nUnlock device with PIN/PW if prompted")
curses.echo()
try:
c3 = str(Mobilebackup2Service(lockdown).change_password(old="12345"))
except:
c3 = 'None'
pass
if c3 == 'None':
beep_timer.cancel()
else:
#curses.endwin()
select_menu(main_screen)
def perf_itunes():
iTunes_bu("iTunes-Style") #call iTunes Backup with "iTunes-Style" written in dialog
try: os.rename(udid, udid + "_iTunes")
except: pass #rename backup folder to prevent conflicts with other workflow-options
d.msgbox("Backup completed!")
select_menu(main_screen)
#Make advanced Backup - l_type(t) defines the type: 'None' for regular; 'UFED' for UFED-Style
def perf_logical_plus(t):
l_type = t
try: os.mkdir(".tar_tmp") #create temp folder for files to zip/tar
except: pass
try: os.mkdir(".tar_tmp/itunes_bu") #create folder for decrypted backup
except: pass
now = datetime.now()
iTunes_bu("Logical+") #call iTunes Backup with "Logical+" written in dialog
if l_type != "UFED":
try:
b = iOSbackup(udid=udid, cleartextpassword="12345", derivedkey=None, backuproot="./") #Load Backup with Password
key = b.getDecryptionKey() #Get decryption Key
b = iOSbackup(udid=udid, derivedkey=key, backuproot="./") #Load Backup again with Key
backupfiles = pd.DataFrame(b.getBackupFilesList(), columns=['backupFile','domain','name','relativePath']) #read dataframe from iOSbackup to pandas module
line_list = []
line_cnt = 0
for line in backupfiles['relativePath']: #get amount of lines (files) of backup
if(line not in line_list):
line_cnt += 1
line_list.append(line)
d_nr = 0
d.gauge_start("Decrypting iTunes Backup: ") #show percentage of decryption-process
tar = tarfile.open(udid + "_logical_plus.tar", "w:")
for file in line_list:
d_nr += 1
dpro = int(100*(d_nr/line_cnt))
d.gauge_update(dpro)
try:
b.getFileDecryptedCopy(relativePath=file, targetName=file, targetFolder=".tar_tmp/itunes_bu") #actually decrypt the backup-files
file_path = os.path.join('.tar_tmp/itunes_bu', file)
tar.add(file_path, arcname=os.path.join("iTunes_Backup/",
backupfiles.loc[backupfiles['relativePath'] == file, 'domain'].iloc[0], file), recursive=False) #add files to the TAR
try: os.remove(file_path) #remove the file after adding
except: pass
except:
pass
d.gauge_stop()
except: #use pyiosbackup as fallback for older devices (atm iOSbackup is behaving more reliable for newer iOS Versions)
d.infobox("Decrypting iTunes Backup - this may take a while.")
Backup.from_path(backup_path=udid, password="12345").unback(".tar_tmp/itunes_bu")
tar = tarfile.open(udid + "_logical_plus.tar", "w:")
tar.add(".tar_tmp/itunes_bu", arcname="iTunes_Backup/", recursive=True)
shutil.rmtree(".tar_tmp/itunes_bu") #remove the backup folder
shutil.rmtree(udid)
else:
zipname = "Apple_" + hardware.upper() + " " + dev_name + ".zip" #create ZIP-File for CLB PA (TAR-handling isn't as good here)
zip = zipfile.ZipFile(zipname, "w")
d.infobox("Processing Backup ...")
base = udid
for root, dirs, files in os.walk(base):
for file in files:
source_file = os.path.join(root, file)
filename = os.path.relpath(source_file, base)
zip.write(source_file, arcname=os.path.join("iPhoneDump/Backup Service", udid, "Snapshot", filename)) #just copy the encrypted backup to a ZIP
shutil.rmtree(udid) #delete the backup after zipping
#Gather Media Directory
try: os.mkdir(".tar_tmp/media")
except: pass
stderr_old = sys.stderr
sys.stderr = None
if l_type != "UFED":
media_export(l_type, dest=".tar_tmp/media", archive=tar)
else:
media_export(l_type, dest=".tar_tmp/media", archive=zip)
shutil.rmtree(".tar_tmp/media")
sys.stderr = stderr_old #remove media-folder
#Gather Shared App-Folders
media_count = 0
d.gauge_start("Performing Extraction of Shared App-Files")
for app in doc_list:
if app == 'yes':
media_count += 1
try: os.mkdir(".tar_tmp/app_doc")
except: pass
m_nr = 0
i = 0
for app in app_id_list:
if doc_list[i] == 'yes':
m_nr += 1
mpro = int(100*(m_nr/media_count))
d.gauge_update(mpro)
file_path = os.path.join(".tar_tmp/app_doc/", app, str((apps.get(app)['EnvironmentVariables'])['CFFIXED_USER_HOME'])[1:], "Documents/")
os.makedirs(file_path, exist_ok=True)
pull(self=HouseArrestService(lockdown, bundle_id=app, documents_only=True), relative_src="/Documents/.", dst=file_path)
if l_type != "UFED":
tar.add(file_path, arcname=os.path.join("App_Share/", app, str((apps.get(app)['EnvironmentVariables'])['CFFIXED_USER_HOME'])[1:], "Documents/"), recursive=True)
else:
for root, dirs, files in os.walk(file_path):
for file in files:
source_file = os.path.join(root, file)
filename = os.path.relpath(source_file, file_path)
zip.write(source_file, arcname=os.path.join("iPhoneDump/Applications/", app, filename))
try: os.remove(file_path)
except: shutil.rmtree(file_path)
i += 1
d.gauge_stop()
shutil.rmtree(".tar_tmp/app_doc")
#Gather Crash-Reports
if l_type != "UFED":
crash_report(".tar_tmp/Crash")
tar.add(".tar_tmp/Crash", arcname=("/Crash"), recursive=True)
shutil.rmtree(".tar_tmp/Crash")
#Gather device information as device_values.plist for UFD-ZIP
else:
de_va1 = ["ActivationPublicKey", "ActivationState", "ActivationStateAcknowledged", "BasebandSerialNumber", "BasebandStatus", "BasebandVersion", "BluetoothAddress", "BuildVersion", "CPUArchitecture", "DeviceCertificate",
"DeviceClass", "DeviceColor", "DeviceName", "DevicePublicKey", "DieID", "FirmwareVersion", "HardwareModel", "HardwarePlatform", "HostAttached", "InternationalMobileEquipmentIdentity", "MLBSerialNumber",
"MobileSubscriberCountryCode", "MobileSubscriberNetworkCode", "ModelNumber", "PartitionType", "PasswordProtected", "ProductionSOC", "ProductType", "ProductVersion", "ProtocolVersion", "ProximitySensorCalibration",
"RegionInfo", "SerialNumber", "SIMStatus", "SoftwareBehavior", "SoftwareBundleVersion", "SupportedDeviceFamilies", "TelephonyCapability", "TimeIntervalSince1970", "TimeZone", "TimeZoneOffsetFromUTC",
"TrustedHostAttached", "UniqueChipID", "UniqueDeviceID", "UseRaptorCerts", "Uses24HourClock", "WiFiAddress" ]
de_va2 = ["com.apple.disk_usage", "com.apple.disk_usage.factory","com.apple.fairplay", "com.apple.iTunes","com.apple.international", "com.apple.iqagent", "com.apple.mobile.backup",
"com.apple.mobile.battery", "com.apple.mobile.chaperone", "com.apple.mobile.data_sync", "com.apple.mobile.debug", "com.apple.mobile.iTunes", "com.apple.mobile.iTunes.SQLMusicLibraryPostProcessCommands",
"com.apple.mobile.iTunes.accessories</key>", "com.apple.mobile.iTunes.store", "com.apple.mobile.internal", "com.apple.mobile.lockdown_cache", "com.apple.mobile.lockdownd",
"com.apple.mobile.mobile_application_usage", "com.apple.mobile.nikita", "com.apple.mobile.restriction", "com.apple.mobile.software_behavior", "com.apple.mobile.sync_data_class",
"com.apple.mobile.tethered_sync", "com.apple.mobile.third_party_termination", "com.apple.mobile.user_preferences", "com.apple.mobile.wireless_lockdown", "com.apple.purplebuddy", "com.apple.xcode.developerdomain"]
de_va_di = {}
de_va_di = {}
for key in de_va1:
try: de_va_di.update([(key,(lockdown.get_value("",key)))])
except: pass
for key in de_va2:
try: de_va_di.update([(key,(lockdown.get_value(key,"")))])
except: pass
with open("device_values.plist", "wb") as file:
plistlib.dump(de_va_di, file)
#Begin Time for UFD-Report
local_timezone = datetime.now(timezone.utc).astimezone().tzinfo
utc_offset = now.astimezone().utcoffset()
utc_offset_hours = utc_offset.total_seconds() / 3600
if utc_offset_hours >= 0:
sign = "+"
else:
sign = "-"
output_format = "%d/%m/%Y %H:%M:%S"
begin = str(now.strftime(output_format)) + " (" + sign + str(int(utc_offset_hours)) + ")"
#End Time for UFD-Report
end = datetime.now()
local_timezone = datetime.now(timezone.utc).astimezone().tzinfo
utc_offset = end.astimezone().utcoffset()
utc_offset_hours = utc_offset.total_seconds() / 3600
if utc_offset_hours >= 0:
sign = "+"
else:
sign = "-"
output_format = "%d/%m/%Y %H:%M:%S"
e_end = str(end.strftime(output_format)) + " (" + sign + str(int(utc_offset_hours)) + ")"
#Create the PhoneInfo.xml for the UFD-ZIP
all_list = lockdown.get_value("","")
dic_a = {'Request': 'GetValue', 'Value': all_list}
with open("PhoneInfo.xml", "wb") as file:
plistlib.dump(dic_a, file)
zip.write("PhoneInfo.xml", arcname=("iPhoneDump/Lockdown Service/PhoneInfo.xml"))
zip.write("device_values.plist", arcname=("iPhoneDump/Lockdown Service/device_values.plist"))
os.remove("PhoneInfo.xml")
os.remove("device_values.plist")
shutil.rmtree(".tar_tmp/")
if l_type != 'UFED':
tar.close()
else:
zip.close()
d.infobox("Calculate SHA256 hash. This may take a while.")
try:
with open(zipname, 'rb', buffering=0) as z:
z_hash = hashlib.file_digest(z, 'sha256').hexdigest()
except:
z_hash = " Error - Python >= 3.11 required"
with open("Apple_" + hardware.upper() + " " + dev_name + ".ufd", "w") as ufdf:
ufdf.write("[DeviceInfo]\nIMEI1=" + imei + "\nIMEI2=" + imei2 + "\nModel=" + product + "\nOS=" + version + "\nVendor=Apple\n\n[Dumps]\nFileDump=Apple_" + hardware.upper() + " " +
dev_name + ".zip\n\n[ExtractionStatus]\nExtractionStatus=Success\n\n[FileDump]\nType=ZIPfolder\nZIPLogicalPath=iPhoneDump\n\n[General]\nAcquisitionTool=UFADE\nBackupPassword=12345\nConnectionType=Cable No. 210 or Original Cable\nDate=" + begin + "\nDevice=" + d_class.upper() + "\nEndTime=" + e_end + "\nExtractionNameFromXML=File System\nExtractionType=AdvancedLogical\nFullName=" +
hardware.upper() + " " + dev_name + "\nGUID=" + udid + "\nInternalBuild=\nIsEncrypted=True\nIsEncryptedBySystem=True\nMachineName=\nModel=" + hardware.upper() + " " + dev_name + "\nUfdVer=1.2\nUnitId=\nUserName=\nVendor=Apple\nVersion=other\n\n[SHA256]\n" + zipname + "=" + z_hash.upper() + "")
d.msgbox("Logical+ Backup completed!")
select_menu(main_screen)
def pull(self, relative_src, dst, callback=None, src_dir=''):
src = posixpath.join(src_dir, relative_src)
if callback is not None:
callback(src, dst)
src = self.resolve_path(src)
if not self.isdir(src):
# normal file
if "default.realm." in src:
pass
mtime = self.stat(src)['st_mtime'].timestamp()
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(relative_src))
with open(dst, 'wb') as f:
f.write(self.get_file_contents(src))
os.utime(dst, (mtime, mtime))
else:
# directory
dst_path = pathlib.Path(dst) / os.path.basename(relative_src)
dst_path.mkdir(parents=True, exist_ok=True)
for filename in self.listdir(src):
src_filename = posixpath.join(src, filename)
dst_filename = dst_path / filename
src_filename = self.resolve_path(src_filename)
if self.isdir(src_filename):
dst_filename.mkdir(exist_ok=True)
pull(self, src_filename, str(dst_path), callback=callback)
continue
pull(self, src_filename, str(dst_path), callback=callback)
def media_export(l_type, dest="Media", archive=None):
media_list = []
tar = archive
zip = archive
d.gauge_start("Performing AFC Extraction of Mediafiles")
for line in AfcService(lockdown).listdir("/"):
media_list.append(line)
if l_type != "folder":
media_list.remove("DCIM") #get amount of lines (files and folders) in media root
media_count = len(media_list)
try: os.mkdir(dest)
except: pass
m_nr = 0
for entry in media_list:
m_nr += 1
mpro = int(100*(m_nr/media_count))
d.gauge_update(mpro)
try:
pull(self=AfcService(lockdown),relative_src=entry, dst=dest)
if l_type != "folder":
file_path = os.path.join(dest, entry) #get the files and folders shared over AFC
if l_type != "UFED":
tar.add(file_path, arcname=os.path.join("Media/", entry), recursive=True) #add the file/folder to the TAR
else:
if os.path.isfile(file_path):
zip.write(file_path, arcname=os.path.join("iPhoneDump/AFC Service/", entry)) #add the file/folder to the ZIP
elif os.path.isdir(file_path):
for root, dirs, files in os.walk(dest):
for file in files:
source_file = os.path.join(root, file)
filename = os.path.relpath(source_file, dest)
zip.write(source_file, arcname=os.path.join("iPhoneDump/AFC Service/", filename))
try: os.remove(file_path)
except: shutil.rmtree(file_path)
else:
pass
except:
pass
d.gauge_stop()
return(archive)
def crash_report(crash_dir):
crash_count = 0
crash_list = []
d.gauge_start("Performing Extraction of Crash Reports")
for entry in CrashReportsManager(lockdown).ls(""):
crash_list.append(entry)
crash_count += 1
try: os.mkdir(crash_dir)
except: pass
c_nr = 0
for entry in crash_list:
c_nr += 1
try: pull(self=AfcService(lockdown, service_name="com.apple.crashreportcopymobile"), relative_src=entry, dst=crash_dir, src_dir="")
except: pass
cpro = int(100*(c_nr/crash_count))
d.gauge_update(cpro)
d.gauge_update(100)
d.gauge_stop()
def backup_tess():
if "net.whatsapp.WhatsApp" not in app_id_list:
d.msgbox("WhatsApp not installed on device!")
advanced_menu()
else:
iTunes_bu("PuMA")
b = iOSbackup(udid=udid, cleartextpassword="12345", derivedkey=None, backuproot=".")
key = b.getDecryptionKey()
b = iOSbackup(udid=udid, derivedkey=key, backuproot="./")
backupfiles = pd.DataFrame(b.getBackupFilesList(), columns=['backupFile','domain','name','relativePath'])
d.infobox("Extracting WhatsApp files from backup.")
b.getFolderDecryptedCopy(targetFolder="WA_PuMA", includeDomains="AppDomainGroup-group.net.whatsapp.WhatsApp.shared")
shutil.move("WA_PuMA/AppDomainGroup-group.net.whatsapp.WhatsApp.shared/Message/Media", "WA_PuMA/Media")
shutil.move("WA_PuMA/AppDomainGroup-group.net.whatsapp.WhatsApp.shared/ChatStorage.sqlite", "WA_PuMA/ChatStorage.sqlite")
shutil.rmtree("WA_PuMA/AppDomainGroup-group.net.whatsapp.WhatsApp.shared")
d.msgbox("Files extracted to \"WA_PuMA\".")
advanced_menu()
#Generate a pcap file of the device network stream
def network_capture():
code, user_input = d.inputbox("Set the number of packets to sniff (0 is endless):",init="0")
if code == d.OK:
try:
count = int(user_input)
if count == 0:
count = -1
packet_c = 0
text = "Sniffing device traffic to PCAP-file.\n\nUse *Ctrl* and *C* to abort this process."
d.infobox(text)
with open(udid + ".pcap", "wb") as pcap_file:
serv_pcap = PcapdService(lockdown)
packets_generator = serv_pcap.watch(packets_count=count)
serv_pcap.write_to_pcap(pcap_file, packets_generator)
d.msgbox("Sniffing process stopped. " + str(count) + " packages received." )
except ValueError:
d.msgbox("Invalid input. Provide digits only.")
except:
d.msgbox("Sniffing process stopped.")
finally:
advanced_menu()
else:
advanced_menu()
#SSH-Dump from given path
def ssh_dump(scr_prt, remote_folder, user, pwd):
d.infobox("Starting FFS Backup.")
mux = usbmux.select_device()
out = mux.connect(scr_prt)
client = SSHClient()
client.set_missing_host_key_policy(AutoAddPolicy())
client.connect(sock=out, hostname='127.0.0.1', port=scr_prt, username=user, password=pwd, look_for_keys=False, allow_agent=False)
stdin, stdout, stderr = client.exec_command(f"du -s {remote_folder}")
remote_folder_size = [int(s) for s in stdout.read().split() if s.isdigit()][0]*512
tar_command = f"tar --exclude *.gl --exclude '.overprovisioning_file' -cf - {remote_folder}"
stdin, stdout, stderr = client.exec_command(tar_command)
tar_data = stdout.channel.recv(65536)
transferred = 0
d.gauge_start(f"Performing Filesystem Backup:\n\n {transferred / (1024 * 1024):.2f} MB received.")
with open(udid + "_ffs.tar", "wb") as f:
while tar_data:
f.write(tar_data)
tar_data = stdout.channel.recv(65536)
transferred += len(tar_data)
ffs_pro = int((transferred / remote_folder_size) * 100)
d.gauge_update(ffs_pro, f"Performing Filesystem Backup: (Start: " + remote_folder + f")\n\n {transferred / (1024 * 1024):.2f} MB received.", update_text=True)
for i in range(ffs_pro, 100):
d.gauge_update(i)
client.close()
d.gauge_stop()
def perf_jailbreak_ssh_dump():
code, jlist = d.form("Provide the SSH parameters. The default values are suitable for Checkra1n and Palera1n: ",
elements=[("Port: ", 1, 1, "44", 1, 18, 8, 7),
("User: ", 2, 1, "root", 2, 18, 8, 20),
("Password:", 3, 1, "alpine", 3, 18, 8, 20),
("Path: ", 4, 1, "/private", 4, 18, 8, 30)])
if code == d.OK:
scr_prt = int(jlist[0])
user = jlist[1]
pwd = jlist[2]
remote_folder = jlist[3]
try:
ssh_dump(scr_prt, remote_folder, user, pwd)
d.msgbox("Filesystem backup complete!")
except:
d.msgbox("Error connecting to SSH. The device has to be in jailbroken state and SSH has to be installed.")
bu_menu()
else:
bu_menu()
#Collect Unified Logs
def collect_ul(time):
try: os.mkdir("unified_logs")
except: pass
d.infobox("Collecting Unified Logs from device. This may take some time.")
try:
OsTraceService(lockdown).collect(out= "unified_logs/" + udid + ".logarchive", start_time=time)
d.msgbox("Unified Logs written to " + udid + ".logarchive")
except:
d.msgbox("Error: \nCoud not collect logs - Maybe the device or its iOS version is too old.")
pass
try: os.rmdir("unified_logs")
except: pass
if d_class == "Watch":
watch_menu(main_screen)
else:
select_menu(main_screen)
def sysdiagnose():
d.infobox("To initiate the creation of the Sysdiagnose archive, press:\n\n[Power] + [VolUp] + [VolDown]\n\n for 0,215 seconds")
diagsrv = CrashReportsManager(lockdown)
try:
sysdiagname = diagsrv._get_new_sysdiagnose_filename()
d.infobox("Creation of Sysdiagnose archive has started.")
diagsrv._wait_for_sysdiagnose_to_finish()
d.infobox("Pulling the Sysdiagnose archive from the device")
diagsrv.pull(out=f"{udid}_sysdiagnose.tar.gz", entry=sysdiagname,erase=True)
d.msgbox("Extraction of Sysdiagnose archive completed!")
except:
d.msgbox("Creation canceled.")
advanced_menu()
#Try to mount a suitable DeveloperDiskImage returns "developer" and sets the global developer value to "True"
def mount_developer():
global developer
d_images = {4:[2,3], 5:[0,1], 6:[0,1], 7:[0,1], 8:[0,1,2,3,4], 9:[0,1,2,3],
10:[0,1,2,3], 11:[0,1,2,3,4], 12:[0,1,2,3,4], 13:[0,1,2,3,4,5,7],
14:[0,1,2,4,5,6,7,7.1,8], 15:[0,1,2,3,3.1,4,5,6,6.1,7],
16:[0,1,2,3,3.1,4,4.1,5,6,7]}
try:
if DeveloperDiskImageMounter(lockdown).copy_devices() != []:
developer = True
return("developer")
developer_options()
except:
pass
try:
if lockdown.developer_mode_status == True:
pass
else:
code = d.yesno("The device has to be rebooted in order to activate the developer mode.\n\n(Deactivate the PIN/PW before you proceed)\n\nDo you want to restart the device?", width=35, height=13)
if code == d.OK:
try:
AmfiService(lockdown).enable_developer_mode(enable_post_restart=True)
d.msgbox("Wait for the device to reboot.\nUnlock it and confirm the activation of the developer mode.\n\nAfter this, press \"OK\".", width=35)
except:
d.msgbox("Uh-Oh, an error was raised. Please remove the PIN/PW and try again")
select_menu(main_screen)
raise SystemExit
else:
select_menu(main_screen)
raise SystemExit
except SystemExit:
raise SystemExit
except:
pass
if int(version.split(".")[0]) < 17:
try:
info = ("Looking for version " + version)
d.infobox(info)
time.sleep(1)
DeveloperDiskImageMounter(lockdown).mount(image=os.path.dirname(__file__) + "/ufade_developer/Developer/" + version + "/DeveloperDiskImage.dmg", signature=os.path.dirname(__file__) + "/ufade_developer/Developer/" + version + "/DeveloperDiskImage.dmg.signature")
developer = True
return("developer")
except:
info = info + "\nVersion " + version + " not found"
d.infobox(info)
time.sleep(1)
v = version.split(".")
v_check = np.array(d_images[int(v[0])])
v_diff = np.absolute(v_check - int(v[1]))
index = v_diff.argmin()
ver = str(v[0]) + "." + str(d_images[int(v[0])][index])
finally:
if int(v[0]) <= 12 or DeveloperDiskImageMounter(lockdown).copy_devices() == []:
info = info + "\nClosest version is " + ver
d.infobox(info)
time.sleep(1)
try:
DeveloperDiskImageMounter(lockdown).mount(image=os.path.dirname(__file__) + "/ufade_developer/Developer/" + ver + "/DeveloperDiskImage.dmg", signature=os.path.dirname(__file__) + "/ufade_developer/Developer/" + ver + "/DeveloperDiskImage.dmg.signature")
info = info + "\nVersion: " + ver + " was used"
developer = True
return("developer")
except exceptions.AlreadyMountedError:
developer = True
return("developer")
except:
for i in range(index)[::-1]:
ver = str(v[0]) + "." + str(d_images[int(v[0])][i])
try:
DeveloperDiskImageMounter(lockdown).mount(image=os.path.dirname(__file__) + "/ufade_developer/Developer/" + ver + "/DeveloperDiskImage.dmg", signature=os.path.dirname(__file__) + "/ufade_developer/Developer/" + ver + "/DeveloperDiskImage.dmg.signature")
info = info + "\nVersion: " + ver + " was used"
d.infobox(info)
time.sleep(1)
break
except:
pass
if int(v[0]) <= 12:
return("developer")
else:
pass
if DeveloperDiskImageMounter(lockdown).copy_devices() == []:
d.msgbox("DeveloperDiskImage not loaded")
return("nope")
else:
d.msgbox("DeveloperDiskImage loaded")
developer = True
return("developer")
else:
d.msgbox("DeveloperDiskImage loaded")
developer = True
return("developer")
else:
try:
d.infobox("Mounting personalized image.")
PersonalizedImageMounter(lockdown).mount(image=Path(os.path.dirname(__file__) + '/ufade_developer/Developer/Xcode_iOS_DDI_Personalized/Image.dmg'), build_manifest=Path(os.path.dirname(__file__) + '/ufade_developer/Developer/Xcode_iOS_DDI_Personalized/BuildManifest.plist'), trust_cache=Path(os.path.dirname(__file__) + '/ufade_developer/Developer/Xcode_iOS_DDI_Personalized/Image.dmg.trustcache'))
return("developer")
except exceptions.AlreadyMountedError:
developer = True
return("developer")
except:
d.msgbox("DeveloperDiskImage not loaded")
return("nope")
def developer_options():
global developer
if len(os.listdir(os.path.join(os.path.dirname(__file__),"ufade_developer"))) != 0:
pass
else:
d.msgbox("Directory \"ufade_developer\" not found.\nPlease clone the submodule:\n\ngit submodule init\ngit submodule update", width=33, height=13)
select_menu(main_screen)
if int(version.split(".")[0]) == 17 and 0 <= int(version.split(".")[1]) < 4:
if sys.platform.system() != "Darwin":
code = d.yesno("On Linux systems a kernel path is needed to create a tunnel connection to devices with iOS versions between 17.0 and 17.3.1.\n" +
"Is your kernel patched?")
if code == d.OK:
pass
else: