From 902c0b8e8c9e65f9c0334b4f16daed72f2c1a75c Mon Sep 17 00:00:00 2001 From: Skydust Date: Sat, 3 Jun 2023 00:04:14 +0200 Subject: [PATCH] Initial Commit --- child_process.py | 107 +++++++++++++++++++++++++++++++++++++++++++++++ main.py | 71 +++++++++++++++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 child_process.py create mode 100644 main.py diff --git a/child_process.py b/child_process.py new file mode 100644 index 0000000..e296310 --- /dev/null +++ b/child_process.py @@ -0,0 +1,107 @@ +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 diff --git a/main.py b/main.py new file mode 100644 index 0000000..91bc99b --- /dev/null +++ b/main.py @@ -0,0 +1,71 @@ +import multiprocessing +import os +import time + +from termcolor import cprint +from child_process import worldlist_bruteforce_partial + +# ============ Setup ============ # + +fileToCrack = "Aazaza.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) + +# =============================== # + +""" +Launches and monitors every process +""" + + +def run_processes(): + # Get the wordlist's size in bytes from the OS + wordlistSize = os.path.getsize(wordlistPath) + + # Calculate the portion of the file each process will read + chunk_size = wordlistSize // num_threads + + # Create and start the processes + processes = [] + total_processes = 0 + for i in range(num_threads): + total_processes += 1 + + start_pos = i * chunk_size + end_pos = start_pos + chunk_size + + process = multiprocessing.Process(target=worldlist_bruteforce_partial, + args=(fileToCrack, wordlistPath, num_threads, i + 1, start_pos, end_pos)) + process.start() + processes.append(process) + + cprint("[MAINPROCESS] Started " + str(total_processes) + "/" + str(num_threads) + " threads", "red", attrs=["bold"]) + + # Check if any process has finished early + while True: + still_alive = False + + for process in processes: + if process.is_alive(): + still_alive = True + else: + if process.exitcode == 111: # It means found + cprint("[MAINPROCESS] Found the code !", "green", attrs=["bold"]) + + # Kill everything + still_alive = False + for proc in processes: + proc.kill() + break + + if not still_alive: # If every process is dead, break the loop + break + + time.sleep(1) # Wait for some time + + +""" +Main function +""" +if __name__ == '__main__': + run_processes()