HCTF 2018 WarmUp的write_up

本人菜鸟一个,大佬轻喷。


  • 打开靶机环境发现就一个笑脸,F12查看网页的前端源码,发现一个source.php的信息

image-20211101202735658

  • 打开source.php后,返回的页面中由php代码,现在就是理解给出的php代码

image-20211102153801692

  • 接下来我们就需要了解其中的一些函数:

    is_string() 函数:检测变量是否是字符串,如果是字符串返回true,否则返回false

    in_array() 函数:搜索数组中是否存在指定的值 ,数组中存在指定值返回true,否则返回false

    mb_substr() 函数: 从一个字符串中,提取从指定位置开始,一定长度的字符串。如果存在则返回字符串的提取部分,不存在返回false或一个空字符串

    mb_strpos() 函数:查找string在一个string首次出现的位置

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
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
highlight_file(__FILE__);
class emmm
{
public static function checkFile(&$page)
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
/*创建了一个关联数组,并给指定键赋值
与$whitelist['source'] = source.php;
$whitelist['hint'] = hint.php;语句含义相同 */

if (! isset($page) || !is_string($page)) {
echo "you can't see it";
return false;
}

//查找$page是否在数组$whitelist中
if (in_array($page, $whitelist)) {
return true;
}

//提取从下标为0开始,长度为mb_strpos($page.'?','?')的字符串
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
//在$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($test)
&& is_string($test)
&& emmm::checkFile($test)
) {
echo "you are true!<br>";
}
if (! empty($_REQUEST['file'])
&& is_string($_REQUEST['file'])
&& emmm::checkFile($_REQUEST['file'])
) {
include $_REQUEST['file']; //注意include是文件包含函数()
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
}
?>
  • 由之前发现的hint.php文件的信息打开,如下图

image-20211102154047442

  • 所以构建hint.php?ffffllllaaaagggg ,hint.php?../ffffllllaaaagggg, hint.php?../../ffffllllaaaagggg等尝试,最后成功试出。

image-20211102154524705