airshark 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- airshark-0.1.0/LICENSE +21 -0
- airshark-0.1.0/PKG-INFO +152 -0
- airshark-0.1.0/README.md +112 -0
- airshark-0.1.0/airshark/TUI.py +264 -0
- airshark-0.1.0/airshark/__init__.py +7 -0
- airshark-0.1.0/airshark/__main__.py +154 -0
- airshark-0.1.0/airshark/capture.py +198 -0
- airshark-0.1.0/airshark/channel.py +391 -0
- airshark-0.1.0/airshark/models.py +340 -0
- airshark-0.1.0/airshark.egg-info/PKG-INFO +152 -0
- airshark-0.1.0/airshark.egg-info/SOURCES.txt +16 -0
- airshark-0.1.0/airshark.egg-info/dependency_links.txt +1 -0
- airshark-0.1.0/airshark.egg-info/entry_points.txt +2 -0
- airshark-0.1.0/airshark.egg-info/requires.txt +6 -0
- airshark-0.1.0/airshark.egg-info/top_level.txt +1 -0
- airshark-0.1.0/pyproject.toml +31 -0
- airshark-0.1.0/setup.cfg +4 -0
airshark-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) chiroyce
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
airshark-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: airshark
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Terminal Wi-Fi monitor for macOS. Puts the interface into monitor mode, hops channels, with support for WPA/WPA2 decryption.
|
|
5
|
+
Author: chiroyce
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) chiroyce
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Repository, https://github.com/chiroyce1/airshark
|
|
29
|
+
Project-URL: Issues, https://github.com/chiroyce1/airshark/issues
|
|
30
|
+
Classifier: Programming Language :: Python :: 3
|
|
31
|
+
Classifier: Operating System :: MacOS
|
|
32
|
+
Requires-Python: >=3.10
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
License-File: LICENSE
|
|
35
|
+
Requires-Dist: textual>=0.40.0
|
|
36
|
+
Requires-Dist: rich>=13.0.0
|
|
37
|
+
Requires-Dist: python-dotenv>=1.0.0
|
|
38
|
+
Requires-Dist: pyobjc-framework-CoreWLAN; sys_platform == "darwin"
|
|
39
|
+
Dynamic: license-file
|
|
40
|
+
|
|
41
|
+
# AirShark
|
|
42
|
+
|
|
43
|
+
  
