WLAN-Pi / wlanpi-profiler

Wi-Fi client capabilities analyzer tool built for the WLAN Pi
BSD 3-Clause "New" or "Revised" License
25 stars 8 forks source link

if `iw dev wlan0 set monitor none` fails, bubble up error to user, and do not start profiler. #81

Closed joshschmelzle closed 2 years ago

joshschmelzle commented 2 years ago

If we have a problem with setting the device in monitor mode, we should stop and tell the user.

Here is an example trying to set wlan0 in monitor mode when the host is a Wi-Fi based CM4:

(venv) wlanpi@wlanpi-cm4-emmc:~/dev/wlanpi-profiler$ sudo ip link set wlan0 down
(venv) wlanpi@wlanpi-cm4-emmc:~/dev/wlanpi-profiler$ sudo iw dev wlan0 set monitor none
command failed: Operation not supported (-95)

Currently, we ignore the command failed error and the profiler processes are started. At this point, scapy errors out making it look like an error with scapy, when it is an interface error instead:

(venv) wlanpi@wlanpi-cm4-emmc:~/dev/wlanpi-profiler$ sudo venv/bin/python3 -m profiler --logging debug
2021-11-05 10:23:51,109 [DEBUG] start: profiler version 1.0.8
2021-11-05 10:23:51,109 [DEBUG] start: python platform version is 3.7.3
2021-11-05 10:23:51,110 [DEBUG] start: scapy version is 2.4.5
2021-11-05 10:23:51,119 [DEBUG] start: profiler.manager pid 14024
2021-11-05 10:23:51,122 [DEBUG] start: config {'GENERAL': {'frequency': '5180', 'ssid': 'WLAN Pi', 'interface': 'wlan0', 'ft_disabled': False, 'he_disabled': False, 'listen_only': False, 'hostname_ssid': False, 'files_path': '/var/www/html/profiler', 'channel': 36}}
2021-11-05 10:23:51,149 [DEBUG] interface: wlan0 claims to support ieee80211
2021-11-05 10:23:51,177 [DEBUG] interface: phys: [phy(phy_id='2', phy_name='wlan2', ifindex='5', addr='00:c0:ca:ad:cc:0f', type='monitor'), phy(phy_id='0', phy_name='wlan1', ifindex='4', addr='d8:f8:83:35:be:07', type='managed'), phy(phy_id='1', phy_name='wlan0', ifindex='3', addr='dc:a6:32:fe:a2:48', type='managed')]
2021-11-05 10:23:51,179 [DEBUG] interface: phy1 maps to wlan0
2021-11-05 10:23:51,179 [DEBUG] interface: frequency is set as 5180 and channel as 36
2021-11-05 10:23:51,232 [WARNING] interface: reg domain appears unset. consider setting it with 'iw reg set XX'
2021-11-05 10:23:51,232 [WARNING] interface: https://wireless.wiki.kernel.org/en/users/documentation/iw#updating_your_regulatory_domain
2021-11-05 10:23:51,232 [DEBUG] interface: mac: dc:a6:32:fe:a2:48, channel: 36, driver: brcmfmac, version: 7.45.229, firmware-version: 01-2dbd9d2e
2021-11-05 10:23:51,243 [DEBUG] interface: wpa_cli version is v2.9
2021-11-05 10:23:51,266 [DEBUG] interface: iw version 5.9
2021-11-05 10:23:51,266 [DEBUG] interface: ip utility, iproute2-ss190107
2021-11-05 10:23:51,277 [DEBUG] interface: run: ip link set wlan0 down
2021-11-05 10:23:51,802 [DEBUG] interface: run: iw dev wlan0 set monitor none
2021-11-05 10:23:51,814 [DEBUG] interface: run: ip link set wlan0 up
2021-11-05 10:23:51,833 [DEBUG] interface: run: iw wlan0 set channel 36 HT20
2021-11-05 10:23:51,845 [DEBUG] start: finish interface setup and staging ...

==========================================================================
Starting profiler AP with interface wlan0 on channel 36:
 - Our fake AP SSID: WLAN Pi
 - Results are saved locally and printed to screen

Instructions:
 - Associate your Wi-Fi client to our SSID: WLAN Pi
 - Enter any random password to connect

The client will fail authentication but should send an association request
==========================================================================

