@@ -13,6 +13,12 @@ class Console::CommandDispatcher::Automotive
13
13
include Console ::CommandDispatcher
14
14
include Msf ::Auxiliary ::Report
15
15
16
+ def initialize ( shell )
17
+ super
18
+ self . tpjobs = [ ]
19
+ self . tpjob_id = 0
20
+ end
21
+
16
22
#
17
23
# List of supported commands.
18
24
#
@@ -21,14 +27,16 @@ def commands
21
27
'supported_buses' => 'Get supported buses' ,
22
28
'busconfig' => 'Get baud configs' ,
23
29
'connect' => 'Get HW supported methods for a bus' ,
24
- 'cansend' => 'Send a CAN packet'
30
+ 'cansend' => 'Send a CAN packet' ,
31
+ 'testerpresent' => 'Sends TesterPresent Pulses to the bus'
25
32
}
26
33
27
34
reqs = {
28
35
'supported_buses' => [ 'get_supported_buses' ] ,
29
36
'busconfig' => [ 'get_bus_config' ] ,
30
37
'connect' => [ 'get_supported_methods' ] ,
31
- 'cansend' => [ 'cansend' ]
38
+ 'cansend' => [ 'cansend' ] ,
39
+ 'testerpresent' => [ 'testpresent' ]
32
40
}
33
41
34
42
# Ensure any requirements of the command are met
@@ -106,9 +114,10 @@ def cmd_connect(*args)
106
114
end
107
115
unless client . automotive . is_valid_bus? bus
108
116
print_error ( "You must specify a valid bus via -b" )
117
+ print_line ( "Current active bus: #{ self . active_bus } " ) if self . active_bus
109
118
return
110
119
end
111
- active_bus = bus
120
+ self . active_bus = bus
112
121
client . automotive . set_active_bus ( bus )
113
122
hw_methods = client . automotive . get_supported_methods ( bus )
114
123
hw_methods
@@ -141,7 +150,7 @@ def cmd_cansend(*args)
141
150
data = val
142
151
end
143
152
end
144
- bus = active_bus if bus . blank? && !active_bus . nil?
153
+ bus = self . active_bus if bus . blank? && !self . active_bus . nil?
145
154
unless client . automotive . is_valid_bus? bus
146
155
print_error ( "You must specify a valid bus via -b" )
147
156
return
@@ -154,17 +163,97 @@ def cmd_cansend(*args)
154
163
success
155
164
end
156
165
166
+ #
167
+ # Sends TesterPresent packets as a background job
168
+ #
169
+ def cmd_testerpresent ( *args )
170
+ bus = ''
171
+ id = ''
172
+ stop = false
173
+ stopid = 0
174
+ tp_opts = Rex ::Parser ::Arguments . new (
175
+ '-h' => [ false , 'Help Banner' ] ,
176
+ '-b' => [ true , 'Target bus' ] ,
177
+ '-I' => [ true , 'CAN ID' ] ,
178
+ '-x' => [ true , 'Stop TesterPresent JobID' ]
179
+ )
180
+ tp_opts . parse ( args ) do |opt , _idx , val |
181
+ case opt
182
+ when '-h'
183
+ print_line ( "Usage: testerpresent -I <ID>\n " )
184
+ print_line ( tp_opts . usage )
185
+ return
186
+ when '-b'
187
+ bus = val
188
+ when '-I'
189
+ id = val
190
+ when '-x'
191
+ stop = true
192
+ stopid = val . to_i
193
+ end
194
+ end
195
+ bus = self . active_bus if bus . blank? && !self . active_bus . nil?
196
+ unless client . automotive . is_valid_bus? bus
197
+ print_error ( "You must specify a valid bus via -b" )
198
+ return
199
+ end
200
+ if id . blank? && !stop
201
+ if self . tpjobs . size > 0
202
+ print_line ( "TesterPresent is currently active" )
203
+ self . tpjobs . each_index do |jid |
204
+ if self . tpjobs [ jid ]
205
+ print_status ( "TesterPresent Job #{ jid } : #{ self . tpjobs [ jid ] [ :args ] . inspect } " )
206
+ end
207
+ end
208
+ else
209
+ print_line ( "TesterPreset is not active. Use -I to start" )
210
+ end
211
+ return
212
+ end
213
+ unless stop
214
+ jid = self . tpjob_id
215
+ print_status ( "Starting TesterPresent sender (#{ self . tpjob_id } )" )
216
+ self . tpjob_id += 1
217
+ self . tpjobs [ jid ] = Rex ::ThreadFactory . spawn ( "TesterPresent(#{ id } )-#{ jid } " , false , jid , args ) do |myjid , xargs |
218
+ ::Thread . current [ :args ] = xargs . dup
219
+ begin
220
+ loop do
221
+ client . automotive . cansend ( bus , id , "023E00" )
222
+ sleep ( 2 )
223
+ end
224
+ rescue ::Exception
225
+ print_error ( "Error in TesterPResent: #{ $!. class } #{ $!} " )
226
+ elog ( "Error in TesterPreset: #{ $!. class } #{ $!} " )
227
+ dlog ( "Callstack: #{ $@. join ( "\n " ) } " )
228
+ end
229
+ self . tpjobs [ myjid ] = nil
230
+ print_status ( "TesterPreset #{ myjid } has stopped (#{ ::Thread . current [ :args ] . inspect } )" )
231
+ end
232
+ else
233
+ if self . tpjobs [ stopid ]
234
+ self . tpjobs [ stopid ] . kill
235
+ self . tpjobs [ stopid ] = nil
236
+ print_status ( "Stopped TesterPresent #{ stopid } " )
237
+ else
238
+ print_error ( "TesterPresent #{ stopid } was not running" )
239
+ end
240
+ end
241
+ end
242
+
157
243
#
158
244
# Name for this dispatcher
159
245
#
160
246
def name
161
247
'Automotive'
162
248
end
163
249
164
- private
165
-
166
250
attr_accessor :active_bus
167
251
252
+ protected
253
+
254
+ attr_accessor :tpjobs , :tpjob_id # :nodoc:
255
+
256
+
168
257
end
169
258
170
259
end
0 commit comments