我注意到在一个漏洞工具包中有一些模糊的Javascript
> a = []["constructor"]
Array() { [native code] }
> b = a["constructor"]
Function() { [native code] }
> b("console.log('a');")
anonymous() {
console.log('a');
}
> b("console.log('a');")()
a
或者
> [].constructor.constructor("console.log('a');")()
a
谁能解释一下这里发生了什么?数组的构造函数的构造函数是什么? [].constructor.constructor("console.log('a');")()
. .这是什么?
[].constructor.constructor
函数(){[本机代码]}
几条……所以它只是一种调用Function
构造函数的方式,它需要一个字符串来eval…然后最后的父类调用它。
Function("console.log('a')")() // Works with or without `new`
你可以在任何JS控制台中输入[].constructor.constructor
并自己查找。
[].constructor
-> Array() { [native code] }
[].constructor.constructor
-> Function() { [native code] }
[].constructor.constructor("console.log('a');")()
-> a