CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/post/hardware/automotive/identifymodules.rb
Views: 11784
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{ Post Module to 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
)
20
)
21
register_options([
22
OptInt.new('STARTID', [true, 'Start scan from this ID', 0x600]),
23
OptInt.new('ENDID', [true, 'End scan at this ID', 0x7F7]),
24
OptString.new('CANBUS', [false, 'CAN Bus to perform scan on, defaults to connected bus', nil])
25
])
26
@found_id = []
27
end
28
29
def run
30
scanned_ids = 0
31
print_line('Starting scan...')
32
(datastore['STARTID']..datastore['ENDID']).each do |id|
33
res = set_dsc(datastore['CANBUS'], id, id + 8, 1)
34
scanned_ids += 1
35
next if res.nil?
36
next unless res.key? 'Packets'
37
next unless res['Packets'].empty?
38
39
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)
40
print_status("Identified module #{'%3x' % id}")
41
@found_id << id
42
end
43
end
44
print_line("Scanned #{scanned_ids} IDs and found #{@found_id.size} modules that responded")
45
@found_id.each do |id|
46
print_line(" #{'%3x' % id}")
47
end
48
end
49
end
50
51