|
| 1 | +#Bitlocker Key Finder v3.2 |
1 | 2 | import re |
2 | 3 | import os |
3 | 4 | import fnmatch |
|
16 | 17 | txt_Files = [] |
17 | 18 | now = datetime.datetime.now() |
18 | 19 |
|
19 | | -# STARTUPINFO to hide the command window |
| 20 | +# STARTUPINFO to hide the command windows |
20 | 21 | startupinfo = subprocess.STARTUPINFO() |
21 | 22 | startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW |
22 | 23 | startupinfo.wShowWindow = subprocess.SW_HIDE |
@@ -217,13 +218,13 @@ def browse_output(self): |
217 | 218 |
|
218 | 219 | def show_help(self): |
219 | 220 | help_message = ( |
220 | | - "North Loop Consulting - Bitlocker Key Finder\n\n" |
| 221 | + "Copyright 2024 North Loop Consulting\n" |
| 222 | + "Bitlocker Key Finder\n\n" |
221 | 223 | "1. Select the directory to search for Bitlocker Recovery Keys or BEK files.\n" |
222 | 224 | "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" |
224 | 226 | " - 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" |
227 | 228 | "3. Optionally, enable the Copy Files option to copy found files to the output directory.\n" |
228 | 229 | "4. Optionally, enable the recovery of keys from the current machine (ADMIN ONLY).\n" |
229 | 230 | "5. Choose the output directory to save results.\n" |
@@ -295,25 +296,41 @@ def get_active_keys(self): |
295 | 296 | if not isAdmin(): |
296 | 297 | self.log_message("Admin rights are required to retrieve BitLocker keys.", "warning") |
297 | 298 | return |
298 | | - |
299 | 299 | 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 | + |
300 | 306 | if not os.path.isdir(output_folder): |
301 | 307 | self.log_message("Invalid output directory. Please select a valid directory.", "warning") |
302 | 308 | 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") |
304 | 315 | try: |
305 | 316 | volumes = subprocess.check_output(["manage-bde", "-status"], startupinfo=startupinfo).decode("utf-8") |
| 317 | + self.log_message(volumes, "info") |
306 | 318 | 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") |
313 | 328 | 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") |
317 | 334 | except Exception as e: |
318 | 335 | self.log_message(f"Error retrieving BitLocker keys: {str(e)}", "error") |
319 | 336 |
|
|
0 commit comments