-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrack_hash.py
More file actions
31 lines (24 loc) · 985 Bytes
/
crack_hash.py
File metadata and controls
31 lines (24 loc) · 985 Bytes
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
import typer
import hashlib
def crack_hash(
hash_value: str = typer.Option(..., "--hash", help="Hash to crack"),
wordlist: str = typer.Option(..., "--wordlist", help="Path to wordlist file"),
algo: str = typer.Option("sha256", "--algo", help="Hash algorithm (md5, sha1, sha256)")
):
try:
with open(wordlist, 'r', encoding='utf-8', errors='ignore') as f:
words = f.readlines()
except FileNotFoundError:
typer.echo(f"[!] Wordlist not found: {wordlist}")
raise typer.Exit()
hash_func = getattr(hashlib, algo, None)
if not hash_func:
typer.echo(f"[!] Unsupported algorithm: {algo}")
raise typer.Exit()
typer.echo(f"[*] Cracking using {algo.upper()}...")
for word in words:
word = word.strip()
if hash_func(word.encode()).hexdigest() == hash_value:
typer.echo(f"[+] Hash cracked! Plaintext: {word}")
return
typer.echo("[-] Failed to crack the hash.")