whad-team / whad-client

Wireless Hacking Devices Protocol client
MIT License
103 stars 4 forks source link

whad.exceptions.WhadDeviceNotReady #45

Open jsmif opened 2 weeks ago

jsmif commented 2 weeks ago

I'm trying to run the suggested CLI command from https://whad.readthedocs.io/en/stable/cli/index.html

On Ubuntu 22.04 (python version 3.10.12, wireshark at version 3.6.2-2)

sudo pip3 install whad

hciconfig
hci0:   Type: Primary  Bus: USB
    BD Address: 56:1A:34:DA:12:0A  ACL MTU: 310:10  SCO MTU: 64:8
    UP RUNNING 
    RX bytes:1250 acl:0 sco:0 events:55 errors:0
    TX bytes:3186 acl:0 sco:0 commands:55 errors:0
sudo wble-connect -i hci0 12:4A:7f:2C:C3:29 | wshark 
Whad device is not ready.
[!] An unexpected exception occured:
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/dist-packages/whad/cli/app.py", line 716, in run_app
    application.run()
  File "/usr/local/lib/python3.10/dist-packages/whad/ble/cli/ble_connect.py", line 264, in run
    self.connect_target(self.args.bdaddr, self.args.random)
  File "/usr/local/lib/python3.10/dist-packages/whad/ble/cli/ble_connect.py", line 325, in connect_target
    central = Central(self.interface)
  File "/usr/local/lib/python3.10/dist-packages/whad/ble/connector/central.py", line 35, in __init__
    super().__init__(device)
  File "/usr/local/lib/python3.10/dist-packages/whad/ble/connector/__init__.py", line 80, in __init__
    self.device.open()
  File "/usr/local/lib/python3.10/dist-packages/whad/device/virtual/hci/__init__.py", line 124, in open
    raise WhadDeviceNotReady()
whad.exceptions.WhadDeviceNotReady

I can run commands like bluetoothctl scan on to scan for devices with this hci0 device just fine, so I know it's working.

I also did sudo wble-connect -i hci0 12:4A:7f:2C:C3:29 | wshark | wble-central profile and that gives the same error + the additional error of [!] You need to specify a target device with option --bdaddr. (so the documentation for wble-central may be wrong now and needs a -b by default?)

Also, in case it matters, the USB BT dongle in use is a CSR one which is known to be able to spoof its bdaddr when used with GATTacker for instance.

virtualabs commented 2 weeks ago

Using USB BT dongles with WHAD requires some privileges and this can be solved by installing the correct udev rules on your system. We provide a setup script to automate this, just run in the project directory:

$ sudo python3 setup.py devices_install

It should install all the required rules for CSR4 USB dongles on your system and you will be able to use them with WHAD.

I guess we forgot to mention this in the documentation, we'll fix this soon.

jsmif commented 2 weeks ago

OK, so in practice we shouldn't run pip install whad like it says on https://github.com/whad-team/whad-client, but we should always clone the git repo and install from there (with sudo python3 setup.py install ? Because that works on 22.04 but not 20.04) and then run sudo python3 setup.py devices_install, correct?

That doesn't seem to be the issue though, because I ran that command and rebooted (since I know sometimes the logout/login doesn't work), but I still get the same error on 22.04


Note: I don't get the above error when testing on Ubuntu 20.04. Instead I see:

sudo wble-connect -i hci0 12:4A:7f:2C:C3:29 | sudo wshark | sudo wble-central -b 12:4A:7f:2C:C3:29 profile
[!] You need to specify a target device with option --bdaddr

But for instance just using connect & wireshark does launch wireshark at least on 20.04

sudo wble-connect -i hci0 12:4A:7f:2C:C3:29 | sudo wshark
[●∙∙]Forwarding 0 packets to wireshark
jsmif commented 2 weeks ago

Note about Ubuntu 20.04: perhaps python3 is too old (3.8.10), and a minimum python version needs to be specified?

