-
Notifications
You must be signed in to change notification settings - Fork 7
/
run.py
152 lines (108 loc) · 5.45 KB
/
run.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
import folium
from furl import furl
from odyssey import Odyssey
from odyssey.utils import (get_ip_address_information, get_ssl_cert_from_url,
match_ip_logger)
def main():
url = input('[+] URL: ')
# Sanity input checks, fixes #1
if not url:
raise Exception(f'Please enter a URL to trace')
original_parsed_url = furl(url)
if not (original_parsed_url.scheme or original_parsed_url.host) or '.' not in original_parsed_url.host:
raise Exception(f'Expected a URL but got something else!')
traceroute = Odyssey().check(url)
if traceroute == {} or not traceroute:
print('[-] No redirects were identified')
return
MAP_CENTER = [0, 0]
route_map = folium.Map(location = MAP_CENTER, zoom_start = 2.5)
TRACEROUTE_MAP_FILENAME = 'route.html'
locations = []
for hop_count, (url, metadata) in enumerate(traceroute.items(), start = 1):
parsed_url = furl(url)
server = metadata.get('server')
cookies = metadata.get('cookies')
ip = metadata.get('ip')
domain = parsed_url.host
country, isp, org, asn, latitude, longitude = get_ip_address_information(ip)
result = f"[No. {hop_count}]\n\t - Server: {server}\n\t - Country: {country} \n\t - Metadata: {ip} ({isp}, {org}, {asn})\n\t - URL: {url}"
if cookies:
cookie_count = len(cookies)
if cookie_count > 0:
result += f'\n\t ' \
f'- Cookies:\n\t\t ' \
f'- Count: {cookie_count}\n\t\t ' \
f'- Cookie Values:'
for cookie_name, cookie_data in cookies.items():
cookie_value = cookie_data.get('value')
cookie_attributes = cookie_data.get('attributes')
result += f'\n\t\t\t - Name: {cookie_name}'
result += f'\n\t\t\t\t - Value: {cookie_value}'
result += f'\n\t\t\t\t - Attributes: {cookie_attributes}'
IS_HTTPS = parsed_url.scheme == 'https'
if IS_HTTPS:
certificate = get_ssl_cert_from_url(url)
subject_common_name = certificate.get('subject').get('commonName')
issuer_organization = certificate.get('issuer').get('organizationName')
serial_number = certificate.get('serialNumber')
result += f'\n\t ' \
f'- SSL Certificate:\n\t\t ' \
f'- Subject: {subject_common_name}\n\t\t ' \
f'- Issuer: {issuer_organization}\n\t\t ' \
f'- Serial Number: {serial_number} '
matched_ip_logger = match_ip_logger(domain, ip, subject_common_name, serial_number, is_https = IS_HTTPS)
else:
matched_ip_logger = match_ip_logger(domain, ip, None, None, is_https = IS_HTTPS)
if matched_ip_logger:
result += '\n\t - IP Loggers:'
result += '\n\t\t\t - ' + matched_ip_logger
result += '\n'
print(result)
# Route map generation using Folium
html = f'''
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Space+Mono&display=swap" rel="stylesheet">
<p style="font-family: 'Space Mono', monospace;">
URL: {url}
<br>
IP: {ip}
<br>
ASN: {asn.split(' ')[0]}
<br>
ORG: {org}
<br>
ISP: {isp}
</p>
'''
iframe = folium.IFrame(html, width = 600, height = 250)
popup = folium.Popup(iframe)
# Added to avoid confusion, to see if URL coords are already in list,
# if so adjust the next URL's coords to be distinct from the previous URL.
offset = 0.005
if (latitude, longitude) in locations:
latitude, longitude = latitude + offset, longitude + offset
# Setting up the markers for the FoliumJS map
START_DATA = (1, 'green')
BOUNCE_DATA = ([x for x in range(1, len(traceroute))], 'orange')
END_DATA = (len(traceroute), 'red')
if hop_count == START_DATA[0]:
folium.Marker((latitude, longitude), popup = popup,
icon = folium.Icon(color = START_DATA[1], icon = "glyphicon-flash",
prefix = "glyphicon")).add_to(
route_map)
elif hop_count == END_DATA[0]:
folium.Marker((latitude, longitude), popup = popup,
icon = folium.Icon(color = END_DATA[1], icon = "glyphicon-flash",
prefix = "glyphicon")).add_to(
route_map)
else:
folium.Marker((latitude, longitude), popup = popup,
icon = folium.Icon(color = BOUNCE_DATA[1], icon = "glyphicon-flash",
prefix = "glyphicon")).add_to(route_map)
locations.append((latitude, longitude))
folium.PolyLine(locations = locations, line_opacity = 1.0, color = 'black').add_to(route_map)
route_map.save(TRACEROUTE_MAP_FILENAME) # Save the route map in the folder it is in as 'route_map.html'
print(f'[+] Saved traceroute map as {TRACEROUTE_MAP_FILENAME}')
if __name__ == '__main__':
main()