-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
84 lines (67 loc) · 2.5 KB
/
main.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
# Python
from typosquatting import URLGenerator
from webcomp import Comparer
import requests
import sys
import os
import os.path as path
def _help():
print()
print(f'Usage: python3 main.py <domain> <typos>')
print(f'The argument must be a domain. More precisely google.com instead of https://google.com')
exit(0)
if __name__ == '__main__':
# clear window
os.system('clear')
print('\n [+] Initialization')
# get command line inputs
if len(sys.argv[1:]) != 2:
_help()
# URLs
target_domain = sys.argv[1]
try:
target_url = requests.get(f'http://{target_domain}').url
except Exception as e:
_help()
# typos
typos = sys.argv[2]
# generate possible malicious domains
print(f' [+] Generating domains based on {target_domain}')
generator = URLGenerator.Generator()
typo_domains = generator.generate(target_domain, int(typos))
# append protocol
typo_urls = []
connection_error_log = []
for domain in typo_domains:
try:
r = requests.get(f'http://{domain}')
typo_urls.append(r.url)
except Exception as e:
connection_error_log.append((domain, e))
# compare urls
scores = []
comparer = Comparer.Comparer()
_LOGGING = True
if _LOGGING:
# if not already exist: create directory logs
if not path.exists('logs'):
os.system('mkdir logs')
# if not already exist: create directory logs/<target_domain>
if not path.exists(f'logs/{target_domain}'):
os.system(f'mkdir logs/{target_domain}')
for i, url in enumerate(typo_urls):
if i == len(typo_urls) - 1:
print(f' [+] Compare website {i + 1} / {len(typo_urls)}')
else:
print(f' [+] Compare website {i + 1} / {len(typo_urls)}', end='\r')
comparer.set_parameter(target_url, url)
if _LOGGING:
comparer.enable_logging(f'logs/{target_domain}/')
achieved_points, max_points = comparer.compare_websites()
# print(f'\t{achieved_points} / {max_points} for comparing {target_url} with {url}')
scores.append((url, achieved_points, max_points))
# print results into file: ./logs/<target-domain>/results.txt
print(f' [+] Complete\n [+] Results are stored in logs/{target_domain}/results.txt\n')
with open(f'logs/{target_domain}/results.txt', 'w') as result_file:
for url, score, max_score in scores:
result_file.write(f'{score} / {max_score} for [ {url} ]\n')