AdguardTeam / AdguardTeam/Scriptlets

Improve 'fingerprintjs2' — 'x64hash128', 'components'

オープン
#339 コメント 0 件 リアクション 1 件 担当者 1 名 @maximtop が担当を希望しています GitHub で見る
bug Priority: P4
主要言語
JavaScript
スター
195
フォーク
33
PR マージ指標
30日以内にマージされた PR はありません

説明

Related issue: https://github.com/AdguardTeam/AdguardFilters/issues/156794

```adblock
||new-in.pmirnc.com/public/fingerprint2.js$script,redirect=fingerprintjs2,important
```

The above filter does not work on the website.
The anti-adblock script requires result of a visitor's environment named as `components` variable.
Its server requires result of `x64hash128` hash function to proceed.
It seems that it is okay to return random int for the hash function if the server does not track the visitor and check its value.

Screenshots

![Screenshot from 2023-07-18 15-28-31](https://github.com/AdguardTeam/Scriptlets/assets/98787049/e4e528f1-0253-40fa-86c3-4690d8650dcf)
![Screenshot from 2023-07-18 15-28-37](https://github.com/AdguardTeam/Scriptlets/assets/98787049/4d686834-7c40-47af-ac96-08ecebeec009)

The anti-adblock script

```javascript
initFingerprintJS();
function initFingerprintJS() {
var options = {fonts: {extendedJsFonts: true}};
try {
var result = function (components) {
var values = components.map(function (component) { return component.value });
var murmur = Fingerprint2.x64hash128(values.join(''), 31);
document.getElementById('hash').value = murmur;
document.forms[0].submit();
};
var js = document.createElement('script');
js.type = 'text/javascript';
/*js.src = 'https://cdnjs.cloudflare.com/ajax/libs/fingerprintjs2/2.1.0/fingerprint2.min.js';*/
js.src = '/public/fingerprint2.js';
document.head.appendChild(js);

js.onerror = function (evt) {
document.write ('

오류가 있습니다.

AD BLOCK이 설치되어 있다면 해제해야 진행 가능합니다.

');
}

js.onload = function () {
setTimeout(function () {
if (window.requestIdleCallback) {
requestIdleCallback(function () {
Fingerprint2.get(options, result);
})
} else {
Fingerprint2.get(options, result);
}
}, 1000);
};
} catch (e) {
document.write(e);
}
}
```

components variable

```javascript
var components = [
{ key: 'userAgent', getData: UserAgent },
{ key: 'webdriver', getData: webdriver },
{ key: 'language', getData: languageKey },
{ key: 'colorDepth', getData: colorDepthKey },
{ key: 'deviceMemory', getData: deviceMemoryKey },
{ key: 'pixelRatio', getData: pixelRatioKey },
{ key: 'hardwareConcurrency', getData: hardwareConcurrencyKey },
{ key: 'screenResolution', getData: screenResolutionKey },
{ key: 'availableScreenResolution', getData: availableScreenResolutionKey },
{ key: 'timezoneOffset', getData: timezoneOffset },
{ key: 'timezone', getData: timezone },
{ key: 'sessionStorage', getData: sessionStorageKey },
{ key: 'localStorage', getData: localStorageKey },
{ key: 'indexedDb', getData: indexedDbKey },
{ key: 'addBehavior', getData: addBehaviorKey },
{ key: 'openDatabase', getData: openDatabaseKey },
{ key: 'cpuClass', getData: cpuClassKey },
{ key: 'platform', getData: platformKey },
{ key: 'doNotTrack', getData: doNotTrackKey },
{ key: 'plugins', getData: pluginsComponent },
{ key: 'canvas', getData: canvasKey },
{ key: 'webgl', getData: webglKey },
{ key: 'webglVendorAndRenderer', getData: webglVendorAndRendererKey },
{ key: 'adBlock', getData: adBlockKey },
{ key: 'hasLiedLanguages', getData: hasLiedLanguagesKey },
{ key: 'hasLiedResolution', getData: hasLiedResolutionKey },
{ key: 'hasLiedOs', getData: hasLiedOsKey },
{ key: 'hasLiedBrowser', getData: hasLiedBrowserKey },
{ key: 'touchSupport', getData: touchSupportKey },
{ key: 'fonts', getData: jsFontsKey, pauseBefore: true },
{ key: 'fontsFlash', getData: flashFontsKey, pauseBefore: true },
{ key: 'audio', getData: audioKey },
{ key: 'enumerateDevices', getData: enumerateDevicesKey },
];
```

x64hash128 hash function

```javascript
//
// Given a string and an optional seed as an int, returns a 128 bit
// hash using the x64 flavor of MurmurHash3, as an unsigned hex.
//
var x64hash128 = function (key, seed) {
key = key || '';
seed = seed || 0;
var remainder = key.length % 16;
var bytes = key.length - remainder;
var h1 = [0, seed];
var h2 = [0, seed];
var k1 = [0, 0];
var k2 = [0, 0];
var c1 = [0x87c37b91, 0x114253d5];
var c2 = [0x4cf5ad43, 0x2745937f];
for (var i = 0; i < bytes; i = i + 16) {
k1 = [
(key.charCodeAt(i + 4) & 0xff) |
((key.charCodeAt(i + 5) & 0xff) << 8) |
((key.charCodeAt(i + 6) & 0xff) << 16) |
((key.charCodeAt(i + 7) & 0xff) << 24),
(key.charCodeAt(i) & 0xff) |
((key.charCodeAt(i + 1) & 0xff) << 8) |
((key.charCodeAt(i + 2) & 0xff) << 16) |
((key.charCodeAt(i + 3) & 0xff) << 24),
];
k2 = [
(key.charCodeAt(i + 12) & 0xff) |
((key.charCodeAt(i + 13) & 0xff) << 8) |
((key.charCodeAt(i + 14) & 0xff) << 16) |
((key.charCodeAt(i + 15) & 0xff) << 24),
(key.charCodeAt(i + 8) & 0xff) |
((key.charCodeAt(i + 9) & 0xff) << 8) |
((key.charCodeAt(i + 10) & 0xff) << 16) |
((key.charCodeAt(i + 11) & 0xff) << 24),
];
k1 = x64Multiply(k1, c1);
k1 = x64Rotl(k1, 31);
k1 = x64Multiply(k1, c2);
h1 = x64Xor(h1, k1);
h1 = x64Rotl(h1, 27);
h1 = x64Add(h1, h2);
h1 = x64Add(x64Multiply(h1, [0, 5]), [0, 0x52dce729]);
k2 = x64Multiply(k2, c2);
k2 = x64Rotl(k2, 33);
k2 = x64Multiply(k2, c1);
h2 = x64Xor(h2, k2);
h2 = x64Rotl(h2, 31);
h2 = x64Add(h2, h1);
h2 = x64Add(x64Multiply(h2, [0, 5]), [0, 0x38495ab5]);
}
k1 = [0, 0];
k2 = [0, 0];
switch (remainder) {
case 15:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 14)], 48));
// fallthrough
case 14:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 13)], 40));
// fallthrough
case 13:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 12)], 32));
// fallthrough
case 12:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 11)], 24));
// fallthrough
case 11:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 10)], 16));
// fallthrough
case 10:
k2 = x64Xor(k2, x64LeftShift([0, key.charCodeAt(i + 9)], 8));
// fallthrough
case 9:
k2 = x64Xor(k2, [0, key.charCodeAt(i + 8)]);
k2 = x64Multiply(k2, c2);
k2 = x64Rotl(k2, 33);
k2 = x64Multiply(k2, c1);
h2 = x64Xor(h2, k2);
// fallthrough
case 8:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 7)], 56));
// fallthrough
case 7:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 6)], 48));
// fallthrough
case 6:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 5)], 40));
// fallthrough
case 5:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 4)], 32));
// fallthrough
case 4:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 3)], 24));
// fallthrough
case 3:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 2)], 16));
// fallthrough
case 2:
k1 = x64Xor(k1, x64LeftShift([0, key.charCodeAt(i + 1)], 8));
// fallthrough
case 1:
k1 = x64Xor(k1, [0, key.charCodeAt(i)]);
k1 = x64Multiply(k1, c1);
k1 = x64Rotl(k1, 31);
k1 = x64Multiply(k1, c2);
h1 = x64Xor(h1, k1);
// fallthrough
}
h1 = x64Xor(h1, [0, key.length]);
h2 = x64Xor(h2, [0, key.length]);
h1 = x64Add(h1, h2);
h2 = x64Add(h2, h1);
h1 = x64Fmix(h1);
h2 = x64Fmix(h2);
h1 = x64Add(h1, h2);
h2 = x64Add(h2, h1);
return (
('00000000' + (h1[0] >>> 0).toString(16)).slice(-8) +
('00000000' + (h1[1] >>> 0).toString(16)).slice(-8) +
('00000000' + (h2[0] >>> 0).toString(16)).slice(-8) +
('00000000' + (h2[1] >>> 0).toString(16)).slice(-8)
);
};
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。