Class: Rex::Post::HWBridge::Ui::Console::CommandDispatcher::RFtransceiver

Inherits:
Object
  • Object
show all
Includes:
Msf::Auxiliary::Report, Rex::Post::HWBridge::Ui::Console::CommandDispatcher
Defined in:
lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb

Overview

RF Transceiver extension - set of commands to be executed on transceivers like the TI cc11XX

Instance Attribute Summary collapse

Attributes included from Ui::Text::DispatcherShell::CommandDispatcher

#shell, #tab_complete_items

Instance Method Summary collapse

Methods included from Msf::Auxiliary::Report

#active_db?, #create_cracked_credential, #create_credential, #create_credential_and_login, #create_credential_login, #db, #db_warning_given?, #get_client, #get_host, #inside_workspace_boundary?, #invalidate_login, #mytask, #myworkspace, #myworkspace_id, #report_auth_info, #report_client, #report_exploit, #report_host, #report_loot, #report_note, #report_service, #report_vuln, #report_web_form, #report_web_page, #report_web_site, #report_web_vuln, #store_cred, #store_local, #store_loot

Methods included from Metasploit::Framework::Require

optionally, optionally_active_record_railtie, optionally_include_metasploit_credential_creation, #optionally_include_metasploit_credential_creation, optionally_require_metasploit_db_gem_engines

Methods included from Rex::Post::HWBridge::Ui::Console::CommandDispatcher

check_hash, #client, #initialize, #log_error, #msf_loaded?, set_hash

Methods included from Ui::Text::DispatcherShell::CommandDispatcher

#cmd_help, #cmd_help_help, #cmd_help_tabs, #deprecated_cmd, #deprecated_commands, #deprecated_help, #docs_dir, #help_to_s, #initialize, #print, #print_error, #print_good, #print_line, #print_status, #print_warning, #tab_complete_directory, #tab_complete_filenames, #tab_complete_generic, #tab_complete_source_address, #update_prompt

Instance Attribute Details

#idxObject

Returns the value of attribute idx


595
596
597
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 595

def idx
  @idx
end

Instance Method Details

#cmd_baud(*args) ⇒ Object

Set baud rate


406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 406

