-
Notifications
You must be signed in to change notification settings - Fork 0
/
blacklight
executable file
·77 lines (62 loc) · 2.2 KB
/
blacklight
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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import json
import re
import sys
import urllib.request
def callAPI(url):
host = 'https://blacklight.api.themarkup.org/'
payload = '{ "inUrl" : "' + url + '"}'
request = urllib.request.Request(
url=host,
data=payload.encode('utf-8'),
method='POST')
request.add_header('content-type', 'text/plain;charset=UTF-8')
with urllib.request.urlopen(request) as response:
responseJson = json.loads(response.read().decode("utf-8"))
if 'error_message' in responseJson.keys():
print('\033[91m\033[1m[ERROR]\033[0m\033[0m '
+ responseJson['nicer_error_message'])
exit()
return responseJson
def printInspectionResult(data):
for group in data['groups']:
if 'Blacklight Inspection Result' in group['title']:
print('> \033[1mInspection result:\033[0m')
for card in group['cards']:
if 'bigNumber' in card.keys():
print(' \033[93m' + str(card['bigNumber'])
+ '\033[0m '
+ card['title'])
else:
mark = '0'
if card['testEventsFound']:
mark = '!'
print(' \033[93m' + mark + '\033[0m ' + card['title'])
def printAdCompany(data):
for group in data['groups']:
if 'Some of the ad-tech companies' in group['title']:
print('> \033[1mAd-tech companies:\033[0m')
for card in group['cards']:
print(' \033[93m' + card['title'] + '\033[0m: '
+ re.sub(r'</?\w+>',
'',
', '.join(card['domains_found'])))
def main():
if len(sys.argv) != 2:
print('\033[91m\033[1m[ERROR]\033[0m\033[0m Wrong input! '
+ '\nUsage: ./blacklight "<url>"')
exit()
if sys.argv[1].startswith('http'):
url = sys.argv[1]
else:
url = 'https://' + sys.argv[1]
data = callAPI(url)
printInspectionResult(data)
print()
printAdCompany(data)
if __name__ == '__main__':
try:
main()
except KeyboardInterrupt:
pass