-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
377 lines (338 loc) · 18 KB
/
index.js
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
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
'use strict';
const protectIt = async (pageOrContext, options) => {
await pageOrContext.addInitScript((options) => {
window.afpOptions = options;
// Canvas Def
const getImageData = CanvasRenderingContext2D.prototype.getImageData;
const noisify = (canvas, context) => {
if (context) {
const shift = {
r: window.afpOptions.canvasRgba
? window.afpOptions.canvasRgba[0]
: Math.floor(Math.random() * 10) - 5,
g: window.afpOptions.canvasRgba
? window.afpOptions.canvasRgba[1]
: Math.floor(Math.random() * 10) - 5,
b: window.afpOptions.canvasRgba
? window.afpOptions.canvasRgba[2]
: Math.floor(Math.random() * 10) - 5,
a: window.afpOptions.canvasRgba
? window.afpOptions.canvasRgba[3]
: Math.floor(Math.random() * 10) - 5,
};
const width = canvas.width;
const height = canvas.height;
if (width && height) {
const imageData = getImageData.apply(context, [0, 0, width, height]);
for (let i = 0; i < height; i++)
for (let j = 0; j < width; j++) {
const n = i * (width * 4) + j * 4;
imageData.data[n + 0] = imageData.data[n + 0] + shift.r;
imageData.data[n + 1] = imageData.data[n + 1] + shift.g;
imageData.data[n + 2] = imageData.data[n + 2] + shift.b;
imageData.data[n + 3] = imageData.data[n + 3] + shift.a;
}
context.putImageData(imageData, 0, 0);
}
}
};
HTMLCanvasElement.prototype.toBlob = new Proxy(HTMLCanvasElement.prototype.toBlob, {
apply(target, self, args) {
noisify(self, self.getContext("2d"));
return Reflect.apply(target, self, args);
},
});
HTMLCanvasElement.prototype.toDataURL = new Proxy(HTMLCanvasElement.prototype.toDataURL, {
apply(target, self, args) {
noisify(self, self.getContext("2d"));
return Reflect.apply(target, self, args);
},
});
CanvasRenderingContext2D.prototype.getImageData = new Proxy(CanvasRenderingContext2D.prototype.getImageData, {
apply(target, self, args) {
noisify(self.canvas, self);
return Reflect.apply(target, self, args);
},
});
//Webgl def
const config = {
random: {
value: () => {
return Math.random();
},
item: (e) => {
const rand = e.length * config.random.value();
return e[Math.floor(rand)];
},
number: (power) => {
const tmp = [];
for (let i = 0; i < power.length; i++) tmp.push(Math.pow(2, power[i]));
return config.random.item(tmp);
},
int: (power) => {
const tmp = [];
for (let i = 0; i < power.length; i++) {
const n = Math.pow(2, power[i]);
tmp.push(new Int32Array([n, n]));
}
return config.random.item(tmp);
},
float: (power) => {
const tmp = [];
for (let i = 0; i < power.length; i++) {
const n = Math.pow(2, power[i]);
tmp.push(new Float32Array([1, n]));
}
return config.random.item(tmp);
},
},
spoof: {
webgl: {
buffer: (target) => {
const proto = target.prototype ? target.prototype : target.__proto__;
proto.bufferData = new Proxy(proto.bufferData, {
apply(target, self, args) {
const index = Math.floor(config.random.value() * args[1].length);
const noise =
args[1][index] !== undefined ? 0.1 * config.random.value() * args[1][index] : 0;
args[1][index] = args[1][index] + noise;
return Reflect.apply(target, self, args);
},
});
},
parameter: (target) => {
const proto = target.prototype ? target.prototype : target.__proto__;
proto.getParameter = new Proxy(proto.getParameter, {
apply(target, receiver, args) {
if (args[0] === 3415) return 0;
else if (args[0] === 3414) return 24;
else if (args[0] === 36348) return 30;
else if (args[0] === 7936) return "WebKit";
else if (args[0] === 37445) return "Google Inc.";
else if (args[0] === 7937) return "WebKit WebGL";
else if (args[0] === 3379)
return window.afpOptions.webglData
? window.afpOptions.webglData["3378"]
: config.random.number([14, 15]);
else if (args[0] === 36347)
return window.afpOptions.webglData
? window.afpOptions.webglData["36347"]
: config.random.number([12, 13]);
else if (args[0] === 34076)
return window.afpOptions.webglData
? window.afpOptions.webglData["34076"]
: config.random.number([14, 15]);
else if (args[0] === 34024)
return window.afpOptions.webglData
? window.afpOptions.webglData["34024"]
: config.random.number([14, 15]);
else if (args[0] === 3386)
return window.afpOptions.webglData
? window.afpOptions.webglData["3386"]
: config.random.int([13, 14, 15]);
else if (args[0] === 3413)
return window.afpOptions.webglData
? window.afpOptions.webglData["3413"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 3412)
return window.afpOptions.webglData
? window.afpOptions.webglData["3412"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 3411)
return window.afpOptions.webglData
? window.afpOptions.webglData["3411"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 3410)
return window.afpOptions.webglData
? window.afpOptions.webglData["3410"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 34047)
return window.afpOptions.webglData
? window.afpOptions.webglData["34047"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 34930)
return window.afpOptions.webglData
? window.afpOptions.webglData["34930"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 34921)
return window.afpOptions.webglData
? window.afpOptions.webglData["34921"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 35660)
return window.afpOptions.webglData
? window.afpOptions.webglData["35660"]
: config.random.number([1, 2, 3, 4]);
else if (args[0] === 35661)
return window.afpOptions.webglData
? window.afpOptions.webglData["35661"]
: config.random.number([4, 5, 6, 7, 8]);
else if (args[0] === 36349)
return window.afpOptions.webglData
? window.afpOptions.webglData["36349"]
: config.random.number([10, 11, 12, 13]);
else if (args[0] === 33902)
return window.afpOptions.webglData
? window.afpOptions.webglData["33902"]
: config.random.float([0, 10, 11, 12, 13]);
else if (args[0] === 33901)
return window.afpOptions.webglData
? window.afpOptions.webglData["33901"]
: config.random.float([0, 10, 11, 12, 13]);
else if (args[0] === 37446)
return window.afpOptions.webglData
? window.afpOptions.webglData["37446"]
: config.random.item(["Graphics", "HD Graphics", "Intel(R) HD Graphics"]);
else if (args[0] === 7938)
return window.afpOptions.webglData
? window.afpOptions.webglData["7938"]
: config.random.item([
"WebGL 1.0",
"WebGL 1.0 (OpenGL)",
"WebGL 1.0 (OpenGL Chromium)",
]);
else if (args[0] === 35724)
return window.afpOptions.webglData
? window.afpOptions.webglData["35724"]
: config.random.item([
"WebGL",
"WebGL GLSL",
"WebGL GLSL ES",
"WebGL GLSL ES (OpenGL Chromium",
]);
return Reflect.apply(target, receiver, args);
},
});
},
},
},
};
config.spoof.webgl.buffer(WebGLRenderingContext);
config.spoof.webgl.buffer(WebGL2RenderingContext);
config.spoof.webgl.parameter(WebGLRenderingContext);
config.spoof.webgl.parameter(WebGL2RenderingContext);
// Font def
const rand = {
noise: () => {
console.log('doing noise')
const SIGN = Math.random() < Math.random() ? -1 : 1;
return window.afpOptions.fontFingerprint
? window.afpOptions.fontFingerprint.noise
: Math.floor(Math.random() + SIGN * Math.random());
},
sign: () => {
const tmp = [-1, -1, -1, -1, -1, -1, +1, -1, -1, -1];
const index = Math.floor(Math.random() * tmp.length);
return window.afpOptions.fontFingerprint
? window.afpOptions.fontFingerprint.sign
: tmp[index];
},
};
Object.defineProperty(HTMLElement.prototype, "offsetHeight", {
get: new Proxy(Object.getOwnPropertyDescriptor(HTMLElement.prototype, "offsetHeight").get, {
apply(target, self, args) {
try {
const height = Math.floor(self.getBoundingClientRect().height);
const valid = height && rand.sign() === 1;
const result = valid ? height + rand.noise() : height;
return result;
} catch (e) {
//return Reflect.apply(target, self, args);
}
},
}),
});
Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
get: new Proxy(Object.getOwnPropertyDescriptor(HTMLElement.prototype, "offsetWidth").get, {
apply(target, self, args) {
const width = Math.floor(self.getBoundingClientRect().width);
const valid = width && rand.sign() === 1;
const result = valid ? width + rand.noise() : width;
return result;
},
}),
});
//Aud def
const context = {
BUFFER: null,
getChannelData: function (e) {
e.prototype.getChannelData = new Proxy(e.prototype.getChannelData, {
apply(target, self, args) {
const results_1 = Reflect.apply(target, self, args);
if (context.BUFFER !== results_1) {
context.BUFFER = results_1;
for (let i = 0; i < results_1.length; i += 100) {
const index = Math.floor(
(window.afpOptions.audioFingerprint
? window.afpOptions.audioFingerprint.getChannelDataIndexRandom
: Math.random()) * i
);
results_1[index] =
results_1[index] +
(window.afpOptions.audioFingerprint
? window.afpOptions.audioFingerprint.getChannelDataResultRandom
: Math.random()) *
0.0000001;
}
}
return results_1;
},
});
},
createAnalyser: function (e) {
e.prototype.__proto__.createAnalyser = new Proxy(e.prototype.__proto__.createAnalyser, {
apply(target, self, args) {
const results_2 = Reflect.apply(target, self, args);
results_2.__proto__.getFloatFrequencyData = new Proxy(
results_2.__proto__.getFloatFrequencyData,
{
apply(target, self, args) {
const results_3 = Reflect.apply(target, self, args);
for (let i = 0; i < arguments[0].length; i += 100) {
const index = Math.floor(
(window.afpOptions.audioFingerprint
? window.afpOptions.audioFingerprint.createAnalyserIndexRandom
: Math.random()) * i
);
arguments[0][index] =
arguments[0][index] +
(window.afpOptions.audioFingerprint
? window.afpOptions.audioFingerprint.createAnalyserResultRandom
: Math.random()) *
0.1;
}
return results_3;
},
}
);
return results_2;
},
});
},
};
context.getChannelData(AudioBuffer);
context.createAnalyser(AudioContext);
context.createAnalyser(OfflineAudioContext);
// Web RTC
if (window.afpOptions.webRTCProtect) navigator.mediaDevices.getUserMedia =
navigator.webkitGetUserMedia =
navigator.mozGetUserMedia =
navigator.getUserMedia =
webkitRTCPeerConnection =
RTCPeerConnection =
MediaStreamTrack =
undefined;
Object.defineProperty(navigator, "deviceMemory", {
get: () =>
window.afpOptions.deviceMemory
? window.afpOptions.deviceMemory
: Math.floor(Math.random() * 8) + 4,
});
window.chrome = { runtime: {} };
window.navigator.chrome = { runtime: {} };
//remove webdriver
const newProto = navigator.__proto__;
delete newProto.webdriver;
navigator.__proto__ = newProto;
}, options);
};
module.exports = protectIt;