自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Phpcms v9漏洞分析

安全 漏洞
本文是對(duì)Phpcms v9漏洞分析。

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

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

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

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

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

屏幕快照 2017-04-12 下午2.59.37.png

屏幕快照 2017-04-12 下午3.02.04.png

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

跟進(jìn)該函數(shù),該函數(shù)位于/phpcms/modules/member/fields/member_input.class.php文件中,此處本來(lái)還想故技重施,在該方法中對(duì)代碼進(jìn)行插樁,但是發(fā)現(xiàn)插樁后的居然無(wú)法打印到頁(yè)面上,沒(méi)轍(原因望各位大神指點(diǎn)一二),只能對(duì)代碼進(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 個(gè)字符!"); 
  19.             if (!array_key_exists($field, $this->fields)) showmessage('模型中不存在'.$field.'字段'); 
  20.             if($maxlength && $length > $maxlength && !$isimport) { 
  21.                 showmessage("$name 不得超過(guò) $maxlength 個(gè)字符!"); 
  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.  
  30.             $info[$field] = $value; 
  31.         } 
  32.     } 
  33.     return $info; 

代碼整體比較容易,可能比較難理解的就是$this->fields這個(gè)參數(shù),這個(gè)參數(shù)是初始化類(lèi)member_input是插入的,這個(gè)參數(shù)分析起來(lái)比較繁瑣,主要是對(duì)PHPCMS架構(gòu)不熟,那就在此走點(diǎn)捷徑吧,在1中,直接將初始化完成后的member_input類(lèi)dump出來(lái),效果還不錯(cuò),所有的參數(shù)都dump到頁(yè)面上了,下面主要摘取比較重要的$this->fields[$field],即:【$this->fields["content"]】這個(gè)參數(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) "<div class="content_attr"><label><input name="add_introduce" type="checkbox"  value="1" checked>是否截取內(nèi)容</label><input type="text" name="introcude_length" value="200" size="3">字符至內(nèi)容摘要 
  15. <label><input type='checkbox' name='auto_thumb' value="1" checked>是否獲取內(nèi)容第</label><input type="text" name="auto_thumb_no" value="1" size="2" class="">張圖片作為標(biāo)題圖片 
  16. </div>
  17.       ["css"]=> 
  18.       string(0) "" 
  19.       ["minlength"]=> 
  20.       string(1) "0" 
  21.       ["maxlength"]=> 
  22.       string(6) "999999" 
  23.       ["pattern"]=> 
  24.       string(0) "" 
  25.       ["errortips"]=> 
  26.       string(18) "內(nèi)容不能為空" 
  27.       ["formtype"]=> 
  28.       string(6) "editor" 
  29.       ["setting"]=> 
  30.       string(199) "array ( 
  31.   'toolbar' => 'full', 
  32.   'defaultvalue' => '', 
  33.   'enablekeylink' => '1', 
  34.   'replacenum' => '2', 
  35.   'link_mode' => '0', 
  36.   'enablesaveimage' => '1', 
  37.   'height' => '', 
  38.   'disabled_page' => '0', 
  39. )" 
  40.       ["formattribute"]=> 
  41.       string(0) "" 
  42.       ["unsetgroupids"]=> 
  43.       string(0) "" 
  44.       ["unsetroleids"]=> 
  45.       string(0) "" 
  46.       ["iscore"]=> 
  47.       string(1) "0" 
  48.       ["issystem"]=> 
  49.       string(1) "0" 
  50.       ["isunique"]=> 
  51.       string(1) "0" 
  52.       ["isbase"]=> 
  53.       string(1) "1" 
  54.       ["issearch"]=> 
  55.       string(1) "0" 
  56.       ["isadd"]=> 
  57.       string(1) "1" 
  58.       ["isfulltext"]=> 
  59.       string(1) "1" 
  60.       ["isposition"]=> 
  61.       string(1) "0" 
  62.       ["listorder"]=> 
  63.       string(2) "13" 
  64.       ["disabled"]=> 
  65.       string(1) "0" 
  66.       ["isomnipotent"]=> 
  67.       string(1) "0" 
  68.       ["toolbar"]=> 
  69.       string(4) "full" 
  70.       ["defaultvalue"]=> 
  71.       string(0) "" 
  72.       ["enablekeylink"]=> 
  73.       string(1) "1" 
  74.       ["replacenum"]=> 
  75.       string(1) "2" 
  76.       ["link_mode"]=> 
  77.       string(1) "0" 
  78.       ["enablesaveimage"]=> 
  79.       string(1) "1" 
  80.       ["height"]=> 
  81.       string(0) "" 
  82.       ["disabled_page"]=> 
  83.       string(1) "0" 
  84.     } 

有了上面的參數(shù)列表后,理解get()函數(shù)的代碼就要輕松許多了,分析過(guò)程略。結(jié)論就是,漏洞的觸發(fā)函數(shù)在倒數(shù)6、7兩行,單獨(dú)截個(gè)圖,如下⤵:

屏幕快照 2017-04-12 下午3.28.38.png

這里比較重要的是要找出$func這個(gè)函數(shù),查查上面的表,找到["formtype"]=>string(6) “editor”,可知$func就是editor()函數(shù),editor函數(shù)傳入的參數(shù)就是上面列出的一長(zhǎng)串字符串,和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.     } 

簡(jiǎn)單閱讀代碼,發(fā)現(xiàn)實(shí)際的觸發(fā)流程發(fā)生在$this->attachment->download()函數(shù)中,直接跟進(jìn)這個(gè)函數(shù),這個(gè)函數(shù)位于/phpcms/libs/classes/attachment.class.php中download()函數(shù),源代碼有點(diǎn)長(zhǎng),就貼一些關(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.  
  19.         $newfile = $uploaddir.$filename; 
  20.         $upload_func = $this->upload_func; 
  21.         if($upload_func($file, $newfile)) { 

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

責(zé)任編輯:趙寧寧 來(lái)源: FreeBuf
相關(guān)推薦

2010-12-07 11:05:03

Cisco SysteNetflow v9

2015-11-17 18:57:56

Veeam備份

2009-12-21 13:50:19

日立JP1 V9

2024-10-14 08:09:09

2011-09-07 01:05:11

ibmdwDB2

2017-02-24 17:26:39

榮耀

2009-12-01 19:08:26

2011-12-26 10:17:12

2018-08-15 15:14:42

中興

2017-07-14 10:34:48

云之家

2010-05-10 10:59:06

日立JP1新版本V9

2009-11-30 13:51:37

2017-03-10 10:29:10

互聯(lián)網(wǎng)

2015-10-19 13:44:48

2018-08-17 14:39:37

中興

2021-03-08 10:49:11

漏洞攻擊網(wǎng)絡(luò)安全

2014-12-03 10:37:45

2015-06-03 10:21:44

漏洞溢出漏洞9patch
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)