100 lines
2.4 KiB
Bash
Executable File
100 lines
2.4 KiB
Bash
Executable File
#!/bin/bash
|
|
# Test script to verify monitor mode works with tshark
|
|
|
|
set -e
|
|
|
|
INTERFACE="${1:-wlan0}"
|
|
CHANNEL="${2:-36}"
|
|
|
|
echo "=== Testing Monitor Mode with tshark ==="
|
|
echo "Interface: $INTERFACE"
|
|
echo "Channel: $CHANNEL"
|
|
echo ""
|
|
|
|
# Check if running as root
|
|
if [ "$EUID" -ne 0 ]; then
|
|
echo "Please run as root (use sudo)"
|
|
exit 1
|
|
fi
|
|
|
|
# Check if tshark is installed
|
|
if ! command -v tshark &> /dev/null; then
|
|
echo "tshark is not installed. Installing..."
|
|
if command -v apt-get &> /dev/null; then
|
|
sudo apt-get update
|
|
sudo apt-get install -y tshark
|
|
elif command -v dnf &> /dev/null; then
|
|
sudo dnf install -y wireshark-cli
|
|
else
|
|
echo "Please install tshark manually"
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Unmanage from NetworkManager
|
|
if command -v nmcli &> /dev/null; then
|
|
echo "Unmanaging interface from NetworkManager..."
|
|
nmcli device set "$INTERFACE" managed no 2>/dev/null || true
|
|
fi
|
|
|
|
# Unblock WiFi
|
|
rfkill unblock wifi 2>/dev/null || true
|
|
|
|
# Bring down interface
|
|
echo "Bringing down interface..."
|
|
ip link set "$INTERFACE" down 2>/dev/null || true
|
|
sleep 0.5
|
|
|
|
# Set monitor mode
|
|
echo "Setting monitor mode..."
|
|
if ! iw dev "$INTERFACE" set type monitor; then
|
|
echo "Error: Failed to set monitor mode"
|
|
exit 1
|
|
fi
|
|
|
|
sleep 0.5
|
|
|
|
# Bring up interface
|
|
echo "Bringing up interface..."
|
|
ip link set "$INTERFACE" up || echo "Warning: Failed to bring interface up"
|
|
|
|
sleep 0.5
|
|
|
|
# Set channel
|
|
echo "Setting channel to $CHANNEL..."
|
|
iw dev "$INTERFACE" set channel "$CHANNEL" || echo "Warning: Failed to set channel"
|
|
|
|
# Verify monitor mode
|
|
echo ""
|
|
echo "Verifying monitor mode..."
|
|
iw dev "$INTERFACE" info | grep -E "(type|channel)" || echo "Could not verify"
|
|
|
|
# Check DLT with tshark
|
|
echo ""
|
|
echo "Checking Data Link Type..."
|
|
tshark -i "$INTERFACE" -T fields -e frame.number -c 1 2>&1 | head -5 || true
|
|
|
|
echo ""
|
|
echo "=== Starting tshark capture (10 seconds) ==="
|
|
echo "Press Ctrl+C to stop early"
|
|
echo ""
|
|
|
|
# Capture for 10 seconds
|
|
timeout 10 tshark -i "$INTERFACE" -n -T fields \
|
|
-e frame.number \
|
|
-e frame.time \
|
|
-e wlan.sa \
|
|
-e wlan.da \
|
|
-e wlan.type \
|
|
-e wlan.fc.type_subtype \
|
|
2>&1 | head -20
|
|
|
|
echo ""
|
|
echo "=== Capture complete ==="
|
|
echo ""
|
|
echo "If you saw packets above, monitor mode is working!"
|
|
echo "If not, check:"
|
|
echo " 1. Is there WiFi traffic on channel $CHANNEL?"
|
|
echo " 2. Is the interface actually in monitor mode? (iw dev $INTERFACE info)"
|
|
echo " 3. Try a different channel (e.g., 1, 6, 11 for 2.4GHz)"
|