diff --git a/child_process.py b/child_process.py index e296310..aa76491 100644 --- a/child_process.py +++ b/child_process.py @@ -10,7 +10,10 @@ decrypted_workbook = io.BytesIO() colors = ["black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "light_grey", "dark_grey", "light_red", "light_green", "light_yellow", "light_blue", "light_magenta", "light_cyan"] -global total_processes +total_processes = 0 +total_decrypt_attempts = 0 + +update_rate = 100000 """ Get a color for a process using an array @@ -26,10 +29,10 @@ Calculates and prints the number of iterations per seconds """ -def calculate_speed(processNumbar, start_time, iterations, word): +def calculate_speed(processNumbar, start_time, last_update, word): elapsed_time = time.time() - start_time if elapsed_time > 0: - loop_speed = iterations / elapsed_time + loop_speed = (total_decrypt_attempts - last_update) / elapsed_time buifulNumbar = '{:,}'.format(round(loop_speed)).replace(',', ' ') print_thread(processNumbar, "Loop speed: " + buifulNumbar + " iterations per second (at word " + word + ")") @@ -43,6 +46,31 @@ def print_thread(processNumbar, text): cprint("[" + str(processNumbar) + "/" + str(total_processes) + "] " + text, get_color(processNumbar)) +""" +Decryption function +""" + + +def decrypt_file(file, text): + global total_decrypt_attempts + total_decrypt_attempts = total_decrypt_attempts + 1 # Global loop iterations + try: + file.load_key(password=text) + file.decrypt(decrypted_workbook) + return True + except Exception as e: + return False + + +""" +Gets multiple different lines to decrypt +""" + + +def get_lines(line): + return [line, line.lower(), line.upper()] + + """ Global function of a child process """ @@ -57,27 +85,34 @@ def worldlist_bruteforce_partial(fileToCrack, wordlistPath, total_proc, processN office_file = msoffcrypto.OfficeFile(file) # First definitions... - i = 0 - iterations = 0 + last_update = total_decrypt_attempts start_time = time.time() # Opens the wordlist and begins cracking with open(wordlistPath, 'r', encoding='latin_1') as wordlistToUse: # Find the right start position in the wordlist for this process print_thread(processNumbar, "Started new process [" + str(startPos) + " -> " + str(endPos) + "]") + wordlistToUse.seek(startPos) + # Move backward until a newline character is found or we reach the beginning of the file + position = startPos + while position > 0: + wordlistToUse.seek(position - 1) + + if wordlistToUse.read(1) == '\n': + wordlistToUse.seek(position - 1) + break + position -= 1 # I love while True loops while True: - i = i + 1 # Global loop iterations - iterations = iterations + 1 # Resets every status update - try: line = wordlistToUse.readline() # End the thread if it has arrived to its given endPos if wordlistToUse.tell() >= endPos: - print_thread(processNumbar, "Thread done at line " + line + " with " + str(i) + " attempts.") + print_thread(processNumbar, "Thread done at line " + line + " with " + str( + total_decrypt_attempts) + " attempts.") break except Exception as e: print(e) # When a line fails to decode properly (Probably a wrong text encoding) @@ -91,17 +126,15 @@ def worldlist_bruteforce_partial(fileToCrack, wordlistPath, total_proc, processN line = line.rstrip() # Removes line endings # Print status every x lines read - if iterations == 100000: - calculate_speed(processNumbar, start_time, iterations, line) + if last_update == update_rate: + calculate_speed(processNumbar, start_time, last_update, line) start_time = time.time() - iterations = 0 + last_update = 0 # Trying to decrypt the file - try: - office_file.load_key(password=line) - office_file.decrypt(decrypted_workbook) - print_thread(processNumbar, - "!!FOUNDPASSWORD!! \"" + line + "\" with " + str(i) + " attempts.") - sys.exit(111) # Exit with found code - except Exception as e: - pass + for lineToDecrypt in get_lines(line): + if decrypt_file(office_file, lineToDecrypt): # Decrypts + print_thread(processNumbar, + "!!FOUNDPASSWORD!! \"" + lineToDecrypt + "\" with " + str( + total_decrypt_attempts) + " attempts.") + sys.exit(111) # Exit with found code diff --git a/main.py b/main.py index 91bc99b..2120d98 100644 --- a/main.py +++ b/main.py @@ -7,7 +7,7 @@ from child_process import worldlist_bruteforce_partial # ============ Setup ============ # -fileToCrack = "Aazaza.xls" # The file to crack +fileToCrack = "Base_MPP_Ouest_2013.xls" # The file to crack wordlistPath = "rockyou.txt" # The wordlist to use num_threads = 16 # Number of processes to launch (should be the same as your number of cpu cores)