thinkphp 5.0.24漏洞

admin2年前javascript1111

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

相关文章

wow.js演示

https://www.dowebok.com/demo/131/...

vue表格系统

https://handsontable.com/docs/javascript-data-grid/column-hiding/...

swiper + 文字特效

swiper + 文字特效

swiper.animate1.0.3.min-1.ziphttps://blog.csdn.net/huayuaer/article/details/101761316...

scrollReveal.js – 页面滚动显示动画JS

scrollReveal.js – 页面滚动显示动画JS

和 WOW.js 一样,scrollReveal.js 也是一款页面滚动显示动画的 JavaScript,能让页面更加有趣,更吸引用户眼球。不同的是 WOW.js 的动画只播放一次,而 scrollR...

laydate使用

laydate.render({         elem: '#dateinput',&n...

解决npm i 下载依赖的时候出现某依赖版本冲突

    npm i 下载依赖的时候出现了报错,大概就是版本的问题npm ERR! code ERESOLVEnpm ERR! ERESOLVE unable to res...

发表评论    

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