|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +import re |
| 4 | +import os |
| 5 | +import requests |
| 6 | +import argparse |
| 7 | +import concurrent.futures |
| 8 | +from hashlib import algorithms_available |
| 9 | + |
| 10 | +parser = argparse.ArgumentParser() |
| 11 | +parser.add_argument('-s', help='hash', dest='hash') |
| 12 | +parser.add_argument('-f', help='file containing hashes', dest='file') |
| 13 | +parser.add_argument('-d', help='directory containing hashes', dest='dir') |
| 14 | +parser.add_argument('-t', help='number of threads', dest='threads', type=int, default=4) |
| 15 | +parser.add_argument('--wordlist', help='dictionary file for dictionary-based attacks', dest='wordlist') |
| 16 | +args = parser.parse_args() |
| 17 | + |
| 18 | +# Colors and other text formatting codes (you can customize them as you like) |
| 19 | +END = '\033[0m' |
| 20 | +RED = '\033[91m' |
| 21 | +GREEN = '\033[92m' |
| 22 | +WHITE = '\033[97m' |
| 23 | +DGREEN = '\033[32m' |
| 24 | +YELLOW = '\033[93m' |
| 25 | +BACK = '\033[7;91m' |
| 26 | +RUN = '\033[97m[~]\033[0m' |
| 27 | +QUE = '\033[94m[?]\033[0m' |
| 28 | +BAD = '\033[91m[-]\033[0m' |
| 29 | +INFO = '\033[93m[!]\033[0m' |
| 30 | +GOOD = '\033[92m[+]\033[0m' |
| 31 | + |
| 32 | +cwd = os.getcwd() |
| 33 | +directory = args.dir |
| 34 | +file = args.file |
| 35 | +thread_count = args.threads |
| 36 | + |
| 37 | +# Check for valid hashing algorithms available on the system |
| 38 | +valid_algorithms = set(algorithms_available) |
| 39 | +hash_algorithms = ['md5', 'sha1', 'sha256', 'sha384', 'sha512'] |
| 40 | +hash_algorithms = [alg for alg in hash_algorithms if alg in valid_algorithms] |
| 41 | + |
| 42 | +# The list of APIs to be used for cracking each hash type (you can add more APIs) |
| 43 | +hash_cracking_apis = { |
| 44 | + 'md5': [ |
| 45 | + 'https://hashtoolkit.com/reverse-hash/?hash=', |
| 46 | + 'https://www.nitrxgen.net/md5db/', |
| 47 | + ], |
| 48 | + 'sha1': [ |
| 49 | + 'https://hashtoolkit.com/reverse-sha1-hash/?hash=', |
| 50 | + ], |
| 51 | + 'sha256': [ |
| 52 | + 'https://hashtoolkit.com/reverse-sha256-hash/?hash=', |
| 53 | + ], |
| 54 | + 'sha384': [ |
| 55 | + 'https://hashtoolkit.com/reverse-sha384-hash/?hash=', |
| 56 | + ], |
| 57 | + 'sha512': [ |
| 58 | + 'https://hashtoolkit.com/reverse-sha512-hash/?hash=', |
| 59 | + ], |
| 60 | +} |
| 61 | + |
| 62 | +# Dictionary to store previously cracked hashes |
| 63 | +hash_cache = {} |
| 64 | + |
| 65 | +# Function to perform hash cracking using online APIs |
| 66 | +def crack_hash_online(hash_value, algorithm): |
| 67 | + if hash_value in hash_cache: |
| 68 | + return hash_cache[hash_value] |
| 69 | + |
| 70 | + if algorithm not in hash_cracking_apis: |
| 71 | + return False |
| 72 | + |
| 73 | + for api_url in hash_cracking_apis[algorithm]: |
| 74 | + try: |
| 75 | + response = requests.get(api_url + hash_value).text |
| 76 | + if response and 'error' not in response.lower(): |
| 77 | + result = re.findall(r'<em>(.*?)</em>', response) |
| 78 | + if result: |
| 79 | + cracked_hash = result[0] |
| 80 | + hash_cache[hash_value] = cracked_hash |
| 81 | + return cracked_hash |
| 82 | + except requests.RequestException: |
| 83 | + continue |
| 84 | + |
| 85 | + return False |
| 86 | + |
| 87 | +# Function to perform dictionary-based hash cracking (optional) |
| 88 | +def crack_hash_dictionary(hash_value, algorithm, wordlist): |
| 89 | + if not wordlist: |
| 90 | + return False |
| 91 | + |
| 92 | + # Implement dictionary-based hash cracking here (use the wordlist) |
| 93 | + # Return the cracked hash if successful, or False if not cracked |
| 94 | + return False |
| 95 | + |
| 96 | +# Function to crack a single hash |
| 97 | +def crack_single_hash(hash_value): |
| 98 | + for algorithm in hash_algorithms: |
| 99 | + if len(hash_value) == len(algorithm) * 4: |
| 100 | + if algorithm in hash_cracking_apis: |
| 101 | + result = crack_hash_online(hash_value, algorithm) |
| 102 | + if result: |
| 103 | + return algorithm, result |
| 104 | + |
| 105 | + # Uncomment the line below to enable dictionary-based cracking (optional) |
| 106 | + # result = crack_hash_dictionary(hash_value, algorithm, args.wordlist) |
| 107 | + # if result: |
| 108 | + # return algorithm, result |
| 109 | + |
| 110 | + return None, None |
| 111 | + |
| 112 | +# Function to display progress during hash cracking |
| 113 | +def display_progress(total_hashes, cracked_hashes): |
| 114 | + progress = cracked_hashes / total_hashes * 100 |
| 115 | + print(f"{INFO} Progress: {cracked_hashes}/{total_hashes} hashes cracked ({progress:.2f}%)", end='\r') |
| 116 | + |
| 117 | +# Main function for hash cracking from file |
| 118 | +def crack_from_file(file_path): |
| 119 | + with open(file_path, 'r') as f: |
| 120 | + hashes = re.findall(r'[a-f0-9]{32,}', f.read()) |
| 121 | + |
| 122 | + total_hashes = len(hashes) |
| 123 | + cracked_hashes = 0 |
| 124 | + |
| 125 | + with concurrent.futures.ThreadPoolExecutor(max_workers=thread_count) as executor: |
| 126 | + futures = {executor.submit(crack_single_hash, hash_value): hash_value for hash_value in hashes} |
| 127 | + |
| 128 | + for future in concurrent.futures.as_completed(futures): |
| 129 | + hash_value = futures[future] |
| 130 | + algorithm, result = future.result() |
| 131 | + |
| 132 | + if result: |
| 133 | + print(f"{hash_value} : {algorithm.upper()} - {result}") |
| 134 | + cracked_hashes += 1 |
| 135 | + display_progress(total_hashes, cracked_hashes) |
| 136 | + |
| 137 | + print(f"{INFO} Finished! Cracked {cracked_hashes} out of {total_hashes} hashes.") |
| 138 | + |
| 139 | +# Main function for hash cracking from directory |
| 140 | +def crack_from_directory(directory_path): |
| 141 | + # Implement searching and cracking hashes from files in the directory |
| 142 | + # You can use regular expressions or other methods to find hash patterns in files |
| 143 | + pass |
| 144 | + |
| 145 | +# Main function to crack a single hash |
| 146 | +def crack_single_hash_command(hash_value): |
| 147 | + algorithm, result = crack_single_hash(hash_value) |
| 148 | + if result: |
| 149 | + print(f"{hash_value} : {algorithm.upper()} - {result}") |
| 150 | + else: |
| 151 | + print(f"{BAD} Hash was not found in any database.") |
| 152 | + |
| 153 | +# Main program flow |
| 154 | +if __name__ == "__main__": |
| 155 | + if directory: |
| 156 | + crack_from_directory(directory) |
| 157 | + elif file: |
| 158 | + crack_from_file(file) |
| 159 | + elif args.hash: |
| 160 | + crack_single_hash_command(args.hash) |
| 161 | + else: |
| 162 | + print(f"{BAD} Please provide either a hash, a file containing hashes, or a directory containing hashes.") |
| 163 | + parser.print_help() |
0 commit comments