Path: blob/master/modules/post/hardware/automotive/canprobe.rb
21628 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post67def initialize(info = {})8super(9update_info(10info,11'Name' => 'Module to Probe Different Data Points in a CAN Packet',12'Description' => %q{13Scans between two CAN IDs and writes data at each byte position. It will14either write a set byte value (Default 0xFF) or iterate through all possible values15of that byte position (takes much longer). Does not check for responses and is16basically a simple blind fuzzer.17},18'License' => MSF_LICENSE,19'Author' => ['Craig Smith'],20'Platform' => ['hardware'],21'SessionTypes' => ['hwbridge'],22'Notes' => {23'Stability' => [CRASH_SERVICE_DOWN],24'SideEffects' => [PHYSICAL_EFFECTS],25'Reliability' => []26}27)28)29register_options([30OptInt.new('STARTID', [false, 'CAN ID to start scan', 0x300]),31OptInt.new('STOPID', [false, 'CAN ID to stop scan', nil]),32OptInt.new('PROBEVALUE', [false, 'Value to inject in the data stream', 0xFF]),33OptInt.new('PADDING', [false, 'If a value is given a full 8 bytes will be used and padded with this value', nil]),34OptBool.new('FUZZ', [false, 'If true interates through all possible values for each data position', false]),35OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])36])37end3839def run40unless client.automotive41print_error('The hwbridge requires a functional automotive extention')42return43end44stopid = datastore['STARTID']45stopid = datastore['STOPID'] unless datastore['STOPID'].nil?46data = '%02X' % datastore['PROBEVALUE']47(datastore['STARTID']..stopid).each do |id|48print_status("Probing 0x#{id.to_s(16)}...")498.times do |pos|50padding = '00' * pos51endpadding = ''52endpadding = ('%02X' % datastore['PADDING']) * (7 - pos) if !datastore['PADDING'].nil?53if datastore['FUZZ']54256.times do |fuzzdata|55client.automotive.cansend(datastore['CANBUS'], id.to_s(16), padding + ('%02X' % fuzzdata) + endpadding)56end57else58client.automotive.cansend(datastore['CANBUS'], id.to_s(16), padding + data + endpadding)59end60end61end62print_status('Probe Complete')63end64end656667