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/hardware/automotive/getvinfo.rb
Views: 11784
##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{15Post Module to query DTCs, Some common engine info and Vehicle Info.16It returns such things as engine speed, coolant temp, Diagnostic17Trouble Codes as well as All info stored by Mode $09 Vehicle Info, VIN, etc18},19'License' => MSF_LICENSE,20'Author' => ['Craig Smith'],21'Platform' => ['hardware'],22'SessionTypes' => ['hwbridge']23)24)25register_options([26OptInt.new('SRCID', [true, 'Module ID to query', 0x7e0]),27OptInt.new('DSTID', [false, 'Expected reponse ID, defaults to SRCID + 8', 0x7e8]),28OptInt.new('PADDING', [false, 'Optinal end of packet padding', nil]),29OptBool.new('FC', [false, 'Optinal forces flow control', nil]),30OptBool.new('CLEAR_DTCS', [false, 'Clear any DTCs and reset MIL if errors are present', false]),31OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])32])33end3435def run36opt = {}37opt['PADDING'] = datastore['PADDING'] if datastore['PADDING']38opt['FC'] = datastore['FC'] if datastore['FC']39pids = get_current_data_pids(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)40if pids.empty?41print_status('No reported PIDs. You may not be properly connected')42else43print_status("Available PIDS for pulling realtime data: #{pids.size} pids")44print_status(" #{pids.inspect}")45end46if pids.include? 147data = get_monitor_status(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)48print_status(" MIL (Engine Light) : #{data['MIL'] ? 'ON' : 'OFF'}") if data.key? 'MIL'49print_status(" Number of DTCs: #{data['DTC_COUNT']}") if data.key? 'DTC_COUNT'50end51if pids.include? 552data = get_engine_coolant_temp(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)53print_status(" Engine Temp: #{data['TEMP_C']} \u00b0C / #{data['TEMP_F']} \u00b0F") if data.key? 'TEMP_C'54end55if pids.include? 0x0C56data = get_rpms(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)57print_status(" RPMS: #{data['RPM']}") if data.key? 'RPM'58end59if pids.include? 0x0D60data = get_vehicle_speed(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)61print_status(" Speed: #{data['SPEED_K']} km/h / #{data['SPEED_M']} mph") if data.key? 'SPEED_K'62end63if pids.include? 0x1C64print_status("Supported OBD Standards: #{get_obd_standards(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)}")65end66dtcs = get_dtcs(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)67unless dtcs.empty?68print_status('DTCS:')69dtcs.each do |dtc|70msg = dtc71msg += ": #{DTC_CODES[dtc]}" if DTC_CODES.key? dtc72print_status(" #{msg}")73end74end75frozen_dtcs = get_frozen_dtcs(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)76unless frozen_dtcs.empty?77print_status('Frozen DTCS:')78frozen_dtcs.each do |dtc|79msg = dtc80msg += ": #{DTC_CODES[dtc]}" if DTC_CODES.key? dtc81print_status(" #{msg}")82end83end84pids = get_vinfo_supported_pids(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)85print_status("Mode $09 Vehicle Info Supported PIDS: #{pids.inspect}") if !pids.empty?86pids.each do |pid|87# Handle known pids88if pid == 289vin = get_vin(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)90print_status("VIN: #{vin}")91elsif pid == 492calid = get_calibration_id(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)93print_status("Calibration ID: #{calid}")94elsif pid == 0x0A95ecuname = get_ecu_name(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)96print_status("ECU Name: #{ecuname}")97else98data = get_vehicle_info(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], pid, opt)99data = response_hash_to_data_array(datastore['DSTID'].to_s(16), data)100print_status("PID #{pid} Response: #{data.inspect}")101end102end103if datastore['CLEAR_DTCS'] == true104clear_dtcs(datastore['CANBUS'], datastore['SRCID'], datastore['DSTID'], opt)105print_status('Cleared DTCs and reseting MIL')106end107end108end109110111