thinkphp 5.0.24漏洞

admin1年前javascript869

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

相关文章

uniapp执行npm命令失败

node在HBuilder x一直报错 重装node以及npm HBuilder关于node报错解决方法因为一年前安装过HBuilder以及node和npm, 今年没卸载就直接装了新的node所以导致...

thinkphp nginx伪静态

location / {if (!-e $request_filename){rewrite ^/(.*)$ /index.php?s=/$1 last;}}...

vue-element-admin文档

https://panjiachen.gitee.io/vue-element-admin-site/zh/...

swiper常用参数

var swiper = new Swiper(".mySwiper", {     &...

懒加载lozad.js

https://www.oschina.net/p/lozadjs?hmsr=aladdin1e1...

vue直传图片到阿里云OSS(单张直接上传)

https://blog.csdn.net/qq_44706619/article/details/121740097...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。