[toc] 影响范围
5.x < 5.1.31 5.x <= 5.0.23
补丁地址 5.0:https://github.com/top-think/framework/commit/b797d72352e6b4eb0e11b6bc2a2ef25907b7756f 5.1:https://github.com/top-think/framework/commit/802f284bec821a608e7543d91126abc5901b2815
漏洞分析
请求public/index.php?s=index/think\request/input?data[]=phpinfo()&filter=assert
测试版本:ThinkPHP V5.1.1 根据补丁可知漏洞点在library/think/route/dispatch/Module.php
可以看到$controller
直接从URL调度中获取。 接着实例化控制器,跟进
Controller
方法,对控制器分层,获取模块名和类名。 跟进
parseModuleAndClass
,解析模块和类名并返回。并且如果$name
包含了\
,则直接将$name
当作类名,并直接返回。而命名空间就含有\
,所以可以利用命名空间来实例化任意类。 回到
controller
方法,会判断类$class
也就是$name
是否存在 不存在会调用
parseClass
方法,对命名空间类名等进行拼接并返回,然后会触发自动加载类并返回。 最后会进入
invokeMethod
,调用反射执行类的方法,绑定请求的参数 我们请求的是
think\request/input?data[]=phpinfo()&filter=assert
,跟进Request
类的input
方法。
1 | public function input($data = [], $name = '', $default = null, $filter = '') |
参数可控,因为$data
为数组,则执行array_walk_recursive($data, [$this, 'filterValue'], $filter);
。跟进filterValue
,最终执行call_user_func('assert','phpinfo()')
。 因为windows会把pathinfo的
\
替换成/
所以要使用兼容模式下的PATHINFO变量名s。
payload
当然还有很多其他payload,可以通过调用任意类的方法根据源码自行构造,这里只是做个记录。 from:https://xz.aliyun.com/t/3570 5.1.x php版本>5.5
1 | http://127.0.0.1/index.php?s=index/think\request/input?data[]=phpinfo()&filter=assert |
5.0.x php版本>=5.4
1 | http://127.0.0.1/index.php?s=index/\think\Container/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1 |
补丁分析
补丁对控制器进行了正则过滤。
Referer
ThinkPhp5.0x_Getshell_分析 ThinkPHP5 RCE漏洞重现及分析 thinkphp 5.x全版本任意代码执行分析全记录