阿里云报网站ThinkPHP5.0.24Request.php远程代码执行漏洞怎么修复

很多小伙伴高高兴兴的做了一个网站放到阿里云上,以为大功告成了,结果收到两条短信,说你的网站有高危漏洞,顿时一阵乌云浮上心头。今天说说怎么修复这个漏洞。

打开你的网站,进入根目录。根据这个路径找到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;
    }

然后就OK了,修改之前记得备份噢。

如果内容有帮助,就点个赞吧!

转载注明出处:http://www.12564.cn/show-14.html

如有疑问请联系 QQ:644233191   微信:zw1688k