-
Notifications
You must be signed in to change notification settings - Fork 0
/
luks_loop.sh
57 lines (48 loc) · 1.54 KB
/
luks_loop.sh
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
#!/bin/bash
# output helper:
# for y in {1988..2024}; do echo "word$y"; done
LUKS_PARTITION="/dev/nvme0n1p3"
LUKS_NAME="encrypted_volume"
MOUNT_POINT="/home/$USER/Desktop/secure"
PASSWORD_FILE="pass.txt"
# Ensure mount point directory exists
if [ ! -d "$MOUNT_POINT" ]; then
echo "Creating mount point at $MOUNT_POINT..."
sudo mkdir -p "$MOUNT_POINT"
fi
# Check if password file exists
if [ ! -f "$PASSWORD_FILE" ]; then
echo "Password file not found: $PASSWORD_FILE"
exit 1
fi
# Loop through each password in the file and try to unlock
while IFS= read -r PASSWORD; do
if [[ $PASSWORD != "#"* ]]; then
PASSWORD=$(echo "$PASSWORD" | sed 's/^[ \t]*//;s/[ \t]*$//')
echo "Trying password: $PASSWORD"
printf "%s" "$PASSWORD" | sudo cryptsetup open "$LUKS_PARTITION" "$LUKS_NAME" --key-file=-
# Check if unlocking was successful
if [ $? -eq 0 ]; then
echo "Successfully unlocked LUKS partition with password."
PASSWORD_FOUND=1
break
# else
# echo "Failed to unlock with this password."
fi
fi
done < "$PASSWORD_FILE"
# If no password worked, exit with an error
if [ -z "$PASSWORD_FOUND" ]; then
echo "All passwords failed. Could not unlock LUKS partition."
exit 1
fi
# Mount the unlocked LUKS partition
echo "Mounting decrypted partition..."
sudo mount "/dev/mapper/$LUKS_NAME" "$MOUNT_POINT"
# Check if mount was successful
if [ $? -eq 0 ]; then
echo "Partition mounted successfully at $MOUNT_POINT."
else
echo "Failed to mount the decrypted partition."
sudo cryptsetup close "$LUKS_NAME"
fi