2021-11-05 10:23:51,846 [DEBUG] start: beacon process
2021-11-05 10:23:51,853 [DEBUG] start: sniffer process
2021-11-05 10:23:51,872 [DEBUG] start: profiler process
2021-11-05 10:23:51,876 [DEBUG] fakeap.py: beacon pid: 14047; parent pid: 14024
2021-11-05 10:23:51,885 [DEBUG] fakeap.py: sniffer pid: 14048; parent pid: 14024
2021-11-05 10:23:51,904 [DEBUG] profiler.py: profiler pid: 14049; parent pid: 14024
2021-11-05 10:23:51,941 [DEBUG] fakeap.py: <socket.socket fd=9, family=AddressFamily.AF_PACKET, type=SocketKind.SOCK_RAW, proto=768, laddr=('wlan0', 3, 0, 1, b'\xdc\xa62\xfe\xa2H')>
2021-11-05 10:23:51,941 [DEBUG] fakeap.py: <socket.socket fd=10, family=AddressFamily.AF_PACKET, type=SocketKind.SOCK_RAW, proto=768, laddr=('wlan0', 3, 0, 1, b'\xdc\xa62\xfe\xa2H')>
2021-11-05 10:23:51,995 [INFO] fakeap.py: starting beacon transmissions
Process sniffer:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/usr/lib/python3.7/multiprocessing/process.py", line 99, in run
    self._target(*self._args, **self._kwargs)
  File "/home/wlanpi/dev/wlanpi-profiler/profiler/fakeap.py", line 360, in __init__
    filter=self.bpf_filter,
  File "/home/wlanpi/dev/wlanpi-profiler/venv/lib/python3.7/site-packages/scapy/sendrecv.py", line 1263, in sniff
    sniffer._run(*args, **kwargs)
  File "/home/wlanpi/dev/wlanpi-profiler/venv/lib/python3.7/site-packages/scapy/sendrecv.py", line 1128, in _run
    **karg)] = iface
  File "/home/wlanpi/dev/wlanpi-profiler/venv/lib/python3.7/site-packages/scapy/arch/linux.py", line 497, in __init__
    attach_filter(self.ins, filter, self.iface)
  File "/home/wlanpi/dev/wlanpi-profiler/venv/lib/python3.7/site-packages/scapy/arch/linux.py", line 166, in attach_filter
    bp = compile_filter(bpf_filter, iface)
  File "/home/wlanpi/dev/wlanpi-profiler/venv/lib/python3.7/site-packages/scapy/arch/common.py", line 157, in compile_filter
    "Failed to compile filter expression %s (%s)" % (filter_exp, ret)
scapy.error.Scapy_Exception: Failed to compile filter expression type mgt subtype probe-req or type mgt subtype auth or type mgt subtype assoc-req or type mgt subtype reassoc-req (-1)
2021-11-05 10:23:52,270 [DEBUG] start: <Process(sniffer, stopped[1])>
2021-11-05 10:23:52,278 [DEBUG] start: <Process(profiler, stopped[SIGKILL])>
2021-11-05 10:23:52,310 [DEBUG] start: <Process(txbeacons, stopped[SIGKILL])>
joshschmelzle commented 2 years ago

Added in 5c621d776ab792b66cc42fe3be4b5288cc3ec94a.

Example:

2021-11-11 15:44:05,571 [INFO] interface: run: iw phy1 interface add wlan1mon type monitor flags none
2021-11-11 15:44:05,594 [INFO] interface: command failed: Operation not supported (-95)
2021-11-11 15:44:05,595 [ERROR] start: problem interface staging ... exiting ...
Traceback (most recent call last):
  File "/home/wlanpi/dev/wlanpi-profiler/profiler/manager.py", line 176, in start
    __iface.stage_interface()
  File "/home/wlanpi/dev/wlanpi-profiler/profiler/interface.py", line 228, in stage_interface
    raise InterfaceError(f"{self.name} does not appear to support monitor mode")
profiler.interface.InterfaceError: wlan1 does not appear to support monitor mode
^CDetected SIGINT or Control-C ... Removing monitor interface ...
2021-11-11 15:44:33,261 [INFO] interface: run: ip link set wlan1mon down
2021-11-11 15:44:33,299 [INFO] interface: run: iw dev wlan1mon del
2021-11-11 15:44:33,323 [INFO] interface: run: ip link set wlan1 up
Exiting ...