-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathcrack.py
More file actions
75 lines (58 loc) · 2.05 KB
/
Copy pathcrack.py
File metadata and controls
75 lines (58 loc) · 2.05 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from passlib.hash import bcrypt
from libs import pingo
from colored import fg
color = fg('#008000')
color_err = fg("#FF0000")
def crack_bcrypt(wordlist: str, hash_to_crack: str) -> str:
'''
crack bcrypt using bruteforce method
Args:
wordlist (str): Path to the wordlist file (opt).
hash_to_crack (str): The hash to be cracked.
Returns:
str: The cracked password or None if not cracked.
'''
try:
with open(wordlist, "r", encoding="cp437") as text_file:
words = text_file.read().splitlines()
except FileNotFoundError:
print(color_err + "Error: Wordlist file is invalid!")
sys.exit(1)
except Exception as err:
print(color_err + f"Error: {err}")
sys.exit(1)
length = len(words)
for index, word in enumerate(words):
pingo(index, length, prefix='Wait:', suffix='Words complete from the list')
if bcrypt.verify(word, hash_to_crack):
return word
return None
def main():
print(color + "\n*************************************************")
print(color + "Debcrypt - Password cracker tools for bcrypt hash")
print(color + "*************************************************\n")
# user can specify a wordlist as cmdline arg if they want.
# uses pass.txt as default if the user didnt provide.
if len(sys.argv) > 1:
wordlist = sys.argv[1]
else:
wordlist = "pass.txt"
# take userinp in consistence manner
options = input(color + '\nDo you want to crack? (y/n): ').strip().lower()
if options != "y":
sys.exit()
hash = input(color + 'Enter the hash to crack: ').strip()
if not hash:
print(color_err + "Error: Hash cannot be empty.")
sys.exit(1)
cracked = crack_bcrypt(wordlist, hash)
if cracked:
print(color + "\n\nPassword found!")
print(color + "Result:", cracked)
else:
print(color_err + "\nUnfortunately, password not found.")
if __name__ == "__main__":
main()