Path: blob/master/modules/post/hardware/automotive/getvinfo.rb
19758 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::Hardware::Automotive::UDS7include Msf::Post::Hardware::Automotive::DTC89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Get the Vehicle Information Such as the VIN from the Target Module',14'Description' => %q{15This module queries DTCs, some common engine info, and vehicle information.1617It returns such things as engine speed, coolant temp, Diagnostic Trouble18Codes, as well as all info stored by Mode $09 Vehicle Info, VIN, etc.19},20'License' => MSF_LICENSE,21'Author' => ['Craig Smith'],22'Platform' => ['hardware'],23'SessionTypes' => ['hwbridge'],24'Notes' => {25'Stability' => [CRASH_SAFE],26'SideEffects' => [],27'Reliability' => []28}29)30)31register_options([32OptInt.new('SRCID', [true, 'Module ID to query', 0x7e0]),33OptInt.new('DSTID', [false, 'Expected reponse ID, defaults to SRCID + 8', 0x7e8]),34OptInt.new('PADDING', [false, 'Optinal end of packet padding', nil]),35OptBool.new('FC', [false, 'Optinal forces flow control', nil]),36OptBool.new('CLEAR_DTCS', [false, 'Clear any DTCs and reset MIL if errors are present', false]),37OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])38])39end4041def run42opt = {}43opt['PADDING'] = datastore['PADDING'] if datastore['PADDING']44opt['FC'] = datastore['FC'] if datastore['FC']45pids = get_current_data_pids(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)46if pids.empty?47print_status('No reported PIDs. You may not be properly connected')48else49print_status("Available PIDS for pulling realtime data: #{pids.size} pids")50print_status(" #{pids.inspect}")51end52if pids.include? 153data = get_monitor_status(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)54print_status(" MIL (Engine Light) : #{data['MIL'] ? 'ON' : 'OFF'}") if data.key? 'MIL'55print_status(" Number of DTCs: #{data['DTC_COUNT']}") if data.key? 'DTC_COUNT'56end57if pids.include? 558data = get_engine_coolant_temp(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)59print_status(" Engine Temp: #{data['TEMP_C']} \u00b0C / #{data['TEMP_F']} \u00b0F") if data.key? 'TEMP_C'60end61if pids.include? 0x0C62data = get_rpms(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)63print_status(" RPMS: #{data['RPM']}") if data.key? 'RPM'64end65if pids.include? 0x0D66data = get_vehicle_speed(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)67print_status(" Speed: #{data['SPEED_K']} km/h / #{data['SPEED_M']} mph") if data.key? 'SPEED_K'68end69if pids.include? 0x1C70print_status("Supported OBD Standards: #{get_obd_standards(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)}")71end72dtcs = get_dtcs(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)73unless dtcs.empty?74print_status('DTCS:')75dtcs.each do |dtc|76msg = dtc77msg += ": #{DTC_CODES[dtc]}" if DTC_CODES.key? dtc78print_status(" #{msg}")79end80end81frozen_dtcs = get_frozen_dtcs(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)82unless frozen_dtcs.empty?83print_status('Frozen DTCS:')84frozen_dtcs.each do |dtc|85msg = dtc86msg += ": #{DTC_CODES[dtc]}" if DTC_CODES.key? dtc87print_status(" #{msg}")88end89end90pids = get_vinfo_supported_pids(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)91print_status("Mode $09 Vehicle Info Supported PIDS: #{pids.inspect}") if !pids.empty?92pids.each do |pid|93# Handle known pids94if pid == 295vin = get_vin(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)96print_status("VIN: #{vin}")97elsif pid == 498calid = get_calibration_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)99print_status("Calibration ID: #{calid}")100elsif pid == 0x0A101ecuname = get_ecu_name(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)102print_status("ECU Name: #{ecuname}")103else104data = get_vehicle_info(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], pid, opt)105data = response_hash_to_data_array(datastore['DSTID'].to_s(16), data)106print_status("PID #{pid} Response: #{data.inspect}")107end108end109if datastore['CLEAR_DTCS'] == true110clear_dtcs(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)111print_status('Cleared DTCs and reseting MIL')112end113end114end115116117