根据以前的经验,在补环境的时候,想要绕过typeof document.all的检测,一般有2条路可以选,对技术门槛会比较高。
第一条,修改v8源码,并重新编译nodejs来实现。
第二条,编写node插件,改变内部数据行为。
现在使用nodejs自带的v8模块,不需要修改v8源码和编写插件也能绕过typeof document.all检测
const v8 = require("v8");
const vm = require("vm");
// 允许使用 V8 内置函数(需启用 --allow-natives-syntax 标志)
v8.setFlagsFromString("--allow-natives-syntax");
// 创建不可检测对象
let undetectable = vm.runInThisContext("%GetUndetectable()");
// 恢复标志禁用(可选)
v8.setFlagsFromString("--no-allow-natives-syntax");
// 测试对象行为
function HTMLAllCollection() {
return undetectable;
}
Object.defineProperties(HTMLAllCollection.prototype, {
[Symbol.toStringTag]: { value: "HTMLAllCollection", configurable: true }
});
undetectable.__proto__ = HTMLAllCollection.prototype;
const document = {};
document.all = new HTMLAllCollection();
length = 3;
for (let i = 0; i < length; i++) {
document.all[i] = "1";
}
document.all.length = length;
console.log(typeof document.all);
console.log(document.all);
console.log(document.all.length);