访问题目链接,看到好大一张滑稽脸
先看一下f12,有提示Sourc.php
访问Sourc.php
包含source.php和hint.php,访问hint.php
猜测flag在ffffllllaaaagggg中
观察Sourc.php中代码和emoji的链接,猜测是考代码审计以及目录穿越
代码审计
<?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); //url对$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\" />";
}
?>
先看代码的主要部分,对file参数进行3次判断:1.是否非空2.是否是字符串3.是否能通过checkFile函数的校验。3次判断都通过后,才能包含。
checkFile函数:
1.先设置了白名单,只包含source.php和hint.php
2.对$page进行判断,判断page?前面的参数是否在白名单中
3.考录到url编码,进行了一次解码,再校验
尝试构造payload:
file=source.php?../../../../../ffffllllaaaagggg
出错了,有一个URL编码问题
将?改成%3F
构造payload:
file=source.php%3F../../../../../ffffllllaaaagggg
成功得到flag
这题比较坑代码审计的题目就是要先读懂代码,然后构造对应的payload.
参考链接: