我使用JSON将javascript脚本代码发送到php脚本进行打包(加密),我使用的是Dead的Packer http://joliclic.free.fr/php/javascript-packer/en/index.php,但是我面临一个奇怪的问题,导致打包的结果出错。
这是我要打包的原始脚本:
<script type='text/javascript'>jwplayer('mediaspace').setup({ 'flashplayer': 'http://www.domain.com/player/player/player.swf', 'file': 'http://doamin.com','image': 'http://www.domain.com/images/background.jpg', 'skin': 'http://www.domain.com/player/skin/glow.zip', 'plugins': 'hd-2,timeslidertooltipplugin-1', 'hd.file': 'http://doamin.com', 'controlbar': 'over', 'stretching': 'exactfit', 'width': '700', 'height': '404' });</script>我在此脚本上使用javascript转义,然后将它发送给我的php脚本。
在逃跑后看起来是这样的:
%3Cscript%20type%3D%27text/javascript%27%3Ejwplayer%28%27mediaspace%27%29.setup%28%7B%20%27flashplayer%27%3A%20%27http%3A//www.domain.com/player/player.swf%27%2C%20%27file%27%3A%20%27http%3A//domain.com%27%2C%20%20%20%20%20%27image%27%3A%20%27http%3A//www.domain.com/images/background.jpg%27%2C%20%27skin%27%3A%20%27http%3A//www.domain.com/player/skin/glow.zip%27%2C%20%27plugins%27%3A%20%27hd-2%2Ctimeslidertooltipplugin-1%27%2C%20%27hd.file%27%3A%20%27http%3A//domain.com%27%2C%20%27controlbar%27%3A%20%27over%27%2C%20%27stretching%27%3A%20%27exactfit%27%2C%20%27width%27%3A%20%27700%27%2C%20%27height%27%3A%20%27404%27%20%7D%29%3B%3C/script%3E然后使用JSON将其发送到我的php脚本。
PHP脚本以获取值并打包脚本,并将打包的脚本返回到javascript:
<?php
$src = $_GET['code'];
$callback = $_GET['callback'];
require 'class.JavaScriptPacker.php';
$packer = new JavaScriptPacker($src, 'Normal', true, false);
$packed = $packer->pack();
$output = array('error'=>'none', 'results'=> $packed , 'source' => $src);
$out_string = json_encode($output);
echo $callback.'('.$out_string.');';
?>我在数组中添加了“source”,这样我就可以检查php到底得到了什么。
现在,我不知道为什么,但是php向源代码/$src添加反斜杠,如下所示:
<script type=\'text/javascript\'>jwplayer(\'mediaspace\').setup({ \'flashplayer\': \'http://www.domain.com/player/player.swf\', \'file\': \'http://domain.com\', \'image\': \'http://www.domain.com/images/ackground.jpg\', \'skin\': \'http://www.domain.com/player/skin/glow.zip\', \'plugins\': \'hd-2,timeslidertooltipplugin-1\', \'hd.file\': \'http://domain.com\', \'controlbar\': \'over\', \'stretching\': \'exactfit\', \'width\': \'700\', \'height\': \'404\' });</script>这破坏了这群人
我想要的结果:
eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c.toString(a)+'\\b','g'),k[c])}}return p}('<8 g=\'f/e\'>d(\'l\').k({\'j\':\'3://6.5.0/4/4/4.n\',\'7\':\'3://b.0\',\'m\':\'3://6.5.0/i/h.c\',\'9\':\'3://6.5.0/4/9/x.z\',\'o\':\'a-2,w-1\',\'a.7\':\'3://b.0\',\'y\':\'v\',\'u\':\'q\',\'p\':\'r\',\'s\':\'t\'});</8>',36,36,'com|||http|player|domain|www|file|script|skin|hd|doamin|jpg|jwplayer|javascript|text|type|background|images|flashplayer|setup|mediaspace|image|swf|plugins|width|exactfit|700|height|404|stretching|over|timeslidertooltipplugin|glow|controlbar|zip'.split('|')))但是我得到的结果是由于反斜杠(这也破坏了脚本)。
eval(function(p,a,c,k,e,d){while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+c+'\\b','g'),k[c])}}return p}('<2 1=\\\'0/3\\\'>4(\\\'7\\\').6({\\\'5\\\':\\\'8:',9,9,'text|type|script|javascript|jwplayer|flashplayer|setup|mediaspace|http'.split('|')))我做错什么了?
发布于 2012-05-31 07:40:46
在php脚本开始时添加以下内容:
if(get_magic_quotes_gpc())
{
function undo_magic_quotes_array($array)
{
return is_array($array) ? array_map('undo_magic_quotes_array', $array) : stripslashes($array));
}
$_GET = undo_magic_quotes_array($_GET);
$_POST = undo_magic_quotes_array($_POST);
$_COOKIE = undo_magic_quotes_array($_COOKIE);
$_FILES = undo_magic_quotes_array($_FILES);
$_REQUEST = undo_magic_quotes_array($_REQUEST);
}发布于 2012-05-31 07:44:38
您可能打开了语录,自动将反斜杠添加到POST、GET和COOKIE变量。
在php.ini中禁用它(它在PHP5.3中被废弃,在5.4中被删除),或者只使用strip斜杠:
$src = $_GET['code'];
if (get_magic_quotes_gpc())
$src = stripslashes($src);或者可以一次转义所有$_GET变量:
$_GET = array_map('stripslashes', $_GET);发布于 2012-05-31 07:40:53
这是因为json_encode。您将整个脚本视为字符串。当然,作为字符串,它需要\转义各种字符。
在这里创建的JSON如下所示:
{
'error':'none',
'results':'eval(...)',
'source':'...whatever your $src is...'
}注意,eval(...)和您的$src现在都是用引号包装的。它们是字符串,必须转义各种字符。
https://stackoverflow.com/questions/10829241
复制相似问题