1. 程式人生 > 其它 >【Web】WarmUp——PHP程式碼審計

【Web】WarmUp——PHP程式碼審計

1、題目資訊

2、解題思路

3、解題過程

4、思路總結

1、題目資訊:

描  述:WarmUp,PHP程式碼審計

2、解題思路:

開啟靶機連結以後,是一張圖片。檢視原始碼:

看到原始碼頁面,就知道是程式碼審計了,按照程式碼邏輯解題

3、解題過程:

 1 <?php
 2     highlight_file(__FILE__);
 3     class emmm
 4     {
 5         public static function checkFile(&$page)
 6         {
 7             $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
8 if (! isset($page) || !is_string($page)) { 9 echo "you can't see it"; 10 return false; 11 } 12 13 if (in_array($page, $whitelist)) { 14 return true; 15 } 16 17 $_page = mb_substr( 18 $page
, 19 0, 20 mb_strpos($page . '?', '?') 21 ); 22 if (in_array($_page, $whitelist)) { 23 return true; 24 } 25 26 $_page = urldecode($page); 27 $_page = mb_substr( 28 $_page, 29 0, 30
mb_strpos($_page . '?', '?') 31 ); 32 if (in_array($_page, $whitelist)) { 33 return true; 34 } 35 echo "you can't see it"; 36 return false; 37 } 38 } 39 40 if (! empty($_REQUEST['file']) 41 && is_string($_REQUEST['file']) 42 && emmm::checkFile($_REQUEST['file']) 43 ) { 44 include $_REQUEST['file']; 45 exit; 46 } else { 47 echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />"; 48 } 49 ?>

檢視程式碼,首先判斷請求是否存在file字串引數,然後將file引數放入emmm checkFile函式中進行判斷。

當checkFile函式返回true後,通過include函式來載入file引數中的頁面。

那麼思路就比較明確了,file引數必須是在白名單內的:source或hint。那先試下hint:

看來flag在ffffllllaaaagggg這個檔案中。

又知道include是目錄包含,那麼只要繞過白名單檢測並進行目錄跳轉就可以了:

checkFile函式$_page取file引數第一個問號之前的欄位檢查檔名是否在白名單內於是構造file引數為hint.php?/../../../../../ffffllllaaaagggg

hint.php?/被當作目錄,之後上跳目錄就好了

4、思路總結

include可以跨目錄包含檔案