sshrd.sh.diff

Created Diff never expires
5 removals
378 lines
8 additions
382 lines
#!/usr/bin/env sh
#!/usr/bin/env sh
if [ ! -e logs ]; then
if [ ! -e logs ]; then
mkdir logs | true
mkdir logs | true
fi
fi
$(rm logs/*.log 2> /dev/null)
$(rm logs/*.log 2> /dev/null)
{
{
set -e
set -e
oscheck=$(uname)
oscheck=$(uname)
arch=$(uname -m)
echo "$arch"
echo "$oscheck"


version="$1"
version="$1"


major=$(echo "$version" | cut -d. -f1)
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
minor=$(echo "$version" | cut -d. -f2)
patch=$(echo "$version" | cut -d. -f3)
patch=$(echo "$version" | cut -d. -f3)
ERR_HANDLER () {
ERR_HANDLER () {
[ $? -eq 0 ] && exit
[ $? -eq 0 ] && exit
echo "[-] An error occurred"
echo "[-] An error occurred"
rm -rf work 12rd | true
rm -rf work 12rd | true
killall iproxy 2>/dev/null | true
killall iproxy 2>/dev/null | true


# echo "[-] Uploading logs. If this fails, it's not a big deal."
# echo "[-] Uploading logs. If this fails, it's not a big deal."
# for file in logs/*.log; do
# for file in logs/*.log; do
# mv "$file" logs/FAILURE_${file##*/}
# mv "$file" logs/FAILURE_${file##*/}
# done
# done
# curl -A SSHRD_Script -F "fileToUpload=@$(ls logs/*.log)" https://nathan4s.lol/SSHRD_Script/log_upload.php > /dev/null 2>&1 | true
# curl -A SSHRD_Script -F "fileToUpload=@$(ls logs/*.log)" https://nathan4s.lol/SSHRD_Script/log_upload.php > /dev/null 2>&1 | true
# echo "[!] Done uploading logs, I'll be sure to look at them and fix the issue you are facing"
# echo "[!] Done uploading logs, I'll be sure to look at them and fix the issue you are facing"
}
}


trap ERR_HANDLER EXIT
trap ERR_HANDLER EXIT


if [ ! -e sshtars/README.md ]; then
if [ ! -e sshtars/README.md ]; then
git submodule update --init --recursive
git submodule update --init --recursive
fi
fi


if [ -e sshtars/ssh.tar.gz ]; then
if [ -e sshtars/ssh.tar.gz ]; then
if [ "$oscheck" = 'Linux' ]; then
if [ "$oscheck" = 'Linux' ]; then
gzip -d sshtars/ssh.tar.gz
gzip -d sshtars/ssh.tar.gz
gzip -d sshtars/t2ssh.tar.gz
gzip -d sshtars/t2ssh.tar.gz
gzip -d sshtars/atvssh.tar.gz
gzip -d sshtars/atvssh.tar.gz
fi
fi
fi
fi


if [ ! -e "$oscheck"/gaster ]; then
if [ ! -e "$oscheck"/gaster ]; then
gaster="gaster-$oscheck"
gaster="gaster-$oscheck"
if [ "$oscheck" = 'Linux' ]; then
if [ "$oscheck" = 'Linux' ]; then
gaster="gaster-$oscheck-x86_64"
gaster="gaster-$oscheck"
fi
fi
curl -sLO https://nightly.link/verygenericname/gaster/workflows/makefile/main/"$gaster".zip
curl -sL "https://static.palera.in/legacy/deps/gaster-$oscheck.zip" -o ./gaster-$oscheck.zip
unzip "$gaster".zip
unzip "$gaster".zip
mv gaster "$oscheck"/
mv gaster "$oscheck"/
rm -rf gaster "$gaster".zip
rm -rf gaster "$gaster".zip
fi
fi


