From 18f35ab726ec8c8d7659f6faa89803d93083dd73 Mon Sep 17 00:00:00 2001 From: Ludwig Date: Fri, 2 Oct 2020 14:52:40 +0200 Subject: Initial commit --- Scripts/decrypt_SWL.sh | 41 +++++++++++++++++++++++++++++++++++++++++ Scripts/decrypt_smime_file.sh | 27 +++++++++++++++++++++++++++ Scripts/mount_ubifs_nac.sh | 21 +++++++++++++++++++++ Scripts/mount_ubifs_rcc.sh | 21 +++++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 Scripts/decrypt_SWL.sh create mode 100644 Scripts/decrypt_smime_file.sh create mode 100644 Scripts/mount_ubifs_nac.sh create mode 100644 Scripts/mount_ubifs_rcc.sh (limited to 'Scripts') diff --git a/Scripts/decrypt_SWL.sh b/Scripts/decrypt_SWL.sh new file mode 100644 index 0000000..3a7386c --- /dev/null +++ b/Scripts/decrypt_SWL.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +DIRECTORY=$1 +FIRMWARE_KEY=$2 + +if [[ -d $DIRECTORY ]]; then + find $DIRECTORY -type f -print0 | while read -d $'\0' FILE; do + DATA=$(head -2 $FILE | grep "smime." 2>&1) + if [[ $DATA =~ '"smime.' ]]; then + cp $FILE $FILE.bak + OPENSSL_RESULT=$(openssl smime -decrypt -in $FILE.bak -inkey $FIRMWARE_KEY 2>&1 > $FILE) + if [[ -f $FILE && $OPENSSL_RESULT == '' ]]; then + echo "${FILE} has been decrypted" + rm -rf $FILE.bak + else + mv $FILE.bak $FILE + echo "${FILE} has not been decrypted, the key is probably invalid !" + echo "Stopping" + exit 1 + fi + else + echo "${FILE} seems already decrypted !" + fi + done + find $DIRECTORY -type f -print0 | while read -d $'\0' FILE; do + if [[ -f $FILE"01" ]]; then + for i in {1..9} + do + if [[ -f $FILE"0"$i ]]; then + cat $FILE"0"$i >> $FILE + rm -rf $FILE"0"$i + fi + done + echo "${FILE} parts have been merged !" + fi + done +else + echo "${DIRECTORY} not found or not a directory !" +fi + +exit 0 \ No newline at end of file diff --git a/Scripts/decrypt_smime_file.sh b/Scripts/decrypt_smime_file.sh new file mode 100644 index 0000000..3045799 --- /dev/null +++ b/Scripts/decrypt_smime_file.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +FILE=$1 +FIRMWARE_KEY=$2 + +if [[ -f "$FILE" ]]; then + DATA=$(head -2 $FILE | grep "smime." 2>&1) + if [[ $DATA =~ '"smime.' ]]; then + cp $FILE $FILE.bak + OPENSSL_RESULT=$(openssl smime -decrypt -in $FILE.bak -inkey $FIRMWARE_KEY 2>&1 > $FILE) + if [[ -f "$FILE" && $OPENSSL_RESULT == '' ]]; then + echo "${FILE} has been decrypted" + rm -rf $FILE.bak + else + mv $FILE.bak $FILE + echo "${FILE} has not been decrypted, the key is probably invalid !" + echo "Stopping" + exit 1 + fi + else + echo "${FILE} seems already decrypted !" + fi +else + echo "${FILE} not found !" +fi + +exit 0 \ No newline at end of file diff --git a/Scripts/mount_ubifs_nac.sh b/Scripts/mount_ubifs_nac.sh new file mode 100644 index 0000000..9d0ea35 --- /dev/null +++ b/Scripts/mount_ubifs_nac.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +UBIFS_IMAGE=$1 + +mkdir -p /mnt/ubifs +if grep -qs '/dev/ubi' /proc/mounts; then + umount /mnt/ubifs + ubidetach -p /dev/mtd0 + rmmod nandsim +fi + +modprobe ubi +modprobe nandsim first_id_byte=0xec second_id_byte=0xd5 third_id_byte=0x51 fourth_id_byte=0xa6 +flash_erase /dev/mtd0 0 0 +ubiformat /dev/mtd0 -s 4096 -O 4096 +ubiattach -m 0 -d 0 -O 4096 +ubimkvol /dev/ubi0 -N NAC_UBIFS -s 1024MiB +ubiupdatevol /dev/ubi0_0 $UBIFS_IMAGE +mount /dev/ubi0_0 /mnt/ubifs + +echo "${UBIFS_IMAGE} mounted on /mnt/ubifs" \ No newline at end of file diff --git a/Scripts/mount_ubifs_rcc.sh b/Scripts/mount_ubifs_rcc.sh new file mode 100644 index 0000000..322d29e --- /dev/null +++ b/Scripts/mount_ubifs_rcc.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +UBIFS_IMAGE=$1 + +mkdir -p /mnt/ubifs +if grep -qs '/dev/ubi' /proc/mounts; then + umount /mnt/ubifs + ubidetach -p /dev/mtd0 + rmmod nandsim +fi + +modprobe ubi +modprobe nandsim first_id_byte=0xec second_id_byte=0xd7 third_id_byte=0x00 fourth_id_byte=0x36 +flash_erase /dev/mtd0 0 0 +ubiformat /dev/mtd0 -s 4096 -O 4096 +ubiattach -m 0 -d 0 -O 4096 +ubimkvol /dev/ubi0 -N NAC_UBIFS -s 1024MiB +ubiupdatevol /dev/ubi0_0 $UBIFS_IMAGE +mount /dev/ubi0_0 /mnt/ubifs + +echo "${UBIFS_IMAGE} mounted on /mnt/ubifs" \ No newline at end of file -- cgit v1.2.3