javascript - 聪明的 JavaScript 绕过 eval 方法

标签 javascript malware

[]["constructor"]["constructor"](<string representing JavaScript code>)()

In JavaScript the "constructor" property returns the prototype of an object. In this case the prototype of [] is the Array class. Accessing the "constructor" property of the Array class returns the Function object. The constructor of Function object then returns a function and the body of that function is the last parameter, which is passed to the constructor. This results in the creation of a function that uses the provided string as the function's body (i.e. code), which is then instantly executed.

如上段所述:https://www.trustwave.com/Resources/SpiderLabs-Blog/Angler-Exploit-Kit-%E2%80%93-Gunning-For-the-Top-Spot/?page=1&year=0&month=0

上面的代码行用于执行混淆的 JavaScript 代码,而不使用“eval”方法。读完这一段后,我不太能理解这行巧妙的代码。谁能解释一下到底发生了什么?

最佳答案

请注意,Array 实例构造函数显然是Array:

[].constructor === Array

此外,Array的构造函数是Function:

[].constructor.constructor === Array.constructor === Function

现在,在 JavaScript 中,Function(source) 返回一个函数实例,其源由参数给出。例如:

Function("alert(1337)");

将创建(并且类似于):

function() {
    alert(1337);
}

您的代码将实例化这样的函数并立即使用 () 调用它。这正是 eval 的行为方式。

因此,如果有帮助,您可以将代码示例缩减为:

Function(source)();

关于javascript - 聪明的 JavaScript 绕过 eval 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36606820/

相关文章:

javascript - 动态突出显示(更改背景)网页中的内容

javascript - JavaScript 中的起始日期不接受早于 13 个月的日期

javascript - 如何在 jQuery 中使用 $ ("body").append() 添加多个 HTML 代码?

javascript - 在没有 I/O 的情况下,javascript(在浏览器中)的异步/ promise 是否有益?

javascript - 如何修复 Lerna Monorepo 中的 VSCode 导入路径建议?

android设备管理员不能被禁用?

java - 如何在 Wildfly 中阻止不良用户代理(恶意软件)?

android - Bkav 防病毒工具在我的应用程序中显示恶意软件,我如何才能找出我的应用程序中的恶意软件。

inno-setup - 使用 Inno Setup 编译后检测到恶意软件

malware - googleads.g.doubleclick.net 询问用户名和密码