[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
GET Flag ! ! !