Files
metasploit-gs/modules/post/windows/manage/clone_proxy_settings.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

163 lines
5.9 KiB
Ruby
Raw Normal View History

2012-10-21 03:13:35 -04:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-10-21 03:13:35 -04:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2012-10-21 03:13:35 -04:00
include Msf::Auxiliary::Report
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
def initialize
super(
2021-09-10 12:53:39 +01:00
'Name' => 'Windows Manage Proxy Setting Cloner',
'Description' => %q{
2012-10-21 03:13:35 -04:00
This module copies the proxy settings from the current user to the
targeted user SID, supports remote hosts as well if remote registry
is allowed.
},
2021-09-10 12:53:39 +01:00
'Author' => [ 'mubix' ],
'License' => MSF_LICENSE,
'Platform' => [ 'win' ],
2021-10-06 13:43:31 +01:00
'SessionTypes' => [ 'meterpreter' ],
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
stdapi_registry_create_key
stdapi_registry_open_key
stdapi_registry_open_remote_key
]
}
}
2012-10-21 03:13:35 -04:00
)
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
register_options(
[
2021-09-10 12:53:39 +01:00
OptAddress.new('RHOST', [ false, 'Remote host to clone settings to, defaults to local' ]),
OptString.new('SID', [ false, 'SID of user to clone settings to, defaults to SYSTEM', 'S-1-5-18' ])
]
)
2012-10-21 03:13:35 -04:00
end
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
def parse_settings(data)
2023-02-08 13:47:34 +00:00
print_status "\tProxy Counter = #{data[4, 1].unpack('C*')[0]}"
case data[8, 1].unpack('C*')[0]
2021-09-10 12:53:39 +01:00
when 1
print_status "\tSetting: No proxy settings"
when 3
print_status "\tSetting: Proxy server"
when 5
print_status "\tSetting: Set proxy via AutoConfigure script"
when 7
print_status "\tSetting: Proxy server and AutoConfigure script"
when 9
print_status "\tSetting: WPAD"
when 11
print_status "\tSetting: WPAD and Proxy server"
when 13
print_status "\tSetting: WPAD and AutoConfigure script"
when 15
print_status "\tSetting: WPAD, Proxy server and AutoConfigure script"
else
print_status "\tSetting: Unknown proxy setting found"
2012-10-21 03:13:35 -04:00
end
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
cursor = 12
2023-02-08 13:47:34 +00:00
proxyserver = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]
print_status "\tProxy Server: #{proxyserver}" if proxyserver != ''
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
cursor = cursor + 4 + data[cursor].unpack('C*')[0]
additionalinfo = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]
print_status "\tAdditional Info: #{additionalinfo}" if additionalinfo != ''
2013-08-30 16:28:54 -05:00
2023-02-08 13:47:34 +00:00
cursor = cursor + 4 + data[cursor].unpack('C*')[0]
autoconfigurl = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]
print_status "\tAutoConfigURL: #{autoconfigurl}" if autoconfigurl != ''
2012-10-21 03:13:35 -04:00
end
2013-08-30 16:28:54 -05:00
2021-09-10 12:53:39 +01:00
def target_settings(dst_root_key, dst_base_key)
2012-10-21 03:13:35 -04:00
if datastore['RHOST']
begin
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
rescue ::Rex::Post::Meterpreter::RequestError
print_error("Unable to contact remote registry service on #{datastore['RHOST']}")
2023-02-08 13:47:34 +00:00
print_status('Attempting to start service remotely...')
2012-10-21 03:13:35 -04:00
begin
2021-09-10 12:53:39 +01:00
service_start('RemoteRegistry', datastore['RHOST'])
2023-02-08 13:47:34 +00:00
rescue StandardError
2012-10-21 03:13:35 -04:00
print_error('Unable to read registry or start the service, exiting...')
return
end
startedreg = true
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
end
dst_open_key = dst_key.open_key(dst_base_key)
else
dst_open_key = session.sys.registry.open_key(dst_root_key, dst_base_key)
end
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
dst_values = dst_open_key.query_value('DefaultConnectionSettings')
2013-08-30 16:28:54 -05:00
2021-09-10 12:53:39 +01:00
# If we started the service we need to stop it.
service_stop('RemoteRegistry', datastore['RHOST']) if startedreg
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
dst_data = dst_values.data
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
print_status('Current proxy settings for target:')
parse_settings(dst_data)
end
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
def run
2023-02-08 13:47:34 +00:00
if (datastore['SID'] == '') && !datastore['RHOST']
2012-10-21 03:13:35 -04:00
print_error('No reason to copy the settings on top of themselves, please set a SID or/and RHOST')
return
end
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
# Pull current user's settings
2023-02-08 13:47:34 +00:00
src_root_key, src_base_key = session.sys.registry.splitkey('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections')
2012-10-21 03:13:35 -04:00
src_open_key = session.sys.registry.open_key(src_root_key, src_base_key)
src_values = src_open_key.query_value('DefaultConnectionSettings')
src_data = src_values.data
print_status('Proxy settings being copied:')
parse_settings(src_data)
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
# Print current settings of target
print_status('Attempting to read target\'s settings...')
if datastore['SID']
dst_root_key, dst_base_key = session.sys.registry.splitkey("HKU\\#{datastore['SID']}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections")
else
2023-02-08 13:47:34 +00:00
dst_root_key, dst_base_key = session.sys.registry.splitkey('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections')
2012-10-21 03:13:35 -04:00
end
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
target_settings(dst_root_key, dst_base_key)
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
print_status('Cloning... bahh..')
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
if datastore['RHOST']
begin
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
rescue ::Rex::Post::Meterpreter::RequestError
print_error("Unable to contact remote registry service on #{datastore['RHOST']}")
2023-02-08 13:47:34 +00:00
print_status('Attempting to start service remotely...')
2012-10-21 03:13:35 -04:00
begin
2021-09-10 12:53:39 +01:00
service_start('RemoteRegistry', datastore['RHOST'])
2023-02-08 13:47:34 +00:00
rescue StandardError
2012-10-21 03:13:35 -04:00
print_error('Unable to read registry or start the service, exiting...')
return
end
startedreg2 = true
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
end
dst_open_key = dst_key.create_key(dst_base_key, KEY_WRITE + 0x0000)
else
dst_open_key = session.sys.registry.create_key(dst_root_key, dst_base_key, KEY_WRITE + 0x0000)
end
2013-08-30 16:28:54 -05:00
2021-09-10 12:53:39 +01:00
# If we started the service we need to stop it.
service_stop('RemoteRegistry', datastore['RHOST']) if startedreg2
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
dst_open_key.set_value('DefaultConnectionSettings', REG_BINARY, src_data)
2013-08-30 16:28:54 -05:00
2012-10-21 03:13:35 -04:00
print_status('New settings:')
target_settings(dst_root_key, dst_base_key)
end
end