usbbluetooth/scapy-usbbluetooth
GitHub: usbbluetooth/scapy-usbbluetooth
该项目为 Scapy 提供 USB 蓝牙通信套接字,使其能够直接与蓝牙控制器进行 HCI 数据包级别的交互。
Stars: 23 | Forks: 5
# Scapy UsbBluetooth
[](https://github.com/usbbluetooth/scapy-usbbluetooth/actions/workflows/build.yml)
[](https://github.com/usbbluetooth/scapy-usbbluetooth/actions/workflows/codeql.yml)
[](https://pypi.org/project/scapy-usbbluetooth/)
[](https://pypi.org/project/scapy-usbbluetooth/)
[](https://snyk.io/advisor/python/scapy-usbbluetooth)
[](https://scorecard.dev/viewer/?uri=github.com/usbbluetooth/scapy-usbbluetooth)
[](LICENSE.md)
此软件包包含的代码允许 Scapy sockets 使用 [UsbBluetooth for Python](https://github.com/usbbluetooth/usbbluetooth-python) 与 Bluetooth 控制器进行通信。
有关项目的一般文档,请访问 [usbbluetooth.github.io](https://usbbluetooth.github.io/)。
如需此库的基础 Python 版本,请查看 [UsbBluetooth for Python](https://github.com/usbbluetooth/usbbluetooth-python)。
对于其他编程语言,您可以访问 [UsbBluetooth for C](ttps://github.com/usbbluetooth/usbbluetooth) 或 [UsbBluetooth for C#](https://github.com/usbbluetooth/usbbluetooth-csharp)。
## 安装说明
只需使用 pip :)
```
pip install scapy-usbbluetooth
```
## 使用说明
请查看 [示例](examples/) 文件夹以获取示例代码。
简短的说明性使用示例如下:
```
import usbbluetooth
from scapy_usbbluetooth import UsbBluetoothSocket
from scapy.layers.bluetooth import HCI_Hdr, HCI_Command_Hdr, HCI_Cmd_Reset
# 获取所有可用设备的列表
devices = usbbluetooth.list_devices()
for dev in devices:
print(dev)
# 使用设备打开 socket
socket = UsbBluetoothSocket(devices[0])
# 创建 reset 数据包
pkt = HCI_Hdr() / HCI_Command_Hdr() / HCI_Cmd_Reset()
# 将数据包发送到 controller 并等待响应
response = socket.sr1(pkt)
response.show()
```
## 平台特性
### Windows
在 Windows 中,您可能需要使用 Zadig 在您的设备上安装 WinUSB 驱动程序。否则,UsbBluetooth 将检测到您的设备,但可能无法控制您的设备。
### Linux
您的 Linux 用户必须具有访问 USB 硬件的权限。以下是确保访问权限的几种选项:
- **以 root 身份运行**:使用 `sudo` 以提升的权限执行应用程序。请注意,出于安全原因,这可能并不理想。
- **将用户添加到组**:将您的用户添加到 `plugdev`、`usb` 或 `uucp` 组(取决于您的发行版)。请记住重新启动或注销并重新登录以使更改生效。例如:
sudo usermod -a -G plugdev $USER
- **创建 udev 规则**:创建自定义的 udev 规则以自动为 USB Bluetooth 设备设置权限。创建一个类似 `/etc/udev/rules.d/99-usbbluetooth.rules` 的文件,内容类似于:
SUBSYSTEM=="usb", ATTR{idVendor}=="your_vendor_id", ATTR{idProduct}=="your_product_id", MODE="0666"
将 `your_vendor_id` 和 `your_product_id` 替换为您设备的实际供应商和产品 ID(您可以使用 `lsusb` 找到它们)。然后使用 `sudo udevadm control --reload-rules && sudo udevadm trigger` 重新加载 udev 规则。
标签:逆向工具