import io import sys import msoffcrypto import time from termcolor import cprint 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 """ Get a color for a process using an array """ def get_color(processNumbar): return colors[int(processNumbar % (len(colors) - 1))] """ Calculates and prints the number of iterations per seconds """ def calculate_speed(processNumbar, start_time, iterations, word): elapsed_time = time.time() - start_time if elapsed_time > 0: loop_speed = iterations / elapsed_time buifulNumbar = '{:,}'.format(round(loop_speed)).replace(',', ' ') print_thread(processNumbar, "Loop speed: " + buifulNumbar + " iterations per second (at word " + word + ")") """ Formats and prints with colors for a process """ def print_thread(processNumbar, text): cprint("[" + str(processNumbar) + "/" + str(total_processes) + "] " + text, get_color(processNumbar)) """ Global function of a child process """ def worldlist_bruteforce_partial(fileToCrack, wordlistPath, total_proc, processNumbar, startPos, endPos): global total_processes total_processes = total_proc # Opens the excel file with open(fileToCrack, 'rb') as file: office_file = msoffcrypto.OfficeFile(file) # First definitions... i = 0 iterations = 0 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) # 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.") break except Exception as e: print(e) # When a line fails to decode properly (Probably a wrong text encoding) line = "error" pass # If the file is done break if not line: break line = line.rstrip() # Removes line endings # Print status every x lines read if iterations == 100000: calculate_speed(processNumbar, start_time, iterations, line) start_time = time.time() iterations = 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