简体   繁体   English

通过PHP进行JS解包-功能(p,a,c,k,e,r)

[英]JS Unpacker via PHP - function(p,a,c,k,e,r)

I searched over the internet but found no solution so far. 我通过互联网进行搜索,但到目前为止没有找到解决方案。

I have to scrape the content of a page (that has a video stream) compressed with the Dean Edwards packer tool , in real time. 我必须实时抓取用Dean Edwards打包工具压缩的页面(具有视频流)的内容。

Therefore, I need to decode the compressed JS via PHP only. 因此,我只需要通过PHP解码压缩的JS。 (The full scenario: curl the content of the page, find the JS content and decode it in real time so I can get the dynamic video stream). (完整的场景:卷曲页面的内容,找到JS内容并实时对其进行解码,这样我就可以获得动态视频流)。

So, is there any way to decode this compressed js example via PHP only? 因此,有什么方法只能通过PHP解码此压缩的js示例吗?

An example of the compressed code: 压缩代码的示例

eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[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(){4 1="5 6 7 8";0 2(3){9(3)}2(1)})();',10,10,'function|b|something|a|var|some|sample|packed|code|alert'.split('|'),0,{}))

Thank you 谢谢

First of all, you have to split the packed javascript into the relevant parts. 首先,您必须将打包的javascript拆分为相关部分。

The first part from "eval" to "}('" is not relevant to you: 从“ eval”到“}('”的第一部分与您无关:

eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[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}('

The second part is your minimized function (payload): 第二部分是最小化功能(有效负载):

(0(){4 1="5 6 7 8";0 2(3){9(3)}2(1)})();

The third part is the radix, that you'll use as your base when you decode the payload: 第三部分是基数,在解码有效负载时将用作基数:

10

The fourth part is the word count: 第四部分是字数统计:

10

The fifth relevant part are your keywords (separated by |): 第五相关部分是您的关键字(用|分隔):

function|b|something|a|var|some|sample|packed|code|alert

The last part is also irrelevant: 最后一部分也无关紧要:

'.split('|'),0,{})) 

So basically you now have all the parts you need for the decoding: 因此,基本上,您现在拥有解码所需的所有部分:

$payload = '(0(){4 1="5 6 7 8";0 2(3){9(3)}2(1)})()';
$radix = 10;
$wordCount = 10;
$words = array("function","b","something","a","var","some","sample","packed","code","alert);

Now you have to replace the all word characters within your payload with the corresponding word within your words array. 现在,您必须用字数组中的相应字替换有效载荷中的所有字字符。 It's easy in your example, because your source javascript just contains 10 words. 在您的示例中很容易,因为您的源javascript仅包含10个单词。

The first word charahter is 0, replace it with $words[0] = function 第一个字符charahter为0,用$ words [0] = function替换

The second word character is 4, replace it with $words[4] = var 第二个单词字符为4,用$ words [4] = var替换

And so on... 等等...

When you're done your result should be: 完成后,您的结果应该是:

(function(){var b="some sample packed code";function something(a){alert(a)}something(b)})();

Of course it's a little bit more complex, when it comes to words > 10. 当然,涉及到字词> 10时,会稍微复杂一些。

But for that, you can check out my unpacker class PHP JavaScript unpacker . 但是,为此,您可以检出我的拆包器类PHP JavaScript unpacker

Especially the Unbaser class within the source. 尤其是源代码中的Unbaser类。

I think you have several things mixed up. 我认为您混淆了几件事。

  • You don't need to decode this, as it is not encoded. 您无需对此进行解码,因为它没有被编码。 (well, it is, as it obviously has a character encoding, but lets not go there) (是的,因为它显然具有字符编码,但是不允许去那里)
  • It might be compressed, but that is not the issue here. 它可能被压缩了,但这不是这里的问题。 Compressing does things for you like remove whitespace, make all variables very short, etc. 压缩可以为您做一些事情,例如删除空格,使所有变量都非常短等。
  • The code seems to be obfuscated on purpose, to avoid this type of issue. 为了避免这种类型的问题,似乎对代码进行了模糊处理。

So your real question is probably: how can I on-obfuscate this. 因此,您真正的问题可能是:我该如何对此进行混淆。

What you see is an eval of something. 您看到的是某种eval That eval 'runs' the javascript code, so the first step is to find out what the actual javascript code inside the eval returns, as that is what your browser/javascript parser will be running. 该eval“运行”了javascript代码,因此第一步是找出eval内部返回的实际javascript代码,因为这将运行您的浏览器/ javascript解析器。 If you are lucky, this is the code you are looking for, but it might need some massaging. 如果幸运的话,这是您要查找的代码,但是可能需要进行一些按摩。

So strip the eval , and then see what the function actually does when run in javascript . 因此, 剥离eval ,然后查看该函数在javascript中运行时的实际作用。 This means you should run it on your server with either a special serverside method, or you can hack something yourself. 这意味着您应该使用特殊的服务器端方法在服务器上运行它,也可以自己修改某些内容。

Now you can see what you have left that wil be evalled. 现在您可以看到剩下的将被评估。 Maybe now you start all over again, but having a javascript parsing method, this should not be an issue. 也许现在您可以重新开始,但是有了javascript解析方法,这应该不是问题。

Example would be (random google hit): http://j4p5.sourceforge.net/ 示例为(随机Google匹配): http : //j4p5.sourceforge.net/

The http://www.php.net/manual/en/book.v8js.php mentioned in the comments is probably a much better choice. 评论中提到的http://www.php.net/manual/zh/book.v8js.php可能是一个更好的选择。

您可以使用JavaScriptUnpacker ,它是用PHP编写的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM