Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/hardware/automotive/identifymodules.rb
19758 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Post
7
include Msf::Post::Hardware::Automotive::UDS
8
9
def initialize(info = {})
10
super(
11
update_info(
12
info,
13
'Name' => 'Scan CAN Bus for Diagnostic Modules',
14
'Description' => %q{Scan the CAN bus for any modules that can respond to UDS DSC queries.},
15
'License' => MSF_LICENSE,
16
'Author' => ['Craig Smith'],
17
'Platform' => ['hardware'],
18
'SessionTypes' => ['hwbridge'],
19
'Notes' => {
20
'Stability' => [CRASH_SAFE],
21
'SideEffects' => [],
22
'Reliability' => []
23
}
24
)
25
)
26
register_options([
27
OptInt.new('STARTID', [true, 'Start scan from this ID', 0x600]),
28
OptInt.new('ENDID', [true, 'End scan at this ID', 0x7F7]),
29
OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])
30
])
31
@found_id = []
32
end
33
34
def run
35
scanned_ids = 0
36
print_line('Starting scan...')
37
(datastore['STARTID']..datastore['ENDID']).each do |id|
38
res = set_dsc(datastore['CANBUS'], id, id + 8, 1)
39
scanned_ids += 1
40
next if res.nil?
41
next unless res.key? 'Packets'
42
next unless res['Packets'].empty?
43
44
if (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)
45
print_status("Identified module #{'%3x' % id}")
46
@found_id << id
47
end
48
end
49
print_line("Scanned #{scanned_ids} IDs and found #{@found_id.size} modules that responded")
50
@found_id.each do |id|
51
print_line(" #{'%3x' % id}")
52
end
53
end
54
end
55
56