-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBrute.py
222 lines (187 loc) · 6.22 KB
/
Brute.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
211
212
213
214
215
216
217
218
219
220
221
222
"""
Bruteforce Password Generator
Author: @itsecurityco
Use: python BrutePWGen.py --merge-words --w keywords.txt
"""
import sys
from time import time
class wgen:
# Construct for class.
def __init__(self):
self.argument = { '--merge-words':False, '--w':False }
self.argument_list = { '--merge-words':[], '--w':[] }
self.leetdict = {
'a':['4','@'],
'e':['3'],
'g':['6'],
'i':['1','!'],
'l':['1','!'],
'o':['0'],
's':['5','$'],
't':['7']
}
# Read the keyword file from file system.
#
# @param string filename
# @return list
def read_file(self, filename):
"""
Returns the list of keywords in file
"""
f = open(filename, 'r')
lines = f.read().splitlines()
f.close()
return lines
# Save the output to file system.
#
# @param string filename
# @param list data
# @return void
def save_file(self, filename, data):
"""
Takes a list of Passwords and
writes it in the file
"""
f = open(filename, 'a')
for passwd in data:
f.write(f"{passwd}\n")
f.close()
return
# Add a prefix to the word list.
#
# @param string word
# @param list wordlist
# @return list
def add_prefix(self, prefix, wordlist):
"""
Addes a prefix to the passwords
"""
return [prefix+word for word in wordlist if prefix != word]
# Add a sufix to the word list.
#
# @param string word
# @param list wordlist
# @return list
def add_Special(self,SpChar, wordlist):
"""
Addes a Special Character to the passwords
"""
Output = []
if SpChar in "[@_!#$%^&*()<>?/\|}{~:]":
Output1 = [word+SpChar for word in wordlist if SpChar != word]
Output2 = [SpChar+word for word in wordlist if SpChar != word]
Output = Output1 + Output2
return Output
# Merge the wordlist keywords.
def merge_words(self, wordlist):
"""
Joins every keyword in wordlist
"""
mlist = []
for word in wordlist:
mlist.append(self.add_prefix(word, wordlist))
return self.merge_lists(mlist)
# Convert letters to numbers, for example admin to 4dm1n.
# Taken from: http://ptscripts.googlecode.com/svn/trunk/leet.py
#
# @param list wordlist
# @return list
def w(self, wordlist):
"""
Changes the letters to there respective symbol
eg.
a->@
"""
mlist = wordlist
for word in wordlist:
for i in range(len(word)):
chars = list(word)
if chars[i].lower() in self.leetdict.keys():
for x in self.leetdict[chars[i].lower()]:
chars[i] = x
neword = ''.join(chars)
if not neword in wordlist:
mlist.append(neword)
return mlist
# Swap case of all letters.
# Taken from: http://ptscripts.googlecode.com/svn/trunk/leet.py
#
# @param list wordlist
# @return list
def case(self, wordlist):
"""
Returns the list of words with swaped letters
"""
mlist = wordlist
for word in wordlist:
for i in range(len(word)):
chars = list(word)
chars[i] = chars[i].swapcase()
neword = ''.join(chars)
if not neword in wordlist:
mlist.append(neword)
return mlist
# Instructions to use the program.
#
# @return string
def banner(self):
return """
Use the program follows:
python3 wgen.py [[--merge-words] [--w]] wordlist
"""
# Merge the lists of different arguments to a main list.
#
# @param mixed object
# @return string
def merge_lists(self, object):
"""
Returns a final list
"""
main_list = []
if type(object) is list:
for sublist in object:
for word in sublist:
main_list.append(word)
return main_list
# Generate the list for all methods selected on the arguments.
def gen_argument_list(self):
output = []
# --w applied to --merge-words.
argv = '--w'
if self.argument[argv] is True:
mlist = self.w(self.argument_list['--merge-words'])
output.append(mlist)
return output
# The main function.
def main(self):
if len(sys.argv) < 3:
print(self.banner())
exit()
output = []
wordlist = self.read_file(sys.argv[-1])
output.append(wordlist)
for argv in sys.argv[1::]:
if argv == '--merge-words':
list_merge_words = self.merge_words(wordlist)
output.append(list_merge_words)
for word in wordlist:
if word in "[@_!#$%^&*()<>?/\|}{~:]":
list_Special_words = self.add_Special(word,list_merge_words)
output.append(list_Special_words)
self.argument[argv] = True
self.argument_list[argv] = list_merge_words
if argv == '--w':
list_w = self.w(wordlist)
output.append(list_w)
self.argument[argv] = True
self.argument_list[argv] = list_w
# Generate the list for all methods selected on the arguments.
gen_argument_list = self.merge_lists(self.gen_argument_list())
output.append(gen_argument_list)
# Save output to file system.
self.save_file('wgen.passwd.txt', self.merge_lists(output))
if __name__ == "__main__":
start_time = time()
wgen = wgen()
wgen.main()
print("--- %d seconds, %d minutes ---" % (int(time()-start_time), int(time()-start_time)/60))