Analysing Bluetooth Keyboard Traffic with hcidump

本文通过使用hcidump工具捕获并解析蓝牙键盘的数据包,揭示了蓝牙键盘输入与数据包之间的直接对应关系,并提供了一个Perl脚本来实时解析这些数据包为对应的键盘输入。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 could find a pattern. hcidump is trivial to use, and can display packets in various 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: 0xffffffffffffffff
> ACL data: handle 11 flags 0x02 dlen 14
L2CAP(d): cid 0x0040 len 10 [psm 0]
A1 01 00 00 17 00 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 00 08 00 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 00 16 00 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 00 17 00 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 calls hcidump, 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 would 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:analysing-bluetooth-keyboard-traffic-with-hcidump&catid=1:home

转载于:https://www.cnblogs.com/wzh206/archive/2010/06/03/1750989.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值