warmup
F12查看:发现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\" />";
}
?>
一步一步看:
第一步:调用了两个页面,一个source.php,另一个hint.php!(source.php,里面装的是源码,那hint.php应该是flag)进去看一下!
第二步:看第一个if(! isset($page) || !is_string($page))
判断是否传入参数,参数是否为字符串,如果不是则输出:you can\'t see it!并返回false!
第二步:看第二个if (in_array($page, $whitelist))
判断page传入参数是否为$whitelist中的参数,有,则true!执行下面的:
$_page = mb_substr(
$page,
0,
mb_strpos($page . \'?\', \'?\')
);
mb_substr() 函数返回字符串的一部分,之前我们学过 substr() 函数,它只针对英文字符,如果要分割的中文文字则需要使用 mb_substr()
mb_strpos():返回要查找的字符串在别一个字符串中首次出现的位置
具体用法请自己去看菜鸟或者其他的了!
这个也就是这题的关键点,先分析完最后在说这题!
第三步:看第三个if (in_array($_page, $whitelist))
和上面一样,只是下面不同$_page = urldecode($page);多个对编码的解析!
第四步:看第四个if (in_array($_page, $whitelist))
成功就true,否就输出you can\'t see it!在flase!
第五步:看第五个
if (! empty($_REQUEST[\'file\'])
&& is_string($_REQUEST[\'file\'])
&& emmm::checkFile($_REQUEST[\'file\'])
)
第一个判断,是否传入file,是否传入字符串,是否执行上面的判断!
分析好了下面就可以做题了!
上面的所说这题的关键点就是那个,那个截取有问题,所以可以利用那个截取漏洞进行绕过!由上面hint.php得出flag的文件!
下面构造payload:(%25==>>%,%3F==>>?)
http://111.198.29.45:52152/?file=source.php%253F/../../../../../../../ffffllllaaaagggg
这样就绕过成功了!