Path: blob/master/modules/post/hardware/automotive/identifymodules.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::UDS78def initialize(info = {})9super(10update_info(11info,12'Name' => 'Scan CAN Bus for Diagnostic Modules',13'Description' => %q{Scan the CAN bus for any modules that can respond to UDS DSC queries.},14'License' => MSF_LICENSE,15'Author' => ['Craig Smith'],16'Platform' => ['hardware'],17'SessionTypes' => ['hwbridge'],18'Notes' => {19'Stability' => [CRASH_SAFE],20'SideEffects' => [],21'Reliability' => []22}23)24)25register_options([26OptInt.new('STARTID', [true, 'Start scan from this ID', 0x600]),27OptInt.new('ENDID', [true, 'End scan at this ID', 0x7F7]),28OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])29])30@found_id = []31end3233def run34scanned_ids = 035print_line('Starting scan...')36(datastore['STARTID']..datastore['ENDID']).each do |id|37res = set_dsc(datastore['CANBUS'], id, id + 8, 1)38scanned_ids += 139next if res.nil?40next unless res.key? 'Packets'41next unless res['Packets'].empty?4243if (res['Packets'][0].key? 'DATA') && res['Packets'][0]['DATA'].size > 3 && (res['Packets'][0]['DATA'][0].hex == 3 && res['Packets'][0]['DATA'][1].hex == 0x7f && res['Packets'][0]['DATA'][2].hex == 0x10)44print_status("Identified module #{'%3x' % id}")45@found_id << id46end47end48print_line("Scanned #{scanned_ids} IDs and found #{@found_id.size} modules that responded")49@found_id.each do |id|50print_line(" #{'%3x' % id}")51end52end53end545556