Cracking Weak Passwords with Python: Building a Simple Brute Force Tool
Requirements: Kali Linux or Termux or any other linux
follow the below commands:
nano hash_cracker.py
paste the below code in that file
import hashlib
import threading
import time
from queue import Queue
ALGORITHMS = {
'md5': hashlib.md5,
'sha1': hashlib.sha1,
'sha256': hashlib.sha256,
'sha512': hashlib.sha512
}
def worker(queue, target_hash, hash_type, success_flag):
while not queue.empty() and not success_flag[0]:
word = queue.get()
word_hash = ALGORITHMShash_type.hexdigest()
if word_hash == target_hash:
print(f"\n[+] Password found: {word}")
success_flag[0] = True
queue.task_done()
def crack_password(target_hash, wordlist_file, hash_type='md5', thread_count=4):
if hash_type not in ALGORITHMS:
print(f"[-] Unsupported hash type: {hash_type}")
return
word_queue = Queue()
success_flag = [False]
try:
with open(wordlist_file, "r") as file:
for word in file:
word_queue.put(word.strip())
except FileNotFoundError:
print(f"[-] Error: Wordlist file '{wordlist_file}' not found.")
return
except Exception as e:
print(f"[-] Error reading wordlist file: {e}")
return
print(f"[+] Starting password cracking using {thread_count} threads...")
start_time = time.time()
threads = []
for _ in range(thread_count):
t = threading.Thread(target=worker, args=(word_queue, target_hash, hash_type, success_flag))
t.start()
threads.append(t)
word_queue.join()
for t in threads:
t.join()
end_time = time.time()
time_taken = end_time - start_time
if not success_flag[0]:
print("[-] Password not found.")
print(f"[+] Time taken: {time_taken:.2f} seconds")
if name == "main":
hashed_password = input("Enter the hashed password (in hex format): ")
wordlist = input("Enter the wordlist file path: ")
hash_type = input("Enter the hash type (md5/sha1/sha256/sha512): ").lower()
thread_count = int(input("Enter the number of threads to use: "))
crack_password(hashed_password, wordlist, hash_type, thread_count)
pip install hashlib
Install module like this if there is any module not found error
python pass_cracker.py
and then run the above script like this..
Top comments (0)