From 27d64d2bed305c29d9015dfcd52c12b41f07149e Mon Sep 17 00:00:00 2001 From: Yaro Kasear Date: Tue, 6 May 2025 09:04:53 -0500 Subject: [PATCH] Enhance channel hopping by adding dynamic hop interval calculation based on observation duration --- listener.py | 9 +++++---- runtest.sh | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/listener.py b/listener.py index 8091a42..ba9229d 100755 --- a/listener.py +++ b/listener.py @@ -35,7 +35,7 @@ unlinked_candidates = set() bssid_channels = {} vendor_cache = {} -CHANNEL_LIST = [1, 6, 11, 36, 40, 48, 52, 64, 153, 161] # Channels to hop +CHANNEL_LIST = [1, 6, 11, 36, 40, 48, 52, 64, 100, 104, 108, 112, 149, 153, 161] # Channels to hop CHANNEL_HOP_INTERVAL = 5 # Seconds per channel def get_channel_from_freq(freq): @@ -245,14 +245,14 @@ def print_suspect_aps(): else: print(" None found (yet).") -def channel_hopper(interface): +def channel_hopper(interface, hop_interval): global running i = 0 while running: channel = CHANNEL_LIST[i % len(CHANNEL_LIST)] set_monitor_channel(interface, channel) i += 1 - time.sleep(CHANNEL_HOP_INTERVAL) + time.sleep(hop_interval) def is_deadpoint(ap_bssid): return sum(ap_clients[ap_bssid].values()) < 2 # No meaningful client interaction @@ -267,6 +267,7 @@ def main(): group = parser.add_mutually_exclusive_group() group.add_argument("--channel", type=int, help="Channel to lock monitor interface to") group.add_argument("--channel-hop", action="store_true", help="Enable channel hopping") + group.add_argument("--hop-interval", type=int, default=CHANNEL_HOP_INTERVAL, help="Interval for channel hopping (default: 5 seconds)") args = parser.parse_args() @@ -300,7 +301,7 @@ def main(): print("[+] Sniffing... (waiting for SIGINT to stop)") if args.channel_hop: - hopper_thread = threading.Thread(target=channel_hopper, args=(args.monitor_iface,)) + hopper_thread = threading.Thread(target=channel_hopper, args=(args.monitor_iface,args.hop_interval)) hopper_thread.daemon = True hopper_thread.start() diff --git a/runtest.sh b/runtest.sh index 171df78..923d31c 100755 --- a/runtest.sh +++ b/runtest.sh @@ -169,6 +169,8 @@ for ((COUNTER = 1; COUNTER <= NUM_TESTS; COUNTER++)); do log "Test run $COUNTER of $NUM_TESTS" for ((i = 1; i <= NUM_SAMPLES; i++)); do + OBS_START=$(date +%s) + if [ "$LISTENER_ENABLED" -eq 1 ]; then LISTENER_SAMPLE_FILE="${TEST_FILE%.csv}-listener-$COUNTER-$i.csv" @@ -176,12 +178,23 @@ for ((COUNTER = 1; COUNTER <= NUM_TESTS; COUNTER++)); do READY_FILE="/tmp/listener_ready_${COUNTER}_${i}" - log "Launching listener with args: --main-iface $INTERFACE --monitor-iface $LISTEN_INTERFACE --outfile $LISTENER_SAMPLE_FILE ${LISTENER_ARGS[*]}" + ADAPTIVE_ARGS=("${LISTENER_ARGS[@]}") + if [[ " ${LISTENER_ARGS[*]} " =~ "--channel-hop" ]]; then + NUM_CHANNELS=15 # Update if your list changes + OBS_NOW=$(date +%s) + ESTIMATED_OBS_DURATION=$((OBS_NOW - OBS_START)) + HOP_INTERVAL=$((ESTIMATED_OBS_DURATION / (NUM_CHANNELS + 1))) + [[ "$HOP_INTERVAL" -lt 2 ]] && HOP_INTERVAL=2 # Don't go too fast + log "Estimated observation time: ${ESTIMATED_OBS_DURATION}s → Setting hop interval: ${HOP_INTERVAL}s" + ADAPTIVE_ARGS+=("--hop-interval" "$HOP_INTERVAL") + fi + + log "Launching listener with args: --main-iface $INTERFACE --monitor-iface $LISTEN_INTERFACE --outfile $LISTENER_SAMPLE_FILE ${ADAPTIVE_ARGS[*]}" sudo "${SCRIPT_DIRECTORY}/listener.py" \ --main-iface "$INTERFACE" \ --monitor-iface "$LISTEN_INTERFACE" \ --outfile "$LISTENER_SAMPLE_FILE" \ - "${LISTENER_ARGS[@]}" > >(tee "$READY_FILE") & + "${ADAPTIVE_ARGS[@]}" > >(tee "$READY_FILE") & LISTENER_PID=$! # Wait for the READY_FILE to contain "LISTENING_STARTED"