日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Phpcmsv9漏洞分析

最近研究源碼審計(jì)相關(guān)知識,會抓起以前開源的CMS漏洞進(jìn)行研究,昨天偶然看見了這個PHPCMS的漏洞,就準(zhǔn)備分析研究一番,最開始本來想直接從源頭對代碼進(jìn)行靜態(tài)分析,但是發(fā)現(xiàn)本身對PHPCMS架構(gòu)不是很熟悉,導(dǎo)致很難定位代碼的位置,***就采用動態(tài)調(diào)試&靜態(tài)分析的方式對漏洞的觸發(fā)進(jìn)行分析,下面進(jìn)入正題。

1. 漏洞觸發(fā)代碼定位

通過漏洞的POC(/phpcms/index.php?m=member&c=index&a=register&siteid=1 )判斷,漏洞觸發(fā)點(diǎn)的入口位于/phpcms/modules/member/index.php文件中的register()方法中,在代碼中插入一些echo函數(shù),觀察輸出(見下)的變化。從下面的結(jié)果變化可知,img標(biāo)簽的src屬性是在執(zhí)行完下面的get()函數(shù):

 
 
 
  1. $user_model_info = $member_input->get($_POST['info'])

后發(fā)生變化,因此基本可以確定,漏洞的觸發(fā)點(diǎn)就是位于這個函數(shù)中。

2. 定位member_input->get()跟進(jìn)分析

跟進(jìn)該函數(shù),該函數(shù)位于/phpcms/modules/member/fields/member_input.class.php文件中,此處本來還想故技重施,在該方法中對代碼進(jìn)行插樁,但是發(fā)現(xiàn)插樁后的居然無法打印到頁面上,沒轍(原因望各位大神指點(diǎn)一二),只能對代碼進(jìn)行一行行推敲,先把代碼貼上,方便分析:

 
 
 
  1. function get($data) {
  2.     $this->data = $data = trim_script($data);
  3.     $model_cache = getcache('member_model', 'commons');
  4.     $this->db->table_name = $this->db_pre.$model_cache[$this->modelid]['tablename'];
  5.     $info = array();
  6.     $debar_filed = array('catid','title','style','thumb','status','islink','description');
  7.     if(is_array($data)) {
  8.         foreach($data as $field=>$value) {
  9.             if($data['islink']==1 && !in_array($field,$debar_filed)) continue;
  10.             $field = safe_replace($field);
  11.             $name = $this->fields[$field]['name'];
  12.             $minlength = $this->fields[$field]['minlength'];
  13.             $maxlength = $this->fields[$field]['maxlength'];
  14.             $pattern = $this->fields[$field]['pattern'];
  15.             $errortips = $this->fields[$field]['errortips'];
  16.             if(empty($errortips)) $errortips = "$name 不符合要求!";
  17.             $length = empty($value) ? 0 : strlen($value);
  18.             if($minlength && $length < $minlength && !$isimport) showmessage("$name 不得少于 $minlength 個字符!");
  19.             if (!array_key_exists($field, $this->fields)) showmessage('模型中不存在'.$field.'字段');
  20.             if($maxlength && $length > $maxlength && !$isimport) {
  21.                 showmessage("$name 不得超過 $maxlength 個字符!");
  22.             } else {
  23.                 str_cut($value, $maxlength);
  24.             }
  25.             if($pattern && $length && !preg_match($pattern, $value) && !$isimport) showmessage($errortips);
  26.                         if($this->fields[$field]['isunique'] && $this->db->get_one(array($field=>$value),$field) && ROUTE_A != 'edit') showmessage("$name 的值不得重復(fù)!");
  27.             $func = $this->fields[$field]['formtype'];
  28.             if(method_exists($this, $func)) $value = $this->$func($field, $value);
  29.             $info[$field] = $value;
  30.         }
  31.     }
  32.     return $info;
  33. }

