Skip to content

Instantly share code, notes, and snippets.

@lukeswitz
Created March 16, 2024 12:58
Show Gist options
  • Save lukeswitz/d0024a7bfcedcb1363fdd2e545829273 to your computer and use it in GitHub Desktop.
Save lukeswitz/d0024a7bfcedcb1363fdd2e545829273 to your computer and use it in GitHub Desktop.
PiWardriver: A script to dynamically start kismet
#!/bin/bash
# Adapted from github.com/bksieski/WardrivingScript_pi4_rig
# Wait 30s for interfaces and GPS to init
sleep 30
# Function to enable monitor mode on network adapters
enable_monitor_mode() {
echo "Enabling monitor mode on ${interfaces[@]}..."
for interface in "${interfaces[@]}"; do
ifconfig "$interface" down
iwconfig "$interface" mode Monitor
ifconfig "$interface" up
done
}
# Function to disable monitor mode on network adapters
disable_monitor_mode() {
echo "Disabling monitor mode on ${interfaces[@]}..."
for interface in "${interfaces[@]}"; do
ifconfig "$interface" down
iwconfig "$interface" mode Managed
ifconfig "$interface" up
done
}
# Start Kismet
start_kismet() {
# Create a folder with the current date
current_date=$(date +%Y%m%d)
kismet_folder="/home/toothpaste/wardriving/${current_date}"
echo "Starting Kismet with data directory: $kismet_folder"
# Check if the folder exists, if not, create it
if [ ! -d "$kismet_folder" ]; then
mkdir -p "$kismet_folder"
fi
# Start Kismet with the specified interfaces
kismet_command="kismet -p '$kismet_folder' -t wardrive --override wardrive"
for interface in "${interfaces[@]}"; do
kismet_command+=" -c $interface"
done
kismet_command+=" &"
eval "$kismet_command"
# The '&' runs the command in the background, allowing the script to continue
# Store the PID (Process ID) of the Kismet process
kismet_pid=$!
}
# Start gpsd with the specified GPS device
gpsd -n /dev/ttyUBS0 &
# Detect network interfaces
interfaces=()
for interface in $(ls /sys/class/net); do
if [[ $interface =~ ^wlan ]]; then
interfaces+=("$interface")
fi
done
# Enable monitor mode
enable_monitor_mode
# Start Kismet in the background
start_kismet
# Monitor keyboard input to stop Kismet
echo "Press any key to stop Kismet session."
# Wait for any key press (this will block until a key is pressed)
read -n 1 -s
# Stop Kismet by killing the process
echo "Stopping Kismet..."
kill "$kismet_pid"
# Disable monitor mode after Kismet is stopped
disable_monitor_mode
echo "Wardriving/warcycling/warwalking session completed."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment