Skip to content

Commit c885113

Browse files
authored
Merge pull request #7 from CyberRoute/timeout_progress
chore: format Python code and update README
2 parents 0cf497f + dbee778 commit c885113

11 files changed

Lines changed: 1485 additions & 291 deletions

File tree

.pylintrc

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
11
[MASTER]
22
init-hook='import sys; sys.path.append(".")'
3-
extension-pkg-allow-list=netifaces
3+
extension-pkg-allow-list=netifaces,scapy,setuptools
4+
5+
[DESIGN]
6+
max-args=11
7+
max-positional-arguments=11
8+
max-attributes=15
9+
max-locals=18
10+
max-statements=80
11+
12+
[MESSAGES CONTROL]
13+
disable=too-few-public-methods,import-outside-toplevel

README.md

Lines changed: 111 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,169 @@
11
<p align="center">
22
<img alt="Phantom" src="https://raw.githubusercontent.com/CyberRoute/phantom/main/images/phantom_logo.png"/>
3-
<p align="center">
4-
</p>
53
</p>
64

75
---
86

97
# Phantom
108

119
## Overview
12-
Phantom is an **ARP Scanner** mostly designed to detect directly connected IoT devices. The tool provides details like IP addresses, MAC addresses, hostnames, and the manufacturers of the devices based on their MAC addresses.
13-
The tool features a graphical user interface (GUI) built with **PySide6** (Qt framework) and utilizes **scapy** for ARP scanning.
1410

15-
---
11+
Phantom is a **network reconnaissance and security auditing tool** designed for directly connected networks. It discovers devices via ARP scanning, tracks their history, detects ARP spoofing attacks, and can perform MITM interception with live packet analysis powered by a local LLM.
12+
13+
The GUI is built with **PySide6** (Qt framework) and uses **Scapy** for all packet-level operations.
1614

17-
## Features
18-
- **Network Scanning**: Identifies devices on the network via ARP requests.
19-
- **Device Details**: Displays IP address, MAC address, hostname, and vendor information.
20-
- **Graphical User Interface**: Easy-to-use UI to display the scanned devices and packet information.
21-
- **Multithreading**: Ensures non-blocking scans using Python's `QThread`.
22-
- **C extension**: for MacOSX there is a C extension that allows slow sequential but very accurate arp scanning
2315
---
2416

25-
## Prerequisites
17+
## Features
2618