代碼整體比較容易,可能比較難理解的就是$this->fields這個參數(shù),這個參數(shù)是初始化類member_input是插入的,這個參數(shù)分析起來比較繁瑣,主要是對PHPCMS架構(gòu)不熟,那就在此走點(diǎn)捷徑吧,在1中,直接將初始化完成后的member_input類dump出來,效果還不錯,所有的參數(shù)都dump到頁面上了,下面主要摘取比較重要的$this->fields[$field],即:【$this->fields["content"]】這個參數(shù),如下所示?:

 
 
 
  1. ["content"]=>
  2.     array(35) {
  3.       ["fieldid"]=>
  4.       string(2) "90"
  5.       ["modelid"]=>
  6.       string(2) "11"
  7.       ["siteid"]=>
  8.       string(1) "1"
  9.       ["field"]=>
  10.       string(7) "content"
  11.       ["name"]=>
  12.       string(6) "內(nèi)容"
  13.       ["tips"]=>
  14.       string(407) "字符至內(nèi)容摘要
  15. 張圖片作為標(biāo)題圖片
"
  •       ["css"]=>
  •       string(0) ""
  •       ["minlength"]=>
  •       string(1) "0"
  •       ["maxlength"]=>
  •       string(6) "999999"
  •       ["pattern"]=>
  •       string(0) ""
  •       ["errortips"]=>
  •       string(18) "內(nèi)容不能為空"
  •       ["formtype"]=>
  •       string(6) "editor"
  •       ["setting"]=>
  •       string(199) "array (
  •   'toolbar' => 'full',
  •   'defaultvalue' => '',
  •   'enablekeylink' => '1',
  •   'replacenum' => '2',
  •   'link_mode' => '0',
  •   'enablesaveimage' => '1',
  •   'height' => '',
  •   'disabled_page' => '0',
  • )"
  •       ["formattribute"]=>
  •       string(0) ""
  •       ["unsetgroupids"]=>
  •       string(0) ""
  •       ["unsetroleids"]=>
  •       string(0) ""
  •       ["iscore"]=>
  •       string(1) "0"
  •       ["issystem"]=>
  •       string(1) "0"
  •       ["isunique"]=>
  •       string(1) "0"
  •       ["isbase"]=>
  •       string(1) "1"
  •       ["issearch"]=>
  •       string(1) "0"
  •       ["isadd"]=>
  •       string(1) "1"
  •       ["isfulltext"]=>
  •       string(1) "1"
  •       ["isposition"]=>
  •       string(1) "0"
  •       ["listorder"]=>
  •       string(2) "13"
  •       ["disabled"]=>
  •       string(1) "0"
  •       ["isomnipotent"]=>
  •       string(1) "0"
  •       ["toolbar"]=>
  •       string(4) "full"
  •       ["defaultvalue"]=>
  •       string(0) ""
  •       ["enablekeylink"]=>
  •       string(1) "1"
  •       ["replacenum"]=>
  •       string(1) "2"
  •       ["link_mode"]=>
  •       string(1) "0"
  •       ["enablesaveimage"]=>
  •       string(1) "1"
  •       ["height"]=>
  •       string(0) ""
  •       ["disabled_page"]=>
  •       string(1) "0"
  •     }
  • 有了上面的參數(shù)列表后,理解get()函數(shù)的代碼就要輕松許多了,分析過程略。結(jié)論就是,漏洞的觸發(fā)函數(shù)在倒數(shù)6、7兩行,單獨(dú)截個圖,如下?:

    這里比較重要的是要找出$func這個函數(shù),查查上面的表,找到["formtype"]=>string(6) “editor”,可知$func就是editor()函數(shù),editor函數(shù)傳入的參數(shù)就是上面列出的一長串字符串,和img標(biāo)簽的內(nèi)容,下面將跟進(jìn)editor函數(shù),真相好像馬上就要大白于天下了。

    3. 跟進(jìn)editor函數(shù)及后續(xù)函數(shù)

    editor()函數(shù)位于/phpcms/modules/member/fields/editor/imput.inc.php文件中,老規(guī)矩,先貼出代碼:

     
     
     
    1. function editor($field, $value) {
    2.         $setting = string2array($this->fields[$field]['setting']);
    3.         $enablesaveimage = $setting['enablesaveimage'];
    4.         if(isset($_POST['spider_img'])) $enablesaveimage = 0;
    5.         if($enablesaveimage) {
    6.             $site_setting = string2array($this->site_config['setting']);
    7.             $watermark_enable = intval($site_setting['watermark_enable']);
    8.             $value = $this->attachment->download('content', $value, $watermark_enable);
    9.         }
    10.         return $value;
    11.     }

    簡單閱讀代碼,發(fā)現(xiàn)實(shí)際的觸發(fā)流程發(fā)生在$this->attachment->download()函數(shù)中,直接跟進(jìn)這個函數(shù),這個函數(shù)位于/phpcms/libs/classes/attachment.class.php中download()函數(shù),源代碼有點(diǎn)長,就貼一些關(guān)鍵代碼,?

     
     
     
    1. $string = new_stripslashes($value);
    2.     if(!preg_match_all("/(href|src)=([\"|']?)([^ \"'>]+\.($ext))\\2/i", $string, $matches)) return $value;
    3.     $remotefileurls = array();
    4.     foreach($matches[3] as $matche)
    5.     {
    6.         if(strpos($matche, '://') === false) continue;
    7.         dir_create($uploaddir);
    8.         $remotefileurls[$matche] = $this->fillurl($matche, $absurl, $basehref);
    9.     }
    10.     unset($matches, $string);
    11.     $remotefileurls = array_unique($remotefileurls);
    12.     $oldpath = $newpath = array();
    13.     foreach($remotefileurls as $k=>$file) {
    14.                        if(strpos($file, '://') === false || strpos($file, $upload_url) !== false) continue;
    15.         $filename = fileext($file);
    16.         $file_name = basename($file);
    17.         $filename = $this->getname($filename);
    18.         $newfile = $uploaddir.$filename;
    19.         $upload_func = $this->upload_func;
    20.         if($upload_func($file, $newfile)) {

    代碼主要是進(jìn)行一些正則過濾等等操作,這里真正關(guān)鍵的是代碼的***一行的操作$upload_func($file, $newfile),其中$this->upload_func = ‘copy’;,寫的在明白點(diǎn)就是copy($file, $newfile),漏洞就是一個copy操作造成的。


    新聞標(biāo)題:Phpcmsv9漏洞分析
    標(biāo)題網(wǎng)址:http://www.5511xx.com/article/coohpgj.html