漏洞名称:ThinkPHP5 核心类Request远程代码执行高危漏洞

漏洞描述

2019年1月11日,阿里云云盾应急响应中心监测到ThinkPHP官方发布安全更新,披露了一个高危安全漏洞,攻击者构造特定的 恶意请求,可以直接获取服务器权限,受影响的版本包括5.0.0~5.0.23版本及5.1多个版本。

漏洞造成的影响

由于ThinkPHP5框架对Request类的method处理存在缺陷,导致黑客构造特定的请求,可直接GetWebShell。

验证请求:
POST http://xxx.xx/
s=c4ca4238a0b923820dcc509a6f75849b&_method=__construct&filter[]=print_r&method=
返回内容:
xxx.xxc4ca4238a0b923820dcc509a6f75849b__constructprint_rc4ca4238a0b923820dcc509a6f75849b__const
ructprint
修复方法 
\thinkphp\library\think\Request.php
找到

public function method($method = false)
    {
        if (true === $method) {
            // 获取原始请求类型
            return $this->server('REQUEST_METHOD') ?: 'GET';
        } elseif (!$this->method) {
            if (isset($_POST[Config::get('var_method')])) {
                $this->method = strtoupper($_POST[Config::get('var_method')]);
                $this->{$this->method}($_POST);
            } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
                $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
            } else {
                $this->method = $this->server('REQUEST_METHOD') ?: 'GET';
            }
        }
        return $this->method;
    }
 

替换为

public function method($method = false)
    {
        if (true === $method) {
            // 获取原始请求类型
            return $this->server('REQUEST_METHOD') ?: 'GET';
        } elseif (!$this->method) {
            if (isset($_POST[Config::get('var_method')])) {
                $method = strtoupper($_POST[Config::get('var_method')]);
                if (in_array($method, ['GET', 'POST', 'DELETE', 'PUT', 'PATCH'])) {
                    $this->method = $method;
                    $this->{$this->method}($_POST);
                } else {
                    $this->method = 'POST';
                }
                unset($_POST[Config::get('var_method')]);
            } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {
                $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);
            } else {
                $this->method = $this->server('REQUEST_METHOD') ?: 'GET';
            }
        }
        return $this->method;
    }

 

posted @ 2020-05-06 17:11  A毛毛  阅读(802)  评论(0编辑  收藏  举报