I own a rocketfish RF-BTMKY Bluetooth keyboard and I really like it. today, I tried using hcidump to dump the Bluetooth traffic from my keyboard and see if I cocould find a pattern. hcidump is trivial to use, and can display packets in varous formats. you can also dump the packets to a file that can then be read by Wireshark. hcidump requires root access to be able to capture the packets. here is a sample capture, took while I was typing the word "test ":
Debian:/home/aghaster/BT # hcidump-x
HCI sniffer-Bluetooth packet analyzer ver 1.42
Device: hci0 snap_len: 1028 filter: 0 xffffffffffffff
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 001700 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 00 00 00 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 000800 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 00 00 00 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 001600 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 00 00 00 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 001700 00 00 00 00
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP (d): Cid 0x0040 Len 10 [PSM 0]
A1 01 00 00 00 00 00 00 00 00
Quick observation reveals that there is direct equivalence between a code and a key that has been typed:
T: 0x17
E: 0x08
S: 0x16
T: 0x07
I 've heard of wireless keyboards that scramble the codes, but this one apparently doesn' t. the packets where the code is set to 0 are probably used to indicate that a key has been released. I didn't take the time to figure out all the codes, but here are the codes for letters and numbers:
A to Z: 0x04 to 0x1d
1 to 9: 0x1e to 0x26
0: 0x27 (the digits are in the same order as on the keyboard, So 0 comes after 9)
Just for fun, I made a Perl script that callhcidump, analyses the packets and outputs the corresponding characters:
#!/usr/bin/perl
@keys =
(
"", "", "", "",
"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M",
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"
);
use IO::Handle;
open("BT", "hcidump -x |") or die("Can't start hcidump");
while($line = ) {
# Sample packet:
# A1 01 00 00 CC 00 00 00 00 00
# Where CC is the code for the key
if($line =~ m/\s+A1/) {
@bytes = split(/ /, $line);
$code = hex($bytes[10]);
if($code != 0) {
printf("%02X\t%s\n", $code, $keys[$code]);
}
}
}
close("BT");
And here is sample output:
Debian:/home/aghaster/BT # Perl btkbdsniff. pl
17 T
08 E
16 S
17 T
2c
1e 1
1f 2
20 3
Don't forget to run the script as root so that hcidump can capture the packets. even though it is trivial to figure out the keys from the packet capture, one still needs to be able to capture the Bluetooth traffic. hcidump requires root access, so there is nothing to worry about (I wocould worry more about someone having unauthorized root access before worrying about him keylogging me ).
Http://www.awakecoding.com/index.php? Option = com_content & view = article & id = 13: Analyzing-Bluetooth-keyboard-traffic-with-hcidump & catid = 1: Home