文章目錄
在JavaScript逆向时一些奇奇怪怪的检测里,我们写过一个使用Node v8内置函数来过 document.all 补环境检测的demo, 代码如下
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
| const v8 = require("v8"); const vm = require("vm");
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; document = {} document.all = new HTMLAllCollection()
length = 3; for (let i = 0; i < length; i++) { document.all[i] = '1'; } debugger; document.all.length = length; console.log(typeof document.all) console.log(document.all) console.log(document.all.length)
|
有道友说这种检测已经算简单了,可以回去看看document.all(), 测试了下这函数也没啥啊,就返回null, 后来去看了下document.all的特性,才发现它有和form表单一样的特性,例子如下
1 2 3 4 5 6 7 8 9 10
| var input = document.createElement('input') input.name = 'aaa' document.body.append(input) input = document.createElement('input') input.id = 'bbb' document.body.append(input) document.all.aaa document.all('aaa') document.all.bbb document.all('bbb')
|
这就令人头秃了。想来安全人员为了兼容还是留了一手了,要不然真的难搞了。以前刚学补环境的时候,就像拿到个锤子,总是锤来锤去,后面锤多了才发现越来越难锤,慢慢就回归到自动化了。毕竟算法,补环境,自动化都是工具,什么好用就用啥了。