chmod +x "$oscheck"/*
chmod +x "$oscheck"/*


if [ "$1" = 'clean' ]; then
if [ "$1" = 'clean' ]; then
rm -rf sshramdisk work
rm -rf sshramdisk work
echo "[*] Removed the current created SSH ramdisk"
echo "[*] Removed the current created SSH ramdisk"
exit
exit
elif [ "$1" = 'dump-blobs' ]; then
elif [ "$1" = 'dump-blobs' ]; then
"$oscheck"/iproxy 2222 22 &>/dev/null &
"$oscheck"/iproxy 2222 22 &>/dev/null &
version=$("$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "sw_vers -productVersion")
version=$("$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "sw_vers -productVersion")
version=${version%%.*}
version=${version%%.*}
if [ "$version" -ge 16 ]; then
if [ "$version" -ge 16 ]; then
device=rdisk2
device=rdisk2
else
else
device=rdisk1
device=rdisk1
fi
fi
"$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "cat /dev/$device" | dd of=dump.raw bs=256 count=$((0x4000))
"$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "cat /dev/$device" | dd of=dump.raw bs=256 count=$((0x4000))
"$oscheck"/img4tool --convert -s dumped.shsh2 dump.raw
"$oscheck"/img4tool --convert -s dumped.shsh2 dump.raw
killall iproxy 2>/dev/null | true
killall iproxy 2>/dev/null | true
echo "[*] Onboard blobs should have dumped to the dumped.shsh2 file"
echo "[*] Onboard blobs should have dumped to the dumped.shsh2 file"
exit
exit
elif [ "$1" = 'reboot' ]; then
elif [ "$1" = 'reboot' ]; then
"$oscheck"/iproxy 2222 22 &>/dev/null &
"$oscheck"/iproxy 2222 22 &>/dev/null &
"$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "/sbin/reboot"
"$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost "/sbin/reboot"
echo "[*] Device should now reboot"
echo "[*] Device should now reboot"
exit
exit
elif [ "$1" = 'ssh' ]; then
elif [ "$1" = 'ssh' ]; then
killall iproxy 2>/dev/null | true
killall iproxy 2>/dev/null | true
"$oscheck"/iproxy 2222 22 &>/dev/null &
"$oscheck"/iproxy 2222 22 &>/dev/null &
"$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost || true
"$oscheck"/sshpass -p 'alpine' ssh -o StrictHostKeyChecking=no -p2222 root@localhost || true
killall iproxy 2>/dev/null | true
killall iproxy 2>/dev/null | true
exit
exit
elif [ "$oscheck" = 'Darwin' ]; then
elif [ "$oscheck" = 'Darwin' ]; then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); then
if ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); then
echo "[*] Waiting for device in DFU mode"
echo "[*] Waiting for device in DFU mode"
fi
fi
while ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); do
while ! (system_profiler SPUSBDataType 2> /dev/null | grep ' Apple Mobile Device (DFU Mode)' >> /dev/null); do
sleep 1
sleep 1
done
done
else
else
if ! (lsusb 2> /dev/null | grep ' Apple, Inc. Mobile Device (DFU Mode)' >> /dev/null); then
if ! (lsusb 2> /dev/null | grep ' Apple, Inc. Mobile Device (DFU Mode)' >> /dev/null); then
echo "[*] Waiting for device in DFU mode"
echo "[*] Waiting for device in DFU mode"
fi
fi
while ! (lsusb 2> /dev/null | grep ' Apple, Inc. Mobile Device (DFU Mode)' >> /dev/null); do
while ! (lsusb 2> /dev/null | grep ' Apple, Inc. Mobile Device (DFU Mode)' >> /dev/null); do
sleep 1
sleep 1
done
done
fi
fi


echo "[*] Getting device info and pwning... this may take a second"
echo "[*] Getting device info and pwning... this may take a second"
check=$("$oscheck"/irecovery -q | grep CPID | sed 's/CPID: //')
check=$("$oscheck"/irecovery -q | grep CPID | sed 's/CPID: //')
replace=$("$oscheck"/irecovery -q | grep MODEL | sed 's/MODEL: //')
replace=$("$oscheck"/irecovery -q | grep MODEL | sed 's/MODEL: //')
deviceid=$("$oscheck"/irecovery -q | grep PRODUCT | sed 's/PRODUCT: //')
deviceid=$("$oscheck"/irecovery -q | grep PRODUCT | sed 's/PRODUCT: //')
ipswurl=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | "$oscheck"/jq '.firmwares | .[] | select(.version=="'$1'")' | "$oscheck"/jq -s '.[0] | .url' --raw-output)
ipswurl=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | "$oscheck"/jq '.firmwares | .[] | select(.version=="'$1'")' | "$oscheck"/jq -s '.[0] | .url' --raw-output)


if [ -e work ]; then
if [ -e work ]; then
rm -rf work
rm -rf work
fi
fi


if [ -e 12rd ]; then
if [ -e 12rd ]; then
rm -rf 12rd
rm -rf 12rd
fi
fi


if [ ! -e sshramdisk ]; then
if [ ! -e sshramdisk ]; then
mkdir sshramdisk
mkdir sshramdisk
fi
fi


if [ "$1" = 'reset' ]; then
if [ "$1" = 'reset' ]; then
if [ ! -e sshramdisk/iBSS.img4 ]; then
if [ ! -e sshramdisk/iBSS.img4 ]; then
echo "[-] Please create an SSH ramdisk first!"
echo "[-] Please create an SSH ramdisk first!"
exit
exit
fi
fi


"$oscheck"/gaster pwn > /dev/null
"$oscheck"/gaster pwn > /dev/null
"$oscheck"/gaster reset > /dev/null
"$oscheck"/gaster reset > /dev/null
"$oscheck"/irecovery -f sshramdisk/iBSS.img4
"$oscheck"/irecovery -f sshramdisk/iBSS.img4
sleep 2
sleep 2
"$oscheck"/irecovery -f sshramdisk/iBEC.img4
"$oscheck"/irecovery -f sshramdisk/iBEC.img4


if [ "$check" = '0x8010' ] || [ "$check" = '0x8015' ] || [ "$check" = '0x8011' ] || [ "$check" = '0x8012' ]; then
if [ "$check" = '0x8010' ] || [ "$check" = '0x8015' ] || [ "$check" = '0x8011' ] || [ "$check" = '0x8012' ]; then
"$oscheck"/irecovery -c go
"$oscheck"/irecovery -c go
fi
fi


sleep 2
sleep 2
"$oscheck"/irecovery -c "setenv oblit-inprogress 5"
"$oscheck"/irecovery -c "setenv oblit-inprogress 5"
"$oscheck"/irecovery -c saveenv
"$oscheck"/irecovery -c saveenv
"$oscheck"/irecovery -c reset
"$oscheck"/irecovery -c reset


echo "[*] Device should now show a progress bar and erase all data"
echo "[*] Device should now show a progress bar and erase all data"
exit
exit
fi
fi


if [ "$2" = 'TrollStore' ]; then
if [ "$2" = 'TrollStore' ]; then
if [ -z "$3" ]; then
if [ -z "$3" ]; then
echo "[-] Please pass an uninstallable system app to use (Tips is a great choice)"
echo "[-] Please pass an uninstallable system app to use (Tips is a great choice)"
exit
exit
fi
fi
fi
fi


if [ "$1" = 'boot' ]; then
if [ "$1" = 'boot' ]; then
if [ ! -e sshramdisk/iBSS.img4 ]; then
if [ ! -e sshramdisk/iBSS.img4 ]; then
echo "[-] Please create an SSH ramdisk first!"
echo "[-] Please create an SSH ramdisk first!"
exit
exit
fi
fi


major=$(cat sshramdisk/version.txt | awk -F. '{print $1}')
major=$(cat sshramdisk/version.txt | awk -F. '{print $1}')
minor=$(cat sshramdisk/version.txt | awk -F. '{print $2}')
minor=$(cat sshramdisk/version.txt | awk -F. '{print $2}')
patch=$(cat sshramdisk/version.txt | awk -F. '{print $3}')
patch=$(cat sshramdisk/version.txt | awk -F. '{print $3}')
major=${major:-0}
major=${major:-0}
minor=${minor:-0}
minor=${minor:-0}
patch=${patch:-0}
patch=${patch:-0}
"$oscheck"/gaster pwn > /dev/null
"$oscheck"/gaster pwn > /dev/null
"$oscheck"/gaster reset > /dev/null
"$oscheck"/gaster reset > /dev/null
"$oscheck"/irecovery -f sshramdisk/iBSS.img4
"$oscheck"/irecovery -f sshramdisk/iBSS.img4
sleep 2
sleep 2
"$oscheck"/irecovery -f sshramdisk/iBEC.img4
"$oscheck"/irecovery -f sshramdisk/iBEC.img4


if [ "$check" = '0x8010' ] || [ "$check" = '0x8015' ] || [ "$check" = '0x8011' ] || [ "$check" = '0x8012' ]; then
if [ "$check" = '0x8010' ] || [ "$check" = '0x8015' ] || [ "$check" = '0x8011' ] || [ "$check" = '0x8012' ]; then
"$oscheck"/irecovery -c go
"$oscheck"/irecovery -c go
fi
fi
sleep 2
sleep 2
"$oscheck"/irecovery -f sshramdisk/logo.img4
"$oscheck"/irecovery -f sshramdisk/logo.img4
"$oscheck"/irecovery -c "setpicture 0x1"
"$oscheck"/irecovery -c "setpicture 0x1"
"$oscheck"/irecovery -f sshramdisk/ramdisk.img4
"$oscheck"/irecovery -f sshramdisk/ramdisk.img4
"$oscheck"/irecovery -c ramdisk
"$oscheck"/irecovery -c ramdisk
"$oscheck"/irecovery -f sshramdisk/devicetree.img4
"$oscheck"/irecovery -f sshramdisk/devicetree.img4
"$oscheck"/irecovery -c devicetree
"$oscheck"/irecovery -c devicetree
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
:
:
else
else
"$oscheck"/irecovery -f sshramdisk/trustcache.img4
"$oscheck"/irecovery -f sshramdisk/trustcache.img4
"$oscheck"/irecovery -c firmware
"$oscheck"/irecovery -c firmware
fi
fi
"$oscheck"/irecovery -f sshramdisk/kernelcache.img4
"$oscheck"/irecovery -f sshramdisk/kernelcache.img4
"$oscheck"/irecovery -c bootx
"$oscheck"/irecovery -c bootx


echo "[*] Device should now show text on screen"
echo "[*] Device should now show text on screen"
exit
exit
fi
fi


if [ -z "$1" ]; then
if [ -z "$1" ]; then
printf "1st argument: iOS version for the ramdisk\nExtra arguments:\nreset: wipes the device, without losing version.\nTrollStore: install trollstore to system app\n"
printf "1st argument: iOS version for the ramdisk\nExtra arguments:\nreset: wipes the device, without losing version.\nTrollStore: install trollstore to system app\n"
exit
exit
fi
fi


if [ ! -e work ]; then
if [ ! -e work ]; then
mkdir work
mkdir work
fi
fi


"$oscheck"/gaster pwn > /dev/null
"$oscheck"/gaster pwn > /dev/null
"$oscheck"/img4tool -e -s other/shsh/"${check}".shsh -m work/IM4M
"$oscheck"/img4tool -e -s other/shsh/"${check}".shsh -m work/IM4M


cd work
cd work
../"$oscheck"/pzb -g BuildManifest.plist "$ipswurl"
../"$oscheck"/pzb -g BuildManifest.plist "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/iBSS[.]/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/iBSS[.]/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/iBEC[.]/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/iBEC[.]/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/DeviceTree[.]/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/DeviceTree[.]/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"


if [ "$oscheck" = 'Darwin' ]; then
if [ "$oscheck" = 'Darwin' ]; then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
:
:
else
else
../"$oscheck"/pzb -g Firmware/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)".trustcache "$ipswurl"
../"$oscheck"/pzb -g Firmware/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)".trustcache "$ipswurl"
fi
fi
else
else
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
:
:
else
else
../"$oscheck"/pzb -g Firmware/"$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')".trustcache "$ipswurl"
../"$oscheck"/pzb -g Firmware/"$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')".trustcache "$ipswurl"
fi
fi
fi
fi


../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/kernelcache.release/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"
../"$oscheck"/pzb -g "$(awk "/""${replace}""/{x=1}x&&/kernelcache.release/{print;exit}" BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" "$ipswurl"


if [ "$oscheck" = 'Darwin' ]; then
if [ "$oscheck" = 'Darwin' ]; then
../"$oscheck"/pzb -g "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" "$ipswurl"
../"$oscheck"/pzb -g "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" "$ipswurl"
else
else
../"$oscheck"/pzb -g "$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" "$ipswurl"
../"$oscheck"/pzb -g "$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" "$ipswurl"
fi
fi


cd ..
cd ..
if [ "$major" -gt 18 ] || [ "$major" -eq 18 ]; then
if [ "$major" -gt 18 ] || [ "$major" -eq 18 ]; then
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/iBSS[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" -o work/iBSS.dec
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/iBSS[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" -o work/iBSS.dec
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/iBEC[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" -o work/iBEC.dec
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/iBEC[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" -o work/iBEC.dec
else
else
"$oscheck"/gaster decrypt work/"$(awk "/""${replace}""/{x=1}x&&/iBSS[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" work/iBSS.dec
"$oscheck"/gaster decrypt work/"$(awk "/""${replace}""/{x=1}x&&/iBSS[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" work/iBSS.dec
"$oscheck"/gaster decrypt work/"$(awk "/""${replace}""/{x=1}x&&/iBEC[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" work/iBEC.dec
"$oscheck"/gaster decrypt work/"$(awk "/""${replace}""/{x=1}x&&/iBEC[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]dfu[/]//')" work/iBEC.dec
fi
fi
"$oscheck"/iBoot64Patcher work/iBSS.dec work/iBSS.patched
"$oscheck"/iBoot64Patcher work/iBSS.dec work/iBSS.patched
"$oscheck"/img4 -i work/iBSS.patched -o sshramdisk/iBSS.img4 -M work/IM4M -A -T ibss
"$oscheck"/img4 -i work/iBSS.patched -o sshramdisk/iBSS.img4 -M work/IM4M -A -T ibss
"$oscheck"/iBoot64Patcher work/iBEC.dec work/iBEC.patched -b "rd=md0 debug=0x2014e -v wdt=-1 `if [ -z "$2" ]; then :; else echo "$2=$3"; fi` `if [ "$check" = '0x8960' ] || [ "$check" = '0x7000' ] || [ "$check" = '0x7001' ]; then echo "nand-enable-reformat=1 -restore"; fi`" -n
"$oscheck"/iBoot64Patcher work/iBEC.dec work/iBEC.patched -b "rd=md0 debug=0x2014e -v wdt=-1 `if [ -z "$2" ]; then :; else echo "$2=$3"; fi` `if [ "$check" = '0x8960' ] || [ "$check" = '0x7000' ] || [ "$check" = '0x7001' ]; then echo "nand-enable-reformat=1 -restore"; fi`" -n
"$oscheck"/img4 -i work/iBEC.patched -o sshramdisk/iBEC.img4 -M work/IM4M -A -T ibec
"$oscheck"/img4 -i work/iBEC.patched -o sshramdisk/iBEC.img4 -M work/IM4M -A -T ibec


"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" -o work/kcache.raw
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" -o work/kcache.raw
"$oscheck"/KPlooshFinder work/kcache.raw work/kcache.patched
"$oscheck"/KPlooshFinder work/kcache.raw work/kcache.patched
"$oscheck"/kerneldiff work/kcache.raw work/kcache.patched work/kc.bpatch
"$oscheck"/kerneldiff work/kcache.raw work/kcache.patched work/kc.bpatch
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" -o sshramdisk/kernelcache.img4 -M work/IM4M -T rkrn -P work/kc.bpatch `if [ "$oscheck" = 'Linux' ]; then echo "-J"; fi`
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/kernelcache.release/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1)" -o sshramdisk/kernelcache.img4 -M work/IM4M -T rkrn -P work/kc.bpatch `if [ "$oscheck" = 'Linux' ]; then echo "-J"; fi`
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/DeviceTree[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]all_flash[/]//')" -o sshramdisk/devicetree.img4 -M work/IM4M -T rdtr
"$oscheck"/img4 -i work/"$(awk "/""${replace}""/{x=1}x&&/DeviceTree[.]/{print;exit}" work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | sed 's/Firmware[/]all_flash[/]//')" -o sshramdisk/devicetree.img4 -M work/IM4M -T rdtr


if [ "$oscheck" = 'Darwin' ]; then
if [ "$oscheck" = 'Darwin' ]; then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
:
:
else
else
"$oscheck"/img4 -i work/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)".trustcache -o sshramdisk/trustcache.img4 -M work/IM4M -T rtsc
"$oscheck"/img4 -i work/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)".trustcache -o sshramdisk/trustcache.img4 -M work/IM4M -T rtsc
fi
fi
"$oscheck"/img4 -i work/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" -o work/ramdisk.dmg
"$oscheck"/img4 -i work/"$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - work/BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" -o work/ramdisk.dmg
else
else
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ] || [ "$check" != '0x8012' ])); then
:
:
else
else
"$oscheck"/img4 -i work/"$(Linux/PlistBuddy work/BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')".trustcache -o sshramdisk/trustcache.img4 -M work/IM4M -T rtsc
"$oscheck"/img4 -i work/"$(Linux/PlistBuddy work/BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')".trustcache -o sshramdisk/trustcache.img4 -M work/IM4M -T rtsc
fi
fi
"$oscheck"/img4 -i work/"$(Linux/PlistBuddy work/BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" -o work/ramdisk.dmg
"$oscheck"/img4 -i work/"$(Linux/PlistBuddy work/BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" -o work/ramdisk.dmg
fi
fi


if [ "$oscheck" = 'Darwin' ]; then
if [ "$oscheck" = 'Darwin' ]; then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
:
:
else
else
hdiutil resize -size 210MB work/ramdisk.dmg
hdiutil resize -size 210MB work/ramdisk.dmg
fi
fi
hdiutil attach -mountpoint /tmp/SSHRD work/ramdisk.dmg -owners off
hdiutil attach -mountpoint /tmp/SSHRD work/ramdisk.dmg -owners off
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
hdiutil create -size 210m -imagekey diskimage-class=CRawDiskImage -format UDZO -fs HFS+ -layout NONE -srcfolder /tmp/SSHRD -copyuid root work/ramdisk1.dmg
hdiutil create -size 210m -imagekey diskimage-class=CRawDiskImage -format UDZO -fs HFS+ -layout NONE -srcfolder /tmp/SSHRD -copyuid root work/ramdisk1.dmg
hdiutil detach -force /tmp/SSHRD
hdiutil detach -force /tmp/SSHRD
hdiutil attach -mountpoint /tmp/SSHRD work/ramdisk1.dmg -owners off
hdiutil attach -mountpoint /tmp/SSHRD work/ramdisk1.dmg -owners off
else
else
:
:
fi
fi
if [ "$replace" = 'j42dap' ]; then
if [ "$replace" = 'j42dap' ]; then
"$oscheck"/gtar -x --no-overwrite-dir -f sshtars/atvssh.tar.gz -C /tmp/SSHRD/
"$oscheck"/gtar -x --no-overwrite-dir -f sshtars/atvssh.tar.gz -C /tmp/SSHRD/
elif [ "$check" = '0x8012' ]; then
elif [ "$check" = '0x8012' ]; then
"$oscheck"/gtar -x --no-overwrite-dir -f sshtars/t2ssh.tar.gz -C /tmp/SSHRD/
"$oscheck"/gtar -x --no-overwrite-dir -f sshtars/t2ssh.tar.gz -C /tmp/SSHRD/
echo "[!] WARNING: T2 MIGHT HANG AND DO NOTHING WHEN BOOTING THE RAMDISK!"
echo "[!] WARNING: T2 MIGHT HANG AND DO NOTHING WHEN BOOTING THE RAMDISK!"
else
else
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ])); then
mkdir 12rd
mkdir 12rd
ipswurl12=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | "$oscheck"/jq '.firmwares | .[] | select(.version=="'12.0'")' | "$oscheck"/jq -s '.[0] | .url' --raw-output)
ipswurl12=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | "$oscheck"/jq '.firmwares | .[] | select(.version=="'12.0'")' | "$oscheck"/jq -s '.[0] | .url' --raw-output)
cd 12rd
cd 12rd
../"$oscheck"/pzb -g BuildManifest.plist "$ipswurl12"
../"$oscheck"/pzb -g BuildManifest.plist "$ipswurl12"
../"$oscheck"/pzb -g "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" "$ipswurl12"
../"$oscheck"/pzb -g "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" "$ipswurl12"
../"$oscheck"/img4 -i "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" -o ramdisk.dmg
../"$oscheck"/img4 -i "$(/usr/bin/plutil -extract "BuildIdentities".0."Manifest"."RestoreRamDisk"."Info"."Path" xml1 -o - BuildManifest.plist | grep '<string>' |cut -d\> -f2 |cut -d\< -f1 | head -1)" -o ramdisk.dmg
hdiutil attach -mountpoint /tmp/12rd ramdisk.dmg -owners off
hdiutil attach -mountpoint /tmp/12rd ramdisk.dmg -owners off
cp /tmp/12rd/usr/lib/libiconv.2.dylib /tmp/12rd/usr/lib/libcharset.1.dylib /tmp/SSHRD/usr/lib/
cp /tmp/12rd/usr/lib/libiconv.2.dylib /tmp/12rd/usr/lib/libcharset.1.dylib /tmp/SSHRD/usr/lib/
hdiutil detach -force /tmp/12rd
hdiutil detach -force /tmp/12rd
cd ..
cd ..
rm -rf 12rd
rm -rf 12rd
else
else
:
:
fi
fi
"$oscheck"/gtar -x --no-overwrite-dir -f sshtars/ssh.tar.gz -C /tmp/SSHRD/
"$oscheck"/gtar -x --no-overwrite-dir -f sshtars/ssh.tar.gz -C /tmp/SSHRD/
fi
fi


hdiutil detach -force /tmp/SSHRD
hdiutil detach -force /tmp/SSHRD
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
hdiutil resize -sectors min work/ramdisk1.dmg
hdiutil resize -sectors min work/ramdisk1.dmg
else
else
hdiutil resize -sectors min work/ramdisk.dmg
hdiutil resize -sectors min work/ramdisk.dmg
fi
fi
else
else
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
echo "Sorry, 16.1 and above doesn't work on Linux at the moment!"
echo "Sorry, 16.1 and above doesn't work on Linux at the moment!"
exit
exit
else
else
:
:
fi
fi
"$oscheck"/hfsplus work/ramdisk.dmg grow 210000000 > /dev/null
"$oscheck"/hfsplus work/ramdisk.dmg grow 210000000 > /dev/null


if [ "$replace" = 'j42dap' ]; then
if [ "$replace" = 'j42dap' ]; then
"$oscheck"/hfsplus work/ramdisk.dmg untar sshtars/atvssh.tar > /dev/null
"$oscheck"/hfsplus work/ramdisk.dmg untar sshtars/atvssh.tar > /dev/null
elif [ "$check" = '0x8012' ]; then
elif [ "$check" = '0x8012' ]; then
"$oscheck"/hfsplus work/ramdisk.dmg untar sshtars/t2ssh.tar > /dev/null
"$oscheck"/hfsplus work/ramdisk.dmg untar sshtars/t2ssh.tar > /dev/null
echo "[!] WARNING: T2 MIGHT HANG AND DO NOTHING WHEN BOOTING THE RAMDISK!"
echo "[!] WARNING: T2 MIGHT HANG AND DO NOTHING WHEN BOOTING THE RAMDISK!"
else
else
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ])); then
if [ "$major" -lt 11 ] || ([ "$major" -eq 11 ] && ([ "$minor" -lt 4 ] || [ "$minor" -eq 4 ] && [ "$patch" -le 1 ])); then
mkdir 12rd
mkdir 12rd
ipswurl12=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | "$oscheck"/jq '.firmwares | .[] | select(.version=="'12.0'")' | "$oscheck"/jq -s '.[0] | .url' --raw-output)
ipswurl12=$(curl -sL "https://api.ipsw.me/v4/device/$deviceid?type=ipsw" | "$oscheck"/jq '.firmwares | .[] | select(.version=="'12.0'")' | "$oscheck"/jq -s '.[0] | .url' --raw-output)
cd 12rd
cd 12rd
../"$oscheck"/pzb -g BuildManifest.plist "$ipswurl12"
../"$oscheck"/pzb -g BuildManifest.plist "$ipswurl12"
../"$oscheck"/pzb -g "$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" "$ipswurl12"
../"$oscheck"/pzb -g "$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" "$ipswurl12"
../"$oscheck"/img4 -i "$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" -o ramdisk.dmg
../"$oscheck"/img4 -i "$(../Linux/PlistBuddy BuildManifest.plist -c "Print BuildIdentities:0:Manifest:RestoreRamDisk:Info:Path" | sed 's/"//g')" -o ramdisk.dmg
../"$oscheck"/hfsplus ramdisk.dmg extract usr/lib/libcharset.1.dylib libcharset.1.dylib
../"$oscheck"/hfsplus ramdisk.dmg extract usr/lib/libcharset.1.dylib libcharset.1.dylib
../"$oscheck"/hfsplus ramdisk.dmg extract usr/lib/libiconv.2.dylib libiconv.2.dylib
../"$oscheck"/hfsplus ramdisk.dmg extract usr/lib/libiconv.2.dylib libiconv.2.dylib
../"$oscheck"/hfsplus ../work/ramdisk.dmg add libiconv.2.dylib usr/lib/libiconv.2.dylib
../"$oscheck"/hfsplus ../work/ramdisk.dmg add libiconv.2.dylib usr/lib/libiconv.2.dylib
../"$oscheck"/hfsplus ../work/ramdisk.dmg add libcharset.1.dylib usr/lib/libcharset.1.dylib
../"$oscheck"/hfsplus ../work/ramdisk.dmg add libcharset.1.dylib usr/lib/libcharset.1.dylib
cd ..
cd ..
rm -rf 12rd
rm -rf 12rd
else
else
:
:
fi
fi
"$oscheck"/hfsplus work/ramdisk.dmg untar sshtars/ssh.tar > /dev/null
"$oscheck"/hfsplus work/ramdisk.dmg untar sshtars/ssh.tar > /dev/null
fi
fi
fi
fi
if [ "$oscheck" = 'Darwin' ]; then
if [ "$oscheck" = 'Darwin' ]; then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
if [ "$major" -gt 16 ] || ([ "$major" -eq 16 ] && ([ "$minor" -gt 1 ] || [ "$minor" -eq 1 ] && [ "$patch" -ge 0 ])); then
"$oscheck"/img4 -i work/ramdisk1.dmg -o sshramdisk/ramdisk.img4 -M work/IM4M -A -T rdsk
"$oscheck"/img4 -i work/ramdisk1.dmg -o sshramdisk/ramdisk.img4 -M work/IM4M -A -T rdsk
else
else
"$oscheck"/img4 -i work/ramdisk.dmg -o sshramdisk/ramdisk.img4 -M work/IM4M -A -T rdsk
"$oscheck"/img4 -i work/ramdisk.dmg -o sshramdisk/ramdisk.img4 -M work/IM4M -A -T rdsk
fi
fi
else
else
"$oscheck"/img4 -i work/ramdisk.dmg -o sshramdisk/ramdisk.img4 -M work/IM4M -A -T rdsk
"$oscheck"/img4 -i work/ramdisk.dmg -o sshramdisk/ramdisk.img4 -M work/IM4M -A -T rdsk
fi
fi
"$oscheck"/img4 -i other/bootlogo.im4p -o sshramdisk/logo.img4 -M work/IM4M -A -T rlgo
"$oscheck"/img4 -i other/bootlogo.im4p -o sshramdisk/logo.img4 -M work/IM4M -A -T rlgo
echo ""
echo ""
echo "[*] Cleaning up work directory"
echo "[*] Cleaning up work directory"
rm -rf work 12rd
rm -rf work 12rd


# echo "[*] Uploading logs. If this fails, your ramdisk is still created."
# echo "[*] Uploading logs. If this fails, your ramdisk is still created."
# set +e
# set +e
# for file in logs/*.log; do
# for file in logs/*.log; do
# mv "$file" logs/SUCCESS_${file##*/}
# mv "$file" logs/SUCCESS_${file##*/}
# done
# done
# curl -A SSHRD_Script -F "fileToUpload=@$(ls logs/*.log)" https://nathan4s.lol/SSHRD_Script/log_upload.php > /dev/null 2>&1 | true
# curl -A SSHRD_Script -F "fileToUpload=@$(ls logs/*.log)" https://nathan4s.lol/SSHRD_Script/log_upload.php > /dev/null 2>&1 | true
# set -e
# set -e
# echo "[*] Done uploading logs!"
# echo "[*] Done uploading logs!"


echo ""
echo ""
echo "[*] Finished! Please use ./sshrd.sh boot to boot your device"
echo "[*] Finished! Please use ./sshrd.sh boot to boot your device"
echo $1 > sshramdisk/version.txt
echo $1 > sshramdisk/version.txt


} | tee logs/"$(date +%T)"-"$(date +%F)"-"$(uname)"-"$(uname -r)".log
} | tee logs/"$(date +%T)"-"$(date +%F)"-"$(uname)"-"$(uname -r)".log