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ù)學(xué)習(xí),以下是我的心得:
__invoke:當(dāng)嘗試將該函數(shù)所存在的對象用函數(shù)方法調(diào)用時(shí)觸發(fā)
__construct:當(dāng)一個(gè)對象被創(chuàng)建時(shí)調(diào)用,類似于構(gòu)造函數(shù)
__toString:當(dāng)對象被當(dāng)作字符串使用時(shí)調(diào)用
__wakeup:當(dāng)調(diào)用unserialize反序列化的時(shí)候提前調(diào)用
__get:當(dāng)調(diào)用不可訪問的屬性時(shí)調(diào)用該函數(shù)(1、私有屬性,2、沒有初始化的屬性)
現(xiàn)在我們要利用include讀取flag.txt,就肯定要調(diào)用invoke,就必須把這三個(gè)類聯(lián)系在一起,因?yàn)镾how類里面有wakeup函數(shù),include函數(shù)在modifier里面,肯定是最后一個(gè)看,因此我們要從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ù)里面是一個(gè)正則表達(dá)式,目前對我們沒有多大用處,toString這個(gè)函數(shù)如果被調(diào)用了(目前不知道怎么調(diào)用這個(gè)函數(shù)就先跳過),會返回$this->str->source;這時(shí)我們想到,如果$this->str代表的是一個(gè)Test類呢
public function __get($key){
$function = $this->p;
return $function();
}因?yàn)門est類中沒有source這個(gè)屬性,因此會調(diào)用get方法,就這樣可以把Show和Test連接在一起,我們可以構(gòu)造一個(gè)這個(gè):$a->str=new Test();調(diào)用get方法后,很明顯是一個(gè)將$this->看成一個(gè)對象,用函數(shù)的方法調(diào)用,因此來引發(fā)invoke方法
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}因此我們繼續(xù)構(gòu)造:$a->str->p=new Modifier();這里需要用到var屬性,我們就可以將var賦值為php://filter/read=convert.base64-encode/resource=flag.php,因?yàn)檫@里沒有過濾,就可以放心用。
現(xiàn)在問題就是怎么開始調(diào)用toString()這個(gè)函數(shù),看了別人的wp說可以再實(shí)例化一次,$b=new Show($a);因?yàn)镾how里面的construct函數(shù)是$file='index.php'參數(shù),如果不傳參的話就會使默認(rèn)值,當(dāng)我們把$a這個(gè)對象傳入后,this->source=$a,然后遇到正則表達(dá)式,因?yàn)檎齽t表達(dá)式是對字符串進(jìn)行過濾嘛,因此$a被當(dāng)作了字符串,因此引發(fā)了toString這個(gè)函數(shù)。
最終我們的構(gòu)造是

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

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


又知道一個(gè)pop序列化鏈的知識
以上就是Ezpop pop序列化鏈反序列化知識的詳細(xì)內(nèi)容,更多關(guān)于Ezpop pop序列化鏈反序列化的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
php時(shí)間計(jì)算相關(guān)問題小結(jié)
這篇文章主要介紹了php時(shí)間計(jì)算相關(guān)問題,結(jié)合實(shí)例形式總結(jié)分析了php關(guān)于時(shí)間與日期的常見操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-05-05
WordPress中給媒體文件添加分類和標(biāo)簽的PHP功能實(shí)現(xiàn)
這篇文章主要介紹了WordPress中給媒體文件添加分類和標(biāo)簽的PHP功能實(shí)現(xiàn),同時(shí)文中也提到了Media Library Categories這個(gè)插件同樣可以達(dá)到目的,需要的朋友可以參考下2015-12-12

