Skip to content

Commit 8914985

Browse files
Update Bitlocker Key Finder v3.2.py
1 parent ccbb5e2 commit 8914985

1 file changed

Lines changed: 33 additions & 16 deletions

File tree

Bitlocker Key Finder v3.2.py

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Bitlocker Key Finder v3.2
12
import re
23
import os
34
import fnmatch
@@ -16,7 +17,7 @@
1617
txt_Files = []
1718
now = datetime.datetime.now()
1819

19-
# STARTUPINFO to hide the command window
20+
# STARTUPINFO to hide the command windows
2021
startupinfo = subprocess.STARTUPINFO()
2122
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
2223
startupinfo.wShowWindow = subprocess.SW_HIDE
@@ -217,13 +218,13 @@ def browse_output(self):
217218

218219
def show_help(self):
219220
help_message = (
220-
"North Loop Consulting - Bitlocker Key Finder\n\n"
221+
"Copyright 2024 North Loop Consulting\n"
222+
"Bitlocker Key Finder\n\n"
221223
"1. Select the directory to search for Bitlocker Recovery Keys or BEK files.\n"
222224
"2. Choose search options:\n"
223-
" - File Name Search: Quickly finds files with specific names.\n"
225+
" - File Name Search: A quick search for file names consistent with key files.\n"
224226
" - UTF-16LE String Search: Searches for Bitlocker keys in UTF-16LE encoded files.\n"
225-
" - Exhaustive String Search: Performs a thorough search but is slower.\n"
226-
" *String search occurs in files smaller than 1MB\n"
227+
" - Exhaustive String Search: Performs a search of all .txt files smaller than 1MB for keys.\n"
227228
"3. Optionally, enable the Copy Files option to copy found files to the output directory.\n"
228229
"4. Optionally, enable the recovery of keys from the current machine (ADMIN ONLY).\n"
229230
"5. Choose the output directory to save results.\n"
@@ -295,25 +296,41 @@ def get_active_keys(self):
295296
if not isAdmin():
296297
self.log_message("Admin rights are required to retrieve BitLocker keys.", "warning")
297298
return
298-
299299
output_folder = self.output_entry.get()
300+
comp_name = os.environ['COMPUTERNAME'] #gets target computer name for report title
301+
comp_name = comp_name.strip('\\')
302+
key_report = os.path.join(output_folder, comp_name + '-BitlockerReport.txt')
303+
Drive_letters = ['%s:' % d for d in string.ascii_uppercase if os.path.exists('%s:' % d)] #Produces list of volumes on target system
304+
305+
300306
if not os.path.isdir(output_folder):
301307
self.log_message("Invalid output directory. Please select a valid directory.", "warning")
302308
return
303-
309+
with open(key_report, 'w') as report:
310+
report.write("Bitlocker Key Finder v3.0 \n") #writing the header for the report 1) Version 2) Date 3)User of System
311+
report.write(now.strftime("%Y-%m-%d, %H:%M:%S"))
312+
report.write("\nUser Account Used: ")
313+
report.write(os.getlogin())
314+
report.write("\n\n")
304315
try:
305316
volumes = subprocess.check_output(["manage-bde", "-status"], startupinfo=startupinfo).decode("utf-8")
317+
self.log_message(volumes, "info")
306318
volume_lines = volumes.splitlines()
307-
for line in volume_lines:
308-
if "Volume" in line:
309-
volume = line.split()[1]
310-
try:
311-
recovery_keys = subprocess.check_output(["manage-bde", "-protectors", "-get", volume], startupinfo=startupinfo).decode("utf-8")
312-
with open(os.path.join(output_folder, f"{volume}_keys.txt"), "w") as key_file:
319+
with open(key_report, "a") as key_file:
320+
for line in volume_lines:
321+
322+
if "Volume " in line:
323+
volume = line.split()[1]
324+
print(volume)
325+
try:
326+
recovery_keys = subprocess.check_output(["manage-bde", "-protectors", "-get", volume], startupinfo=startupinfo).decode("utf-8")
327+
key_file.write(f"Bitlocker key found for {volume}!\n\n")
313328
key_file.write(recovery_keys)
314-
self.log_message(f"Copied BitLocker key for volume {volume}", "success")
315-
except subprocess.CalledProcessError:
316-
self.log_message(f"Failed to retrieve keys for volume {volume}", "warning")
329+
self.log_message(f"BitLocker key for volume {volume} written to report at {key_report}", "success")
330+
# self.log_message(f"{recovery_keys}", "info")
331+
except subprocess.CalledProcessError:
332+
# self.log_message(f"No BitLocker credentials found for {volume}", "warning")
333+
key_file.write(f"No BitLocker credentials found for {volume}\n\n")
317334
except Exception as e:
318335
self.log_message(f"Error retrieving BitLocker keys: {str(e)}", "error")
319336

0 commit comments

Comments
 (0)