def cmd_baud(*args)
  self.idx ||= 0
  baud = -1
  mhz = nil
  arg = {}
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-b' => [ true, 'Baud rate' ],
    '-m' => [ true, 'Mhz' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: baud -b <baud rate>\n")
      print_line(opts.usage)
      return
    when '-b'
      baud = val.to_i
    when '-m'
      mhz = val.to_i
    end
  end
  if baud == -1
    print_line("You must specify a baud rate")
    return
  end
  arg['mhz'] = mhz if mhz
  r = client.rftransceiver.set_baud_rate(idx, baud, arg)
  print_success(r)
end

#cmd_channel(*args) ⇒ Object

Set channel


344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 344

def cmd_channel(*args)
  self.idx ||= 0
  channel = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-c' => [ true, 'Channel number' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: channel -c <channel number>\n")
      print_line(opts.usage)
      return
    when '-c'
      channel = val.to_i
    end
  end
  if channel == -1
    print_line("You must specify a channel number")
    return
  end
  r = client.rftransceiver.set_channel(idx, channel)
  print_success(r)
end

#cmd_channel_bw(*args) ⇒ Object

Set channel bandwidth


372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 372

def cmd_channel_bw(*args)
  self.idx ||= 0
  bandwidth = -1
  mhz = nil
  arg = {}
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-b' => [ true, 'Bandwidth' ],
    '-m' => [ true, 'Mhz' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: channel_bw -b <bandwidth>\n")
      print_line(opts.usage)
      return
    when '-b'
      bandwidth = val.to_i
    when '-m'
      mhz = val.to_i
    end
  end
  if bandwidth == -1
    print_line("You must specify the bandwidth (-b)")
    return
  end
  arg['mhz'] = mhz if mhz
  r = client.rftransceiver.set_channel_bandwidth(idx, bandwidth, arg)
  print_success(r)
end

#cmd_deviation(*args) ⇒ Object

Set Deviation


440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 440

def cmd_deviation(*args)
  self.idx ||= 0
  deviat = -1
  mhz = nil
  arg = {}
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-d' => [ true, 'Deviat' ],
    '-m' => [ true, 'Mhz' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: deviation -d <deviat value>\n")
      print_line(opts.usage)
      return
    when '-d'
      deviat = val.to_i
    when '-m'
      mhz = val.to_i
    end
  end
  if deviat == -1
    print_line("You must specify a deviat value")
    return
  end
  arg['mhz'] = mhz if mhz
  r = client.rftransceiver.set_deviation(idx, deviat, arg)
  print_success(r)
end

#cmd_enable_crc(*args) ⇒ Object

Enable CRC


304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 304

def cmd_enable_crc(*args)
  self.idx ||= 0
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ]
  )
  opts.parse(args) do |opt, _idx, _val|
    case opt
    when '-h'
      print_line("Usage: enable_crc\n")
      print_line(opts.usage)
      return
    end
  end
  r = client.rftransceiver.enable_packet_crc(idx)
  print_success(r)
end

#cmd_enable_manchester(*args) ⇒ Object

Enable Manchester encoding


324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 324

def cmd_enable_manchester(*args)
  self.idx ||= 0
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: enable_manchester\n")
      print_line(opts.usage)
      return
    end
  end
  r = client.rftransceiver.enable_manchester(idx)
  print_success(r)
end

#cmd_flen(*args) ⇒ Object

Sets the fixed length


174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 174

def cmd_flen(*args)
  self.idx ||= 0
  flen = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-l' => [ true, 'Fixed Length' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: flen -l <length>\n")
      print_line(opts.usage)
      return
    when '-l'
      flen = val.to_i
    end
  end
  if flen == -1
    print_line("You must specify a length")
    return
  end
  r = client.rftransceiver.make_pkt_flen(idx, flen)
  print_success(r)
end

#cmd_freq(*args) ⇒ Object

Sets the frequency


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 105

def cmd_freq(*args)
  self.idx ||= 0
  freq = -1
  mhz = nil
  arg = {}
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-f' => [ true, 'frequency to set, example: 433000000' ],
    '-m' => [ true, 'Mhz' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: freq -f <frequency number>\n")
      print_line(opts.usage)
      return
    when '-f'
      freq = val.to_i
    when '-m'
      mhz = val.to_i
    end
  end
  if freq == -1
    cmd_freq_help
    return
  end
  arg['mhz'] = mhz if mhz
  r = client.rftransceiver.set_freq(idx, freq, arg)
  print_success(r)
end

#cmd_freq_helpObject


85
86
87
88
89
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 85

def cmd_freq_help
  print_line("Sets the RF Frequency\n")
  print_line("Usage: freq -f <frequency number>")
  print_line("\nExample: freq -f 433000000")
end

#cmd_idx(*args) ⇒ Object

Sets the USB IDS


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 66

def cmd_idx(*args)
  self.idx = 0
  idx_opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-i' => [ true, 'USB index, default 0' ]
  )
  idx_opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: idx -i <Index number>\n")
      print_line(idx_opts.usage)
      return
    when '-i'
      self.idx = val
    end
  end
  print_line("set index to #{self.idx}")
end

#cmd_lowball(*args) ⇒ Object


536
537
538
539
540
541
542
543
544
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 536

def cmd_lowball(*args)
  self.idx ||= 0
  if args.length > 0
    cmd_lowball_help
    return
  end
  r = client.rftransceiver.set_lowball(idx)
  print_success(r)
end

#cmd_lowball_helpObject


532
533
534
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 532

def cmd_lowball_help
  print_line("Lowball is frequency dependent.  Set frequency first")
end

#cmd_maxpower(*args) ⇒ Object

Sets max power


553
554
555
556
557
558
559
560
561
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 553

def cmd_maxpower(*args)
  self.idx ||= 0
  if args.length > 0
    cmd_maxpower_help
    return
  end
  r = client.rftransceiver.set_maxpower(idx)
  print_success(r)
end

#cmd_maxpower_helpObject


546
547
548
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 546

def cmd_maxpower_help
  print_line("Max power is frequency dependent.  Set frequency first")
end

#cmd_modulation(*args) ⇒ Object

Sets the modulation


146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 146

def cmd_modulation(*args)
  self.idx ||= 0
  mod = nil
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-M' => [ true, 'Modulation name, See help for options' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      cmd_modulation_help
      print_line(opts.usage)
      return
    when '-M'
      mod = val
    end
  end
  unless mod
    cmd_modulation_help
    return
  end
  r = client.rftransceiver.set_modulation(idx, mod)
  print_success(r)
end

#cmd_modulation_helpObject


136
137
138
139
140
141
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 136

def cmd_modulation_help
  print_line("Usage: modulation -M <Modulation name>\n")
  print_line("Modulation names:\n")
  print_line("  #{client.rftransceiver.get_supported_modulations(idx)}")
  print_line("\nExample: modulation -M ASK/OOK")
end

#cmd_power(*args) ⇒ Object


563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 563

def cmd_power(*args)
  self.idx ||= 0
  power = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-p' => [ true, 'Power level' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: power -p <power level>\n")
      print_line(opts.usage)
      return
    when '-p'
      power = val.to_i
    end
  end
  if power == -1
    print_line("You must specify the power level")
    return
  end
  r = client.rftransceiver.set_power(idx, power)
  print_success(r)
end

#cmd_preamble(*args) ⇒ Object

Set Preamble size


507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 507

def cmd_preamble(*args)
  self.idx ||= 0
  preamble = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-n' => [ true, 'Number of preamble' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: preamble -n <number bits>\n")
      print_line(opts.usage)
      return
    when '-n'
      preamble = val.to_i
    end
  end
  if preamble == -1
    print_line("You must specify the number of preamble bits")
    return
  end
  r = client.rftransceiver.set_number_preamble(idx, preamble)
  print_success(r)
end

#cmd_preamble_helpObject


499
500
501
502
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 499

def cmd_preamble_help
  print_line("get the minimum number of preamble bits to be transmitted. note this is a flag, not a count")
  print_line("so the return value must be interpeted - e.g. 0x30 == 0x03 << 4 == MFMCFG1_NUM_PREAMBLE_6 == 6 bytes")
end

#cmd_recv(*args) ⇒ Object

Recieve data packet


269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 269

def cmd_recv(*args)
  self.idx ||= 0
  arg = {}
  timeout = -1
  blocksize = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-t' => [ true, 'timeout' ],
    '-b' => [ true, 'blocksize' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: recv\n")
      print_line(opts.usage)
      return
    when '-t'
      timeout = val.to_i
    when '-b'
      blocksize = val.to_i
    end
  end
  arg['blocksize'] = blocksize unless blocksize == -1
  arg['timeout'] = timeout unless timeout == -1
  r = client.rftransceiver.rfrecv(idx, arg)
  if r.key?('data') && r.key?('timestamp')
    print_line(" #{r['timestamp']}: #{r['data'].inspect}")
  else
    print_line("Error")
  end
end

#cmd_supported_idxObject


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 45

def cmd_supported_idx
  indexes = client.rftransceiver.supported_idx
  if !indexes || !indexes.key?('indexes')
    print_line("error retrieving index list")
    return
  end
  indexes = indexes['indexes']
  unless indexes.size > 0
    print_line('none')
    return
  end
  self.idx = indexes[0].to_i if indexes.size.zero?
  str = "Supported Indexes: "
  str << indexes.join(', ')
  str << "\nUse idx to set your desired bus, default is 0"
  print_line(str)
end

#cmd_sync_word(*args) ⇒ Object

Set Sync word


474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 474

def cmd_sync_word(*args)
  self.idx ||= 0
  word = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-w' => [ true, 'Sync word (Integer)' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: sync_word -w <int>\n")
      print_line(opts.usage)
      return
    when '-w'
      word = val.to_i
    end
  end
  if word == -1
    print_line("You must specify a sync word")
    return
  end
  r = client.rftransceiver.set_sync_word(idx, word)
  print_success(r)
end

#cmd_vlen(*args) ⇒ Object

Sets the variable length


202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 202

def cmd_vlen(*args)
  self.idx ||= 0
  vlen = -1
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-l' => [ true, 'Variable Length' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: vlen -l <length>\n")
      print_line(opts.usage)
      return
    when '-l'
      vlen = val.to_i
    end
  end
  if vlen == -1
    print_line("You must specify a length")
    return
  end
  r = client.rftransceiver.make_pkt_vlen(idx, vlen)
  print_success(r)
end

#cmd_xmit(*args) ⇒ Object

Xmit packet


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 230

def cmd_xmit(*args)
  self.idx ||= 0
  data = nil
  repeat = -1
  offset = -1
  arg = {}
  opts = Rex::Parser::Arguments.new(
    '-h' => [ false, 'Help Banner' ],
    '-d' => [ true, 'Variable Length' ],
    '-r' => [ true, 'Repeat' ],
    '-o' => [ true, 'Data offset' ]
  )
  opts.parse(args) do |opt, _idx, val|
    case opt
    when '-h'
      print_line("Usage: xmit -d <data>\n")
      print_line(opts.usage)
      return
    when '-d'
      data = val
    when '-r'
      repeat = val.to_i
    when '-o'
      offset = val.to_i
    end
  end
  unless data
    print_line("You must specify the data argument (-d)")
    return
  end
  arg['repeat'] = repeat unless repeat == -1
  arg['offset'] = offset unless offset == -1
  r = client.rftransceiver.rfxmit(idx, data, arg)
  print_success(r)
end

#commandsObject

List of supported commands.


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 19

def commands
  all = {
    'supported_idx'     => 'suppored USB indexes',
    'idx'               => 'sets an active idx',
    'freq'              => 'sets the frequency',
    'modulation'        => 'sets the modulation',
    'flen'              => 'sets the fixed length packet size',
    'vlen'              => 'sets the variable length packet size',
    'xmit'              => 'transmits some data',
    'recv'              => 'receive a packet of data',
    'enable_crc'        => 'enables crc',
    'enable_manchester' => 'enables manchester encoding',
    'channel'           => 'sets channel',
    'channel_bw'        => 'sets the channel bandwidth',
    'baud'              => 'sets the baud rate',
    'deviation'         => 'sets the deviation',
    'sync_word'         => 'sets the sync word',
    'preamble'          => 'sets the preamble number',
    'lowball'           => 'sets lowball',
    'power'             => 'sets the power level',
    'maxpower'          => 'sets max power'
  }

  all
end

#nameObject

Name for this dispatcher


591
592
593
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 591

def name
  'RFtransceiver'
end

Takes the results of a client request and prints Ok on success


94
95
96
97
98
99
100
# File 'lib/rex/post/hwbridge/ui/console/command_dispatcher/rftransceiver.rb', line 94

def print_success(r)
  if r.key?('success') && r['success'] == true
    print_line("Ok")
  else
    print_line("Error")
  end
end