buuctf-web(一)


[HCTF 2018]熱身

首先點擊打開靶機,發現只有一個表情包。

然后便查看此網頁的源代碼,發現存在着一個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\" />";
    }  
?>

在這里有兩個文件,分別為:source.php和hint.php。進去hint.php里會有

 

 然后,回過來看source.php,經過審計你會發現需要三個條件:1 file不能為空。2 file內容是字符串。 3 checkfile函數返回值為true。進到Chekfile函數里,進行分析。有一個whitellist。還有第一個if是說page不為空值並且不能是字符串;第二個if的意思是表示page有沒有包含在whitelist里;之后有兩個函數:mb_substr和mb_strpos。截取?之后的字符串賦給page;還有一個if再一次表示說page有沒有包含在whitelist里;然后又進行了urldecode解碼。

最后構造pyload。傳遞參數。要在目錄里找到存放flag的地址ffffllllaaaagggg。而且問號上傳的時候會自動進行解碼。這里需要二重編碼得到%253f。

構造出pyload:file=source.php%253f/../../../../ffffllllaaaagggg

得出最終flag

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM