-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbruteforge.py
210 lines (170 loc) · 6.09 KB
/
bruteforge.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/env python3
Tool_Name = "BruteForge"
Version = "1.2.0"
"""
Author: Sajjad
GitHub: https://github.com/Cyber-Anonymous
"""
import itertools
import string
import argparse
import sys
import time
import os
import math
charsets = {
"digits": string.digits,
"lowercase": string.ascii_lowercase,
"uppercase": string.ascii_uppercase,
"special": string.punctuation,
"all": string.digits + string.ascii_lowercase + string.ascii_uppercase + string.punctuation
}
#charset = string.printable
parser = argparse.ArgumentParser(description="Generate a brute-force wordlist.")
parser.add_argument("-m", "--min_length", type=int, help="Minimum combination length.")
parser.add_argument("-M", "--max_length", type=int, help="Maximum combination length.")
parser.add_argument("-c", "--charset", choices=["digits", "lowercase", "uppercase", "special", "all"], help="Character set to use.")
parser.add_argument("-s", "--custom_charset", type=str, help="Custom character set.")
parser.add_argument("-o", "--output", type=str, help="Output file name.")
parser.add_argument("-v", "--verbose", action="store_true", help="Display progress information.")
parser.add_argument("--version", action="version", version="{} {}".format(Tool_Name, Version))
args = parser.parse_args()
charset = charsets["all"]
start_time = time.time()
def banner():
print("\033[1;94m")
print("""
____ __ ______
/ __ )_______ __/ /____ / ____/___ _________ ____
/ __ / ___/ / / / __/ _ \/ /_ / __ \/ ___/ __ `/ _ \\
/ /_/ / / / /_/ / /_/ __/ __/ / /_/ / / / /_/ / __/
/_____/ / \__,_/\__/\___/_/ \____/_/ \__, /\\___/
/____/
Coded by Sajjad
""")
print("\033[0;0m")
if(bool(args.min_length) == True):
min_length = args.min_length
elif(bool(args.min_length) == False):
banner()
while(True):
min_length = input("Minimum length > ")
try:
min_length = int(min_length)
break
except:
print("\033[0;91mInvalid minimum length.\033[0;00m\n")
else:
pass
if(bool(args.max_length) == True):
max_length = args.max_length
elif(bool(args.max_length) == False):
while(True):
max_length = input("Maximum length > ")
try:
max_length = int(max_length)
break
except:
print("\033[0;91mInvalid maximum length.\033[0;00m\n")
else:
pass
try:
if bool(args.charset) == True and bool(args.custom_charset) == False:
charset = charsets[args.charset]
if args.verbose:
print("\nCharacter Set Used: {}".format(charset))
else:
pass
else:
pass
if bool(args.custom_charset) == True and bool(args.charset) == False:
charset = args.custom_charset
if args.verbose:
print("Custom Character Set: {}".format(charset))
else:
pass
else:
pass
if args.charset and args.custom_charset:
charset = charsets[args.charset] + args.custom_charset
if args.verbose:
print("")
print("Selected Character Set: {}".format(charsets[args.charset]))
print("Custom Character Set: {}".format(args.custom_charset))
else:
pass
else:
pass
except Exception as error:
print("\033[0;91m[ERROR] {}\033[0m".format(error))
sys.exit()
if(bool(args.output) == True):
filename = args.output
file = open(filename, "w")
elif(bool(args.output) == False):
while(True):
try:
filename = input("File name > ")
file = open(filename, "w")
break
except Exception as error:
print("\033[0;91m[ERROR] {}\033[0m]".format(error))
else:
pass
print("")
def convert_size(size_bytes):
if size_bytes == 0:
return "0B"
size_name = ("B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB")
i = int(math.floor(math.log(size_bytes, 1024)))
p = math.pow(1024, i)
s = round(size_bytes / p, 2)
return "{} {}".format(s, size_name[i])
def print_progress_bar(count, total):
bar_length = 40
progress = count / total
percent = progress * 100
arrow = "#" * int(round(progress * bar_length))
spaces = " " * (bar_length - len(arrow))
sys.stdout.write("\r[{}{}] {}/{} ({:.2f}%)".format(arrow, spaces, count, total, percent))
sys.stdout.flush()
try:
if args.verbose:
print("Process started at {}\n".format(time.ctime(start_time)))
total_combination = 0
count = 0
for length in range(min_length, max_length +1):
comb_per_length = len(charset) ** length
total_combination += comb_per_length
for length in range(min_length, max_length +1):
for combination in itertools.product(charset, repeat=length):
password = "".join(combination)
file.write(password + "\n")
count += 1
if bool(args.verbose) == False:
print_progress_bar(count, total_combination)
if args.verbose:
progress = (count / total_combination) * 100
sys.stdout.write("\r[INFO] Progress: {:.2f}%".format(progress))
sys.stdout.write(" | Password: {}".format(password))
sys.stdout.flush()
else:
pass
file.flush()
os.fsync(file.fileno())
file.close()
print("")
file_size = os.path.getsize(filename)
print("\nGenerated {} combinations.".format(count))
end_time = time.time()
if args.verbose:
elapsed = end_time - start_time
elapsed_time = time.strftime("%H:%M:%S", time.gmtime(elapsed))
print("Elapsed Time: {}".format(elapsed_time))
print("Total data generated: {} bytes ({})".format(file_size, convert_size(file_size)))
if args.verbose:
print("\nProcess ended at {}".format(time.ctime(end_time)))
print("\nBrute-force list generated and saved to {}\n".format(filename))
except Exception as error:
print("\033[0;91m[ERROR] {}\033[0m]".format(error))
sys.exit()