[网鼎杯 2020 青龙组]AreUSerialz

栏目: IT技术 · 发布时间: 6年前

内容简介:1.正常构造payload的话因为$op、$fliename、$content都是protected属性,序列化的的结果的属性名前面会有/002.php>7.1版本对类属性的检测不严格来绕过,将序列化里的portected属性换成public属性,就不会有/00。

题目分析

<?php

        include("flag.php");

        highlight_file(__FILE__);

        class FileHandler {

            protected $op;
            protected $filename;
            protected $content;

            function __construct() {
                $op = "1";
                $filename = "/tmp/tmpfile";
                $content = "Hello World!";
                $this->process();
            }

            public function process() {
                if($this->op == "1") {
                    $this->write();
                } else if($this->op == "2") {
                    $res = $this->read();
                    $this->output($res);
                } else {
                    $this->output("Bad Hacker!");
                }
            }

            private function write() {
                if(isset($this->filename) && isset($this->content)) {
                    if(strlen((string)$this->content) > 100) {
                        $this->output("Too long!");
                        die();
                    }
                    $res = file_put_contents($this->filename, $this->content);
                    if($res) $this->output("Successful!");
                    else $this->output("Failed!");
                } else {
                    $this->output("Failed!");
                }
            }

            private function read() {
                $res = "";
                if(isset($this->filename)) {
                    $res = file_get_contents($this->filename);
                }
                return $res;
            }

            private function output($s) {
                echo "[Result]: <br>";
                echo $s;
            }

            function __destruct() {
                if($this->op === "2")
                    $this->op = "1";
                $this->content = "";
                $this->process();
            }

        }

        function is_valid($s) {
            for($i = 0; $i < strlen($s); $i++)
                if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
                    return false;
            return true;
        }

        if(isset($_GET{'str'})) {

            $str = (string)$_GET['str'];
            if(is_valid($str)) {
                $obj = unserialize($str);
            }

        }
1.传入str,经过处理反序列化。
2.is_valid过滤:传入的string要是可见字符ascii值为32-125。
3.$op:op=="1"的时候会进入write方法处理,op=="2"的时候进入read方法处理。

利用php>7.1版本对类属性的检测不严格(对属性类型不敏感)

1.正常构造payload的话因为$op、$fliename、$content都是protected属性,序列化的的结果的属性名前面会有/00 /00(或者%00 %00),/00的ascii为0不可见的字符如下图,就会被is_valid方法拦下来。

[网鼎杯 2020 青龙组]AreUSerialz

2.php>7.1版本对类属性的检测不严格来绕过,将序列化里的portected属性换成public属性,就不会有/00。

[网鼎杯 2020 青龙组]AreUSerialz

3.弱类型绕过

然后$obj = unserialize($str);会调用__destruct魔术方法,如果$op=

"2"的话就把$op="1"

[网鼎杯 2020 青龙组]AreUSerialz

这时候要使op

="2"不成立且op=="2"成立,这里可以自己使用op等于整数2使得进入read方法里面。

构造payload

1.非预期的解法

[网鼎杯 2020 青龙组]AreUSerialz

2.通过 php 伪协议读取

[网鼎杯 2020 青龙组]AreUSerialz

比赛的是通过读取/proc/self/cmdline下的配置文件得到网站的绝对路径然后通过php伪协议读取flag的

参考:( https://blog.csdn.net/Oavinci/article/details/106998738 )[ https://blog.csdn.net/Oavinci/article/details/106998738 ]


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。

Big Java Late Objects

Big Java Late Objects

Horstmann, Cay S. / 2012-2 / 896.00元

The introductory programming course is difficult. Many students fail to succeed or have trouble in the course because they don't understand the material and do not practice programming sufficiently. ......一起来看看 《Big Java Late Objects》 这本书的介绍吧!

图片转BASE64编码
图片转BASE64编码

在线图片转Base64编码工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换