[WEB安全]phpMyadmin后台任意文件包含漏洞分析(CVE-2018-12613)

0x00 简介

影响版本:4.8.0——4.8.1

本次实验采用版本:4.8.1

0x01 效果展示

payload:

http://your-ip:8080/index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd

0x02 漏洞分析

漏洞产生点位于:index.php文件54—67行

可以看到如果要包含文件成功,必需条件有5个:
1、不为空  
2、字符串  
3、不以index开头  
4、不在$target_blacklist这个黑名单中  
5、Core::checkPageValidity()函数为TRUE

首先查看$target_blacklist变量的值:

然后进入条件5所述函数中。此函数位于:libraries\classes\Core.php文件443—476行:

public static function checkPageValidity(&$page, array $whitelist = [])
{
    if (empty($whitelist)) {
        $whitelist = self::$goto_whitelist;
    }
    if (! isset($page) || !is_string($page)) {
        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;
    }
 
    return false;
}

可以看到在第一次$_page出现时即可绕过。其含义为截取$page 第一个'?'之前的部分,如果在白名单中,即返回TRUE。接下来查看白名单的值:

public static $goto_whitelist = array(
        'db_datadict.php',
        'db_sql.php',
        'db_events.php',
        'db_export.php',
        'db_importdocsql.php',
        'db_multi_table_query.php',
        'db_structure.php',
        'db_import.php',
        'db_operations.php',
        'db_search.php',
        'db_routines.php',
        'export.php',
        'import.php',
        'index.php',
        'pdf_pages.php',
        'pdf_schema.php',
        'server_binlog.php',
        'server_collations.php',
        'server_databases.php',
        'server_engines.php',
        'server_export.php',
        'server_import.php',
        'server_privileges.php',
        'server_sql.php',
        'server_status.php',
        'server_status_advisor.php',
        'server_status_monitor.php',
        'server_status_queries.php',
        'server_status_variables.php',
        'server_variables.php',
        'sql.php',
        'tbl_addfield.php',
        'tbl_change.php',
        'tbl_create.php',
        'tbl_import.php',
        'tbl_indexes.php',
        'tbl_sql.php',
        'tbl_export.php',
        'tbl_operations.php',
        'tbl_structure.php',
        'tbl_relation.php',
        'tbl_replace.php',
        'tbl_row_action.php',
        'tbl_select.php',
        'tbl_zoom_select.php',
        'transformation_overview.php',
        'transformation_wrapper.php',
        'user_password.php',
    );

随便选中其中之一即可。此处选中 "tbl_sql.php" 。

这里着重看下这个问号:

$_page为 以?分割然后取出前面的字符串再判断值是否存在与$goto_whilelist某个数组中。

这个判断的作用是,如果target值带有参数的情况下,phpmyadmin也能正确的包含文件。

也正是因为phpmyadmin团队考虑的太全面了,才会出现此漏洞......

后面又将$page参数用urlencode解码再进行以?分割取出前面的值做判断。

那么构造payload:

/index.php?target=tbl_sql.php%253f/../../../../../../../../etc/passwd

这里的%253f是问号的双重url编码

0x04 总结

目前有三种getshell的方法,第一个是上传sql文件,然后包含mysql的sql文件,第二个是开启general_log来完成getshell

不过这两种思路都有些繁琐,下面复现下第三种思路:

首先在sql中select ‘要执行的代码’:

然后包含phpsession文件:

要包含session的文件名可以在cookie中的phpmyadmin参数找到。

猜你喜欢

转载自www.cnblogs.com/-mo-/p/11447331.html