|
|
44
|
+
|
|
45
|
+
Terminal Wi-Fi monitor for macOS. Puts the interface into monitor mode, hops channels, with support for WPA/WPA2 decryption.
|
|
46
|
+
|
|
47
|
+
> [!NOTE]
|
|
48
|
+
> Currently in early development. Only been tested on Apple Silicon (M1) with Wi-Fi 5.
|
|
49
|
+
|
|
50
|
+
- **Capture:** `dumpcap` while the interface is in monitor mode and captures raw frames, which are piped into `tshark` (`-T ek`) to generate JSON, which is fed into a background thread for the TUI to read off of.
|
|
51
|
+
- **Channel hopping:** Implemented using CoreWLAN via PyObjC. The interface is disassociated once at startup to allow raw packet capture.
|
|
52
|
+
- **UI:** [Textual](https://github.com/Textualize/textual).
|
|
53
|
+
|
|
54
|
+
## Requirements
|
|
55
|
+
|
|
56
|
+
- macOS
|
|
57
|
+
- Python 3.10+
|
|
58
|
+
- [Wireshark](https://www.wireshark.org/download.html) / tshark
|
|
59
|
+
During install, make sure to enable the **ChmodBPF** capture permissions. This allows AirShark to capture packets entirely **without `sudo`**.
|
|
60
|
+
|
|
61
|
+
## Installation
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
pip install airshark
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Or clone from source and install in editable mode:
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
git clone <repo-url>
|
|
71
|
+
cd airshark
|
|
72
|
+
pip install -e .
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
Credentials for decryption can come from the CLI or a .env file:
|
|
78
|
+
|
|
79
|
+
```env
|
|
80
|
+
SSID="YourNetworkName"
|
|
81
|
+
PASSWORD="YourPassphrase"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
CLI flags (`-s`/`-k`) can override `.env`.
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Monitor channel 6
|
|
90
|
+
airshark -i en0 -c 6
|
|
91
|
+
|
|
92
|
+
# Hop 2.4 GHz, 0.5 s per channel
|
|
93
|
+
airshark -i en0 --band 2.4 --dwell 0.5
|
|
94
|
+
|
|
95
|
+
# 5 GHz hop + live decryption
|
|
96
|
+
airshark -i en0 --band 5 -s HomeNet -k s3cr3t
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Keybindings while running:
|
|
100
|
+
|
|
101
|
+
| Key | Action |
|
|
102
|
+
| --------- | -------------------------------------- |
|
|
103
|
+
| `h` | Toggle channel hopping on / off |
|
|
104
|
+
| `,` / `.` | Previous / Next channel (when hopping) |
|
|
105
|
+
| `=` / `-` | Increase / decrease channel dwell time |
|
|
106
|
+
| `q` | Quit |
|
|
107
|
+
|
|
108
|
+
## Known Limitations
|
|
109
|
+
|
|
110
|
+
### EAPOL (4-Way Handshake) Capture
|
|
111
|
+
|
|
112
|
+
For reliable EAPOL capture (and subsequent WPA decryption), it is recommended to **lock AirShark to the target AP's specific channel** (e.g., `airshark -c 60`) rather than sweeping an entire band, or use the `h` keybind and select the channel using `,` and `.` keys.
|
|
113
|
+
|
|
114
|
+
### Multi-Band Hopping (2.4 + 5 GHz + 6 GHz)
|
|
115
|
+
|
|
116
|
+
The macOS `CoreWLAN` framework imposes hardware limitations that prevent the Wi-Fi radio from transparently hopping across different frequency bands. If attempted, the initial cross-band hop may succeed, but subsequent hops are silently ignored by the macOS Wi-Fi driver. Therefore, AirShark restricts channel hopping to a single band at a time (e.g., 2.4 GHz, 5 GHz, or 6 GHz).
|
|
117
|
+
Refer to this [post](https://developer.apple.com/forums/thread/818603?answerId=881663022#881663022) on the Apple developer forums for additional technical context.
|
|
118
|
+
|
|
119
|
+
## Named pipe support
|
|
120
|
+
|
|
121
|
+
You can stream packets from AirShark to other tools like Wireshark using Unix named pipes.
|
|
122
|
+
|
|
123
|
+
1. **Create the named pipe:**
|
|
124
|
+
```bash
|
|
125
|
+
mkfifo /tmp/airshark.pipe
|
|
126
|
+
```
|
|
127
|
+
2. **Start Wireshark reading from the pipe first:**
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
wireshark -k -i /tmp/airshark.pipe &
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
3. **Run AirShark and output to the pipe:**
|
|
134
|
+
```bash
|
|
135
|
+
airshark --band 5 -o /tmp/airshark.pipe
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## CLI Reference
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
capture:
|
|
142
|
+
-i IFACE, --interface Wireless interface (default: en0)
|
|
143
|
+
-I, --monitor Enable monitor mode (default: on)
|
|
144
|
+
-o FILE, --output Output PCAP file or named pipe (default: airshark_capture.pcap)
|
|
145
|
+
-c N, --channel Channel for single mode (default: 6)
|
|
146
|
+
--band BAND Band to sweep: single | 2.4 | 5 | 6
|
|
147
|
+
--dwell SECS Seconds per channel when hopping (default: 0.75)
|
|
148
|
+
|
|
149
|
+
decryption:
|
|
150
|
+
-s, -S, --ssid SSID Network SSID for WPA decryption
|
|
151
|
+
-k PASSPHRASE, --key WPA/WPA2 passphrase
|
|
152
|
+
```
|
airshark-0.1.0/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# AirShark
|
|
2
|
+
|
|
3
|
+
  
|
|
4
|
+
|
|
5
|
+
Terminal Wi-Fi monitor for macOS. Puts the interface into monitor mode, hops channels, with support for WPA/WPA2 decryption.
|
|
6
|
+
|
|
7
|
+
> [!NOTE]
|
|
8
|
+
> Currently in early development. Only been tested on Apple Silicon (M1) with Wi-Fi 5.
|
|
9
|
+
|
|
10
|
+
- **Capture:** `dumpcap` while the interface is in monitor mode and captures raw frames, which are piped into `tshark` (`-T ek`) to generate JSON, which is fed into a background thread for the TUI to read off of.
|
|
11
|
+
- **Channel hopping:** Implemented using CoreWLAN via PyObjC. The interface is disassociated once at startup to allow raw packet capture.
|
|
12
|
+
- **UI:** [Textual](https://github.com/Textualize/textual).
|
|
13
|
+
|
|
14
|
+
## Requirements
|
|
15
|
+
|
|
16
|
+
- macOS
|
|
17
|
+
- Python 3.10+
|
|
18
|
+
- [Wireshark](https://www.wireshark.org/download.html) / tshark
|
|
19
|
+
During install, make sure to enable the **ChmodBPF** capture permissions. This allows AirShark to capture packets entirely **without `sudo`**.
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install airshark
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Or clone from source and install in editable mode:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
git clone <repo-url>
|
|
31
|
+
cd airshark
|
|
32
|
+
pip install -e .
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Configuration
|
|
36
|
+
|
|
37
|
+
Credentials for decryption can come from the CLI or a .env file:
|
|
38
|
+
|
|
39
|
+
```env
|
|
40
|
+
SSID="YourNetworkName"
|
|
41
|
+
PASSWORD="YourPassphrase"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
CLI flags (`-s`/`-k`) can override `.env`.
|
|
45
|
+
|
|
46
|
+
## Usage
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
# Monitor channel 6
|
|
50
|
+
airshark -i en0 -c 6
|
|
51
|
+
|
|
52
|
+
# Hop 2.4 GHz, 0.5 s per channel
|
|
53
|
+
airshark -i en0 --band 2.4 --dwell 0.5
|
|
54
|
+
|
|
55
|
+
# 5 GHz hop + live decryption
|
|
56
|
+
airshark -i en0 --band 5 -s HomeNet -k s3cr3t
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
Keybindings while running:
|
|
60
|
+
|
|
61
|
+
| Key | Action |
|
|
62
|
+
| --------- | -------------------------------------- |
|
|
63
|
+
| `h` | Toggle channel hopping on / off |
|
|
64
|
+
| `,` / `.` | Previous / Next channel (when hopping) |
|
|
65
|
+
| `=` / `-` | Increase / decrease channel dwell time |
|
|
66
|
+
| `q` | Quit |
|
|
67
|
+
|
|
68
|
+
## Known Limitations
|
|
69
|
+
|
|
70
|
+
### EAPOL (4-Way Handshake) Capture
|
|
71
|
+
|
|
72
|
+
For reliable EAPOL capture (and subsequent WPA decryption), it is recommended to **lock AirShark to the target AP's specific channel** (e.g., `airshark -c 60`) rather than sweeping an entire band, or use the `h` keybind and select the channel using `,` and `.` keys.
|
|
73
|
+
|
|
74
|
+
### Multi-Band Hopping (2.4 + 5 GHz + 6 GHz)
|
|
75
|
+
|
|
76
|
+
The macOS `CoreWLAN` framework imposes hardware limitations that prevent the Wi-Fi radio from transparently hopping across different frequency bands. If attempted, the initial cross-band hop may succeed, but subsequent hops are silently ignored by the macOS Wi-Fi driver. Therefore, AirShark restricts channel hopping to a single band at a time (e.g., 2.4 GHz, 5 GHz, or 6 GHz).
|
|
77
|
+
Refer to this [post](https://developer.apple.com/forums/thread/818603?answerId=881663022#881663022) on the Apple developer forums for additional technical context.
|
|
78
|
+
|
|
79
|
+
## Named pipe support
|
|
80
|
+
|
|
81
|
+
You can stream packets from AirShark to other tools like Wireshark using Unix named pipes.
|
|
82
|
+
|
|
83
|
+
1. **Create the named pipe:**
|
|
84
|
+
```bash
|
|
85
|
+
mkfifo /tmp/airshark.pipe
|
|
86
|
+
```
|
|
87
|
+
2. **Start Wireshark reading from the pipe first:**
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
wireshark -k -i /tmp/airshark.pipe &
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
3. **Run AirShark and output to the pipe:**
|
|
94
|
+
```bash
|
|
95
|
+
airshark --band 5 -o /tmp/airshark.pipe
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## CLI Reference
|
|
99
|
+
|
|
100
|
+
```
|
|
101
|
+
capture:
|
|
102
|
+
-i IFACE, --interface Wireless interface (default: en0)
|
|
103
|
+
-I, --monitor Enable monitor mode (default: on)
|
|
104
|
+
-o FILE, --output Output PCAP file or named pipe (default: airshark_capture.pcap)
|
|
105
|
+
-c N, --channel Channel for single mode (default: 6)
|
|
106
|
+
--band BAND Band to sweep: single | 2.4 | 5 | 6
|
|
107
|
+
--dwell SECS Seconds per channel when hopping (default: 0.75)
|
|
108
|
+
|
|
109
|
+
decryption:
|
|
110
|
+
-s, -S, --ssid SSID Network SSID for WPA decryption
|
|
111
|
+
-k PASSPHRASE, --key WPA/WPA2 passphrase
|
|
112
|
+
```
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from textual.app import App, ComposeResult
|
|
4
|
+
from textual.binding import Binding
|
|
5
|
+
from textual.containers import Horizontal, Vertical
|
|
6
|
+
from textual.widgets import DataTable, Footer, Label, Static
|
|
7
|
+
|
|
8
|
+
import airshark
|
|
9
|
+
from airshark.channel import ChannelHopper
|
|
10
|
+
|
|
11
|
+
from .models import SessionState
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class StatusBar(Static):
|
|
15
|
+
"""Single-line status strip rendered at the top of the screen."""
|
|
16
|
+
|
|
17
|
+
def update_status(
|
|
18
|
+
self,
|
|
19
|
+
hopper: ChannelHopper,
|
|
20
|
+
total_pkts: int,
|
|
21
|
+
decrypted_pkts: int,
|
|
22
|
+
ssid: str,
|
|
23
|
+
ap_count: int,
|
|
24
|
+
client_count: int,
|
|
25
|
+
) -> None:
|
|
26
|
+
dec = (
|
|
27
|
+
f" │ Decryption [bold green]Active ({ssid})[/] [white]\\[{decrypted_pkts}][/]"
|
|
28
|
+
if ssid
|
|
29
|
+
else ""
|
|
30
|
+
)
|
|
31
|
+
mode_str = "[red]PAUSED[/]" if hopper.is_paused else f"[yellow]{hopper.mode}[/]"
|
|
32
|
+
self.update(
|
|
33
|
+
f"[bold green]▸ AirShark[/] "
|
|
34
|
+
f"CH [cyan]{hopper.current_channel}[/] │ "
|
|
35
|
+
f"Mode {mode_str} │ "
|
|
36
|
+
f"Dwell [yellow]{hopper.interval:.2f}s[/] │ "
|
|
37
|
+
f"Pkts [white]{total_pkts}[/]{dec} │ "
|
|
38
|
+
f"APs [yellow]{ap_count}[/] │ "
|
|
39
|
+
f"Clients [blue]{client_count}[/]"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class AirSharkApp(App):
|
|
44
|
+
"""Live Wi-Fi monitoring dashboard built with Textual."""
|
|
45
|
+
|
|
46
|
+
CSS = """
|
|
47
|
+
Screen {
|
|
48
|
+
layout: vertical;
|
|
49
|
+
}
|
|
50
|
+
StatusBar {
|
|
51
|
+
height: 1;
|
|
52
|
+
background: $surface;
|
|
53
|
+
color: $text;
|
|
54
|
+
padding: 0 1;
|
|
55
|
+
}
|
|
56
|
+
#tables {
|
|
57
|
+
height: 1fr;
|
|
58
|
+
layout: horizontal;
|
|
59
|
+
}
|
|
60
|
+
#ap-panel {
|
|
61
|
+
width: 3fr;
|
|
62
|
+
border: tall $primary;
|
|
63
|
+
padding: 0;
|
|
64
|
+
box-sizing: border-box;
|
|
65
|
+
}
|
|
66
|
+
#client-panel {
|
|
67
|
+
width: 2fr;
|
|
68
|
+
border: tall $success;
|
|
69
|
+
padding: 0;
|
|
70
|
+
box-sizing: border-box;
|
|
71
|
+
}
|
|
72
|
+
DataTable {
|
|
73
|
+
height: 1fr;
|
|
74
|
+
}
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
BINDINGS = [ # type: ignore[assignment] # noqa: RUF012
|
|
78
|
+
Binding("h", "toggle_hop", "Hop", show=True),
|
|
79
|
+
Binding("comma", "prev_channel", "Prev CH", show=True, key_display=","),
|
|
80
|
+
Binding("full_stop", "next_channel", "Next CH", show=True, key_display="."),
|
|
81
|
+
Binding("=", "interval_up", "+Dwell", show=True),
|
|
82
|
+
Binding("-", "interval_down", "-Dwell", show=True),
|
|
83
|
+
Binding("q", "quit", "Quit", show=True),
|
|
84
|
+
Binding("ctrl+c", "quit", "Quit", show=False),
|
|
85
|
+
]
|
|
86
|
+
|
|
87
|
+
def __init__(
|
|
88
|
+
self,
|
|
89
|
+
hopper: ChannelHopper,
|
|
90
|
+
write_path: str,
|
|
91
|
+
ssid: str | None = None,
|
|
92
|
+
password: str | None = None,
|
|
93
|
+
interface: str = "en0",
|
|
94
|
+
monitor: bool = True,
|
|
95
|
+
):
|
|
96
|
+
super().__init__()
|
|
97
|
+
self.hopper = hopper
|
|
98
|
+
self.write_path = write_path
|
|
99
|
+
self.ssid = ssid
|
|
100
|
+
self.password = password
|
|
101
|
+
self.interface = interface
|
|
102
|
+
self.monitor = monitor
|
|
103
|
+
self.state = SessionState()
|
|
104
|
+
self.session: airshark.CaptureSession | None = None
|
|
105
|
+
|
|
106
|
+
def compose(self) -> ComposeResult:
|
|
107
|
+
yield StatusBar(id="status")
|
|
108
|
+
with Horizontal(id="tables"):
|
|
109
|
+
with Vertical(id="ap-panel"):
|
|
110
|
+
yield Label(" Access Points")
|
|
111
|
+
yield DataTable(id="ap-table", zebra_stripes=True)
|
|
112
|
+
with Vertical(id="client-panel"):
|
|
113
|
+
yield Label(" Clients")
|
|
114
|
+
yield DataTable(id="client-table", zebra_stripes=True)
|
|
115
|
+
yield Footer()
|
|
116
|
+
|
|
117
|
+
def on_mount(self) -> None:
|
|
118
|
+
ap_table = self.query_one("#ap-table", DataTable)
|
|
119
|
+
ap_table.cursor_type = "none"
|
|
120
|
+
for col, key in [("BSSID", "bssid"), ("SSID", "ssid"), ("CH", "ch"), ("RSSI", "rssi"), ("Pkts", "pkts")]:
|
|
121
|
+
ap_table.add_column(col, key=key)
|
|
122
|
+
|
|
123
|
+
cl_table = self.query_one("#client-table", DataTable)
|
|
124
|
+
cl_table.cursor_type = "none"
|
|
125
|
+
for col, key in [("Client MAC", "mac"), ("Associated AP", "ap"), ("CH", "ch"), ("HS", "hs"), ("Pkts", "pkts")]:
|
|
126
|
+
cl_table.add_column(col, key=key)
|
|
127
|
+
|
|
128
|
+
self.session = airshark.CaptureSession(
|
|
129
|
+
interface=self.interface,
|
|
130
|
+
monitor_mode=self.monitor,
|
|
131
|
+
output_file=self.write_path,
|
|
132
|
+
callback=self.handle_packet,
|
|
133
|
+
ssid=self.ssid,
|
|
134
|
+
password=self.password,
|
|
135
|
+
app_notify=self.notify,
|
|
136
|
+
)
|
|
137
|
+
self.session.start()
|
|
138
|
+
self.set_interval(0.5, self._refresh_tables)
|
|
139
|
+
|
|
140
|
+
def handle_packet(self, pkt: airshark.Packet) -> None:
|
|
141
|
+
if pkt.is_eapol:
|
|
142
|
+
# freeze channel for 5s to ensure we capture the full 4-way handshake
|
|
143
|
+
self.hopper.pause(5.0)
|
|
144
|
+
|
|
145
|
+
# Process directly in the background thread (State is thread-safe!).
|
|
146
|
+
# This completely bypasses the UI queue, allowing thousands of packets/sec!
|
|
147
|
+
self.state.process_packet(pkt)
|
|
148
|
+
|
|
149
|
+
def _refresh_tables(self) -> None:
|
|
150
|
+
aps = self.state.get_access_points_snapshot()
|
|
151
|
+
clients = self.state.get_clients_snapshot()
|
|
152
|
+
|
|
153
|
+
self._render_ap_table(aps)
|
|
154
|
+
self._render_client_table(aps, clients)
|
|
155
|
+
|
|
156
|
+
self.query_one(StatusBar).update_status(
|
|
157
|
+
self.hopper,
|
|
158
|
+
self.state.total_packets,
|
|
159
|
+
self.state.decrypted_packets,
|
|
160
|
+
self.ssid or "",
|
|
161
|
+
len(aps),
|
|
162
|
+
len(clients),
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
def _rssi_markup(self, rssi: int | None) -> str:
|
|
166
|
+
if rssi is None:
|
|
167
|
+
return "N/A"
|
|
168
|
+
if rssi >= -60:
|
|
169
|
+
return f"[bold green]{rssi} dBm[/]"
|
|
170
|
+
if rssi >= -75:
|
|
171
|
+
return f"[yellow]{rssi} dBm[/]"
|
|
172
|
+
return f"[red]{rssi} dBm[/]"
|
|
173
|
+
|
|
174
|
+
def _render_ap_table(self, aps: dict) -> None:
|
|
175
|
+
from textual.widgets.data_table import DuplicateKey
|
|
176
|
+
table = self.query_one("#ap-table", DataTable)
|
|
177
|
+
for bssid, data in aps.items():
|
|
178
|
+
ssid = data["SSID"] or ""
|
|
179
|
+
if self.ssid and ssid == self.ssid:
|
|
180
|
+
ssid_display = f"[bold green]{ssid}[/] [dim][dec][/dim]"
|
|
181
|
+
elif ssid:
|
|
182
|
+
ssid_display = ssid
|
|
183
|
+
else:
|
|
184
|
+
ssid_display = "[dim]<Hidden>[/dim]"
|
|
185
|
+
|
|
186
|
+
ch_display = str(data["Channel"]) if data["Channel"] is not None else "?"
|
|
187
|
+
rssi_display = self._rssi_markup(data["RSSI"])
|
|
188
|
+
pkts_display = str(data["Packets"])
|
|
189
|
+
|
|
190
|
+
try:
|
|
191
|
+
table.add_row(
|
|
192
|
+
bssid, ssid_display, ch_display, rssi_display, pkts_display,
|
|
193
|
+
key=bssid,
|
|
194
|
+
)
|
|
195
|
+
except DuplicateKey:
|
|
196
|
+
table.update_cell(bssid, "ssid", ssid_display)
|
|
197
|
+
table.update_cell(bssid, "ch", ch_display)
|
|
198
|
+
table.update_cell(bssid, "rssi", rssi_display)
|
|
199
|
+
table.update_cell(bssid, "pkts", pkts_display)
|
|
200
|
+
|
|
201
|
+
table.sort("rssi", key=lambda val: int(str(val).split(" dBm")[0].split("]")[-1]) if "dBm" in str(val) else -200, reverse=True)
|
|
202
|
+
|
|
203
|
+
def _render_client_table(self, aps: dict, clients: dict) -> None:
|
|
204
|
+
from textual.widgets.data_table import DuplicateKey
|
|
205
|
+
table = self.query_one("#client-table", DataTable)
|
|
206
|
+
for mac, data in clients.items():
|
|
207
|
+
ap_bssid = data["AP BSSID"]
|
|
208
|
+
ap_ssid = aps.get(ap_bssid, {}).get("SSID")
|
|
209
|
+
ap_label = f"[green]{ap_ssid}[/]" if ap_ssid else (ap_bssid or "?")
|
|
210
|
+
|
|
211
|
+
eapol = data.get("eapol_msgs", set())
|
|
212
|
+
if not eapol:
|
|
213
|
+
hs = ""
|
|
214
|
+
elif {1, 2, 3, 4}.issubset(eapol):
|
|
215
|
+
hs = "[bold red]4WHS[/]"
|
|
216
|
+
else:
|
|
217
|
+
hs = ",".join(str(m) for m in sorted(eapol))
|
|
218
|
+
|
|
219
|
+
ch_display = str(data["Channel"]) if data["Channel"] is not None else "?"
|
|
220
|
+
pkts_display = str(data["Packets"])
|
|
221
|
+
|
|
222
|
+
try:
|
|
223
|
+
table.add_row(
|
|
224
|
+
mac, ap_label, ch_display, hs, pkts_display,
|
|
225
|
+
key=mac,
|
|
226
|
+
)
|
|
227
|
+
except DuplicateKey:
|
|
228
|
+
table.update_cell(mac, "ap", ap_label)
|
|
229
|
+
table.update_cell(mac, "ch", ch_display)
|
|
230
|
+
table.update_cell(mac, "hs", hs)
|
|
231
|
+
table.update_cell(mac, "pkts", pkts_display)
|
|
232
|
+
|
|
233
|
+
table.sort("pkts", key=lambda val: int(str(val)) if str(val).isdigit() else 0, reverse=True)
|
|
234
|
+
|
|
235
|
+
def action_toggle_hop(self) -> None:
|
|
236
|
+
self.hopper.toggle_pause()
|
|
237
|
+
|
|
238
|
+
def action_next_channel(self) -> None:
|
|
239
|
+
self.hopper.next_channel()
|
|
240
|
+
|
|
241
|
+
def action_prev_channel(self) -> None:
|
|
242
|
+
self.hopper.prev_channel()
|
|
243
|
+
|
|
244
|
+
def action_interval_up(self) -> None:
|
|
245
|
+
self.hopper.adjust_interval(+0.25)
|
|
246
|
+
|
|
247
|
+
def action_interval_down(self) -> None:
|
|
248
|
+
self.hopper.adjust_interval(-0.25)
|
|
249
|
+
|
|
250
|
+
def on_unmount(self) -> None:
|
|
251
|
+
self.hopper.stop()
|
|
252
|
+
if self.session:
|
|
253
|
+
self.session.stop()
|
|
254
|
+
|
|
255
|
+
# Restore normal Wi-Fi connection when app closes
|
|
256
|
+
from airshark.channel import reconnect_wifi
|
|
257
|
+
reconnect_wifi(self.interface)
|
|
258
|
+
|
|
259
|
+
async def action_quit(self) -> None:
|
|
260
|
+
import asyncio
|
|
261
|
+
self.hopper.stop()
|
|
262
|
+
if self.session:
|
|
263
|
+
await asyncio.to_thread(self.session.stop)
|
|
264
|
+
self.exit()
|