Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/windows/gather/enum_proxy.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Windows::Registry7include Msf::Post::Windows::Services89def initialize10super(11'Name' => 'Windows Gather Proxy Setting',12'Description' => %q{13This module pulls a user's proxy settings. If neither RHOST or SID14are set it pulls the current user, else it will pull the user's settings15for the specified SID and target host.16},17'Author' => [ 'mubix' ],18'License' => MSF_LICENSE,19'Platform' => [ 'win' ],20'SessionTypes' => %w[meterpreter powershell shell],21'Notes' => {22'Stability' => [CRASH_SAFE],23'Reliability' => [],24'SideEffects' => []25},26'Compat' => {27'Meterpreter' => {28'Commands' => %w[29stdapi_registry_open_key30stdapi_registry_open_remote_key31]32}33}34)3536register_options([37OptAddress.new('RHOST', [ false, 'Remote host to clone settings to, defaults to local' ]),38OptString.new('SID', [ false, 'SID of user to clone settings to (SYSTEM is S-1-5-18)' ])39])40end4142def run43if datastore['SID']44root_key, base_key = split_key("HKU\\#{datastore['SID']}\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections")45else46root_key, base_key = split_key('HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings\\Connections')47end4849if datastore['RHOST']50if session.type != 'meterpreter'51fail_with(Failure::BadConfig, "Cannot query remote registry on #{datastore['RHOST']}. Unsupported sesssion type #{session.type}")52end5354begin55key = session.sys.registry.open_remote_key(datastore['RHOST'], root_key)56rescue ::Rex::Post::Meterpreter::RequestError57print_error("Unable to contact remote registry service on #{datastore['RHOST']}")58print_status('Attempting to start RemoteRegistry service remotely...')59begin60service_start('RemoteRegistry', datastore['RHOST'])61rescue StandardError62fail_with(Failure::Unknown, 'Unable to start RemoteRegistry service, exiting...')63end64startedreg = true65key = session.sys.registry.open_remote_key(datastore['RHOST'], root_key)66end6768open_key = key.open_key(base_key)69values = open_key.query_value('DefaultConnectionSettings')70data = values.data7172# If we started the service we need to stop it.73service_stop('RemoteRegistry', datastore['RHOST']) if startedreg74else75data = registry_getvaldata("#{root_key}\\#{base_key}", 'DefaultConnectionSettings')76end7778fail_with(Failure::Unknown, "Could not retrieve 'DefaultConnectionSettings' data") if data.blank?79fail_with(Failure::Unknown, "Retrieved malformed proxy settings (too small: #{data.length} bytes <= 24 bytes)") if data.length <= 248081print_status("Proxy Counter = #{data[4, 1].unpack('C*')[0]}")8283case data[8, 1].unpack('C*')[0]84when 185print_status('Setting: No proxy settings')86when 387print_status('Setting: Proxy server')88when 589print_status('Setting: Set proxy via AutoConfigure script')90when 791print_status('Setting: Proxy server and AutoConfigure script')92when 993print_status('Setting: WPAD')94when 1195print_status('Setting: WPAD and Proxy server')96when 1397print_status('Setting: WPAD and AutoConfigure script')98when 1599print_status('Setting: WPAD, Proxy server and AutoConfigure script')100else101print_status('Setting: Unknown proxy setting found')102end103104cursor = 12105proxyserver = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]106print_status("Proxy Server: #{proxyserver}") unless proxyserver.blank?107108cursor = cursor + 4 + data[cursor].unpack('C*')[0]109additionalinfo = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]110print_status("Additional Info: #{additionalinfo}") unless additionalinfo.blank?111112cursor = cursor + 4 + data[cursor].unpack('C*')[0]113autoconfigurl = data[cursor + 4, data[cursor, 1].unpack('C*')[0]]114print_status("AutoConfigURL: #{autoconfigurl}") unless autoconfigurl.blank?115end116end117118119