【问题标题】:Javascript obfuscation helpJavascript 混淆帮助
【发布时间】:2010-04-11 05:44:11
【问题描述】:

我需要一些帮助来了解这段代码是如何被混淆的。代码是:

<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&amp;node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a>

而混淆是:

\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74

现在我在上面的混淆代码上使用了 unescape 来阅读它。我想知道究竟是什么用来混淆这样的代码?基本上,我需要将可读代码自定义为相同的混淆。

任何帮助将不胜感激。

【问题讨论】:

  • 您不需要使用unescape 来“解码”这样的字符串。只需警告/打印字符串就会向您显示其未混淆的状态。 unescape 用于解码 HTML 编码的字符串,甚至为此目的已弃用。

标签: javascript obfuscation


【解决方案1】:

如果您使用 255 以上的 unicode 字符,则需要进行一些特殊处理。您还需要确保正确使用 0 填充十六进制代码,否则该函数会因小于 16 的字符(例如 \n 和 \t)而中断:

function obfuscate(str) {
  var escaped = [];
  for (var i = 0; i < str.length; i++) {
    var c = str.charCodeAt(i);
    var cs = "0000" + c.toString(16);
    if (c < 256) {
      cs = "\\x" + cs.substr(-2);
    } else {
      cs = "\\u" + cs.substr(-4);
    }
    escaped.push(cs);
  }
  return escaped.join('');
}

var ob = obfuscate("Hello world!");
alert(ob);

【讨论】:

    【解决方案2】:

    你不应该对任何严肃的事情使用混淆,但玩起来会很有趣:

    var readable = '<a id="suggest" href="#" ajaxify="/ajax/social_graph/invite_dialog.php?class=FanManager&amp;node_id=108463912505356" class=" profile_action actionspro_a" rel="dialog-post">Suggest to Friends</a>';
    
    Array.prototype.map.call(readable,
    function(c){
      return "\\x" + c.charCodeAt().toString(16);
    }).join("");
    

    【讨论】:

    • 请注意,map 方法在 ECMAScript 第 5 版实现(和大多数 Firefox 版本)中可用。例如,它在 IE8 中不存在。
    【解决方案3】:

    在地址栏中输入以下代码:

    javascript:alert("\x3c\x61\x20\x69\x64\x3d\x22\x73\x75\x67\x67\x65\x73\x74\x22\x20\x68\x72\x65\x66\x3d\x22\x23\x22\x20\x61\x6a\x61\x78\x69\x66\x79\x3d\x22\x2f\x61\x6a\x61\x78\x2f\x73\x6f\x63\x69\x61\x6c\x5f\x67\x72\x61\x70\x68\x2f\x69\x6e\x76\x69\x74\x65\x5f\x64\x69\x61\x6c\x6f\x67\x2e\x70\x68\x70\x3f\x63\x6c\x61\x73\x73\x3d\x46\x61\x6e\x4d\x61\x6e\x61\x67\x65\x72\x26\x61\x6d\x70\x3b\x6e\x6f\x64\x65\x5f\x69\x64\x3d\x31\x30\x38\x34\x36\x33\x39\x31\x32\x35\x30\x35\x33\x35\x36\x22\x20\x63\x6c\x61\x73\x73\x3d\x22\x20\x70\x72\x6f\x66\x69\x6c\x65\x5f\x61\x63\x74\x69\x6f\x6e\x20\x61\x63\x74\x69\x6f\x6e\x73\x70\x72\x6f\x5f\x61\x22\x20\x72\x65\x6c\x3d\x22\x64\x69\x61\x6c\x6f\x67\x2d\x70\x6f\x73\x74\x22\x3e\x53\x75\x67\x67\x65\x73\x74\x20\x74\x6f\x20\x46\x72\x69\x65\x6e\x64\x73\x3c\x2f\x61\x3e","\x73\x75\x67\x67\x65\x73\x74")
    

    它会被解码。

    【讨论】:

    • 是的,我知道,我想学习如何反其道而行之,自定义可读代码,然后以同样的方式对其进行模糊处理
    猜你喜欢
    • 2012-09-14
    • 1970-01-01
    • 2011-03-24
    • 2019-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多