enotkrutoy commited on
Commit
d1afbb4
1 Parent(s): 26da11f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +109 -63
app.py CHANGED
@@ -1,66 +1,112 @@
1
- import streamlit as st
2
- from components.passbeaker import PasswordCracker
3
-
4
- def crack_password(password_hash, wordlist_file, algorithm, salt, parallel, complexity, min_length, max_length, character_set, brute_force):
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
- def main():
29
- st.title("GVA Password Cracker")
30
-
31
- st.sidebar.header("Settings")
32
- password_hash = st.sidebar.text_input("Password Hash")
33
- wordlist_file = st.sidebar.file_uploader("Upload Wordlist File", type=['txt'])
34
- algorithm = st.sidebar.selectbox("Hash Algorithm", ["md5", "sha1", "sha256", "sha512"])
35
- salt = st.sidebar.text_input("Salt (optional)")
36
- parallel = st.sidebar.checkbox("Use Parallel Processing")
37
- complexity = st.sidebar.checkbox("Check for Password Complexity")
38
- min_length = st.sidebar.number_input("Minimum Password Length", min_value=1, value=1)
39
- max_length = st.sidebar.number_input("Maximum Password Length", min_value=1, value=6)
40
- character_set = st.sidebar.text_input("Character Set", "abcdefghijklmnopqrstuvwxyz0123456789")
41
- brute_force = st.sidebar.checkbox("Perform Brute Force Attack")
42
-
43
- if st.sidebar.button("Crack Password"):
44
- if not wordlist_file:
45
- st.error("Please upload a wordlist file.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  return
47
-
48
- cracking_spinner = st.spinner("Cracking...")
49
- with cracking_spinner:
50
- stats = crack_password(
51
- password_hash=password_hash,
52
- wordlist_file=wordlist_file,
53
- algorithm=algorithm,
54
- salt=salt,
55
- parallel=parallel,
56
- complexity=complexity,
57
- min_length=min_length,
58
- max_length=max_length,
59
- character_set=character_set,
60
- brute_force=brute_force
61
- )
62
- st.success(f"Password Cracked! Statistics data:\n{stats}")
63
- st.balloons()
64
-
65
- if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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()