RuberTooth - a Complete Ruby Porting of the Ubertooth Libraries and Utilities.


Today, finally my ubertooth arrived and I immediately started hacking with it.

ubertooth

I installed its libraries and tools both on OS X and on my Linux virtual machine, and after a while I noticed a few things:

  • The compilation process is not well documented for newer versions of OS X, thus manual code patching here and there is required.
  • Some of the tools are only available for GNU/Linux.
  • Some of the tools are unstable.
  • There’s no way to create my own UberTooth scripts without using C.

Regarding the last point, there is a Python porting which is incomplete, it lacks most of the features that the native libraries have, so ubertooth is definitely not a scriptable device … or maybe not :)

I studied the USB communication protocol implemented inside libubertooth and found out that is very easy and well implemented, so I started to write some Ruby code ( I hate Python! ) using the libusb gem and a new project was born :)

rubertooth in action

This project, RuberTooth, aims to be a complete Ruby porting of the ubertooth libraries and utilities, made by hackers for hackers, so anyone will be able to easily create scripts for their ubertooth devices.

Here’s an example BLE packet sniffer ( which is the equivalent of the ubertooth-btle native tool ).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require 'ubertooth'
require 'usbpktrx'
require 'lepacket'
MODES = { :follow => 0, :promisc => 1 }
mode = MODES[:follow]
uber = RUbertooth::Ubertooth.new
puts "Found device: '#{uber.device.inspect}'"
uber.set_modulation RUbertooth::Ubertooth::MODULATIONS[:MOD_BT_LOW_ENERGY]
if mode == MODES[:follow]
uber.set_channel 2402
uber.btle_sniffing 2
else
uber.btle_promisc
end
prev_ts = 0
puts "Starting polling loop ..."
uber.keep_polling 0.5 do |pkt|
ts_diff = pkt.clk100ns - prev_ts
prev_ts = pkt.clk100ns
printf "\nfreq=%d addr=%08x delta_t=%.03f ms\n", pkt.frequency, pkt.access_address, ts_diff / 10000.0
(4..pkt.data_length - 1).each do |i|
printf " %02x", pkt.data[i]
end
puts
lepkt = RUbertooth::BlueTooth::LePacket.decode pkt.data, pkt.frequency, pkt.clk100ns
lepkt.dump
end