54 lines
1.8 KiB
Ruby
54 lines
1.8 KiB
Ruby
|
##
|
||
|
# This module requires Metasploit: http://metasploit.com/download
|
||
|
# Current source: https://github.com/rapid7/metasploit-framework
|
||
|
##
|
||
|
|
||
|
require 'msf/core'
|
||
|
require 'rex'
|
||
|
require 'msf/core/post/hardware/automotive/uds'
|
||
|
|
||
|
class MetasploitModule < Msf::Post
|
||
|
|
||
|
include Msf::Post::Hardware::Automotive::UDS
|
||
|
|
||
|
def initialize(info={})
|
||
|
super( update_info( info,
|
||
|
'Name' => 'Scan CAN Bus for Diagnostic Modules',
|
||
|
'Description' => %q{ Post Module to scan the CAN bus for any modules that can respond to UDS DSC queries},
|
||
|
'License' => MSF_LICENSE,
|
||
|
'Author' => ['Craig Smith'],
|
||
|
'Platform' => ['hardware'],
|
||
|
'SessionTypes' => ['hwbridge']
|
||
|
))
|
||
|
register_options([
|
||
|
OptInt.new('STARTID', [true, "Start scan from this ID", 0x600]),
|
||
|
OptInt.new('ENDID', [true, "End scan at this ID", 0x7F7]),
|
||
|
OptString.new('CANBUS', [false, "CAN Bus to perform scan on, defaults to connected bus", nil])
|
||
|
], self.class)
|
||
|
@found_id = Array.new
|
||
|
end
|
||
|
|
||
|
def run
|
||
|
scanned_ids = 0
|
||
|
print_line("Starting scan...")
|
||
|
(datastore["STARTID"]..datastore["ENDID"]).each do |id|
|
||
|
res = set_dsc(datastore["CANBUS"], id, id+8, 1)
|
||
|
scanned_ids += 1
|
||
|
next if res == nil
|
||
|
next if not res.has_key? "Packets"
|
||
|
next if not res["Packets"].size > 0
|
||
|
if res["Packets"][0].has_key? "DATA" and res["Packets"][0]["DATA"].size > 3
|
||
|
if res["Packets"][0]["DATA"][0].hex == 3 and res["Packets"][0]["DATA"][1].hex == 0x7f and res["Packets"][0]["DATA"][2].hex == 0x10
|
||
|
print_status("Identified module #{"%3x" % id}")
|
||
|
@found_id << id
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
print_line("Scanned #{scanned_ids} IDs and found #{@found_id.size} modules that responded")
|
||
|
@found_id.each do |id|
|
||
|
print_line(" #{"%3x" % id}")
|
||
|
end
|
||
|
end
|
||
|
|
||
|
end
|