phpwind 7.5 Multiple Include Vulnerabilities

壹.api/class_base.php本地包含漏洞

1.描敘

api/class_base.php文件裏callback函數裏$mode變量沒有過濾導致任意包含本地文件,從而可以執行任意PHP命令.

2. 具體分析

api/class_base.php文件裏:

function callback($mode, $method, $params) {
if (!isset($this->classdb[$mode])) {
if (!file_exists(R_P.’api/class_’ . $mode . ‘.php’)) {
return new ErrorMsg(API_MODE_NOT_EXISTS, “Class($mode) Not Exists”);
}
require_once(R_P.’api/class_’ . $mode . ‘.php’); //這裏
$this->classdb[$mode] = new $mode($this);
}
if (!method_exists($this->classdb[$mode], $method)) {
return new ErrorMsg(API_METHOD_NOT_EXISTS, “Method($method of $mode) Not Exists”);
}
!is_array($params) &&$params = array();
return @call_user_func_array(array(&$this->classdb[$mode], $method), $params);
}

我們繼續跟壹下具體變量傳遞的過程. 上面的函數在run()裏有調用:

function run($request) {
$request = $this->strips($request);
if (isset($request['type']) &&$request['type'] == ‘uc’) {
$this->type = ‘uc’;
$this->apikey = $GLOBALS['uc_key'];//註意這個變量也是該漏洞的關鍵
} else {
$this->type = ‘app’;
$this->apikey = $GLOBALS['db_siteownerid'];
$this->siteappkey = $GLOBALS['db_siteappkey'];
}
/***
if ($this->type == ‘app’ &&!$GLOBALS['o_appifopen']) {
return new ErrorMsg(API_CLOSED, ‘App Closed’);
}
***/
ksort($request);
reset($request);
$arg = ”;
foreach ($request as $key => $value) {
if ($value &&$key != ‘sig’) {
$arg .= “$key=$value&”;
}
}
if (md5($arg . $this->apikey) != $request['sig']) { //註意這個判斷,需要繞過它.上面的代碼可以看的出來$this->apikey = $GLOBALS['uc_key'],和$request['sig']我們
//都可以操控,那麽很轻易繞過它
return new ErrorMsg(API_SIGN_ERROR, ‘Error Sign’);
}
$mode = $request['mode']; //取$mode 沒有過濾直接進入下面的callback()
$method = $request['method'];
$params = isset($request['params']) ? unserialize($request['params']) : array();
if (isset($params['appthreads'])) {
if (PHP_VERSION <5.2) {
require_once(R_P.’api/class_json.php’);
$json = new Services_JSON(true);
$params['appthreads'] = $json->decode(@gzuncompress($params['appthreads']));
} else {
$params['appthreads'] = json_decode(@gzuncompress($params['appthreads']),true);
}
}
if ($params &&isset($request['charset'])) {
$params = pwConvert($params, $this->charset, $request['charset']);
}
return $this->callback($mode, $method, $params); //調用callback ()
}

我們繼續看看run()函數的調用:

在pw_api.php文件裏:

$api = new api_client();
$response = $api->run($_POST + $_GET);//直接run了$_POST , $_GET提交的變量.

上面的分析是逆行分析了整個漏洞變量提交的過程,其實我們這個漏洞還包含壹次編碼與解碼的問:require_once(R_P.’api/class_’ . $mode . ‘.php’);這個需要繞過魔術引號才可以
包含轻易文件.我們註意看run()的第壹句

$request = $this->strips($request);

strips()的代碼:

function strips($param) {
if (is_array($param)) {
foreach ($param as $key => $value) {
$param[$key] = $this->strips($value);
}
} else {
$param = stripslashes($param); //變量直接使用了stripslashes,那麽我們可以直接繞過魔術引號了 :)
}
return $param;
}

3.POC/EXP

4.FIX

由於漏洞信息的外泄,官方針對這個漏洞已經做出了修補:

http://www.phpwind.net/read-htm-tid-914851.html

具體代碼:

require_once Pcv(R_P.’api/class_’ . $mode . ‘.php’);

function Pcv($filename,$ifcheck=1){
$tmpname = strtolower($filename);
$tmparray = array(‘ http://’,”\0“); //過濾了http:// \0 意思是不讓遠程 不讓截斷
$ifcheck &&$tmparray[] = ‘..’;    //過濾了.. 意思是不讓轉跳目錄
if (str_replace($tmparray,”,$tmpname)!=$tmpname) {
exit(‘Forbidden’);
}
return $filename;
}

從Pcv()可以看出來phpwind的補丁風格是很猥瑣的,單從這個pcv來看 還有很多的邏輯問題,比如http://這個過濾很搞笑,人家就不可以用ftp://? …
二.apps/share/index.php遠程包含漏洞

1.描敘

apps/share/index.php 裏$route和$basePath變量沒有初始化,導致遠程包含或者本地包含php文件,導致執行任意php代碼

2.具體分析

<?php
if ($route == “share”) {
require_once $basePath . ‘/action/m_share.php’;
} elseif ($route == “sharelink”) {
require_once $basePath . ‘/action/m_sharelink.php’;
}
?>

這個漏洞好象不太需要分析!!!! 我建議寫這個代碼的人應該扣除年終獎…

3.POC/EXP

4.FIX

等待官方補丁,假如用不著的朋友直接把這個文件刪除好了.

三.apps/groups/index.php遠程包含漏洞

1.描敘

apps/groups/index.php 裏$route和$basePath變量沒有初始化,導致遠程包含或者本地包含php文件,導致執行任意php代碼

2.具體分析

<?php
if ($route == “groups”) {
require_once $basePath . ‘/action/m_groups.php’;
} elseif ($route == “group”) {
require_once $basePath . ‘/action/m_group.php’;
} elseif ($route == “galbum”) {
require_once $basePath . ‘/action/m_galbum.php’;
}
這個漏洞好象不太需要分析!!!! 我建議寫這個代碼的人應該扣除年終獎…

3.POC/EXP

4.FIX

等待官方補丁,假如用不著的朋友直接把這個文件刪除好了.

最新消息 目前官方已經發布補丁http://www.phpwind.net/read-htm-tid-914851.html