27

ThinkPHP 5.0.* 远程命令执行漏洞预警

 5 years ago
source link: https://www.anquanke.com/post/id/169481?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

R3YJjiy.png!web

0x00 事件背景

2019年1月11日,360CERT发现某安全社区出现关于ThinkPHP5 RCE漏洞的威胁情报,不久之后ThinkPHP5官方与GitHub发布更新。

该更新修复了一处严重漏洞,该漏洞可导致远程命令代码执行

0x01 影响范围

ThinkPHP 5.0.x

  • 5.0.x ~ 5.0.23

0x02 修复建议

官方在GitHub中进行了更新: 版本更新

myayIj7.png!web

  • 升级代码到最新版本5.0.24
  • 同时建议用户在线上环境中关闭debug模式

0x03 漏洞验证

该漏洞危害高,影响严重:

Z3IBRju.png!web

0x04 漏洞分析

漏洞主要出现在ThinkPHP Request类的method方法中 (thinkphp/library/think/Request.php)

Request类可以实现对HTTP请求的一些设置,其中成员方法method用来获取当前请求类型,其定义如下:

uE3uyan.png!web

当传入的参数为false的时候,会取配置项var_method,其默认值为_method

RNF7BfY.png!web

$this->{$this->method}($_POST); 通过post参数_method可以实现对当前类的任意方法进行调用。

通过调用当前类的构造方法可以覆盖任意成员属性的值:

NrIBRzU.png!web

这里通过覆盖filter属性,filter属性保存了用于全局过滤的函数。

但是在thinkphp5.0.23中,会对filter值重新赋值为空,导致无法利用。

IRJ3Urj.png!web

在thinkphp/library/think/App.php中开启debug的时候会调用Request类的param方法。

j6bUrer.png!web

在thinkphp/library/think/Request.php param方法中会调用到method方法,并将参数设置为true。

u6Rfa2E.png!web

当参数为true的时候,会调用server方法

77ryqy2.png!web

rIVRZrj.png!web

会走到 input方法,通过之前方法覆盖server成员属性值为array(),input方法代码如下:

6v6JBzA.png!web 最终会调用filterValue形成任意代码执行:

63YVvia.png!web

0x05 时间线

2019-01-11 360CERT发现漏洞威胁情报

2019-01-11 ThinkPHP发布补丁更新

2019-01-11 360CERT发布预警分析

0x06 参考链接

  1. ThinkPHP5 github更新

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK