Spaces:
Sleeping
Sleeping
enotkrutoy
commited on
Commit
•
d1afbb4
1
Parent(s):
26da11f
Update app.py
Browse files
app.py
CHANGED
@@ -1,66 +1,112 @@
|
|
1 |
-
import
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
Cracker = PasswordCracker(
|
6 |
-
password_hash=password_hash,
|
7 |
-
wordlist_file=wordlist_file,
|
8 |
-
algorithm=algorithm,
|
9 |
-
salt=salt,
|
10 |
-
parallel=parallel,
|
11 |
-
complexity_check=complexity
|
12 |
-
)
|
13 |
-
if brute_force:
|
14 |
-
Cracker.crack_passwords_with_brute_force(min_length, max_length, character_set)
|
15 |
-
else:
|
16 |
-
Cracker.crack_passwords_with_wordlist()
|
17 |
-
|
18 |
-
# Получаем статистику
|
19 |
-
stats = Cracker.get_statistics()
|
20 |
-
|
21 |
-
# Преобразуем статистику в строку для отображения в Streamlit
|
22 |
-
stats_str = f"Total Attempts: {stats.get('total_attempts', 'N/A')}\n"
|
23 |
-
stats_str += f"Cracked Password: {stats.get('cracked_password', 'N/A')}\n"
|
24 |
-
stats_str += f"Time Taken: {stats.get('time_taken', 'N/A')}\n"
|
25 |
-
|
26 |
-
return stats_str
|
27 |
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
return
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
main()
|
|
|
1 |
+
import hashlib
|
2 |
+
import argparse
|
3 |
+
import itertools
|
4 |
+
from multiprocessing import Pool
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
+
|
7 |
+
class PasswordCracker:
|
8 |
+
def __init__(self, password_hash, wordlist_file, algorithm, salt=None, parallel=False, complexity_check=False):
|
9 |
+
self.password_hash = password_hash
|
10 |
+
self.wordlist_file = wordlist_file
|
11 |
+
self.algorithm = algorithm
|
12 |
+
self.salt = salt
|
13 |
+
self.parallel = parallel
|
14 |
+
self.complexity_check = complexity_check
|
15 |
+
self.total_passwords = 0
|
16 |
+
self.matched_password = None
|
17 |
+
|
18 |
+
def crack_hash(self, word):
|
19 |
+
if self.salt:
|
20 |
+
word_with_salt = f'{self.salt}{word}'
|
21 |
+
else:
|
22 |
+
word_with_salt = word
|
23 |
+
hashed_word = hashlib.new(self.algorithm, word_with_salt.encode()).hexdigest()
|
24 |
+
if hashed_word == self.password_hash:
|
25 |
+
self.matched_password = word
|
26 |
+
return True
|
27 |
+
return False
|
28 |
+
|
29 |
+
def generate_passwords(self, min_length, max_length, character_set):
|
30 |
+
passwords = []
|
31 |
+
for length in range(min_length, max_length + 1):
|
32 |
+
for combination in itertools.product(character_set, repeat=length):
|
33 |
+
password = ''.join(combination)
|
34 |
+
passwords.append(password)
|
35 |
+
return passwords
|
36 |
+
|
37 |
+
def evaluate_complexity(self, password):
|
38 |
+
has_lowercase = any(char.islower() for char in password)
|
39 |
+
has_uppercase = any(char.isupper() for char in password)
|
40 |
+
has_digit = any(char.isdigit() for char in password)
|
41 |
+
has_special = any(not char.isalnum() for char in password)
|
42 |
+
|
43 |
+
return len(password) >= 8 and has_lowercase and has_uppercase and has_digit and has_special
|
44 |
+
|
45 |
+
def crack_passwords(self, passwords):
|
46 |
+
for password in passwords:
|
47 |
+
self.total_passwords += 1
|
48 |
+
if self.crack_hash(password):
|
49 |
+
return
|
50 |
+
|
51 |
+
def crack_passwords_parallel(self, passwords):
|
52 |
+
with Pool() as pool:
|
53 |
+
pool.map(self.crack_password, passwords)
|
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_with_wordlist(self):
|
63 |
+
with open(self.wordlist_file, 'r', encoding="latin-1") as wordlist:
|
64 |
+
passwords = wordlist.read().splitlines()
|
65 |
+
if self.parallel:
|
66 |
+
self.crack_passwords_parallel(passwords)
|
67 |
+
else:
|
68 |
+
self.crack_passwords(passwords)
|
69 |
+
|
70 |
+
def crack_passwords_with_brute_force(self, min_length, max_length, character_set):
|
71 |
+
passwords = self.generate_passwords(min_length, max_length, character_set)
|
72 |
+
if self.parallel:
|
73 |
+
self.crack_passwords_parallel(passwords)
|
74 |
+
else:
|
75 |
+
self.crack_passwords(passwords)
|
76 |
+
|
77 |
+
def print_statistics(self):
|
78 |
+
print(f"Total Number of Passwords Tried: {self.total_passwords}")
|
79 |
+
if self.matched_password:
|
80 |
+
print(f"Password Cracked! Password: {self.matched_password}")
|
81 |
+
else:
|
82 |
+
print("Password Failed.")
|
83 |
+
|
84 |
+
|
85 |
+
def main():
|
86 |
+
parser = argparse.ArgumentParser(description='Password cracking source PassBreaker')
|
87 |
+
parser.add_argument('password_hash', help='Password hash')
|
88 |
+
parser.add_argument('wordlist_file', help='Wordlist File')
|
89 |
+
parser.add_argument('--algorithm', choices=hashlib.algorithms_available, required=True, help='Hash algorithm')
|
90 |
+
parser.add_argument('-s', '--salt', help='Salt Value')
|
91 |
+
parser.add_argument('-p', '--parallel', action='store_true', help='Use parallel processing')
|
92 |
+
parser.add_argument('-c', '--complexity', action='store_true', help='Check for password complexity')
|
93 |
+
parser.add_argument('-b', '--brute-force', action='store_true', help='Perform a brute force attack')
|
94 |
+
parser.add_argument('--min-length', type=int, default=1, help='Minimum password length for brute force attack')
|
95 |
+
parser.add_argument('--max-length', type=int, default=6, help='Minimum password length for brute force attack')
|
96 |
+
parser.add_argument('--character-set', default='abcdefghijklmnopqrstuvwxyz0123456789',
|
97 |
+
help='Character set for brute force attack')
|
98 |
+
|
99 |
+
args = parser.parse_args()
|
100 |
+
|
101 |
+
cracker = PasswordCracker(args.password_hash, args.wordlist_file, args.algorithm, args.salt, args.parallel, args.complexity)
|
102 |
+
|
103 |
+
if args.brute_force:
|
104 |
+
cracker.crack_passwords_with_brute_force(args.min_length, args.max_length, args.character_set)
|
105 |
+
else:
|
106 |
+
cracker.crack_passwords_with_wordlist()
|
107 |
+
|
108 |
+
cracker.print_statistics()
|
109 |
+
|
110 |
+
|
111 |
+
if __name__ == '__main__':
|
112 |
main()
|