thinkphp 5.0.24漏洞
Thinkphp 5.0.24存在反序化漏洞,入口点在thinkphp/library/think/process/pipes/Windows.php中__destruct魔术方法。
网上有很多讲解如何利用这个漏洞进行攻击,百度Thinkphp 5.0.24反序化漏洞会出来一堆。
但是如何修复这个漏洞没有讲解,我去Thinkphp 官网上也没有查到,我的建议一个是升级Thinkphp版本。
下面是我的修复方案:
第1种方案:修改removeFiles方法如下:
/**
* 删除临时文件
*/
private function removeFiles()
{
foreach ($this->files as $filename) {
if(is_object($filename)){
continue;
}
if (file_exists($filename)) {
@unlink($filename);
}
}
$this->files = [];
}
第2种方案:在Windows.php中添加两个方法
public function __sleep()
{
throw new Exception('Cannot serialize '.__CLASS__);
}
public function __wakeup()
{
throw new Exception('Cannot unserialize '.__CLASS__);
}
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/glfxml/article/details/110086839
影响版本
ThinkPHP 5.0系列 < 5.0.24
安全版本
ThinkPHP 5.0系列 5.0.24
ThinkPHP 5.1系列 5.1.31
修改文件 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;
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_40880022/article/details/130067296