打開題目,f12發(fā)現
<!--source.php-->
以及hint和link:http://warmup.2018.hctf.io/index.php?file=hint.php
網頁內容:
hint.png
訪問source.php冀泻,發(fā)現源代碼
<?php
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)) { //in_array(search,array,type) 函數搜索數組中是否存在指定的值葵蒂。
return true;
}
$_page = mb_substr( //mb_substr — 獲取部分字符串
$page,
0,
mb_strpos($page . '?', '?') //mb_strpos — 查找字符串在另一個字符串中首次出現的位置
);
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'])
&& 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\" />";
}
?>
- 思路
發(fā)現checkFile函數$_page取file參數第一個問號
之前的字段檢查文件名是否在白名單內
是構造file參數為hint.php?/../../../../../ffffllllaaaagggg -
原理
原理是hint.php?/被當作目錄缓屠,之后上跳目錄就好了(這個只適用于linux)
image.png