forked from highmeh/pentest_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_emails.py
executable file
·187 lines (153 loc) · 6.84 KB
/
generate_emails.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
#!/usr/bin/env python3
# -*- UTF-8 -*-
import argparse
import re
import os
def sanitize(infile, outfile, domain, addrformat):
print("[+] Sanitizing {0}".format(infile))
# Note: Add more excluded titles as required. Common IT, Infosec, and HR titles listed.
excluded_words = ['CEH','OSCP','OSCE','GCIA','GCIH','GXPN','GPEN','GCED','GSE','CISSP',
'CISA','QSA','CCNA','CCNP','CCIE','MCSE','MCSA','MCP','ITIL','PMP','HRM','SHRM',
'SHRM-CP','SHRM-SCP','PHR','PHRca','SPHR','GPHR','HR']
sanitized_names = []
with open(infile, "r+") as r:
for name in r:
disassembled_name = ((re.findall("[\w']+", name)))
for piece in disassembled_name:
if piece in excluded_words:
disassembled_name.remove(piece)
sanitized_name = disassembled_name[0] + " " + disassembled_name[-1]
sanitized_names.append(sanitized_name)
formatNames(sanitized_names, outfile, domain, addrformat)
def formatNames(sanitized_names, outfile, domain, addrformat):
print("[+] Formatting output...")
if addrformat == "flast":
fmt_flast(sanitized_names, outfile, domain)
if addrformat == "underscore":
fmt_underscore(sanitized_names, outfile, domain)
if addrformat == "firstlast":
fmt_firstlast(sanitized_names, outfile, domain)
if addrformat == "firstl":
fmt_firstl(sanitized_names, outfile, domain)
if addrformat == "firstonly":
fmt_firstonly(sanitized_names, outfile, domain)
if addrformat == "lastf":
fmt_lastf(sanitized_names, outfile, domain)
if addrformat == "truncated":
fmt_truncated(sanitized_names, outfile, domain)
if addrformat == "dot":
fmt_dot(sanitized_names, outfile, domain)
def fmt_flast(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = first_name[0] + last_name.strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_underscore(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = first_name + "_" + last_name.strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_dot(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = first_name + "." + last_name.strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_firstlast(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = first_name.strip() + last_name.strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_firstl(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = first_name + last_name[0].strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_lastf(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = last_name.strip() + first_name[0].strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_firstonly(sanitized_names, outfile, domain):
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
formatted_name = first_name.strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def fmt_truncated(sanitized_names, outfile, domain):
# Change this value to change the truncated length. John Smith with truncated=3 becomes johsmi.
truncated = 3
for name in sanitized_names:
full_name = name.split(" ")
first_name = full_name[0]
last_name = full_name[1]
formatted_name = first_name[:truncated].strip() \
+ last_name[:truncated].strip() + "@" + domain + "\n"
with open(outfile, "a") as completed_file:
completed_file.write(formatted_name.lower())
errorcheck(outfile)
def errorcheck(outfile):
if os.path.exists(outfile):
print("[+] Done! Created: {0}".format(outfile))
else:
print("[-] Failed to create: {0}".format(outfile))
exit()
progdesc = """Takes a list of full names (such as a list generated by TheHarvester)
and converts them to email format, to assist in brute force or password reuse attacks during
black-box penetration tests. Attempts to sanitize the username list by removing middle names,
punctuation, intials, and titles from the list. Valid Formats: flast ([email protected]), underscore
"""
parser = argparse.ArgumentParser(description=progdesc)
parser.add_argument('-i', metavar='InputFile', action='store', default='None',
help='Ex: fullnames.txt')
parser.add_argument('-o', metavar='OutputFile', action='store', default='None',
help='Ex: emails.txt')
parser.add_argument('-d', metavar='DomainName', action='store', default=
'Please_Specify_A_Domain_Name.thx', help='Ex: pwn3d.org')
parser.add_argument('-f', metavar='FormatChoice', action='store', default='flast',
help='Valid formats: flast (*default), underscore, firstlast, firstl,\
firstonly, lastf, truncated, dot')
args = parser.parse_args()
if args.i:
if os.path.exists(args.i):
infile = args.i
else:
print("[-] Input file '{0}' does not exist!\n".format(args.i))
exit()
if args.o:
outfile = args.o
if args.d:
domain = args.d
if args.f:
addrformat = args.f.lower()
try:
sanitize(infile, outfile, domain, addrformat)
except:
parser.print_help()