-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsshrd32.sh
More file actions
executable file
·2438 lines (2333 loc) · 85.1 KB
/
sshrd32.sh
File metadata and controls
executable file
·2438 lines (2333 loc) · 85.1 KB
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
#!/bin/bash
script_dir=".."
tmp="."
saved="../saved"
ssh_port=2222
isoscheck=1
jelbrek=../resources/Jailbreak
script_path=$(dirname "$0")/$(basename "$0")
enable_latest_enter=0
ship_build_check=0
if [[ "$debug" == "1" ]]; then
menu_old=1
set -x
fi
log() {
GREEN='\033[32m'
RESET='\033[0m'
echo -e "${GREEN}[Log]${RESET} ${GREEN}$@${RESET}" > /dev/tty
eval "$@" >/dev/null 2>&1
}
error() {
RED='\033[31m'
RESET='\033[0m'
echo -e "${RED}[ERROR]${RESET} ${RED}$@${RESET}" > /dev/tty
eval "$@" >/dev/null 2>&1
}
warning() {
YELLOW='\033[33m'
RESET='\033[0m'
echo -e "${YELLOW}[WARNING]${RESET} ${YELLOW}$@${RESET}" > /dev/tty
eval "$@" >/dev/null 2>&1
}
debug() {
local BLUE='\033[38;5;45m'
RESET='\033[0m'
echo -e "${BLUE}[DEBUG]${RESET} ${BLUE}$@${RESET}" > /dev/tty
eval "$@" >/dev/null 2>&1
}
tip() {
local PURPLE='\033[0;35m'
local NC='\033[0m'
echo -e "${PURPLE}$1${NC}"
}
print() {
local PURPLE='\033[0;35m'
local NC='\033[0m'
echo -e "${PURPLE}$1${NC}"
}
input() {
YELLOW='\033[33m'
RESET='\033[0m'
echo -e "${YELLOW}[Input]${RESET} ${YELLOW}$@${RESET}" > /dev/tty
eval "$@" >/dev/null 2>&1
}
pause() {
local i
local arg="(or press Ctrl+C to cancel)"
local filtered_args=""
for i in "$@"; do
if [[ $i == noctrlc ]]; then
local arg=""
else
filtered_args="$filtered_args $i"
fi
done
filtered_args=$(echo "$filtered_args" | sed 's/^ //')
if [ -z "$filtered_args" ]; then
input "Press Enter/Return to continue $arg"
else
input "$filtered_args $arg"
fi
read -s
}
oscheck() {
if [[ -f ../resources/current_platform ]]; then
local local_platform_message=$(cat ../resources/current_platform 2>/dev/null)
else
local local_platform_message=""
fi
arch_path=
if [[ "$isoscheck" == "1" ]]; then
platform_check=$(uname)
arch_check=$(uname -m)
if [[ "$platform_check" == "Darwin" ]]; then
platform=macos
if [[ "$arch_check" == "x86_64" ]]; then
platform_arch=x86_64
elif [[ "$arch_check" == "arm64" ]]; then
platform_arch=arm64
else
error Unsupport platform,please use support platform
exit
fi
elif [[ "$platform_check" == "Linux" ]]; then
platform=linux
if [[ "$arch_check" == "x86_64" ]]; then
platform_arch=x86_64
elif [[ "$arch_check" == "arm64" ]]; then
platform_arch=arm64
else
error Unsupport platform,please use support platform
exit
fi
else
error Unsupport platform,please use support platform
exit
fi
if [[ "$platform" == "macos" ]]; then
if [[ "$platform_arch" == "arm64" ]]; then
if [[ "$ship_platform_check" != "1" ]]; then
warning "Using M-series chips may cause compatibility issues; please use with caution."
pause Press Enter to ignore this issue.
fi
dir="../bin/macos/arm64"
else
dir="../bin/macos"
fi
macos_ver="${1:-$(sw_vers -productVersion)}"
macos_major_ver="${macos_ver:0:2}"
if [[ $macos_major_ver == 10 ]]; then
macos_minor_ver=${macos_ver:3}
macos_minor_ver=${macos_minor_ver%.*}
if (( macos_minor_ver < 11 )); then
if [[ "$ship_platform_check" != "1" ]]; then
error "Your macOS version is too old. Please upgrade to macOS High Sierra or later."
exit
fi
fi
case $macos_minor_ver in
#11 ) macos_name="El Capitan";; too old
#12 ) macos_name="Sierra";; too old
13 ) macos_name="High Sierra";;
14 ) macos_name="Mojave";;
15 ) macos_name="Catalina";;
esac
fi
case $macos_major_ver in
11 ) macos_name="Big Sur";;
12 ) macos_name="Monterey";;
13 ) macos_name="Ventura";;
14 ) macos_name="Sonoma";;
15 ) macos_name="Sequoia";;
26 ) macos_name="Tahoe";;
esac
if (( macos_major_ver > 12 )); then
warning "There may be compatibility issues when using devices running macOS Monterey or later. Do you want to continue?"
yesno continue?
if [[ $? == 1 ]]; then
:
else
exit
fi
fi
platform_message="macOS ${macos_name}($platform_arch)"
elif [[ "$platform" == "linux" ]]; then
warning The Linux version is still being adapted, and some features have not yet been fixed. Should we continue using it?
pause Press Enter to continue.
check_sudo
linux_part
arch_path="linux/"
linux_name=$(grep '^NAME=' /etc/os-release | cut -d'"' -f2)
platform_message="${linux_name} ($platform_arch)"
dir="../bin/linux"
if [[ $linux_name != Ubuntu ]]; then
error Support ubuntu only,change your distro to ubuntu
exit
fi
fi
fi
if [[ $platform_message != $local_platform_message ]]; then
install_depends
fi
}
linux_part() {
if [[ -n $UBUNTU_CODENAME ]]; then
case $UBUNTU_CODENAME in
"jammy" | "kinetic" ) ubuntu_ver=22;;
"lunar" | "mantic" ) ubuntu_ver=23;;
"noble" | "oracular" ) ubuntu_ver=24;;
"plucky" | "questing" ) ubuntu_ver=25;;
esac
if [[ -z $ubuntu_ver ]]; then
source /etc/upstream-release/lsb-release 2>/dev/null
ubuntu_ver="$(echo "$DISTRIB_RELEASE" | cut -c -2)"
fi
if [[ -z $ubuntu_ver ]]; then
ubuntu_ver="$(echo "$VERSION_ID" | cut -c -2)"
fi
elif [[ -e /etc/debian_version ]]; then
debian_ver=$(cat /etc/debian_version)
case $debian_ver in
*"sid" | "kali"* ) debian_ver="sid";;
* ) debian_ver="$(echo "$debian_ver" | cut -c -2)";;
esac
elif [[ $ID == "fedora" || $ID_LIKE == "fedora" || $ID == "nobara" ]]; then
fedora_ver=$VERSION_ID
fi
if [[ $ID == "arch" || $ID_LIKE == "arch" || $ID == "artix" ]]; then
distro="arch"
elif (( ubuntu_ver >= 22 )) || (( debian_ver >= 12 )) || [[ $debian_ver == "sid" ]]; then
distro="debian"
elif (( fedora_ver >= 40 )); then
distro="fedora"
if [[ $(command -v rpm-ostree) ]]; then
distro="fedora-atomic"
fi
elif [[ $ID == "opensuse-tumbleweed" ]]; then
distro="opensuse"
elif [[ $ID == "gentoo" || $ID_LIKE == "gentoo" || $ID == "pentoo" ]]; then
distro="gentoo"
elif [[ $ID == "void" ]]; then
distro="void"
elif [[ -n $ubuntu_ver || -n $debian_ver || -n $fedora_ver ]]; then
error "Your distro version ($platform_ver - $platform_arch) is not supported. See the repo README for supported OS versions/distros"
else
warning "Your distro ($platform_ver - $platform_arch) is not detected/supported. See the repo README for supported OS versions/distros"
print "* You may still continue, but you will need to install required packages and libraries manually as needed."
sleep 5
pause
fi
}
check_sudo() {
if [ -z "$SUDO_USER" ]; then
log "Please enter your password."
if sudo -v >/dev/null 2>&1; then
clear
return 0
else
error "Unable to obtain sudo privileges"
exit 1
fi
else
clear
return 0
fi
}
set_path() {
if [[ "$script_dir/" =~ [[:space:]] ]]; then
error "Directory path contains whitespace characters!" >&2
error "Current directory: '$script_dir'" >&2
pause Press enter to exit
exit 1
fi
chmod +x $dir/*
if [[ "$platform" == "macos" ]]; then
sshpass=""
irecovery=""
iproxy=""
ipwnder=""
idevicerestore=""
futurerestore=""
futurerestore_old=""
ideviceinfo=""
dmg=""
zenity="$dir/zenity"
ideviceactivation=""
ideviceinstaller=""
primepwn=""
gaster=""
iBoot32Patcher=""
xpwntool=""
hfsplus=""
pzb=""
jq=""
ticket=""
validate=""
img4tool=""
irecovery2=""
aria2c=""
tsschecker=""
z7z=""
sha1sum="$(command -v shasum) -a 1"
bspatch="$(command -v bspatch)"
elif [[ "$platform" == "linux" ]]; then
export LD_LIBRARY_PATH="$dir/lib"
sshpass="sudo "
irecovery="sudo "
iproxy="sudo "
ipwnder="sudo "
idevicerestore="sudo LD_LIBRARY_PATH=$dir/lib "
futurerestore="sudo "
futurerestore_old="sudo "
ideviceinfo="sudo LD_LIBRARY_PATH=$dir/lib "
dmg="sudo "
zenity="sudo GSETTINGS_BACKEND=memory $(command -v zenity)"
ideviceactivation="sudo LD_LIBRARY_PATH=$dir/lib "
ideviceinstaller="sudo LD_LIBRARY_PATH=$dir/lib "
primepwn="sudo "
gaster="sudo "
iBoot32Patcher="sudo "
xpwntool="sudo "
hfsplus="sudo "
pzb="sudo "
jq="sudo "
ticket="sudo "
validate="sudo "
img4tool="sudo "
irecovery2="sudo "
aria2c="sudo "
z7z="sudo "
tsschecker="sudo "
afc=”sudo“
bspatch=$dir/bspatch
fi
sshpass+=$dir/sshpass
irecovery+="$dir/irecovery"
iproxy+=$dir/iproxy
ipwnder+=$dir/ipwnder
idevicerestore+=$dir/idevicerestore
futurerestore+=$dir/futurerestore
futurerestore_old+=$dir/futurerestore_old
ideviceinfo+=$dir/ideviceinfo
dmg+=$dir/dmg
ideviceactivation+=$dir/ideviceactivation
ideviceinstaller+=$dir/ideviceinstaller
primepwn+=$dir/primepwn
iBoot32Patcher+=$dir/iBoot32Patcher
xpwntool+=$dir/xpwntool
hfsplus+=$dir/hfsplus
pzb+=$dir/pzb
jq+=$dir/jq
ticket+=$dir/ticket
validate+=$dir/validate
img4tool+=$dir/img4tool
irecovery2+=$dir/irecovery2
aria2c+=$dir/aria2c
tsschecker+=$dir/tsschecker
z7z+=$dir/7zz
afc+=$dir/afc_tool
sha1sum="$(command -v shasum) -a 1"
}
prepare_udev_rules() {
local owner="$1"
local group="$2"
echo "ACTION==\"add\", SUBSYSTEM==\"usb\", ATTR{idVendor}==\"05ac\", ATTR{idProduct}==\"122[27]|128[0-3]|1338\", OWNER=\"$owner\", GROUP=\"$group\", MODE=\"0660\" TAG+=\"uaccess\"" > 39-libirecovery.rules
}
install_depends() {
rm -f "../resources/current_platform"
touch "../resources/current_platform"
if [[ $platform == "linux" ]]; then
print "Install depends now"
print "* Enter your user password when prompted"
pause
prepare_udev_rules usbmux plugdev
if [[ -n $ubuntu_ver ]]; then
sudo add-apt-repository -y universe
fi
sudo apt update
sudo apt install -y \
aria2 \
ca-certificates \
curl \
git \
libimobiledevice6 \
libimobiledevice-utils \
libssl3 \
libzstd1 \
openssh-client \
patch \
python3 \
python3-pip \
sshfs \
unzip \
usbmuxd \
usbutils \
vim-common \
xxd \
zenity \
zip \
zlib1g
pip3 install pyimg4 pylibfdt-iOS
if [[ $(command -v systemctl 2>/dev/null) ]]; then
sudo systemctl enable --now udev systemd-udevd usbmuxd 2>/dev/null
fi
echo "$platform_message" > "../resources/current_platform"
if [[ $platform == "linux" ]]; then
if [[ $(command -v systemctl) ]]; then
sudo systemctl enable --now systemd-udevd usbmuxd 2>/dev/null
fi
sudo cp 39-libirecovery.rules /etc/udev/rules.d/39-libirecovery.rules
sudo chown root:root /etc/udev/rules.d/39-libirecovery.rules
sudo chmod 0644 /etc/udev/rules.d/39-libirecovery.rules
sudo udevadm control --reload-rules
sudo udevadm trigger -s usb
fi
log "Install depends done! Please run the script again to proceed"
exit
else
echo "$platform_message" > "../resources/current_platform"
fi
}
set_ssh_config() {
if [ -z "$1" ]; then
cp ../resources/ssh_config .
if [[ $(ssh -V 2>&1 | grep -c SSH_8.8) == 1 || $(ssh -V 2>&1 | grep -c SSH_8.9) == 1 ||
$(ssh -V 2>&1 | grep -c SSH_9.) == 1 || $(ssh -V 2>&1 | grep -c SSH_1) == 1 ]]; then
echo " PubkeyAcceptedAlgorithms +ssh-rsa" >> ./ssh_config
elif [[ $(ssh -V 2>&1 | grep -c SSH_6) == 1 ]]; then
cat $script_dir/bin/Others/ssh_config | sed "s,Add,#Add,g" | sed "s,HostKeyA,#HostKeyA,g" > ssh_config
fi
fi
if [ -z "$1" ]; then
ssh="$dir/sshpass -p alpine ssh -F ./ssh_config"
scp="$dir/sshpass -p alpine scp -F ./ssh_config"
fi
if [[ "$1" == "pass" ]]; then
ssh="$dir/sshpass -p $2 ssh -F ./ssh_config"
scp="$dir/sshpass -p $2 scp -F ./ssh_config"
fi
}
checkmode() {
if [[ $2 != irec ]]; then
if [ "$1" = "DFU" ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); then
if [[ "$2" != "none" ]]; then
log "[*] Waiting for the device to enter DFU mode"
fi
fi
while ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); do
sleep 1
done
elif [ "$1" = "rec" ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (Recovery Mode)' >> /dev/null); then
if [[ "$2" != "none" ]]; then
log "[*] Waiting for the device to enter Recovery mode"
fi
fi
while ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (Recovery Mode)' >> /dev/null); do
sleep 1
done
elif [ "$1" = "nor" ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep -E ' (iPod|iPhone|iPad)' >> /dev/null); then
if [[ "$2" != "none" ]]; then
log "[*] Waiting for the device to enter Normal mode"
fi
fi
while ! (system_profiler SPUSBDataType 2> /dev/null | grep -E ' (iPod|iPhone|iPad)' >> /dev/null); do
sleep 1
done
elif [ "$1" = "DFUreal" ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' USB DFU Device' >> /dev/null); then
if [[ "$2" != "none" ]]; then
log "[*] Waiting for the device to enter DFU mode"
fi
fi
while ! (system_profiler SPUSBDataType 2> /dev/null | grep ' USB DFU Device' >> /dev/null); do
sleep 1
done
elif [ "$1" = "DFUall" ]; then
log "[*] Waiting for the device to enter DFU mode"
while true;do
if (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); then
break
fi
sleep 1
if (system_profiler SPUSBDataType 2> /dev/null | grep ' USB DFU Device' >> /dev/null); then
break
fi
done
fi
else
local mode
case $1 in
nor )
log "[*] Waiting for the device to enter Normal mode"
while true; do
device_ver=$($ideviceinfo -s 2>/dev/null | grep "ProductVersion:" | cut -d' ' -f2)
if [[ $device_ver =~ ^[0-9]+\.[0-9]+(\.[0-9]+)*$ ]]; then
break
fi
sleep 1
done
;;
rec | DFU | DFUall )
if [[ $1 == rec ]]; then
local mode="Recovery"
elif [[ $1 == DFU ]]; then
local mode="DFU"
elif [[ $1 == DFUall ]]; then
local mode="DFU"
fi
log "[*] Waiting for the device to enter $mode mode"
while true; do
device_mode="$($irecovery -q 2>/dev/null | grep -w "MODE" | cut -c 7-)"
if [[ $device_mode == "$mode" ]]; then
break
elif [[ $device_mode == "WTF" ]]; then
break
fi
sleep 1
done
;;
esac
fi
}
device_info() {
if [[ -z $device_type ]]; then
device_type=$($irecovery -q | grep -i "product" | awk -F': ' '{print $2}')
else
if [[ $device_type =~ ^(iPhone|iPad|iPod)[1-9][0-9]*,[0-9]+$ ]]; then
:
else
while true; do
error Device type entered incorrectly,please please re-enter.
read $device_type
if [[ $device_type =~ ^(iPhone|iPad|iPod)[1-9][0-9]*,[0-9]+$ ]]; then
break
fi
done
fi
fi
if [ ! -d "$saved/$device_type" ]; then
mkdir $saved/$device_type
fi
case $device_type in
iPhone1,* | iPod1,1 )
device_proc=1;; # S5L8900
iPad1,1 | iPhone[23],* | iPod[234],1 )
device_proc=4;; # A4/S5L8720/8920/8922
iPad2,* | iPad3,[123] | iPhone4,1 | iPod5,1 )
device_proc=5;; # A5
iPad3,* | iPhone5,* )
device_proc=6;; # A6
esac
case $device_type in
iPad1,1 ) device_model="k48";;
iPad2,1 ) device_model="k93";;
iPad2,2 ) device_model="k94";;
iPad2,3 ) device_model="k95";;
iPad2,4 ) device_model="k93a";;
iPad2,5 ) device_model="p105";;
iPad2,6 ) device_model="p106";;
iPad2,7 ) device_model="p107";;
iPad3,1 ) device_model="j1";;
iPad3,2 ) device_model="j2";;
iPad3,3 ) device_model="j2a";;
iPad3,4 ) device_model="p101";;
iPad3,5 ) device_model="p102";;
iPad3,6 ) device_model="p103";;
iPhone1,1) device_model="m68";;
iPhone1,2) device_model="n82";;
iPhone2,1) device_model="n88";;
iPhone3,1) device_model="n90";;
iPhone3,2) device_model="n90b";;
iPhone3,3) device_model="n92";;
iPhone4,1) device_model="n94";;
iPhone5,1) device_model="n41";;
iPhone5,2) device_model="n42";;
iPhone5,3) device_model="n48";;
iPhone5,4) device_model="n49";;
iPod1,1 ) device_model="n45";;
iPod2,1 ) device_model="n72";;
iPod3,1 ) device_model="n18";;
iPod4,1 ) device_model="n81";;
iPod5,1 ) device_model="n78";;
* ) error "Unsupport for 64Bit device,try to use(https://github.com/verygenericname/SSHRD_Script)"; exit;;
esac
device_ecid=$($idevicerestore -l 2>/dev/null | grep -i "ECID" | awk '{print $3}')
}
update() {
log Checking update
local local_ver=$(git rev-parse --short HEAD)
local commit_info=$(curl -s "https://api.github.com/repos/appleiPodTouch4/SSHRD_Script_32Bit/commits?per_page=1" | $jq -r '.[0]')
local sha=$(echo "$commit_info" | $jq -r '.sha')
local latest=${sha:0:7}
if [[ -z $local_ver || -z $latest ]]; then
error Unable get version message,please check internet connection
return
fi
if [[ $local_ver == $latest ]]; then
log It is already the latest commit,no upgrade required
else
yesno "Newest commit is $latest. Do you want to update?" 1
if [[ $? == 1 ]]; then
cd ../
if [[ -z $(command -v git) ]]; then
error Please install git first
return
fi
git fetch origin
git reset --hard origin/main
if [[ $(git rev-parse --short HEAD) == $latest ]]; then
log Update successfully,run ./sshrd.sh again
else
error Update failed,please check internet connection
return
fi
else
return
fi
fi
}
######pwn######
device_pwn() {
local a5
log Getting device info and pwning... this may take a second
local device_pwnd="$($irecovery -q | grep "PWND" | cut -c 7-)"
if [[ -z $device_pwnd ]]; then
case $device_proc in
1 ) device_s5l8900xall ;;
4 )
case $device_type in
iPad1,1 | iPhone3,* | iPod[24],1 )
if [[ $platform == linux ]]; then
$ipwnder -p
else
$primepwn
fi
;;
* )
log Pwn:ipwnder
if [[ $platform == macos ]]; then
$ipwnder
else
$ipwnder -p
fi
;;
esac
;;
5 ) a5=1 ;;
6 )
log Pwn:ipwnder
if [[ $platform == macos ]]; then
$ipwnder
else
$ipwnder -p
fi
;;
esac
fi
if [[ $device_proc == 5 ]]; then
if [[ $ship_send_pwnibss != 1 ]]; then
while true; do
local device_pwnd2="$($irecovery -q | grep "PWND" | cut -c 7-)"
if [ "$device_pwnd2" != "checkm8" ]; then
print "pwn a5 device needs Arduino+USB Host Shield or Pi Pico"
pause when you have been pwned,press enter to continue
else
break
fi
done
device_send_unpacked_ibss
else
warning make sure you have been sent pwnibss
pause press enter to continue
fi
fi
device_pwnd1="$($irecovery -q | grep "PWND" | cut -c 7-)"
if [[ $device_proc != 1 ]]; then
if [[ $device_proc != 5 && $device_proc != 6 ]]; then
if [[ -n $device_pwnd1 ]]; then
log Device has been pwned✅
else
error "Unable to pwn device❎(close i4/3u tools and try again)"
exit 1
fi
else
log "Device has been pwned✅(may be)"
log "If the dumping gets stuck, you can press Ctrl+C to cancel, then retry."
fi
fi
}
device_send_unpacked_ibss() {
local pwnrec="pwned iBSS"
device_rd_build=
patch_ibss
log "Sending unpacked iBSS..."
$primepwn pwnediBSS
local tool_pwned=$?
if [[ $tool_pwned != 0 ]]; then
error "Failed to send iBSS. Your device has likely failed to enter PWNED DFU mode." \
"* You might need to exit DFU and (re-)enter PWNED DFU mode before retrying."
fi
sleep 1
log "Checking for device"
local irec="$($irecovery -q 2>&1)"
device_pwnd="$(echo "$irec" | grep "PWND" | cut -c 7-)"
if [[ -z $device_pwnd && $irec != "ERROR"* ]]; then
log "Device should now be in $pwnrec mode."
log Device has been pwned✅
else
error "Device failed to enter $pwnrec mode."
error "Unable to pwn device❎(close i4/3u tools and try again)"
exit 1
fi
}
#####main######
ramdisk() {
local comps=("iBSS" "iBEC" "DeviceTree" "Kernelcache")
local name
local iv
local key
local path
local url
local decrypt
local ramdisk_path
local version
local build_id
local local_build_id
local files
local mode="$1"
local rec=2
all_flash="Firmware/all_flash/all_flash.${device_model}ap.production"
if [[ no_ramdisk == 1 ]]; then
return
fi
if [[ $1 == "setnvram" ]]; then
rec=$2
fi
if [[ $1 != "justboot" ]]; then
comps+=("RestoreRamdisk")
fi
case $device_type in
iPhone1,[12] | iPod1,1 ) device_target_build="7E18"; device_target_vers="3.1.3";;
iPod2,1 ) device_target_build="8C148";;
iPod3,1 | iPad1,1 ) device_target_build="9B206";;
iPhone2,1 | iPod4,1 ) device_target_build="10B500";;
iPhone5,[34] ) device_target_build="11D257";;
* ) device_target_build="10B329";;
esac
if [[ -n $device_rd_build_custom ]]; then
if [[ $ship_build_check != 1 ]]; then
if [[ "$device_rd_build_custom" =~ ^[0-9]+[A-Za-z][0-9]+[a-z]?$ ]]; then
log Get version info
get_firmware_info build $device_rd_build_custom
if [ -z "$url" ]; then
error Unable get url of this version
exit 1
fi
device_rd_build=$device_rd_build_custom
else
log Get version info
get_firmware_info ver $device_rd_build_custom
if [ -z "$url" ]; then
error Unable get url of this version
pause
exit 1
fi
device_rd_build=$buildid
fi
else
device_rd_build=$device_rd_build_custom
fi
tip "Use custom version:$device_rd_build"
elif [[ -n $device_rd_build_custom ]]; then
if [[ $ship_build_check != 1 ]]; then
log Get version info
get_firmware_info build $device_target_build
if [ -z "$url" ]; then
error Unable get url of this version
pause
exit 1
fi
fi
fi
if [[ -n $device_rd_build ]]; then
device_target_build=$device_rd_build
device_rd_build=
fi
version=$device_target_vers
build_id=$device_target_build
device_fw_key_check
ipsw_get_url $build_id $version
if [[ $arg_l != 1 ]]; then
ramdisk_path="../saved/$device_type/ramdisk_$build_id"
else
ramdisk_path="../current_ramdisk"
if [[ -f ../current_ramdisk/build_id ]]; then
local_build_id=$(cat ../current_ramdisk/build_id)
if [[ $local_build_id != $build_id ]]; then
log Clean old ramdsk
rm -f ../current_ramdisk
fi
fi
fi
if [[ -d $ramdisk_path ]]; then
local ramdisk_files=("Ramdisk.dmg" "DeviceTree.dec" "Kernelcache.dec")
for files in $ramdisk_files; do
if [[ ! -f $ramdisk_path/$files ]]; then
warning "$files missed,redownload"
pause
rm -rf $ramdisk_path
break
fi
done
fi
mkdir $ramdisk_path 2>/dev/null
if [[ $arg_l == 1 ]]; then
touch ../current_ramdisk/build_id
echo "$build_id" > "../current_ramdisk/build_id"
fi
for getcomp in "${comps[@]}"; do
name=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .filename')
iv=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .iv')
key=$(echo $device_fw_key | $jq -j '.keys[] | select(.image == "'$getcomp'") | .key')
case $getcomp in
"iBSS" | "iBEC" ) path="Firmware/dfu/";;
"DeviceTree" )
path="Firmware/all_flash/"
case $build_id in
14[EFG]* ) :;;
* ) path="$all_flash/";;
esac
;;
* ) path="";;
esac
if [[ -z $name ]]; then
local hwmodel="$device_model"
case $build_id in
14[EFG]* )
case $device_type in
iPhone5,[12] ) hwmodel="iphone5";;
iPhone5,[34] ) hwmodel="iphone5b";;
iPad3,[456] ) hwmodel="ipad3b";;
esac
;;
[789]* | 10* | 11* ) hwmodel+="ap";;
esac
case $getcomp in
"iBSS" | "iBEC" ) name="$getcomp.$hwmodel.RELEASE.dfu";;
"DeviceTree" ) name="$getcomp.${device_model}ap.img3";;
"Kernelcache" ) name="kernelcache.release.$hwmodel";;
esac
fi
log "$getcomp"
if [[ -n $ipsw_justboot_path ]]; then
file_extract_from_archive "$ipsw_justboot_path.ipsw" "${path}$name"
elif [[ -s $ramdisk_path/$name ]]; then
cp $ramdisk_path/$name .
else
"$dir/pzb" -g "${path}$name" -o "$name" "$ipsw_url"
fi
if [[ ! -s $name ]]; then
error "Failed to get $name. Please run the script again."
fi
if [[ ! -s $ramdisk_path/$name ]]; then
cp $name $ramdisk_path/
fi
mv $name $getcomp.orig
if [[ $getcomp == "Kernelcache" || $getcomp == "iBSS" ]] && [[ $device_proc == 1 || $device_type == "iPod2,1" ]]; then
decrypt="-iv $iv -k $key"
"$dir/xpwntool" $getcomp.orig $getcomp.dec $decrypt
elif [[ $build_id == "14"* ]]; then
cp $getcomp.orig $getcomp.dec
else
"$dir/xpwntool" $getcomp.orig $getcomp.dec -iv $iv -k $key -decrypt
fi
done
if [[ $1 != "justboot" ]]; then
log "Make RestoreRamdisk"
"$dir/xpwntool" RestoreRamdisk.dec Ramdisk.raw
if [[ $device_proc != 1 ]]; then
"$dir/hfsplus" Ramdisk.raw grow 30000000
"$dir/hfsplus" Ramdisk.raw untar ../resources/sbplist.tar
fi
fi
if [[ $device_proc == 1 ]]; then
$bspatch Ramdisk.raw Ramdisk.patched ../resources/patch/018-6494-014.patch
"$dir/xpwntool" Ramdisk.patched Ramdisk.dmg -t RestoreRamdisk.dec
log "Make iBSS"
$bspatch iBSS.orig iBSS ../resources/patch/iBSS.${device_model}ap.RELEASE.patch
log "Make Kernelcache"
mv Kernelcache.dec Kernelcache0.dec
$bspatch Kernelcache0.dec Kernelcache.patched ../resources/patch/kernelcache.release.s5l8900x.patch
"$dir/xpwntool" Kernelcache.patched Kernelcache.dec -t Kernelcache.orig $decrypt
rm DeviceTree.dec
mv DeviceTree.orig DeviceTree.dec
elif [[ $device_type == "iPod2,1" ]]; then
"$dir/hfsplus" Ramdisk.raw untar ../resources/ssh_old.tar
"$dir/xpwntool" Ramdisk.raw Ramdisk.dmg -t RestoreRamdisk.dec
log "Make iBSS"
$bspatch iBSS.dec iBSS.patched ../resources/patch/iBSS.${device_model}ap.RELEASE.patch
"$dir/xpwntool" iBSS.patched iBSS -t iBSS.orig
log "Make Kernelcache"
mv Kernelcache.dec Kernelcache0.dec
$bspatch Kernelcache0.dec Kernelcache.patched ../resources/patch/kernelcache.release.${device_model}.patch
"$dir/xpwntool" Kernelcache.patched Kernelcache.dec -t Kernelcache.orig $decrypt
rm DeviceTree.dec
mv DeviceTree.orig DeviceTree.dec
else
if [[ $1 != "justboot" ]]; then
"$dir/hfsplus" Ramdisk.raw untar ../resources/ssh.tar
if [[ $1 == "jailbreak" && $device_vers == "8"* ]]; then
"$dir/hfsplus" Ramdisk.raw untar ../resources/jailbreak/daibutsu/bin.tar
fi
"$dir/hfsplus" Ramdisk.raw mv sbin/reboot sbin/reboot_bak
"$dir/hfsplus" Ramdisk.raw mv sbin/halt sbin/halt_bak
case $build_id in
"12"* | "13"* | "14"* )
echo '#!/bin/bash' > restored_external
echo "/sbin/sshd; exec /usr/local/bin/restored_external_o" >> restored_external
"$dir/hfsplus" Ramdisk.raw mv usr/local/bin/restored_external usr/local/bin/restored_external_o
"$dir/hfsplus" Ramdisk.raw add restored_external usr/local/bin/restored_external
"$dir/hfsplus" Ramdisk.raw chmod 755 usr/local/bin/restored_external
"$dir/hfsplus" Ramdisk.raw chown 0:0 usr/local/bin/restored_external
;;
esac
if [[ $just_password == 1 ]]; then
if [[ $just_password_legacy != 1 ]]; then
case $build_id in
"12"* | "13"* | "14"* )
"$dir/hfsplus" Ramdisk.raw mv usr/local/bin/restored_external usr/local/bin/restored_external.real
cp ../resources/bruteforce/setup.sh ./restored_external
"$dir/hfsplus" Ramdisk.raw add restored_external usr/local/bin/restored_external
"$dir/hfsplus" Ramdisk.raw chmod 755 usr/local/bin/restored_external
"$dir/hfsplus" Ramdisk.raw chown 0:0 usr/local/bin/restored_external
;;
esac
"$dir/hfsplus" Ramdisk.raw rm usr/local/bin/restored_external.real
cp ../resources/bruteforce/restored_external ./restored_external.sshrd
"$dir/hfsplus" Ramdisk.raw add restored_external.sshrd usr/local/bin/restored_external.sshrd
"$dir/hfsplus" Ramdisk.raw chmod 755 usr/local/bin/restored_external.sshrd
cp ../resources/bruteforce/bruteforce .
"$dir/hfsplus" Ramdisk.raw add bruteforce usr/bin/bruteforce
"$dir/hfsplus" Ramdisk.raw chmod 755 usr/bin/bruteforce
cp ../resources/bruteforce/setup.sh ./restored_external
"$dir/hfsplus" Ramdisk.raw add restored_external usr/local/bin/restored_external
"$dir/hfsplus" Ramdisk.raw chmod 755 usr/local/bin/restored_external
"$dir/hfsplus" Ramdisk.raw chown 0:0 usr/local/bin/restored_external
fi
fi
"$dir/xpwntool" Ramdisk.raw Ramdisk.dmg -t RestoreRamdisk.dec
fi
log "Make iBSS"
"$dir/xpwntool" iBSS.dec iBSS.raw
if [[ $device_type == "iPad2,"* || $device_type == "iPhone3,3" ]]; then
case $build_id in
8[FGHJKL]* | 8E600 | 8E501 ) device_boot4=1;;
esac
fi
if [[ $device_boot4 == 1 ]]; then
"$dir/iBoot32Patcher" iBSS.raw iBSS.patched --rsa --debug -b "-v amfi=0xff cs_enforcement_disable=1"
else
"$dir/iBoot32Patcher" iBSS.raw iBSS.patched --rsa --debug -b "$device_bootargs"
fi
"$dir/xpwntool" iBSS.patched iBSS -t iBSS.dec
if [[ $build_id == "7"* || $build_id == "8"* ]] && [[ $device_type != "iPad"* ]]; then
:
else
log "Make iBEC"
"$dir/xpwntool" iBEC.dec iBEC.raw
if [[ $1 == "justboot" ]]; then
"$dir/iBoot32Patcher" iBEC.raw iBEC.patched --rsa --debug -b "$device_bootargs"
else
local bootarg="rd=md0 -v amfi=0xff amfi_get_out_of_my_way=1 cs_enforcement_disable=1 pio-error=0"
"$dir/iBoot32Patcher" iBEC.raw iBEC.patched --rsa --debug -b "$bootarg"
fi
"$dir/xpwntool" iBEC.patched iBEC -t iBEC.dec
fi
fi
if [[ $device_boot4 == 1 ]]; then
log "Make Kernelcache"
mv Kernelcache.dec Kernelcache0.dec
"$dir/xpwntool" Kernelcache0.dec Kernelcache.raw
$bspatch Kernelcache.raw Kernelcache.patched ../resources/patch/kernelcache.release.${device_model}.${build_id}.patch
"$dir/xpwntool" Kernelcache.patched Kernelcache.dec -t Kernelcache0.dec
fi
mv iBSS iBEC DeviceTree.dec Kernelcache.dec Ramdisk.dmg $ramdisk_path 2>/dev/null