From eddc339da1297d9aa636b3b746ab0610e31b6b64 Mon Sep 17 00:00:00 2001 From: "Jordan Chatha (chathaj)" Date: Fri, 15 Nov 2024 18:42:21 +0000 Subject: [PATCH] Add files via upload --- Bruteforce.py | 77 +++++++++++++++++++++++++++++++++++++++++++++++ sha256_hashes.csv | 0 2 files changed, 77 insertions(+) create mode 100644 Bruteforce.py create mode 100644 sha256_hashes.csv diff --git a/Bruteforce.py b/Bruteforce.py new file mode 100644 index 0000000..5865a63 --- /dev/null +++ b/Bruteforce.py @@ -0,0 +1,77 @@ +import itertools # (Educative, n.d.) + +def generate_pass_attempts(minimum_length, maximum_length, characters): + for length in range(minimum_length, maximum_length + 1): + for combination in itertools.product(characters, repeat=length): + pass_attempt = "".join(combination) + yield pass_attempt + +# This will ask for the amount of hashes that the user wants to enter +def hash_user(): + hash_num = int(input("Enter the number of hashes you would like to enter: ")) + + # This line starts an list that is empty in order to store passwords and the hashes + hashes = [] + + # This line will collect the hashes from the user + for x in range(hash_num): + value_hash = input("Please enter the value of hash {}: ".format(x + 1)) + password = input("Please enter the corresponding password: ") + hashes.append((value_hash, password)) + + # This reads the hashes and the corresponding passwords from the csv file + # Also changes the file path and indices for the columns correctly + import csv # (Python, 2023) + csv_file = "sha256_hashes.csv" + with open(csv_file, "r") as file: + reader = csv.reader(file) + for row in reader: + value_hash = row[0] + password = row[1] + hashes.append((value_hash, password)) + + # This part is the brute force to crack the hashes + characters = "abcdefjhijklmnopqrstuvwxyzABCDEFJHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*_+=~':;,.()_/£¬`€" + maximum_length = 6 + minimum_length = 1 + + maximum_attempts = 100000000000 + + # This part gives me the time taken in order for the process to finish + import time # (Create a Timer in Python: Elapsed Time, Decorators, and More – LearnDataSci, n.d.) + start_time = time.time() + end_time = start_time + + for value_hash, password in hashes: + cracked_value = None + attempts = 0 + + pass_attempts = generate_pass_attempts(minimum_length, maximum_length, characters) + + for pass_attempt in pass_attempts: + attempts += 1 + + # Uses SHA256 in order to hash the password + import hashlib # (Hashlib — Secure Hashes and Message Digests, n.d.) + hashed_password = hashlib.sha256(pass_attempt.encode()).hexdigest() + + # This section compares the targeted hash with the one that has been generated + if hashed_password == value_hash: + cracked_value = pass_attempt + break + + if attempts >= maximum_attempts or time.time() >= end_time: + break + + # This part tells the user if the brute force was successful or not, by printing out a message to let the user know if they were successful or unsuccessful + if cracked_value: + print("Hash Value:", value_hash, "Password:", password, "Cracked Value:", cracked_value) + else: + print("Hash:", value_hash, "Password:", password, "The cracking failed using the maximum attempts given") + + # This prints a message to tell the user the amount of time taken in seconds for the code to finish + elapsed_time = time.time() - start_time # (Create a Timer in Python: Elapsed Time, Decorators, and More – LearnDataSci, n.d.) + print("The amount of time taken:", elapsed_time, "Seconds") + +# This calls for the hash_user function in order to start the program +hash_user() diff --git a/sha256_hashes.csv b/sha256_hashes.csv new file mode 100644 index 0000000..e69de29