-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_scanner.py
230 lines (214 loc) · 8.62 KB
/
test_scanner.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
from fingerprint_data_manager import FingerprintDataManager
from inconsistency_scanner import Scanner
fp_manager = FingerprintDataManager()
scanner = Scanner()
# TODO warning I removed features
# def test_canvas_defender():
# ALLOWED_TESTS_TO_FAIL = {Scanner.CANVAS_OVERWRITTEN, Scanner.CANVAS_PIXELS, Scanner.EMOJI}
# # emoji is allowed to fail since when canvas is blank it has a bad prediction
# fingerprints = fp_manager.get_fingerprints_countermeasure('cd') + fp_manager.get_fingerprints_countermeasure('cfpb')
#
# print('Testing canvas defender: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
# def test_user_agent_spoofers():
# ALLOWED_TESTS_TO_FAIL = {Scanner.PLATFORM_OS_REF, Scanner.PLUGINS_OS, Scanner.ETSL, Scanner.PRODUCT_SUB,
# Scanner.ERRORS_BROWSER, Scanner.ACCELEROMETER, Scanner.TOUCH_SUPPORT, Scanner.EMOJI,
# Scanner.FONTS_OS, Scanner.MQ_OS, Scanner.SCREEN_SIZE}
#
# fingerprints = fp_manager.get_fingerprints_countermeasure('uas')
# print('Testing user agent spoofers: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
# def test_no_countermeasures():
# ALLOWED_TESTS_TO_FAIL = {Scanner.EMOJI, Scanner.SAME_UAS} # We allow emoji since it is non deterministic, but ideally it should not fail
# # Same UAs may fail in case of ie 11
#
# fingerprints = fp_manager.get_fingerprints_countermeasure('no')
# print('Testing no countermeasure: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
# def test_ras_countermeasures():
# ALLOWED_TESTS_TO_FAIL = {Scanner.MQ_OS, Scanner.ETSL, Scanner.PRODUCT_SUB, Scanner.ERRORS_BROWSER,
# Scanner.NAVIGATOR_OVERWRITTEN, Scanner.CANVAS_OVERWRITTEN, Scanner.EMOJI,
# Scanner.WEBGL_OS, Scanner.TOUCH_SUPPORT, Scanner.ACCELEROMETER, Scanner.SCREEN_SIZE,
# Scanner.FONTS_OS}
#
# fingerprints = fp_manager.get_fingerprints_countermeasure('rasp') + \
# fp_manager.get_fingerprints_countermeasure('ras')
#
# print('Testing RAS: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
# def test_brave_countermeasures():
# ALLOWED_TESTS_TO_FAIL = {Scanner.NAVIGATOR_OVERWRITTEN, Scanner.CANVAS_PIXELS, Scanner.EMOJI}
# # emoji is allowed since blocking canvas engenders a wrongs prediction with the neural network
#
# fingerprints = fp_manager.get_fingerprints_countermeasure('brave')
#
# print('Testing Brave: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
# def test_firefox_protection_countermeasures():
# ALLOWED_TESTS_TO_FAIL = {Scanner.MQ_OS, Scanner.EMOJI, Scanner.FONTS_OS, Scanner.WEBGL_OS}
#
# fingerprints = fp_manager.get_fingerprints_countermeasure('ffp')
#
# print('Testing Firefox protection: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
# def test_fp_random():
# ALLOWED_TESTS_TO_FAIL = {Scanner.CANVAS_PIXELS}
# fingerprints = fp_manager.get_fingerprints_countermeasure('fpr')
#
# print('Testing FPRandom: {:d} fingerprints'.format(len(fingerprints)))
#
# for fingerprint in fingerprints:
# tests_failed = []
# scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
# results_failed = []
# for scan_res in scan_results:
# if not scan_res.is_consistent:
# tests_failed.append(scan_res.name)
# results_failed.append(scan_res)
#
# if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
# print('-------------')
# print(fingerprint)
# print(tests_failed)
# for elt in results_failed:
# print(elt)
# print()
# assert False
# else:
# assert True
def test_blink():
ALLOWED_TESTS_TO_FAIL = {}
fingerprints = fp_manager.get_fingerprints_countermeasure('blink')
print('Testing Blink: {:d} fingerprints'.format(len(fingerprints)))
for fingerprint in fingerprints:
tests_failed = []
scan_results = scanner.check_fingerprint(fingerprint, run_all=True)
results_failed = []
for scan_res in scan_results:
if not scan_res.is_consistent:
tests_failed.append(scan_res.name)
results_failed.append(scan_res)
if not set(tests_failed).issubset(ALLOWED_TESTS_TO_FAIL):
print('-------------')
print(fingerprint)
print(tests_failed)
for elt in results_failed:
print(elt)
print()
assert False
else:
assert True