Files
metasploit-gs/modules/post/windows/gather/enum_proxy.rb
T

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

118 lines
4.2 KiB
Ruby
Raw Normal View History

2012-10-20 23:25:40 -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-20 23:25:40 -04:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
include Msf::Post::Windows::Registry
include Msf::Post::Windows::Services
2013-08-30 16:28:54 -05:00
2012-10-20 23:25:40 -04:00
def initialize
super(
2021-09-10 12:53:39 +01:00
'Name' => 'Windows Gather Proxy Setting',
'Description' => %q{
2012-10-20 23:25:40 -04:00
This module pulls a user's proxy settings. If neither RHOST or SID
are set it pulls the current user, else it will pull the user's settings
for the specified SID and target host.
2012-10-20 23:25:40 -04:00
},
2021-09-10 12:53:39 +01:00
'Author' => [ 'mubix' ],
'License' => MSF_LICENSE,
'Platform' => [ 'win' ],
'SessionTypes' => %w[meterpreter powershell shell],
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [],
'SideEffects' => []
},
2021-10-06 13:43:31 +01:00
'Compat' => {
'Meterpreter' => {
'Commands' => %w[
stdapi_registry_open_key
stdapi_registry_open_remote_key
]
}
}
2012-10-20 23:25:40 -04:00
)
2013-08-30 16:28:54 -05:00
register_options([
OptAddress.new('RHOST', [ false, 'Remote host to clone settings to, defaults to local' ]),
OptString.new('SID', [ false, 'SID of user to clone settings to (SYSTEM is S-1-5-18)' ])
])
2012-10-20 23:25:40 -04:00
end
2013-08-30 16:28:54 -05:00
2012-10-20 23:25:40 -04:00
def run
if datastore['SID']
root_key, base_key = split_key("HKU\\#{datastore['SID']}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections")
2012-10-20 23:25:40 -04:00
else
root_key, base_key = split_key('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections')
2012-10-20 23:25:40 -04:00
end
2013-08-30 16:28:54 -05:00
2012-10-20 23:25:40 -04:00
if datastore['RHOST']
if session.type != 'meterpreter'
fail_with(Failure::BadConfig, "Cannot query remote registry on #{datastore['RHOST']}. Unsupported sesssion type #{session.type}")
end
begin
key = session.sys.registry.open_remote_key(datastore['RHOST'], root_key)
rescue ::Rex::Post::Meterpreter::RequestError
print_error("Unable to contact remote registry service on #{datastore['RHOST']}")
print_status('Attempting to start RemoteRegistry service remotely...')
begin
2021-09-10 12:53:39 +01:00
service_start('RemoteRegistry', datastore['RHOST'])
rescue StandardError
fail_with(Failure::Unknown, 'Unable to start RemoteRegistry service, exiting...')
end
startedreg = true
key = session.sys.registry.open_remote_key(datastore['RHOST'], root_key)
end
2012-10-20 23:25:40 -04:00
open_key = key.open_key(base_key)
values = open_key.query_value('DefaultConnectionSettings')
data = values.data
# If we started the service we need to stop it.
service_stop('RemoteRegistry', datastore['RHOST']) if startedreg
2012-10-20 23:25:40 -04:00
else
data = registry_getvaldata("#{root_key}\\#{base_key}", 'DefaultConnectionSettings')
2012-10-20 23:25:40 -04:00
end
2013-08-30 16:28:54 -05:00
fail_with(Failure::Unknown, "Could not retrieve 'DefaultConnectionSettings' data") if data.blank?
fail_with(Failure::Unknown, "Retrieved malformed proxy settings (too small: #{data.length} bytes <= 24 bytes)") if data.length <= 24
2013-08-30 16:28:54 -05:00
print_status("Proxy Counter = #{data[4, 1].unpack('C*')[0]}")
2013-08-30 16:28:54 -05:00
case data[8, 1].unpack('C*')[0]
2021-09-10 12:53:39 +01:00
when 1
print_status('Setting: No proxy settings')
2021-09-10 12:53:39 +01:00
when 3
print_status('Setting: Proxy server')
2021-09-10 12:53:39 +01:00
when 5
print_status('Setting: Set proxy via AutoConfigure script')
2021-09-10 12:53:39 +01:00
when 7
print_status('Setting: Proxy server and AutoConfigure script')
2021-09-10 12:53:39 +01:00
when 9
print_status('Setting: WPAD')
2021-09-10 12:53:39 +01:00
when 11
print_status('Setting: WPAD and Proxy server')
2021-09-10 12:53:39 +01:00
when 13
print_status('Setting: WPAD and AutoConfigure script')
2021-09-10 12:53:39 +01:00
when 15
print_status('Setting: WPAD, Proxy server and AutoConfigure script')
2021-09-10 12:53:39 +01:00
else
print_status('Setting: Unknown proxy setting found')
2012-10-20 23:25:40 -04:00
end
2013-08-30 16:28:54 -05:00
2012-10-20 23:25:40 -04:00
cursor = 12
proxyserver = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]
print_status("Proxy Server: #{proxyserver}") unless proxyserver.blank?
2013-08-30 16:28:54 -05:00
cursor = cursor + 4 + data[cursor].unpack('C*')[0]
additionalinfo = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]
print_status("Additional Info: #{additionalinfo}") unless additionalinfo.blank?
2013-08-30 16:28:54 -05:00
cursor = cursor + 4 + data[cursor].unpack('C*')[0]
autoconfigurl = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]
print_status("AutoConfigURL: #{autoconfigurl}") unless autoconfigurl.blank?
2012-10-20 23:25:40 -04:00
end
2012-10-22 17:18:14 -05:00
end