sudo python3 setup.py install
Traceback (most recent call last):
  File "setup.py", line 116, in <module>
    setup()
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 144, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.8/distutils/core.py", line 134, in setup
    ok = dist.parse_command_line()
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 707, in parse_command_line
    result = _Distribution.parse_command_line(self)
  File "/usr/lib/python3.8/distutils/dist.py", line 483, in parse_command_line
    args = self._parse_command_opts(parser, args)
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 1014, in _parse_command_opts
    nargs = _Distribution._parse_command_opts(self, parser, args)
  File "/usr/lib/python3.8/distutils/dist.py", line 539, in _parse_command_opts
    cmd_class = self.get_command_class(command)
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 829, in get_command_class
    return self.cmdclass[command]
TypeError: string indices must be integers
jsmif commented 2 weeks ago

Ubuntu 24.04 results:

$ sudo wble-connect -i hci0 12:4A:7f:2C:C3:29 | sudo wshark | sudo wble-central --bdaddr 12:4A:7f:2C:C3:29 profile
[!] You need to specify a target device with option --bdaddr.
$

Wireshark opens, but the CLI command exits immediately without closing wireshark, and as you can see I provided the full --bdaddr option so I don't know where that error's coming from.

virtualabs commented 2 weeks ago

Allright, I removed the capabilities set by our setup script from my Python interpreter executable to have a setup similar as yours. I am using a virtual environment in which I ran pip install whad.

When I run wble-connect -i hci1 a4:c1:38:60:fc:5c | wshark | wble-central profile, targeting a device close to me, I have the following error:

$ wble-connect -i hci1 a4:c1:38:60:fc:5c | wshark | wble-central profile
[!] Cannot access WHAD adapter, check permissions.
[!] You need to specify a target device with option --bdaddr.

If I use sudo then my system throws some errors as it cannot find the requested executables (wble-connect, wshark and wble-central).

When I run the same command line on my previous configuration (virtualenv + pip install whad + sudo python3 setup.py devices_install) everything is working fine.

I have some questions then:

You can also try to clone the repository and then create a virtual environment as root:

$ git clone https://github.com/whad-team/whad-client.git
$ cd whad-client
$ sudo su
# python3 -m venv venv-root
# . ./venv-root/bin/activate
# pip install .

And then use WHAD's CLI tools and see if it works better, or not.

jsmif commented 2 weeks ago

Are you using a virtual environment to run WHAD?

No, since the instructions didn't say to.

It looks like your system correctly finds WHAD executables even when they are run with sudo, have you installed WHAD as root or system-wide ?

Both. After installing w/ pip install whad and finding even if I added .local/bin to my path, sudo -E still wouldn't work, so I then did sudo pip install whad to install it as root.

Using the instructions to create a root venv does seem to be working on Ubuntu 22.04 in the sense that I see wireshark open and see a single ATT packet. But then it times out. I'll need to find some other devices to test on though because I think probably the one which is physically close doesn't respond to GATT, and the USB BT dongle is too weak an antenna to pick up my usual test devices.

I'll let you know the result once I've tested across the other OSes as well. Thank you

virtualabs commented 2 weeks ago

I see, we definitely need to improve the instructions to ease the installation and avoid further issues. And maybe move the code from setup.py into a small CLI tool to configure the system in order to allow using BT USB dongles as user.

Thank you for reporting this anyway, we'll do our best to improve the framework and its documentation (and fix issues too :smile:). Keep us posted if you managed to connect to a device and interact with it or if nothing works as expect.

jsmif commented 2 weeks ago

I can confirm that I at least could launch the CLI tools without error on all of 20.04, 22.04, and 24.04 with the above root venv instructions. The target seems to be finicky about responding post-connection so I only got the full GATT enumeration working on 20.04 and 22.04. But for the purposes of this ticket I consider everything working. I think you can close this once the documentation's updated. If it's just updated to be the instructions above you can fully close it. If it's some other instructions then I'd ask you give me a chance to try the new instructions to confirm they work. Thank you