一、基础
序列化和反序列化
php中的两个函数
序列化函数:serialize()
反序列化函数:unserialize()
当在php中创建了一个对象后,可以通过serialize()把这个对象转变成一个字符串,保存对象的值方便之后的传递与使用。
具体使用如下:
<?php
class xu{
var $a='1';
}
$class1=new xu;
echo serialize($class1);
?>
运行结果:O:2:“xu”:1:{s:1:“a”;s:1:“1”;}
反序列化
<?php
$data='O:2:"xu":1:{s:1:"a";s:1:"1";}';
$class2=unserialize($data);
var_dump($class2);
?>
php中有一类特殊的方法叫“Magic function”, 这里我们着重关注一下几个:
构造函数__construct():当对象创建(new)时会自动调用。但在unserialize()时是不会自动调用的。
析构函数__destruct()和__wakeup():当对象被销毁时会自动调用。
题目:
xctf:Web_php_unserialize
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4

本文介绍了PHP中的序列化和反序列化概念,强调了`serialize()`和`unserialize()`函数的使用。在讨论中,作者提到了在解决xctf的Web_php_unserialize题目时遇到的问题,涉及`__construct()`, `__destruct()`, `__wakeup()`等魔术方法。题目解答关键在于理解`%00`截断和私有属性的访问。最终,作者通过修改源代码并利用base64编码找到了正确答案。"
82192933,5114835,使用Apache Curator实现Zookeeper分布式锁,"['分布式锁', 'zookeeper', 'Apache Curator']
最低0.47元/天 解锁文章
5970

被折叠的 条评论
为什么被折叠?



