-
Notifications
You must be signed in to change notification settings - Fork 0
/
crackz.py
85 lines (68 loc) · 3.11 KB
/
crackz.py
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
import zipfile
import argparse
import os
import platform
def clear_terminal():
"""Clears the terminal screen based on the operating system."""
if platform.system() == 'Windows':
os.system('cls')
else:
os.system('clear')
clear_terminal()
print("""
#### ##### #### #### ## ## ######
## ## ## ## ## ## ## ## #### ##
## ##### ###### ## ### ##
## ## ## ## ## ## ## ## #### ##
#### ## ## ## ## #### ## ## ######
https://github.com/smog-root
""")
def crack_password(password_list, zip_file_obj, output_path, should_extract):
"""Attempts to crack the zip file password using the given wordlist."""
for idx, word in enumerate(password_list, start=1):
try:
if should_extract:
zip_file_obj.extractall(path=output_path, pwd=word.encode())
print(f"[+]Password found at line: {idx}, Password: {word}")
print(f"[+]Files extracted successfully to: {os.path.abspath(output_path)}")
return True
else:
zip_file_obj.extractall(pwd=word.encode())
print(f"[+]Password found at line: {idx}")
print(f"[+]Password: {word}")
return True
except (RuntimeError, zipfile.BadZipFile):
continue
return False
# Initialize argument parser
parser = argparse.ArgumentParser(description="Zip file password bruteforce attack!")
parser.add_argument('-f', '--file', required=True, help="Enter zip file path.")
parser.add_argument('-w', '--wordlist', required=True, help="Enter password word list path.")
parser.add_argument('-o', '--output', help="Enter output directory for extracted files.")
parser.add_argument('-ex', '--extract', action='store_true', help="Extract files if password is found.")
args = parser.parse_args()
password_list_path = args.wordlist
zip_file_path = args.file
output_path = args.output
should_extract = args.extract
# Validation checks
if should_extract and not output_path:
print("[-]Error: The -ex option requires an output directory to be specified with -o.")
exit(1)
if output_path and not should_extract:
print("[-]Error: To extract the files, you need to define the -ex option.")
exit(1)
if should_extract and output_path:
os.makedirs(output_path, exist_ok=True)
try:
with zipfile.ZipFile(zip_file_path) as obj:
with open(password_list_path, 'r', encoding='utf-8') as file: # Specify UTF-8 encoding
password_list = file.read().splitlines()
if not crack_password(password_list, obj, output_path, should_extract):
print("[*]Password not found in this file!")
except FileNotFoundError:
print(f"[-]Error: The file '{password_list_path}' does not exist.")
except zipfile.BadZipFile:
print(f"[-]Error: '{zip_file_path}' is not a valid zip file.")
except Exception as e:
print(f"[-]An unexpected error occurred: {e}")