Skip to main content

MVC-PHP代码审计6-框架-文件包含

·151 words·1 min
IIIIIIIIIIII
Author
IIIIIIIIIIII
A little bit about you

MVC-PHP代码审计6-框架-文件包含
#

判断是否是框架:
	搜索version  THINK_VERSION
	判断语法
	看文件名

案例一:ThinkPHP-文件包含cacheFile=demo.php
#

漏洞影响版本: 5.0.0<=ThinkPHP5<=5.0.185.1.0<=ThinkPHP<=5.1.10

include require_once require 三个函数导致文件包含

先看效果在index下面直接包含就可以执行php脚本命令

直接触发了

1

分析
#

index下面用了这两行tp自带代码

  1. request()->get() - 获取所有GET参数

  2. $this->assign() - 将GET参数全部作为模板变量赋值

    所以catchfile才能传入

<?php
namespace app\index\controller;
use think\Controller;
class Index extends Controller
{
    public function index()
    {
        $this->assign(request()->get());
        return $this->fetch(); // 当前模块/默认视图目录/当前控制器(小写)/当前操作(小写).html
    }
    

跟踪assign

到了controller.php ,这个view是模板实例不是变量

 @var \think\View 
 protected $view;
 $this->view = View::instance(Config::get('template'), Config::get('view_replace_str'));

protected function assign($name, $value = '')
{
    $this->view->assign($name, $value);

    return $this;
}

跟踪assign到了view.php

public function assign($name, $value = '')
{
    if (is_array($name)) {
        $this->data = array_merge($this->data, $name);
    } else {
        $this->data[$name] = $value;
    }
    return $this;
}

也没什么东西啊

thinkphp/library/think/template/driver/File.php

找到了关键的代码这里要理解extract的函数作用

extract:用于通过函数来手动给变量赋值导致变量覆盖

public function read($cacheFile, $vars = [])
{
    if (!empty($vars) && is_array($vars)) {
        // 模板阵列变量分解成为独立变量
        extract($vars, EXTR_OVERWRITE);
    }
    //载入模版缓存文件
    include $cacheFile;
}

正常来说 include应该是缓存文件的路径 比如你访问index下面就是include index页面缓存文件 但是通过变量覆盖修改路径为我们的恶意php文件

?cacheFile=1.txt $cacheFile=1.txt 直接·赋值

启动动态调试来测试流程
#

phpstudy在php设置那里开启x-debug

1

打开对应php.ini

zend_extension=E:/phpstudy_pro/Extensions/php/php7.4.3nts/ext/php_xdebug.dll
xdebug.collect_params=1
xdebug.collect_return=1
xdebug.auto_trace=Off
xdebug.trace_output_dir=E:/phpstudy_pro/Extensions/php_log/php7.4.3nts.xdebug.trace
xdebug.profiler_enable=Off
xdebug.profiler_output_dir=E:/phpstudy_pro/Extensions/php_log/php7.4.3nts.xdebug.profiler
xdebug.remote_enable=On
xdebug.remote_host=localhost
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM
xdebug.remote_handler=dbgp
没有的自己添加上去特别是phpstorm那个idekey

配置phpstorm

端口是网站端口

1

可以看看官方github对比版本修复情况 是否是内部测试人员没有公开 就可以拿到漏洞

Related

MVC-PHP代码审计5-框架-反序列化构建链
·249 words·2 mins
MVC-PHP代码审计4-框架-SQL注入
·309 words·2 mins
MVC-PHP代码审计2
·204 words·1 min
MVC-PHP代码审计3-反序列化-原生-框架-phar
·452 words·3 mins
MVC-PHP代码审计
·336 words·2 mins