-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhashcat.py
More file actions
77 lines (62 loc) · 1.62 KB
/
hashcat.py
File metadata and controls
77 lines (62 loc) · 1.62 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
import subprocess
from pathlib import Path
import re
import time
BASE = Path(__file__).resolve().parent
HASHCAT_DIR = BASE / "hashcat-7.1.2"
HASHCAT_EXE = HASHCAT_DIR / "hashcat.exe"
out_file = HASHCAT_DIR / "cracked.txt"
hash_map = {
"md5": "0",
"sha256": "1400",
"bcrypt": "3200"
}
def crack(hash, hashtype):
if out_file.exists():
out_file.unlink()
cmd = [
HASHCAT_EXE,
"-m", hashtype, # hash type (MD5 example)
"-a", "3", # attack mode
hash,
"?a?a?a?a?a?a",
"--increment",
"--potfile-disable",
"-o", str(out_file),
"--quiet"
]
time_start = time.perf_counter()
subprocess.run(
cmd,
cwd=HASHCAT_DIR
)
time_end = time.perf_counter()
elapsed = time_end - time_start
if out_file.exists() and out_file.stat().st_size > 0:
line = out_file.read_text().strip()
_, password = line.split(":", 1)
return password, elapsed
return None, None
def benchmark(hashtype):
if out_file.exists():
out_file.unlink()
cmd = [
HASHCAT_EXE,
"-m", hashtype, # hash type (MD5 example)
"-b",
"-o", str(out_file),
"--quiet"
]
result = subprocess.run(
cmd,
cwd=HASHCAT_DIR,
capture_output=True,
text=True
)
for line in result.stdout.splitlines():
match = re.search(r"([\d\.]+)\s*([kMGT]?H/s)", line)
if match:
value = float(match.group(1))
unit = match.group(2)
return value, unit
return None