美文网首页
php反序列化漏洞

php反序列化漏洞

作者: suntwo | 来源:发表于2019-04-21 20:48 被阅读0次

php反序列化

反序列化漏洞产生的原因:

php在传递和保存数据时通常会将一个对象按照一定的格式来保存,这个过程称为序列化,当需要使用到这个对象时再通过反序列化,还原成原来的对象,但是在php的类中有一些魔术方法,这些方法,在一定的条件下会自动执行,因此攻击者通过构造传输的值,便会产生意料不到的结果。

魔术方法:

__construct(), __destruct(), __call(), __callStatic(), __get(), __set(), __isset(), __unset(),__sleep(), __wakeup(), __toString(), __invoke(), __set_state(), __clone() 和 __debugInfo() 等方法在 PHP 中被称为"魔术方法"(Magic methods)。

__wakeup()方法:

当使用unserialize()时会检查石头有 __wakeup()方法,如果有会自动调用。

eg:

源代码:

<?phpclass xctf{public $flag = '111';public function __wakeup(){echo "hello";}}$aa=new xctf();unserialize($_GET["id"]);?>

我们构造的请求为:http://localhost/bb.php?id=O:4:%22xctf%22:1:{s:4:%22flag%22;s:3:%22111%22;}

结果为:hello

不过我们可以绕过 __wakeup()方法。

构造为:http://localhost/bb.php?id=O:4:%22xctf%22:2:{s:4:%22flag%22;s:3:%22111%22;}

__construct()方法:

创建类对象时这个方法会自动执行。

<?phpclass xctf{public $flag = '111';public function __construct(){echo "hello";}}$aa=new xctf();?>

当我们访问:http://localhost/bb.php时便会执行这个$aa=new xctf();创建一个对象,__construct()方法会被自动执行,因此会输出hello。

__sleep()方法:

当调用serialize()自动调用。

__destruct()方法:

当类被摧毁是自动调用

相关文章

网友评论

      本文标题:php反序列化漏洞

      本文链接:https://www.haomeiwen.com/subject/uktsgqtx.html