-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPassword-Profiler.py
265 lines (233 loc) · 12 KB
/
Password-Profiler.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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#!/usr/bin/python3
"""PasswordProfiler, a simple wordlist generator and mangler written in python 3.8."""
import argparse
from itertools import islice, permutations
from multiprocessing import Pool
from os import remove
from sys import exit
from typing import Iterator, List
TEMP_OUTPUT_FILE = 'temp-output.txt'
OUTPUT_FILE = 'output.txt'
LEET_TRANSLATIONS = str.maketrans('oOaAeEiIsS', '0044331155')
print("""
$$$$$$$\ $$\ $$$$$$$\ $$$$$$\ $$\ $$\
$$ __$$\ $$ |$$ __$$\ $$ __$$\ \__|$$ |
$$ | $$ |$$$$$$\ $$$$$$$\ $$$$$$$\ $$\ $$\ $$\ $$$$$$$ |$$ | $$ | $$$$$$\ $$$$$$\ $$ / \__|$$\ $$ | $$$$$$\ $$$$$$\
$$$$$$$ |\____$$\ $$ _____|$$ _____|$$ | $$ | $$ |$$ __$$ |$$$$$$$ |$$ __$$\ $$ __$$\ $$$$\ $$ |$$ |$$ __$$\ $$ __$$\
$$ ____/ $$$$$$$ |\$$$$$$\ \$$$$$$\ $$ | $$ | $$ |$$ / $$ |$$ ____/ $$ | \__|$$ / $$ |$$ _| $$ |$$ |$$$$$$$$ |$$ | \__|
$$ | $$ __$$ | \____$$\ \____$$\ $$ | $$ | $$ |$$ | $$ |$$ | $$ | $$ | $$ |$$ | $$ |$$ |$$ ____|$$ |
$$ | \$$$$$$$ |$$$$$$$ |$$$$$$$ |\$$$$$\$$$$ |\$$$$$$$ |$$ | $$ | \$$$$$$ |$$ | $$ |$$ |\$$$$$$$\ $$ |
\__| \_______|\_______/ \_______/ \_____\____/ \_______|\__| \__| \______/ \__| \__|\__| \_______|\__|
$$\ $$\ $$\
$$ | $$ | $$ |
$$$$$$$\ $$\ $$\ $$ | $$\ $$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\$$$$\ $$$$$$$\ $$$$$$$\
$$ __$$\ $$ | $$ | $$ | $$ |\____$$\ $$ _____|$$ __$$\ $$ _$$ _$$\ $$ _____|$$ __$$\
$$ | $$ |$$ | $$ | $$$$$$ / $$$$$$$ |\$$$$$$\ $$$$$$$$ |$$ / $$ / $$ |\$$$$$$\ $$ | $$ |
$$ | $$ |$$ | $$ | $$ _$$< $$ __$$ | \____$$\ $$ ____|$$ | $$ | $$ | \____$$\ $$ | $$ |
$$$$$$$ |\$$$$$$$ | $$ | \$$\\$$$$$$$ |$$$$$$$ |\$$$$$$$\ $$ | $$ | $$ |$$$$$$$ |$$ | $$ |
\_______/ \____$$ | \__| \__|\_______|\_______/ \_______|\__| \__| \__|\_______/ \__| \__|
$$\ $$ |
\$$$$$$ |
\______/ """)
def init_argparse() -> argparse.ArgumentParser:
"""
Define and manage arguments passed to PasswordProfiler via terminal.
:return argparse.ArgumentParser
"""
parser = argparse.ArgumentParser(
description='A simple wordlist generator and mangler written in python.')
required = parser.add_argument_group('required arguments')
# Required arguments
required.add_argument('--input', help='Input file name', required=True)
required.add_argument('--perm', help='Max number of words to be combined on the same line',
required=True, type=int)
required.add_argument('--min', help='Minimum generated password length', required=True,
type=int)
required.add_argument('--max', help='Maximum generated password length', required=True,
type=int)
# Optional arguments
parser.add_argument('--test', help='Output first N iterations (single process/core)',
required=False, type=int)
parser.add_argument('--cores',
help='Manually specify processes/cores pool that you want to use',
required=False, type=int)
parser.add_argument('--leet', help='Activate l33t mutagen EXAMPLE==> P@ssw0rd', action='store_true')
parser.add_argument('--cap', help='Activate capitalize first Letter of a word', action='store_true')
parser.add_argument('--up', help='Activate uppercase words', action='store_true')
parser.add_argument('--append', help='Append chosen word (append \'word\' to all passwords)',
required=False)
parser.add_argument('--prepend', help='Prepend chosen word (prepend \'word\' to all passwords)',
required=False)
parser.add_argument('--getchar', help='Extract a substring from words at the specified index to append',
required=False, type=int)
return parser
def printer(combo_printer: List) -> set:
"""
Print generated words to stdout and in case apply chosen mutagens (append, prepend, leet).
:param combo_printer: a slice of the word list that must be elaborated
:type combo_printer: List
:return data: set
"""
data = set()
if len(set(map(str.lower, combo_printer))) == len(combo_printer):
line_printer = ''.join(combo_printer)
if args.min <= len(line_printer) <= args.max:
data.add(line_printer)
if args.append is not None and len(line_printer) + len(args.append) <= args.max:
data.add(f'{line_printer}{args.append}')
if args.prepend is not None and len(line_printer) + len(args.prepend) <= args.max:
data.add(f'{args.prepend}{line_printer}')
if args.leet is True:
for x in leet(line_printer):
data.add(x)
if data:
return data
def slice_and_run(single_iterator: Iterator):
"""
Makes slices from iterator and process them via a process pool.
:param single_iterator: Iterator returning permutations to be sliced and sent to printer() func
:type single_iterator: Iterator
"""
step = 10000000
start = 0
check = True
with open(TEMP_OUTPUT_FILE, 'a') as out_f:
with Pool(args.cores) as pool:
while check:
check = False
cake_slice = islice(single_iterator, start, start + step)
data = (result for result in pool.map(printer, cake_slice) if result)
for result in data:
check = True
out_f.write('\n'.join(result) + '\n')
start += step
def leet(line_leet: str) -> str:
"""
Generator that returns the leeted version of a string and also returns it with applied prepend
and append mutagens if required by user's parameters.
:param line_leet: the string to be leeted
:type line_leet: str
:return _: str
"""
line_leet = line_leet.translate(LEET_TRANSLATIONS)
yield line_leet
if args.append is not None:
yield f'{line_leet}{args.append}'
if args.prepend is not None:
yield f'{args.prepend}{line_leet}'
def get_substr_from_word(word: str, length: int) -> str:
"""
Get a substring from the beginning of the input word.
:param word: The input word from which to extract the substring.
:type word: str
:param length: The length of the substring to extract.
:type length: int
:return: The extracted substring.
:rtype: str
"""
if length < 0 or length > len(word):
raise ValueError("Invalid length value")
return word[:length]
def test_printer(x_test: int, out_counter_test: int) -> int:
"""Test printer."""
input_list = read_input_file(args.input)
for combo in permutations(input_list, x_test + 1):
if len(set(map(str.lower, combo))) == len(combo):
line = ''.join(combo)
if args.min <= len(line) <= args.max:
print(line)
out_counter_test += 1
if out_counter_test >= args.test:
return out_counter_test
if args.append is not None:
print(f'{line}{args.append}')
out_counter_test += 1
if out_counter_test >= args.test:
return out_counter_test
if args.prepend is not None:
print(f'{args.prepend}{line}')
out_counter_test += 1
if out_counter_test >= args.test:
return out_counter_test
if args.leet is True:
line = line.translate(LEET_TRANSLATIONS)
print(line)
out_counter_test += 1
if out_counter_test >= args.test:
return out_counter_test
if args.append is not None:
print(f'{line}{args.append}')
out_counter_test += 1
if out_counter_test >= args.test:
return out_counter_test
if args.prepend is not None:
print(f'{args.prepend}{line}')
out_counter_test += 1
if out_counter_test >= args.test:
return out_counter_test
return out_counter_test
def read_input_file(file_path: str) -> set:
"""
Read input file and return a set of words.
:param file_path: the path to the file with the user supplied wordlist
:type file_path: str
:return _: set
"""
try:
with open(file_path, 'r') as input_file:
data = input_file.read().splitlines()
except FileNotFoundError:
print('Input file not found!\nExiting...')
exit(1)
# Apply capitalize mutagen and upper mutagen if needed
input_list = set(data)
for word in data:
if args.cap is True:
input_list.add(word.capitalize())
if args.up is True:
input_list.add(word.upper())
return input_list
def test_run():
"""Test run to generate only N words."""
out_counter = 0
n_perm = args.perm
n_test = args.test
for x in range(n_perm):
out_counter = test_printer(x, out_counter)
if out_counter >= n_test:
break
def real_run() -> None:
"""Real run."""
input_list = read_input_file(args.input)
n_perm = args.perm
for x in range(n_perm):
my_iterator = permutations(input_list, x + 1)
slice_and_run(my_iterator)
args = init_argparse().parse_args()
if __name__ == '__main__':
# Test run or real run
if args.test is not None:
test_run()
else:
open(OUTPUT_FILE, 'w').write('')
open(TEMP_OUTPUT_FILE, 'w').write('')
real_run()
definitive = set()
with open(TEMP_OUTPUT_FILE, 'r') as f_in:
with open(OUTPUT_FILE, 'a') as f_out:
for my_line in f_in:
if my_line not in definitive:
definitive.add(my_line)
f_out.write(my_line)
if args.getchar is not None:
try:
length = int(args.getchar)
input_words = my_line.strip().split() # Split the line into words
for input_word in input_words:
substring = get_substr_from_word(input_word, length)
f_out.write(f"{input_word}{substring}\n") # Append the substring
#f_out.write(f"{substring}{input_word}\n") # To be tested
except ValueError:
pass
remove(TEMP_OUTPUT_FILE)
print('\nOutput saved to \'output.txt\'!\n')