From 3e19ca6d262c20afbd5f8db0d50e27e9d98a2d1e Mon Sep 17 00:00:00 2001 From: jgaunt Date: Thu, 4 Feb 2021 09:53:00 -0500 Subject: [PATCH 1/2] Add 'dislocker.sh' --- dislocker.sh | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 dislocker.sh diff --git a/dislocker.sh b/dislocker.sh new file mode 100644 index 0000000..7b9e579 --- /dev/null +++ b/dislocker.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +# Variables +bitlockerPartitionMountPoint="/mnt/bitlocker" +dislockerFileMountPoint="/mnt/bitlocker/dislocker-file" +unlockedBitlockerMountPoint="/mnt/unlockedBitlocker" + +# get list of drives and find ones labeled with bitlocker +bitlockerPartition=`dislocker-find` +bitlockerRecoveryKeyID=`dislocker-metadata -V ${bitlockerPartition} | awk '/Recovery Key GUI:/ {print $10; exit}' | sed "s/'//g"` + +# confirm drive + +# make temp directories +mkdir ${bitlockerPartitionMountPoint} +mkdir ${unlockedBitlockerMountPoint} + +# ask for the recovery key with dashses +read -p "Enter recovery key with dashes for bitlocker recovery ID ${bitlockerRecoveryKeyID}: " bitlockerRecoveryKey + +# try unlocking the drive +dislocker -v -V ${bitlockerPartition} -p${bitlockerRecoveryKey} -- ${bitlockerPartitionMountPoint} + +# test if the dislockerFileMountPoint was created +if [ -f ${dislockerFileMountPoint} ]; then + # mount the file + mount -o loop,ro ${dislockerFileMountPoint} ${unlockedBitlockerMountPoint} + echo "The drive was unlocked and is availabe at ${unlockedBitlockerMountPoint}" +fi From 36c2f647a5dc047dee1c5828b90297b42a0c07ba Mon Sep 17 00:00:00 2001 From: John Gaunt Date: Thu, 4 Feb 2021 15:55:45 -0500 Subject: [PATCH 2/2] added regex to test for correct recovery password format --- dislocker.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/dislocker.sh b/dislocker.sh index 7b9e579..403e7b4 100644 --- a/dislocker.sh +++ b/dislocker.sh @@ -16,8 +16,12 @@ mkdir ${bitlockerPartitionMountPoint} mkdir ${unlockedBitlockerMountPoint} # ask for the recovery key with dashses -read -p "Enter recovery key with dashes for bitlocker recovery ID ${bitlockerRecoveryKeyID}: " bitlockerRecoveryKey - +# regex to match bitlocker key "^[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}$" +regex="^[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}-[0-9]{6}$" +while : ; do + read -p "Enter recovery key with dashes for bitlocker recovery ID ${bitlockerRecoveryKeyID}: " bitlockerRecoveryKey + [[ ${bitlockerRecoveryKey} =~ ${regex} ]] || break +done # try unlocking the drive dislocker -v -V ${bitlockerPartition} -p${bitlockerRecoveryKey} -- ${bitlockerPartitionMountPoint}