forked from ayushbrmn08/Hash-Cracker-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHash_Cracker_GUI.py
More file actions
334 lines (273 loc) · 13 KB
/
Hash_Cracker_GUI.py
File metadata and controls
334 lines (273 loc) · 13 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
import time
import hashlib
import pyfiglet
import threading
import concurrent.futures
import customtkinter as ctk
from itertools import islice
from tkinter import filedialog
from multiprocessing import freeze_support
from tkinterdnd2 import TkinterDnD, DND_FILES
def check_hash_match(target, wordlist, hash_algorithm):
"""Checks if any word in the list matches the target hash."""
def hash_word(word):
return hashlib.new(hash_algorithm, word.encode()).hexdigest()
for word in wordlist:
for variant in (word, word.upper(), word.lower(), word.capitalize()):
if hash_word(variant) == target:
return variant
return None
class HashCracker:
def __init__(self, hash_algorithm, target, wordlistfile, wordchunks=10000):
self.hash_algorithm = hash_algorithm
self.wordchunks = wordchunks
self.total_processes = 0 # Total processes (chunks) needed for the wordlist
# Validate hash algorithm
if hash_algorithm not in hashlib.algorithms_available:
raise ValueError(f"Unsupported hash algorithm: {hash_algorithm}.")
# Validate target
if "\n" in target or "\r" in target:
self.targets = [line.strip() for line in target.splitlines() if line.strip()]
else:
self.targets = [target.strip()]
if not self.targets:
raise ValueError("Target hash cannot be empty or invalid.")
# Validate wordlist file and calculate total processes
self.wordlistfile = wordlistfile
# self.calculate_total_processes()
# def calculate_total_processes(self):
# """Calculate the total number of chunks (processes) required."""
# with open(self.wordlistfile, 'r') as f:
# total_words = sum(1 for _ in f)
# self.total_processes = math.ceil(total_words / self.wordchunks)
# def hash_word(self, word):
# """Hashes a word using the specified algorithm."""
# return hashlib.new(self.hash_algorithm, word.encode()).hexdigest()
def start_attack(self, target, process_callback):
"""Starts the cracking process for a single target hash."""
with open(self.wordlistfile, 'r') as f:
with concurrent.futures.ProcessPoolExecutor() as executor:
results = []
more_words = True
while more_words:
wordlist = list(islice(f, self.wordchunks))
wordlist = [word.strip() for word in wordlist if word.strip()]
if not wordlist:
more_words = False
break
# Submit process
self.total_processes += 1
process_callback(self.total_processes)
results.append(executor.submit(check_hash_match, target, wordlist, self.hash_algorithm))
for future in concurrent.futures.as_completed(results):
self.total_processes -= 1
process_callback(self.total_processes)
result = future.result()
if result:
self.total_processes = 0
process_callback(self.total_processes)
return result
return None
def crack(self, output_callback, process_callback):
"""Runs the cracking process for all targets."""
# Notify UI about total processes required
# process_callback(self.total_processes)
for target in self.targets:
output_callback(f"\nAttempting to crack hash: {target}")
result = self.start_attack(target, process_callback)
if result:
output_callback(f"Cracked Password for {target}: {result}")
else:
output_callback(f"Could not find a matching password for {target}.")
class HashCrackerApp(TkinterDnD.Tk):
def __init__(self):
super().__init__()
self.title("Hash Cracker GUI")
self.geometry("900x600")
self.configure(bg="black")
# Set dark appearance mode for customtkinter
ctk.set_appearance_mode("Dark")
ctk.set_default_color_theme("green")
self.process_count_var = ctk.StringVar(value="Processes Spawned: 0")
self.create_widgets()
def create_widgets(self):
# Display ASCII logo
self.ascii_banner = pyfiglet.figlet_format("HashCracker")
self.logo_label = ctk.CTkLabel(
self,
text="",
font=("Courier", 14),
text_color="#00FF00",
bg_color="black",
)
self.logo_label.pack(pady=10)
# Animate the ASCII banner
threading.Thread(target=self.animate_banner, daemon=True).start()
# Input frame for all user inputs
self.input_frame = ctk.CTkFrame(
self,
corner_radius=25,
fg_color="#222831",
border_color="#393E46",
border_width=2
)
self.input_frame.configure(corner_radius=20)
self.input_frame.pack(pady=20, padx=20, fill="both", expand=False)
# Hash Algorithm Dropdown
self.hash_algorithm_label = ctk.CTkLabel(
self.input_frame, text="Hash Algorithm:", text_color="#00FF00"
)
self.hash_algorithm_label.grid(row=0, column=0, pady=10, padx=10, sticky="w")
self.hash_algorithm_dropdown = ctk.CTkOptionMenu(
self.input_frame,
values=sorted(hashlib.algorithms_available),
fg_color="black",
text_color="#00FF00",
)
self.hash_algorithm_dropdown.grid(row=0, column=1, pady=10, padx=10, sticky="ew")
# Target Hash Entry
self.target_label = ctk.CTkLabel(
self.input_frame, text="Target Hash (Drag file or type):", text_color="#00FF00"
)
self.target_label.grid(row=1, column=0, pady=10, padx=10, sticky="w")
self.target_entry = ctk.CTkEntry(
self.input_frame, placeholder_text="Enter hash or drop file", fg_color="black", text_color="#00FF00"
)
self.target_entry.grid(row=1, column=1, pady=10, padx=10, sticky="ew")
self.target_browse_button = ctk.CTkButton(
self.input_frame, text="Browse", command=self.browse_hash_file, fg_color="#00FF00", text_color="black"
)
self.target_browse_button.grid(row=1, column=2, pady=10, padx=10)
self.target_entry.drop_target_register(DND_FILES)
self.target_entry.dnd_bind("<<Drop>>", self.handle_hash_drop)
# Wordlist File Selector
self.wordlist_label = ctk.CTkLabel(
self.input_frame, text="Dictionary File:", text_color="#00FF00"
)
self.wordlist_label.grid(row=2, column=0, pady=10, padx=10, sticky="w")
self.wordlist_entry = ctk.CTkEntry(
self.input_frame, placeholder_text="Drag file or browse", fg_color="black", text_color="#00FF00"
)
self.wordlist_entry.grid(row=2, column=1, pady=10, padx=10, sticky="ew")
self.wordlist_browse_button = ctk.CTkButton(
self.input_frame, text="Browse", command=self.browse_wordlist_file, fg_color="#00FF00", text_color="black"
)
self.wordlist_browse_button.grid(row=2, column=2, pady=10, padx=10)
# Words Per Process Entry
self.words_per_process_label = ctk.CTkLabel(
self.input_frame, text="Words Per Process:", text_color="#00FF00"
)
self.words_per_process_label.grid(row=3, column=0, pady=10, padx=10, sticky="w")
self.words_per_process_entry = ctk.CTkEntry(
self.input_frame, placeholder_text="e.g., 10000", fg_color="black", text_color="#00FF00"
)
self.words_per_process_entry.grid(row=3, column=1, pady=10, padx=10, sticky="ew")
# Clear Inputs Button
self.clear_button = ctk.CTkButton(
self.input_frame, text="Clear", command=self.clear_inputs, fg_color="#FF0000", text_color="white"
)
self.clear_button.grid(row=4, column=1, pady=10, padx=10)
# Start Button
self.start_button = ctk.CTkButton(
self, text="Start Cracking", command=self.start_cracking, fg_color="#00FF00", text_color="black"
)
self.start_button.pack(pady=20)
self.start_button.configure(
hover_color="#005f00"
)
# Output and Process Count Frames
self.output_frame = ctk.CTkFrame(self, corner_radius=15, fg_color="#1A1A1A")
self.output_frame.pack(pady=20, padx=20, fill="both", expand=True)
# Output Text Box (Left)
self.output_text = ctk.CTkTextbox(
self.output_frame, width=500, height=300, fg_color="black", text_color="#00FF00", font=("Courier", 12), state="disabled"
)
self.output_text.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
# Process Count Display (Right)
self.process_count_box = ctk.CTkFrame(self.output_frame, corner_radius=15, fg_color="#333333")
self.process_count_box.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
self.process_count_label = ctk.CTkLabel(
self.process_count_box,
textvariable=self.process_count_var,
font=("Courier", 16),
text_color="#FFA500",
bg_color="#333333",
)
self.process_count_label.pack(pady=50, padx=20, anchor="center")
# Configure grid weights for resizing
self.output_frame.grid_columnconfigure(0, weight=3)
self.output_frame.grid_columnconfigure(1, weight=1)
self.output_frame.grid_rowconfigure(0, weight=1)
def animate_banner(self):
"""Simulates a typing effect for the ASCII banner."""
for char in self.ascii_banner:
self.logo_label.configure(text=self.logo_label.cget("text") + char)
time.sleep(0.02)
def browse_hash_file(self):
"""Opens file dialog to select a hash input file."""
file_path = filedialog.askopenfilename(
title="Select Hash File",
filetypes=(("Text Files", "*.txt"), ("All Files", "*.*"))
)
if file_path:
with open(file_path, "r") as f:
self.target_entry.delete(0, "end")
self.target_entry.insert(0, f.read().strip())
def browse_wordlist_file(self):
"""Opens file dialog to select a wordlist file."""
file_path = filedialog.askopenfilename(
title="Select Dictionary File",
filetypes =(("Text Files", "*.txt"), ("All Files", "*.*"))
)
if file_path:
self.wordlist_entry.delete(0, "end")
self.wordlist_entry.insert(0, file_path)
def clear_inputs(self):
"""Clears all input fields."""
self.target_entry.delete(0, "end")
self.wordlist_entry.delete(0, "end")
self.words_per_process_entry.delete(0, "end")
self.output_text.configure(state="normal")
self.output_text.delete("1.0", "end")
self.output_text.configure(state="disabled")
self.process_count_var.set("Processes Spawned: 0")
def handle_hash_drop(self, event):
"""Handles dropped hash file."""
self.browse_hash_file()
def start_cracking(self):
"""Starts the cracking process."""
hash_algorithm = self.hash_algorithm_dropdown.get()
target = self.target_entry.get()
wordlist_file = self.wordlist_entry.get()
words_per_process = self.words_per_process_entry.get()
if not hash_algorithm or not target or not wordlist_file:
self.log_output("Please fill in all required fields!")
return
try:
words_per_process = int(words_per_process)
except ValueError:
self.log_output("Invalid Words Per Process value.")
return
self.output_text.configure(state="normal")
self.output_text.delete("1.0", "end")
self.output_text.configure(state="disabled")
self.process_count_var.set("Processes Spawned: 0")
self.hash_cracker = HashCracker(hash_algorithm, target, wordlist_file, words_per_process)
threading.Thread(
target=self.hash_cracker.crack,
args=(self.log_output, self.update_process_count),
daemon=True,
).start()
def log_output(self, message):
"""Logs messages to the output box."""
self.output_text.configure(state="normal")
self.output_text.insert("end", f"{message}\n")
self.output_text.configure(state="disabled")
self.output_text.see("end")
def update_process_count(self, count):
"""Updates the process count display."""
self.process_count_var.set(f"Processes Spawned: {count}")
if __name__ == "__main__":
freeze_support()
app = HashCrackerApp()
app.mainloop()