27-
Ensure the following dependencies are installed:
19+
- **ARP Network Scanning**: Discovers devices via ARP requests, displaying IP, MAC, hostname, and vendor.
20+
- **Device History & Persistence**: Stores scan results in a local SQLite database; previously seen devices are shown on startup.
21+
- **New Device & MAC Change Detection**: Highlights new devices (green) and IP-to-MAC binding changes (red) — a classic ARP spoofing indicator.
22+
- **ARP Spoof Detection**: Passive background sniffer that alerts on conflicting ARP bindings and gateway MAC changes.
23+
- **MITM Interception**: ARP-spoof a target to intercept its traffic; captured packets are displayed in real time with a full layer-by-layer breakdown.
24+
- **LLM Packet Analysis**: Send any captured packet to a local [Ollama](https://ollama.com) instance for AI-assisted analysis (protocol identification, risk assessment, credential spotting).
25+
- **PCAP Export**: Save captured packets from a MITM session as a `.pcap` file for offline analysis in Wireshark.
26+
- **Scan Export**: Export scan results to JSON or CSV.
27+
- **Progress Bar**: Live progress feedback during scanning.
28+
- **Custom CIDR Target**: Scan a specific subnet instead of the local interface network.
29+
- **Multithreading**: All network operations run in `QThread` workers — the UI stays responsive throughout.
30+
- **C Extension (macOS)**: A native C extension provides accurate, sequential ARP scanning on macOS where Scapy bulk-send is unreliable.
2831

29-
1. **Python 3.12 or higher**
30-
2. **scapy**: Used for ARP scanning.
31-
3. **PySide6**: For building the GUI.
32-
4. **netifaces**: To retrieve network interface details.
32+
---
3333

3434
## Requirements
3535

3636
- **Python 3.12+**
37-
- **scapy**: For ARP scanning and packet manipulation.
38-
- **PySide6**: For building the graphical user interface.
39-
- **netifaces**: To retrieve network interface details.
37+
- **scapy** — ARP scanning and packet manipulation
38+
- **PySide6** — graphical user interface
39+
- **netifaces** — network interface introspection
40+
- **requests** — Ollama API streaming
41+
- **Ollama** (optional) — local LLM for packet analysis (`ollama serve`)
4042

4143
---
4244

4345
## Installation
4446

4547
1. **Clone the repository**:
4648

47-
Clone the repository to your local machine:
48-
4949
```bash
5050
git clone https://github.com/CyberRoute/phantom.git
5151
cd phantom
5252
```
5353

54-
2. **Install the dependencies with Pipenv**:
55-
56-
Install `pip` if it's not already installed:
54+
2. **Create a virtual environment and install dependencies**:
5755

5856
```bash
5957
virtualenv env
6058
source env/bin/activate
6159
pip install -r requirements.txt
6260
```
6361

64-
3. **Run the application**:
65-
66-
Run the ARP Scanner using the following command. You need to provide the network interface (like `eth0`, `wlan0`, or `wlp0s20f3`) for your system:
62+
3. **(macOS only) Build the native C extension**:
6763

6864
```bash
69-
sudo `which python3` main.py --interface <interface> --timeout 500
70-
```
71-
72-
On Ubuntu in case you run into this error:
73-
```
74-
(env) alessandro@alessandro-XPS-9315:~/Development/phantom$ sudo /home/alessandro/Development/phantom/env/bin/python3 main.py --interface wlp0s20f3
75-
qt.qpa.plugin: From 6.5.0, xcb-cursor0 or libxcb-cursor0 is needed to load the Qt xcb platform plugin.
76-
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
77-
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
78-
Available platform plugins are: eglfs, minimal, wayland, vkkhrdisplay, offscreen, linuxfb, xcb, wayland-egl, minimalegl, vnc.
79-
```
80-
Solution:
81-
```
82-
sudo apt install libxcb-cursor0
83-
```
84-
On Macos there is a C extension that allows accurate but slow arpscan. To build and install the extension:
85-
```
8665
pip install setuptools
8766
cd c_extension
8867
python setup.py build
8968
python setup.py install
69+
cd ..
9070
```
9171

92-
## Usage Instructions
72+
4. **Run the application** (root/sudo is required for raw packet operations):
9373

94-
1. **Start the Application**:
74+
```bash
75+
sudo `which python3` main.py --interface <interface> --timeout 500
76+
```
77+
78+
Optional arguments:
9579

96-
After running the application with the correct interface, the GUI will launch.
80+
| Argument | Default | Description |
81+
|---|---|---|
82+
| `--interface` | *(required)* | Network interface name (e.g. `eth0`, `wlan0`) |
83+
| `--timeout` | `1000` | ARP scan timeout in milliseconds |
84+
| `--target` | interface network | Custom CIDR range to scan (e.g. `10.0.0.0/24`) |
9785

98-
<div align="center">
99-
<img src="/images/phantom.png" width="800px"</img>
100-
</div>
86+
### Troubleshooting (Ubuntu / xcb plugin error)
10187

102-
2. **Scanning the Network**:
88+
```
89+
qt.qpa.plugin: Could not load the Qt platform plugin "xcb"
90+
```
10391
104-
- Click on the **"Scan"** button in the UI to initiate a network scan.
105-
- The tool will display a list of all detected devices in the network, including their IP addresses, MAC addresses, hostnames, and vendors.
92+
Fix:
10693
107-
3. **Device Details**:
94+
```bash
95+
sudo apt install libxcb-cursor0
96+
```
97+
98+
---
10899

109-
- Click on any device in the list to open a detailed window that shows more information about that particular device.
100+
## Usage
110101

111-
4. **Stopping the Scan**:
102+
### 1. Scan the network
112103

113-
- Press the **"Quit"** button to stop the ARP scan and close the application.
104+
Click **Scan** to start an ARP sweep of the local network (or a custom CIDR if `--target` was specified). Devices appear as they respond:
105+
106+
- **White** — previously seen device, confirmed live
107+
- **Green** — new device (first time seen)
108+
- **Red** — IP address answered with a different MAC than before (possible ARP spoofing)
109+
- **Grey** — device from the database not yet confirmed live in this scan
110+
111+
A progress bar tracks scan completion. Results can be exported to JSON or CSV with **Export Results**.
112+
113+
### 2. Inspect a device
114+
115+
Click any device in the list to open its detail window, which shows:
116+
117+
- IP, MAC, hostname, vendor
118+
- First seen / last seen timestamps
119+
- Full MAC address history (useful for spoofing audits)
120+
- MITM controls
121+
122+
### 3. MITM interception
123+
124+
From the device detail window, click **Start MITM** to:
125+
126+
1. ARP-spoof the target and the gateway (Phantom inserts itself in the traffic path).
127+
2. Enable IP forwarding so the target's internet access is preserved.
128+
3. Capture all non-ARP traffic to/from the target in real time.
129+
130+
Click any captured packet to see a full hex dump and layer-by-layer field breakdown.
131+
Click **Save PCAP** to write the captured session to a `.pcap` file.
132+
133+
> **Note:** MITM requires root/sudo. IP forwarding is restored automatically when MITM is stopped.
134+
135+
### 4. LLM packet analysis (Ollama)
136+
137+
With [Ollama](https://ollama.com) running locally (`ollama serve`) and a model pulled (default: `deepseek-r1:1.5b`):
138+
139+
1. Select a captured packet in the MITM window.
140+
2. Optionally add context in the **Context** field (e.g. `"this is a smart TV"`).
141+
3. Click **Analyse with LLM** — the analysis streams in token by token.
142+
143+
The LLM identifies protocol/service, describes what the endpoints are doing, flags security-relevant observations, and provides a risk rating.
144+
145+
---
146+
147+
## Architecture
148+
149+
```
150+
main.py — entry point, CLI args, QApplication bootstrap
151+
core/
152+
arp_scanner.py — ARPScannerThread, DeviceDiscoveryDialog, DeviceDetailsWindow
153+
arp_spoofer.py — low-level ARP spoof / restore primitives
154+
mitm.py — MitmThread (spoof loop + sniffer), IP forwarding management
155+
spoof_detector.py — passive ARP sniff-based spoof detection
156+
ollama_analyst.py — OllamaThread for streaming LLM packet analysis
157+
db.py — SQLite persistence (device history, MAC audit trail)
158+
networking.py — CIDR calculation, hostname resolution helpers
159+
vendor.py — OUI/MAC vendor lookup
160+
platform.py — OS detection helper
161+
c_extension/ — native C ARP scanner for macOS
162+
ui/ — PySide6 .ui compiled files
163+
```
164+
165+
---
114166

115167
## Contribute
116-
Fork the repo and send PRs if you like :)
117168

169+
Fork the repo and send PRs if you like :)

c_extension/setup.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from setuptools import setup, Extension
2-
import sysconfig
1+
"""Build configuration for the native arpscanner C extension."""
32
import os
3+
import sysconfig
4+
5+
from setuptools import setup, Extension # pylint: disable=import-error
46

57
# For macOS, we need to explicitly include libpcap
68
extra_compile_args = []
@@ -20,4 +22,4 @@
2022
name='ArpScanner',
2123
version='1.0',
2224
ext_modules=[module]
23-
)
25+
)

0 commit comments

Comments
 (0)