Ezpop?pop序列化鏈反序列化知識
<?php
//flag is in flag.php
//WTF IS THIS?
//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95
//And Crack It!
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
}
class Show{
public $source;
public $str;
public function __construct($file='index.php'){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){
return $this->str->source;
}
public function __wakeup(){
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}
}
}
class Test{
public $p;
public function __construct(){
$this->p = array();
}
public function __get($key){
$function = $this->p;
return $function();
}
}
if(isset($_GET['pop'])){
@unserialize($_GET['pop']);
}
else{
$a=new Show;
highlight_file(__FILE__);
}一大段代碼,隨意瞟一眼看見wakeup等魔法方法,我就知道要利用反序列化了,還有include文件包含漏洞,但這里考的不是如何繞過反序列化,而是我不知道的序列化POP鏈。
根據(jù)學習,以下是我的心得:
__invoke:當嘗試將該函數(shù)所存在的對象用函數(shù)方法調用時觸發(fā)
__construct:當一個對象被創(chuàng)建時調用,類似于構造函數(shù)
__toString:當對象被當作字符串使用時調用
__wakeup:當調用unserialize反序列化的時候提前調用
__get:當調用不可訪問的屬性時調用該函數(shù)(1、私有屬性,2、沒有初始化的屬性)
現(xiàn)在我們要利用include讀取flag.txt,就肯定要調用invoke,就必須把這三個類聯(lián)系在一起,因為Show類里面有wakeup函數(shù),include函數(shù)在modifier里面,肯定是最后一個看,因此我們要從Show類里面看起(先定義一下$a=new Show()):
public function __toString(){
return $this->str->source;
}
public function __wakeup(){
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}wakeup函數(shù)里面是一個正則表達式,目前對我們沒有多大用處,toString這個函數(shù)如果被調用了(目前不知道怎么調用這個函數(shù)就先跳過),會返回$this->str->source;這時我們想到,如果$this->str代表的是一個Test類呢
public function __get($key){
$function = $this->p;
return $function();
}因為Test類中沒有source這個屬性,因此會調用get方法,就這樣可以把Show和Test連接在一起,我們可以構造一個這個:$a->str=new Test();調用get方法后,很明顯是一個將$this->看成一個對象,用函數(shù)的方法調用,因此來引發(fā)invoke方法
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}因此我們繼續(xù)構造:$a->str->p=new Modifier();這里需要用到var屬性,我們就可以將var賦值為php://filter/read=convert.base64-encode/resource=flag.php,因為這里沒有過濾,就可以放心用。
現(xiàn)在問題就是怎么開始調用toString()這個函數(shù),看了別人的wp說可以再實例化一次,$b=new Show($a);因為Show里面的construct函數(shù)是$file='index.php'參數(shù),如果不傳參的話就會使默認值,當我們把$a這個對象傳入后,this->source=$a,然后遇到正則表達式,因為正則表達式是對字符串進行過濾嘛,因此$a被當作了字符串,因此引發(fā)了toString這個函數(shù)。
最終我們的構造是

這里有點煩的就是由protect屬性,要加%00*%00,這里我學了一個小技巧,我們可以給他進一步url編碼,可以無視那些不可見字符,urlencode()

將編碼后的傳入pop參數(shù)


又知道一個pop序列化鏈的知識
以上就是Ezpop pop序列化鏈反序列化知識的詳細內(nèi)容,更多關于Ezpop pop序列化鏈反序列化的資料請關注腳本之家其它相關文章!
相關文章
WordPress中給媒體文件添加分類和標簽的PHP功能實現(xiàn)
這篇文章主要介紹了WordPress中給媒體文件添加分類和標簽的PHP功能實現(xiàn),同時文中也提到了Media Library Categories這個插件同樣可以達到目的,需要的朋友可以參考下2015-12-12

