Skip to content

Instantly share code, notes, and snippets.

@step135
Created June 16, 2021 22:30
Show Gist options
  • Save step135/b4b935b0d817b1403cfa315ec7ae89de to your computer and use it in GitHub Desktop.
Save step135/b4b935b0d817b1403cfa315ec7ae89de to your computer and use it in GitHub Desktop.
var background = (function () {
var tmp = {};
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
for (var id in tmp) {
if (tmp[id] && (typeof tmp[id] === "function")) {
if (request.path === "background-to-page") {
if (request.method === id) tmp[id](request.data);
}
}
}
});
/* */
return {
"receive": function (id, callback) {tmp[id] = callback},
"send": function (id, data) {chrome.runtime.sendMessage({"path": "page-to-background", "method": id, "data": data})}
}
})();
var inject = function () {
var rn = 4 < 9;
var nat = {};
var strnat = {};
var config = {
"random": {
"value": function () {
return rn ? 0.1314 : Math.random();
},
"item": function (e) {
var rand = e.length * config.random.value();
return e[Math.floor(rand)];
},
"number": function (power) {
var tmp = [];
for (var i = 0; i < power.length; i++) {
tmp.push(Math.pow(2, power[i]));
}
/* */
return config.random.item(tmp);
},
"int": function (power) {
var tmp = [];
for (var i = 0; i < power.length; i++) {
var n = Math.pow(2, power[i]);
tmp.push(new Int32Array([n, n]));
}
/* */
return config.random.item(tmp);
},
"float": function (power) {
var tmp = [];
for (var i = 0; i < power.length; i++) {
var n = Math.pow(2, power[i]);
tmp.push(new Float32Array([1, n]));
}
/* */
return config.random.item(tmp);
}
},
"spoof": {
"webgl": {
"buffer": function (target) {
var proto = target.prototype ? target.prototype : target.__proto__;
nat["bufferData"] = proto.bufferData;
strnat["bufferData"] = nat["bufferData"].toString();
function bufferData() {
var index = Math.floor(config.random.value() * arguments[1].length);
var noise = arguments[1][index] !== undefined ? 0.1 * config.random.value() * arguments[1][index] : 0;
//
arguments[1][index] = arguments[1][index] + noise;
window.top.postMessage("webgl-fingerprint-defender-alert", '*');
//
return nat["bufferData"].apply(this, arguments);
}
proto.bufferData = bufferData;
},
"parameter": function (target) {
var proto = target.prototype ? target.prototype : target.__proto__;
nat["getParameter"] = proto.getParameter;
strnat["getParameter"] = nat["getParameter"].toString();
function getParameter() {
window.top.postMessage("webgl-fingerprint-defender-alert", '*');
//
if (arguments[0] === 3415) return 0;
else if (arguments[0] === 3414) return 24;
else if (arguments[0] === 36348) return 30;
else if (arguments[0] === 7936) return "WebKit";
else if (arguments[0] === 37445) return "Google Inc.";
else if (arguments[0] === 7937) return "WebKit WebGL";
else if (arguments[0] === 3379) return config.random.number([14, 15]);
else if (arguments[0] === 36347) return config.random.number([12, 13]);
else if (arguments[0] === 34076) return config.random.number([14, 15]);
else if (arguments[0] === 34024) return config.random.number([14, 15]);
else if (arguments[0] === 3386) return config.random.int([13, 14, 15]);
else if (arguments[0] === 3413) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 3412) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 3411) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 3410) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 34047) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 34930) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 34921) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 35660) return config.random.number([1, 2, 3, 4]);
else if (arguments[0] === 35661) return config.random.number([4, 5, 6, 7, 8]);
else if (arguments[0] === 36349) return config.random.number([10, 11, 12, 13]);
else if (arguments[0] === 33902) return config.random.float([0, 10, 11, 12, 13]);
else if (arguments[0] === 33901) return config.random.float([0, 10, 11, 12, 13]);
else if (arguments[0] === 37446) return config.random.item(["Graphics", "HD Graphics", "Intel(R) HD Graphics"]);
else if (arguments[0] === 7938) return config.random.item(["WebGL 1.0", "WebGL 1.0 (OpenGL)", "WebGL 1.0 (OpenGL Chromium)"]);
else if (arguments[0] === 35724) return config.random.item(["WebGL", "WebGL GLSL", "WebGL GLSL ES", "WebGL GLSL ES (OpenGL Chromium"]);
//
return nat["getParameter"].apply(this, arguments);
}
proto.getParameter = getParameter;
}
}
}
};
//
config.spoof.webgl.buffer(WebGLRenderingContext);
config.spoof.webgl.buffer(WebGL2RenderingContext);
config.spoof.webgl.parameter(WebGLRenderingContext);
config.spoof.webgl.parameter(WebGL2RenderingContext);
const origToString = Function.prototype.toString;
Function.prototype.toString = function(){
const fnames = Object.keys(nat);
return fnames.indexOf(this.name)>-1 ? strnat[this.name]:
origToString.apply(this, arguments)
};
//
document.documentElement.dataset.wgscriptallow = true;
};
var script_1 = document.createElement("script");
script_1.textContent = "(" + inject + ")()";
document.documentElement.appendChild(script_1);
script_1.remove();
if (document.documentElement.dataset.wgscriptallow !== "true") {
var script_2 = document.createElement("script");
script_2.textContent = `{
const iframes = [...window.top.document.querySelectorAll("iframe[sandbox]")];
for (var i = 0; i < iframes.length; i++) {
if (iframes[i].contentWindow) {
if (iframes[i].contentWindow.WebGLRenderingContext) {
iframes[i].contentWindow.WebGLRenderingContext.prototype.bufferData = WebGLRenderingContext.prototype.bufferData;
iframes[i].contentWindow.WebGLRenderingContext.prototype.getParameter = WebGLRenderingContext.prototype.getParameter;
}
if (iframes[i].contentWindow.WebGL2RenderingContext) {
iframes[i].contentWindow.WebGL2RenderingContext.prototype.bufferData = WebGL2RenderingContext.prototype.bufferData;
iframes[i].contentWindow.WebGL2RenderingContext.prototype.getParameter = WebGL2RenderingContext.prototype.getParameter;
}
}
}
}`;
//
window.top.document.documentElement.appendChild(script_2);
script_2.remove();
}
window.addEventListener("message", function (e) {
if (e.data && e.data === "webgl-fingerprint-defender-alert") {
background.send("fingerprint", {"host": document.location.host});
}
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment