江鸟's Blog

HCTF2018 (持续更新)

字数统计: 291阅读时长: 1 min
2019/10/18 Share

边看wp一边做题。。。。

BUUCTF WEB复现笔记

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
<?php
highlight_file(__FILE__);
class emmm
{
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\" />";
}
?>

代码审计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
由file传入参数,有多层判断
1. ! empty($_REQUEST['file']
2. is_string($_REQUEST['file'] 必须为字符串
3. 进行自定义函数的判断 emmm::checkFile($_REQUEST['file']
其中checkfile内也有多重判断
1.判断必须为字符串
2.只能在白名单中
3.截取问好前传入的内容,判断是否在白名单中
4.进行url解码后再判断是否在白名单中

所以构造payload
?file=source.php%253f/../../../../../../ffffllllaaaagggg

目录穿越
再进行一次url加密
CATALOG
  1. 1. BUUCTF WEB复现笔记
    1. 1.1. HCTF2018 WarmUp目录穿越