-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_domains.py
256 lines (215 loc) · 8.97 KB
/
generate_domains.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
import tldextract
from lib import constants
class GenerateDomainName:
"""
A class to generate domain names using
diffrent type squatting methods
...
Attributes
----------
domain : str
domain that need to be searched for
Typosquatting related entries
Methods
-------
parse_domain():
parse a domain into three parts domain_prefix,
domain_without_tld and domain_tld
append_prefix_suffix():
appends domain_prefix and domain_tld to domain name
get_letters_numbers():
generates numbers [0-9] and letter [a-z]
addition():
adds single characters from [a-z] and [0-9]
to the domain name
omission():
removes a charactor from the domain name
repetition():
using all characters that already exists in the
domain name one by one to create new domain name
replacement():
replaces a charactor in the domain name
replace_char():
replaces a charactor with multiple occurrence
one at a time in a string with another charactor
homoglyphs():
replaces all possible homoglyphs using
the mapping data
bit_squatting():
flips the jTh bit in iTh charactor of any domain to
generate multiple possible bit-squatting
main():
main method that calls all the
functions to generate domain names
"""
def __init__(self, domain: str):
self.domain = domain
prefix, domain_name, tld = self.parse_domain()
self.domain_prefix = prefix
self.domain_name = domain_name
self.domain_tld = tld
self.domain_list = []
def parse_domain(self) -> tuple:
"""
This method splits domain to domain_prefix,
domain_without_tld and domain_tld
Returns:
tuple: domain_prefix, domain_without_tld, domain_tld
"""
domain_extract = tldextract.extract(self.domain)
domain_prefix = domain_extract.subdomain + "."
domain_without_tld = domain_extract.domain
domain_tld = "." + domain_extract.suffix
return domain_prefix, domain_without_tld, domain_tld
def append_prefix_suffix(self, name: str) -> str:
"""
This method appends the domain prefix and tld
to generated domain name
Returns:
list: domain name with prefix and tld
"""
return self.domain_prefix + name + self.domain_tld
@staticmethod
def get_letters_numbers() -> list:
"""
This method generates numbers [0-9] and letter [a-z]
Returns:
list: list of numbers [0-9] and letters [a-z]
"""
number_strings = [str(i) for i in range(10)]
letter_strings = [chr(ord('a') + i) for i in range(26)]
combined_list = number_strings + letter_strings
return combined_list
def addition(self) -> list:
"""
This method adds single characters from [a-z] and [0-9]
to the domain name to create possible domain names
Returns:
list: list of type squatted domains
"""
combined_list = self.get_letters_numbers()
for addition_string in combined_list:
for j in range(0, len(self.domain_name)):
domain_variation = self.append_prefix_suffix(self.domain_name[:j] + \
addition_string + self.domain_name[j:])
if domain_variation not in self.domain_list:
self.domain_list.append(domain_variation)
if j == len(self.domain_name) - 1:
domain_variation = self.append_prefix_suffix(self.domain_name + \
addition_string)
self.domain_list.append(domain_variation)
return self.domain_list
def omission(self) -> list:
"""
This method removes a charactor from the domain name
to create possible domain names
Returns:
list: list of type squatted domains
"""
for i in range(0, len(self.domain_name)):
domain_variation = self.append_prefix_suffix(self.domain_name[0:i] +
self.domain_name[i + 1:len(self.domain_name)])
if domain_variation not in self.domain_list:
self.domain_list.append(domain_variation)
return self.domain_list
def repetition(self) -> list:
"""
This method uses all characters that already exists in the
domain name one by one to create possible domain names
Returns:
list: list of type squatted domains
"""
for i, letter in enumerate(self.domain_name):
domain_variation = self.append_prefix_suffix(self.domain_name[:i]
+ letter + self.domain_name[i:])
if domain_variation not in self.domain_list:
self.domain_list.append(domain_variation)
return self.domain_list
def replacement(self) -> list:
"""
This method replaces a charactor in the domain name
to create possible domain names
Returns:
list: list of type squatted domains
"""
letters_numbers = self.get_letters_numbers()
for replacement_string in letters_numbers:
for j in range(0, len(self.domain_name)):
first = self.domain_name[:j]
last = self.domain_name[j + 1:]
domain_variation = self.append_prefix_suffix(first +
replacement_string + last)
if domain_variation not in self.domain_list:
self.domain_list.append(domain_variation)
return self.domain_list
@staticmethod
def replace_char(original_string: str, target: str, replacement: str) -> list:
"""
This method replaces a charactor with multiple occurrence
one at a time in a string with another charactor
Returns:
list: list of possible strings after replacement
"""
index = []
new_strings = []
for i, char in enumerate(original_string):
if char == target:
index.append(i)
for item in index:
if item != -1:
new_string = original_string[:item] + replacement + \
original_string[item + 1:]
new_strings.append(new_string)
else:
return [original_string]
return new_strings
def homoglyphs(self) -> list:
"""
This method replaces all possible homoglyphs using
the mapping data to create possible domain names
Returns:
list: list of type squatted domains
"""
for item in self.domain_name:
if item in constants.SIMILAR_CHAR:
for glyph in constants.SIMILAR_CHAR[item]:
modified_domains = self.replace_char(self.domain_name,
item, glyph)
for modified_domain in modified_domains:
domain_variation = self.append_prefix_suffix(modified_domain)
if domain_variation not in self.domain_list:
self.domain_list.append(domain_variation)
return self.domain_list
def bit_squatting(self) -> list:
"""
This method flips the jTh bit in iTh charactor of any domain to
generate multiple possible bit-squatting
Returns:
list: list of type squatted domains
"""
for i, _ in enumerate(self.domain_name):
for j in range(8):
bit_squatted_char = chr(ord(self.domain_name[i]) ^ (1 << j))
if bit_squatted_char.isalnum():
domain_variation = self.append_prefix_suffix(
self.domain_name[:i] + bit_squatted_char + self.domain_name[i + 1:])
if domain_variation not in self.domain_list:
self.domain_list.append(domain_variation)
return self.domain_list
def main(self) -> list:
"""
This method is the main method that calls all the
functions to generate domain names
Returns:
list: list of type squatted domains
"""
self.addition()
self.omission()
self.repetition()
self.replacement()
self.homoglyphs()
self.bit_squatting()
return self.domain_list
if __name__ == '__main__':
possible = GenerateDomainName("www.google.com").main()
print(possible)