Path: blob/master/modules/auxiliary/client/hwbridge/connect.rb
19852 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Auxiliary6include Msf::Auxiliary::Report7include Msf::Exploit::Remote::HttpClient89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Hardware Bridge Session Connector',14'Description' => %q{15The Hardware Bridge (HWBridge) is a standardized method for16Metasploit to interact with Hardware Devices. This extends17the normal exploit capabilities to the non-ethernet realm and18enables direct hardware and alternative bus manipulations. You19must have compatible bridging hardware attached to this machine or20reachable on your network to use any HWBridge exploits.2122Use this exploit module to connect the physical HWBridge which23will start an interactive hwbridge session. You can launch a hwbridge24server locally by using compliant hardware and executing the local_hwbridge25module. After that module has started, pass the HWBRIDGE_BASE_URL26options to this connector module.27},28'License' => MSF_LICENSE,29'Author' => [30'Craig Smith' # hwbridge metasploit module31],32'Session' => Msf::Sessions::HWBridge,33'SessionTypes' => [ 'hwbridge' ],34'References' => [35[ 'URL', 'https://web.archive.org/web/20170206145056/http://opengarages.org/hwbridge/' ],36],37'Notes' => {38'Stability' => [CRASH_SAFE],39'SideEffects' => [],40'Reliability' => []41}42)43)44register_options(45[46Opt::RPORT(8080),47Opt::RHOST('127.0.0.1'),48OptBool.new('DEBUGJSON', [false, 'Additional debugging out for JSON requests to HW Bridge', false]),49OptString.new('TARGETURI', [ true, 'The path to the hwbridge API', '/'])50]51)52@last_access = nil53end5455#56# Generic fetch json call. returns hash of json57#58def fetch_json(uri)59tpath = normalize_uri("#{datastore['TARGETURI']}/#{uri}")60res = send_request_cgi({61'uri' => tpath,62'method' => 'GET'63})64return if !res || !res.body || !res.code6566if res.code == 40167print_error "Access Denied: #{res.body}"68return69end7071if res.code == 20072print_status res.body if datastore['DEBUGJSON'] == true73return JSON.parse(res.body)74end7576return77rescue OpenSSL::SSL::SSLError78vprint_error('SSL error')79return80rescue Errno::ENOPROTOOPT, Errno::ECONNRESET, ::Rex::ConnectionRefused, ::Rex::HostUnreachable, ::Rex::ConnectionTimeout, ::ArgumentError81vprint_error('Unable to Connect')82return83rescue ::Timeout::Error, ::Errno::EPIPE84vprint_error('Timeout error')85return86end8788#89# Disclaimer for legal and those without common sense...90#91def print_disclaimer92print_warning('NOTICE: You are about to leave the matrix. All actions performed on this hardware bridge')93print_warning(' could have real world consequences. Use this module in a controlled testing')94print_warning(' environment and with equipment you are authorized to perform testing on.')95end9697#98# Uses status information to automatically load proper extensions99#100def autoload_extensions(sess)101if hw_specialty.key?('automotive') && hw_specialty['automotive'] == (true)102sess.load_automotive103end104if hw_specialty.key?('zigbee') && hw_specialty['zigbee'] == (true)105sess.load_zigbee106end107if hw_specialty.key?('rftransceiver') && hw_specialty['rftransceiver'] == (true)108sess.load_rftransceiver109end110sess.api_version = api_version if api_version111sess.fw_version = fw_version if fw_version112sess.hw_version = hw_version if hw_version113sess.device_name = device_name if device_name114end115116#117# If the hardware contains custom methods, create functions for those118#119def load_custom_methods(sess)120if hw_capabilities.key?('custom_methods') && hw_capabilities['custom_methods'] == (true)121sess.load_custom_methods122end123end124125#126# Fetches the status of the hwbridge127#128def get_status129data = fetch_json('/status')130return if data.nil?131132return unless data.key?('operational')133134@last_access = Time.now135136if data.key? 'hw_specialty'137self.hw_specialty = data['hw_specialty']138end139if data.key? 'hw_capabilities'140self.hw_capabilities = data['hw_capabilities']141end142if data.key? 'api_version'143self.api_version = data['api_version']144end145if data.key? 'fw_version'146self.fw_version = data['fw_version']147end148if data.key? 'hw_version'149self.hw_version = data['hw_version']150end151if data.key? 'device_name'152self.device_name = data['device_name']153end154end155156def run157print_status("Attempting to connect to #{datastore['RHOST']}...")158get_status159160if @last_access.nil?161print_error 'Could not connect to API'162return163end164165sess = Msf::Sessions::HWBridge.new(self)166sess.set_from_exploit(self)167168framework.sessions.register(sess)169print_good('HWBridge session established')170autoload_extensions(sess)171load_custom_methods(sess)172print_status "HW Specialty: #{hw_specialty} Capabilities: #{hw_capabilities}"173print_disclaimer174end175176attr_reader :hw_specialty, :hw_capabilities, :api_version, :fw_version, :hw_version, :device_name177178protected179180attr_writer :hw_specialty, :hw_capabilities, :api_version, :fw_version, :hw_version, :device_name181end182183184