Spaces:
Sleeping
Sleeping
enotkrutoy
commited on
Commit
•
1fdcf7b
1
Parent(s):
bab5d1c
Update components/passbeaker.py
Browse files- components/passbeaker.py +79 -6
components/passbeaker.py
CHANGED
@@ -1,3 +1,7 @@
|
|
|
|
|
|
|
|
|
|
1 |
class PasswordCracker:
|
2 |
def __init__(self, password_hash, wordlist_file, algorithm, salt=None, parallel=False, complexity_check=False):
|
3 |
self.password_hash = password_hash
|
@@ -6,15 +10,84 @@ class PasswordCracker:
|
|
6 |
self.salt = salt
|
7 |
self.parallel = parallel
|
8 |
self.complexity_check = complexity_check
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
def crack_passwords_with_wordlist(self):
|
11 |
-
|
12 |
-
|
|
|
|
|
|
|
13 |
|
14 |
def crack_passwords_with_brute_force(self, min_length, max_length, character_set):
|
15 |
-
|
16 |
-
|
|
|
|
|
|
|
17 |
|
18 |
def get_statistics(self):
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
1 |
+
import hashlib
|
2 |
+
import itertools
|
3 |
+
from multiprocessing import Pool
|
4 |
+
|
5 |
class PasswordCracker:
|
6 |
def __init__(self, password_hash, wordlist_file, algorithm, salt=None, parallel=False, complexity_check=False):
|
7 |
self.password_hash = password_hash
|
|
|
10 |
self.salt = salt
|
11 |
self.parallel = parallel
|
12 |
self.complexity_check = complexity_check
|
13 |
+
self.total_passwords = 0
|
14 |
+
self.matched_password = None
|
15 |
+
|
16 |
+
def crack_hash(self, word):
|
17 |
+
if self.salt:
|
18 |
+
word_with_salt = f'{self.salt}{word}'
|
19 |
+
else:
|
20 |
+
word_with_salt = word
|
21 |
+
hashed_word = hashlib.new(self.algorithm, word_with_salt.encode()).hexdigest()
|
22 |
+
if hashed_word == self.password_hash:
|
23 |
+
self.matched_password = word
|
24 |
+
return True
|
25 |
+
return False
|
26 |
+
|
27 |
+
def generate_passwords(self, min_length, max_length, character_set):
|
28 |
+
passwords = []
|
29 |
+
for length in range(min_length, max_length + 1):
|
30 |
+
for combination in itertools.product(character_set, repeat=length):
|
31 |
+
password = ''.join(combination)
|
32 |
+
passwords.append(password)
|
33 |
+
return passwords
|
34 |
+
|
35 |
+
def evaluate_complexity(self, password):
|
36 |
+
has_lowercase = False
|
37 |
+
has_uppercase = False
|
38 |
+
has_digit = False
|
39 |
+
has_special = False
|
40 |
+
|
41 |
+
for char in password:
|
42 |
+
if char.islower():
|
43 |
+
has_lowercase = True
|
44 |
+
elif char.isupper():
|
45 |
+
has_uppercase = True
|
46 |
+
elif char.isdigit():
|
47 |
+
has_digit = True
|
48 |
+
else:
|
49 |
+
has_special = True
|
50 |
+
|
51 |
+
if len(password) >= 8 and has_lowercase and has_uppercase and has_digit and has_special:
|
52 |
+
return True
|
53 |
+
return False
|
54 |
+
|
55 |
+
def crack_password(self, password):
|
56 |
+
if self.complexity_check and not self.evaluate_complexity(password):
|
57 |
+
return
|
58 |
+
if self.matched_password is None:
|
59 |
+
if self.crack_hash(password):
|
60 |
+
return
|
61 |
+
|
62 |
+
def crack_passwords(self, passwords):
|
63 |
+
for password in passwords:
|
64 |
+
self.total_passwords += 1
|
65 |
+
if self.crack_hash(password):
|
66 |
+
break
|
67 |
+
|
68 |
+
def crack_passwords_parallel(self, passwords):
|
69 |
+
pool = Pool()
|
70 |
+
pool.map(self.crack_password, passwords)
|
71 |
+
pool.close()
|
72 |
|
73 |
def crack_passwords_with_wordlist(self):
|
74 |
+
passwords = self.wordlist_file.splitlines()
|
75 |
+
if self.parallel:
|
76 |
+
self.crack_passwords_parallel(passwords)
|
77 |
+
else:
|
78 |
+
self.crack_passwords(passwords)
|
79 |
|
80 |
def crack_passwords_with_brute_force(self, min_length, max_length, character_set):
|
81 |
+
passwords = self.generate_passwords(min_length, max_length, character_set)
|
82 |
+
if self.parallel:
|
83 |
+
self.crack_passwords_parallel(passwords)
|
84 |
+
else:
|
85 |
+
self.crack_passwords(passwords)
|
86 |
|
87 |
def get_statistics(self):
|
88 |
+
result = f"Total Number of Passwords Tried: {self.total_passwords}\n"
|
89 |
+
if self.matched_password:
|
90 |
+
result += f"Password Cracked! Password: {self.matched_password}"
|
91 |
+
else:
|
92 |
+
result += "Password Failed."
|
93 |
+
return result
|