-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashBeast.py
More file actions
122 lines (104 loc) · 3.84 KB
/
Copy pathHashBeast.py
File metadata and controls
122 lines (104 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import os
import hashlib
import sqlite3
import requests
from datetime import datetime
from colorama import init, Fore, Style
init(autoreset=True)
DB_PATH = "db/hash_store.db"
LOG_PATH = "logs/cracked.log"
DEFAULT_WORDLIST_PATH = "/usr/share/wordlists/rockyou.txt"
FALLBACK_WORDLIST = "wordlists/rockyou.txt"
DOWNLOAD_URL = "https://raw.githubusercontent.com/danielmiessler/SecLists/master/Passwords/Leaked-Databases/rockyou.txt"
os.makedirs("db", exist_ok=True)
os.makedirs("logs", exist_ok=True)
os.makedirs("wordlists", exist_ok=True)
def banner():
print(Fore.RED + r"""
_ _ _ _ _
| | | | | | | | | |
| |_| | __ _ ___| |__ | |__ ___ ___ | |___
| _ |/ _` / __| '_ \| '_ \ / _ \ / _ \| / __|
| | | | (_| \__ \ | | | | | | (_) | (_) | \__ \
\_| |_/\__,_|___/_| |_|_| |_|\___/ \___/|_|___/
🔓 Crack Hashes Like a Beast – #SECBEAST
""" + Style.RESET_ALL)
def setup_db():
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
c.execute("""CREATE TABLE IF NOT EXISTS hashes (
id INTEGER PRIMARY KEY,
plaintext TEXT,
hash TEXT,
algorithm TEXT)""")
conn.commit()
conn.close()
def hash_text(text, algo):
h = hashlib.new(algo)
h.update(text.encode())
return h.hexdigest()
def insert_hash(text, algo):
h = hash_text(text, algo)
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
c.execute("INSERT INTO hashes (plaintext, hash, algorithm) VALUES (?, ?, ?)", (text, h, algo))
conn.commit()
conn.close()
return h
def log_crack(hashv, plain, algo):
with open(LOG_PATH, "a") as f:
f.write(f"[{datetime.now()}] {hashv} => {plain} ({algo})\n")
def crack_from_db(hashv, algo):
conn = sqlite3.connect(DB_PATH)
c = conn.cursor()
c.execute("SELECT plaintext FROM hashes WHERE hash=? AND algorithm=?", (hashv, algo))
result = c.fetchone()
conn.close()
return result[0] if result else None
def download_wordlist():
print(Fore.YELLOW + "[*] Downloading wordlist from GitHub...")
r = requests.get(DOWNLOAD_URL)
with open(FALLBACK_WORDLIST, "wb") as f:
f.write(r.content)
print(Fore.GREEN + "[✓] Downloaded to: " + FALLBACK_WORDLIST)
def get_wordlist_path():
if os.path.exists(DEFAULT_WORDLIST_PATH):
return DEFAULT_WORDLIST_PATH
elif os.path.exists(FALLBACK_WORDLIST):
return FALLBACK_WORDLIST
else:
choice = input(Fore.CYAN + "[?] Wordlist not found. Download now? (Y/n): ").strip().lower()
if choice in ["", "y", "yes"]:
download_wordlist()
return FALLBACK_WORDLIST
else:
return input("Enter full path to wordlist: ").strip()
def brute_force(hashv, algo, wordlist_path):
with open(wordlist_path, "r", encoding="latin1") as f:
for line in f:
word = line.strip()
if hash_text(word, algo) == hashv:
insert_hash(word, algo)
log_crack(hashv, word, algo)
return word
return None
def main():
banner()
setup_db()
print(Fore.CYAN + "== Welcome to HashBeast - Hash Cracker Tool ==")
h = input(Fore.YELLOW + "Enter hash to crack: ").strip()
algo = input(Fore.YELLOW + "Enter algorithm (md5, sha1, sha256): ").strip().lower()
print(Fore.CYAN + "[*] Checking local database...")
result = crack_from_db(h, algo)
if result:
print(Fore.GREEN + f"[✓] Found in DB: {h} = {result}")
return
wordlist_path = get_wordlist_path()
print(Fore.CYAN + "[*] Starting brute-force using wordlist...")
result = brute_force(h, algo, wordlist_path)
if result:
print(Fore.GREEN + f"[✓] Success: {h} = {result}")
else:
print(Fore.RED + "[-] Failed to crack the hash.")
if __name__ == "__main__":
main()