-
Notifications
You must be signed in to change notification settings - Fork 40
/
probes.py
2792 lines (1917 loc) · 89.9 KB
/
probes.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
import socket
import errno
import logging
import os
import platform
if platform.system() != 'Java':
from select import select
else:
from select import cpython_compatible_select as select
# Disable socks support in Jython
if platform.system() != 'Java':
import socks
else:
if os.environ.has_key('socks_proxy'):
logging.warn('Unable to honour socks_proxy environment variable, unsupported in Jython')
from prober_utils import *
settings = {
# Note that changing these will invalidate many of the fingerprints
'default_hello_version': TLSRecord.TLS1_0,
'default_record_version': TLSRecord.TLS1_0,
'socket_timeout': 5
}
class Probe(object):
#
# Reusable standard elements
#
def __init__(self):
self.ipaddress = None
def connect(self, ipaddress, port, starttls_mode):
self.ipaddress = ipaddress
# Check if we're using socks
if os.environ.has_key('socks_proxy'):
socks_host, socks_port = os.environ['socks_proxy'].split(':')
s = socks.socksocket()
s.setproxy(socks.PROXY_TYPE_SOCKS5, socks_host, int(socks_port))
else:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(settings['socket_timeout'])
s.connect((ipaddress, port))
# Do starttls if relevant
starttls(s, port, starttls_mode)
return s.makefile('rw', 0)
def test(self, sock):
pass
def process_response(self, sock):
response = ''
got_done = False
while True:
# Check if there is anything following the server done
if got_done:
# If no data then we're done (the server hasn't sent anything further)
# we allow 500ms to give the followup time to arrive
if not select([sock.fileno(),],[],[],0.5)[0]:
break
try:
record = read_tls_record(sock)
response += '*(%x)' % record.version() # TODO: Not sure that recording the record layer version is worth it?
except socket.timeout, e:
response += 'error:timeout'
break
except socket.error, e:
response += 'error:%s|' % errno.errorcode[e.errno]
break
except IOError, e:
response += 'error:%s|' % str(e)
break
if record.content_type() == TLSRecord.Handshake:
# A single handshake record can contain multiple handshake messages
processed_bytes = 0
while processed_bytes < record.message_length():
message = HandshakeMessage.from_bytes(record.message()[processed_bytes:])
if message.message_type() == message.ServerHello:
response += 'handshake:%s(%x)|' % (message.message_types[message.message_type()], message.server_version())
else:
response += 'handshake:%s|' % (message.message_types[message.message_type()])
if message.message_type() == HandshakeMessage.ServerHelloDone:
got_done = True
processed_bytes += message.message_length() + 4
if got_done:
continue
elif record.content_type() == TLSRecord.Alert:
alert = AlertMessage.from_bytes(record.message())
if alert.alert_level() == AlertMessage.Fatal:
response += 'alert:%s:fatal|' % alert.alert_types[alert.alert_type()]
break
else:
response += 'alert:%s:warning|' % alert.alert_types[alert.alert_type()]
else:
if record.content_types.has_key(record.content_type()):
response += 'record:%s|' % record.content_types[record.content_type()]
else:
response += 'record:type(%x)|' % record.content_type()
if got_done:
break
return response
def probe(self, ipaddress, port, starttls):
sock = self.connect(ipaddress, port, starttls)
try:
result = self.test(sock)
except socket.timeout, e:
result = 'writeerror:timeout'
return result
except socket.error, e:
result = 'writeerror:%s|' % errno.errorcode[e.errno]
return result
if result:
return result
return self.process_response(sock)
class NormalHandshake(Probe):
'''A normal handshake'''
def __init__(self):
super(NormalHandshake, self).__init__()
self.make_hello = make_hello
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
class NormalHandshakePFS(NormalHandshake):
'''Normal handshake with PFS ciphersuites'''
def __init__(self):
super(NormalHandshakePFS, self).__init__()
self.make_hello = make_pfs_hello
class NormalHandshake11(NormalHandshake):
'''Normal TLSv1.1 handshake'''
def __init__(self):
super(NormalHandshake11, self).__init__()
self.make_hello = make_11_hello
class NormalHandshake11PFS(NormalHandshake):
'''Normal TLSv1.1 handshake'''
def __init__(self):
super(NormalHandshake11PFS, self).__init__()
self.make_hello = make_11_pfs_hello
class NormalHandshake12(NormalHandshake):
'''Normal TLSv1.2 handshake'''
def __init__(self):
super(NormalHandshake12, self).__init__()
self.make_hello = make_12_hello
class NormalHandshake12PFS(NormalHandshake):
'''Normal TLSv1.2 handshake with PFS ciphersuites'''
def __init__(self):
super(NormalHandshake12PFS, self).__init__()
self.make_hello = make_12_pfs_hello
class NormalHandshake12PFSw13(Probe):
'''TLSv1.2 with PFS ciphers with a TLSv1.3 version (invalid TLSv1.3)'''
def make_hello(self):
hello = ClientHelloMessage.create(TLSRecord.TLS1_3,
'01234567890123456789012345678901',
DEFAULT_PFS_CIPHERS)
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=TLSRecord.TLS1_0,
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
class InvalidSessionID(Probe):
'''Send session ID that is too long'''
def __init__(self):
self.hello_version = TLSRecord.TLS1_0
self.ciphers = DEFAULT_CIPHERS
def make_hello_payload(self, version, cipher_suites):
session_id = b'0123456789' * 4 # session ID is up to 32 bytes long
ciphers = struct.pack('>H{0}H'.format(len(cipher_suites)),
len(cipher_suites) * 2, *cipher_suites)
hello = (struct.pack('>H32sB',
version,
b'01234567890123456789012345678901',
len(session_id)) +
session_id + ciphers + b'\x01\x00' + b'\x00\x00')
return hello
def make_hello(self, version, cipher_suites):
hello = self.make_hello_payload(version, cipher_suites)
hello_msg = HandshakeMessage.create(HandshakeMessage.ClientHello,
hello)
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=TLSRecord.TLS1_0,
message=hello_msg.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Helo...')
sock.write(self.make_hello(self.hello_version, self.ciphers))
class InvalidSessionID12(InvalidSessionID):
'''Send session ID that is too long in TLSv1.2 hello'''
def __init__(self):
super(InvalidSessionID12, self).__init__()
self.hello_version = TLSRecord.TLS1_2
self.ciphers = DEFAULT_12_CIPHERS
class InvalidSessionID12PFS(InvalidSessionID):
'''Send session ID that is too long in PFS TLSv1.2 hello'''
def __init__(self):
super(InvalidSessionID12PFS, self).__init__()
self.hello_version = TLSRecord.TLS1_2
self.ciphers = DEFAULT_PFS_CIPHERS
class InvalidCiphersLength(InvalidSessionID):
'''Send client hello with length field of ciphers that is invalid (odd)'''
def make_hello_payload(self, version, cipher_suites):
cipher_bytes = struct.pack('>{0}H'.format(len(cipher_suites)),
*cipher_suites) + b'\x00'
ciphers = struct.pack('>H', len(cipher_bytes)) + cipher_bytes
hello = (struct.pack('>H32sB', version,
b'01234567890123456789012345678901',
0) +
ciphers + b'\x01\x00' + b'\x00\x00')
return hello
class InvalidCiphersLength12(InvalidCiphersLength, InvalidSessionID12):
'''As with InvalidCiphersLength but with TLSv1.2 helo'''
pass
class InvalidCiphersLength12PFS(InvalidCiphersLength, InvalidSessionID12PFS):
'''As with InvalidCiphersLength but with PFS TLSv1.2 hello'''
pass
class InvalidExtLength(InvalidSessionID):
'''Send client hello with length of extensions filed truncated'''
def make_hello_payload(self, version, cipher_suites):
ciphers = struct.pack('>H{0}H'.format(len(cipher_suites)),
len(cipher_suites) * 2, *cipher_suites)
hello = (struct.pack('>H32sB',
version,
b'01234567890123456789012345678901',
0) +
ciphers + b'\x01\x00' + b'\x00')
return hello
class InvalidExtLength12(InvalidExtLength, InvalidSessionID12):
'''As with InvalidExtLength but in TLSv1.2 hello'''
pass
class InvalidExtLength12PFS(InvalidExtLength, InvalidSessionID12PFS):
'''As with InvalidExtLength but in PFS TLSv1.2 hello'''
pass
class ExtensionsUnderflow(InvalidSessionID):
'''Send hello with data length lower than stated size'''
def make_hello_payload(self, version, cipher_suites):
ciphers = struct.pack('>H{0}H'.format(len(cipher_suites)),
len(cipher_suites) * 2, *cipher_suites)
hello = (struct.pack('>H32sB',
version,
b'01234567890123456789012345678901',
0) +
ciphers + b'\x01\x00'
b'\x00\x01' # extensions length, just one byte
b'\xff\x01' # extension ID - secure renego indication
b'\x00\x01' # secure renego indication ext length
b'\x00') # valid payload for extension
return hello
class ExtensionsUnderflow12(ExtensionsUnderflow, InvalidSessionID12):
'''As in ExtensionsUnderflow but in TLSv1.2 hello'''
pass
class ExtensionsUnderflow12PFS(ExtensionsUnderflow, InvalidSessionID12PFS):
'''As in ExtensionsUnderflow but in PFS TLSv1.2 hello'''
pass
class EmptyCompression(InvalidSessionID):
'''Send hello with no compression methods'''
def make_hello_payload(self, version, cipher_suites):
ciphers = struct.pack('>H{0}H'.format(len(cipher_suites)),
len(cipher_suites) * 2, *cipher_suites)
hello = (struct.pack('>H32sB',
version,
b'01234567890123456789012345678901',
0) +
ciphers + b'\x00' + b'\x00\x00')
return hello
class EmptyCompression12(EmptyCompression, InvalidSessionID12):
'''As with EmptyCompression but in TLSv1.2 hello'''
pass
class EmptyCompression12PFS(EmptyCompression, InvalidSessionID12PFS):
'''As with EmptyCompression but in PFS TLSv1.2 hello'''
pass
class CompressOnly(InvalidSessionID):
'''Send hello with no support for uncompressed communication'''
def make_hello_payload(self, version, cipher_suites):
ciphers = struct.pack('>H{0}H'.format(len(cipher_suites)),
len(cipher_suites) * 2, *cipher_suites)
hello = (struct.pack('>H32sB',
version,
b'01234567890123456789012345678901',
0) +
ciphers + b'\x02\x01\x40' + b'\x00\x00')
return hello
class CompressOnly12(CompressOnly, InvalidSessionID12):
'''As with CompressOnly but in TLSv1.2 hello'''
pass
class CompressOnly12PFS(CompressOnly, InvalidSessionID12PFS):
'''As with CompressOnly but in PFS TLSv1.2 hello'''
pass
class DoubleClientHello(NormalHandshake):
'''Two client hellos'''
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
class DoubleClientHello12(DoubleClientHello, NormalHandshake12):
'''Two client hellos, TLSv1.2'''
pass
class DoubleClientHello12PFS(DoubleClientHello, NormalHandshake12PFS):
'''Two client hellos, TLSv1.2 w/PFS ciphers'''
pass
class ChangeCipherSpec(NormalHandshake):
'''Send a hello then change cipher spec'''
def __init__(self):
super(ChangeCipherSpec, self).__init__()
self.make_ccs = make_ccs
self.record_version = TLSRecord.TLS1_0
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
logging.debug('Sending ChangeCipherSpec...')
sock.write(self.make_ccs(self.record_version))
class ChangeCipherSpec12(ChangeCipherSpec, NormalHandshake12):
'''Send TLSv1.2 hello then change cipher spec'''
def __init__(self):
super(ChangeCipherSpec12, self).__init__()
self.record_version = TLSRecord.TLS1_2
class ChangeCipherSpec12PFS(NormalHandshake12PFS, ChangeCipherSpec12):
'''Send PFS TLSv1.2 hello then change cipher spec'''
pass
class HelloRequest(NormalHandshake):
'''Send a hello then hello request'''
def __init__(self):
super(HelloRequest, self).__init__()
self.make_hello_request = make_hello_request
self.record_version = TLSRecord.TLS1_0
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
logging.debug('Sending Hello Request...')
sock.write(self.make_hello_request(self.record_version))
class HelloRequest12(HelloRequest, NormalHandshake12):
'''Send a TLSv1.2 hello then hello request'''
def __init__(self):
super(HelloRequest12, self).__init__()
self.record_version = TLSRecord.TLS1_2
class HelloRequest12PFS(NormalHandshake12PFS, HelloRequest12):
'''Send a PFS TLSv1.2 hello then hello request'''
pass
class EmptyChangeCipherSpec(NormalHandshake):
'''Send a hello then an empty change cipher spec'''
def __init__(self):
super(EmptyChangeCipherSpec, self).__init__()
self.record_version = TLSRecord.TLS1_0
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
logging.debug('Sending Empty ChangeCipherSpec...')
record = TLSRecord.create(content_type=TLSRecord.ChangeCipherSpec,
version=self.record_version,
message='')
sock.write(record.bytes)
class EmptyChangeCipherSpec12(EmptyChangeCipherSpec, NormalHandshake12):
'''Send TLSv1.2 hello then an empty change cipher spec'''
def __init__(self):
super(EmptyChangeCipherSpec12, self).__init__()
self.record_version = TLSRecord.TLS1_2
class EmptyChangeCipherSpec12PFS(NormalHandshake12PFS,
EmptyChangeCipherSpec12):
'''Send PFS TLSv1.2 hello then an empty change cipher spec'''
pass
class BadHandshakeMessage(Probe):
'''An invalid handshake message'''
def make_bad_handshake(self):
content = 'Something'
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=TLSRecord.TLS1_0,
message=content)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(make_hello())
logging.debug('Sending bad handshake message...')
sock.write(self.make_bad_handshake())
class OnlyECCipherSuites(Probe):
'''Try connecting with ECC cipher suites only'''
def make_ec_hello(self):
hello = ClientHelloMessage.create(TLSRecord.TLS1_0,
'01234567890123456789012345678901',
[TLS_ECDH_RSA_WITH_RC4_128_SHA,
TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA,
TLS_ECDH_RSA_WITH_AES_128_CBC_SHA,
TLS_ECDH_RSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256])
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=TLSRecord.TLS1_0,
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_ec_hello())
class Heartbeat(NormalHandshake):
'''Try to send a heartbeat message'''
def __init__(self):
super(Heartbeat, self).__init__()
self.record_version = TLSRecord.TLS1_0
def make_hb_hello(self):
hb_extension = HeartbeatExtension.create()
return self.make_hello([hb_extension])
def make_heartbeat(self):
heartbeat = HeartbeatMessage.create(HeartbeatMessage.HeartbeatRequest,
'XXXX')
record = TLSRecord.create(content_type=TLSRecord.Heartbeat,
version=self.record_version,
message=heartbeat.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_hb_hello())
logging.debug('Sending Heartbeat...')
sock.write(self.make_heartbeat())
class Heartbeat12(NormalHandshake12, Heartbeat):
'''Try to send a heartbeat message in TLSv1.2 connection'''
def __init__(self):
super(Heartbeat12, self).__init__()
self.record_version = TLSRecord.TLS1_2
class Heartbeat12PFS(NormalHandshake12PFS, Heartbeat12):
'''Try to send a hearbeat message in PFS TLSv1.2 connection'''
pass
class Heartbleed(Heartbeat):
'''Try to send a heartbleed attack'''
def make_heartbeat(self):
heartbeat = HeartbeatMessage.create(HeartbeatMessage.HeartbeatRequest,
'XXXX', 0x4000)
record = TLSRecord.create(content_type=TLSRecord.Heartbeat,
version=self.record_version,
message=heartbeat.bytes)
#hexdump(record.bytes)
return record.bytes
class Heartbleed12(Heartbeat12, Heartbleed):
'''Try to send a heartbleed attack in TLSv1.2'''
pass
class Heartbleed12PFS(Heartbeat12PFS, Heartbleed):
'''Try to send a heartbleed attack in TLSv1.2'''
pass
class HighTLSVersion(Probe):
'''Set a high TLS version in the record'''
def make_hello(self):
hello = ClientHelloMessage.create(settings['default_hello_version'],
'01234567890123456789012345678901',
DEFAULT_CIPHERS)
return hello
def make_high_tls_hello(self):
hello = self.make_hello()
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=0x400,
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_high_tls_hello())
class HighTLSVersion12(HighTLSVersion):
'''Set a high TLS version in the record of TLSv1.2 hello'''
def make_hello(self):
hello = ClientHelloMessage.create(TLSRecord.TLS1_2,
'01234567890123456789012345678901',
DEFAULT_12_CIPHERS)
return hello
class HighTLSVersion12PFS(HighTLSVersion):
'''Set a high TLS version in the record of PFS TLSv1.2 hello'''
def make_hello(self):
hello = ClientHelloMessage.create(TLSRecord.TLS1_2,
'01234567890123456789012345678901',
DEFAULT_PFS_CIPHERS)
return hello
class VeryHighTLSVersion(HighTLSVersion):
'''Set a very high TLS version in the record'''
def make_high_tls_hello(self):
hello = self.make_hello()
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=0xffff,
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
class VeryHighTLSVersion12(HighTLSVersion12, VeryHighTLSVersion):
'''Set a very high TLS version in the record of TLSv1.2 hello'''
pass
class VeryHighTLSVersion12PFS(HighTLSVersion12PFS, VeryHighTLSVersion):
'''Set a very high TLS version in the record of PFS TLSv1.2 hello'''
pass
class ZeroTLSVersion(HighTLSVersion):
'''Set a zero version in the record'''
def make_high_tls_hello(self):
hello = self.make_hello()
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=0x000,
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
class ZeroTLSVersion12(HighTLSVersion12, ZeroTLSVersion):
'''Set a zero version in the record of TLSv1.2 hello'''
pass
class ZeroTLSVersion12PFS(HighTLSVersion12PFS, ZeroTLSVersion):
'''Set a zero version in the record of PFS TLSv1.2 hello'''
pass
class HighHelloVersion(Probe):
'''Set a high version in the hello'''
def __init__(self):
super(HighHelloVersion, self).__init__()
self.hello_version = 0x400
self.hello_ciphers = DEFAULT_CIPHERS
def make_high_tls_hello(self):
hello = ClientHelloMessage.create(self.hello_version,
'01234567890123456789012345678901',
self.hello_ciphers)
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_high_tls_hello())
class HighHelloVersionNew(HighHelloVersion):
'''Set a high version in a hello with more ciphers'''
def __init__(self):
super(HighHelloVersionNew, self).__init__()
self.hello_ciphers = DEFAULT_12_CIPHERS
class HighHelloVersionPFS(HighHelloVersion):
'''Set a high version in a hello with PFS ciphers'''
def __init__(self):
super(HighHelloVersionPFS, self).__init__()
self.hello_ciphers = DEFAULT_PFS_CIPHERS
class VeryHighHelloVersion(HighHelloVersion):
'''Set a very high version in the hello'''
def __init__(self):
super(VeryHighHelloVersion, self).__init__()
self.hello_version = 0xffff
class VeryHighHelloVersionNew(HighHelloVersionNew, VeryHighHelloVersion):
'''Set a very high version in the hello with more ciphers'''
pass
class VeryHighHelloVersionPFS(HighHelloVersionPFS, VeryHighHelloVersion):
'''Set a very high version in the hello with PFS ciphers'''
pass
class ZeroHelloVersion(Probe):
'''Set a zero version in the hello'''
def make_zero_tls_hello(self):
hello = ClientHelloMessage.create(0x000,
'01234567890123456789012345678901',
DEFAULT_CIPHERS)
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_zero_tls_hello())
class BadContentType(Probe):
'''Use an invalid content type in the record'''
def make_bad_content_type(self):
hello = ClientHelloMessage.create(settings['default_hello_version'],
'01234567890123456789012345678901',
DEFAULT_CIPHERS)
record = TLSRecord.create(content_type=17,
version=settings['default_record_version'],
message=hello.bytes)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_bad_content_type())
class RecordLengthOverflow(Probe):
'''Make the record length exceed the stated one'''
def make_record_length_overflow(self):
hello = ClientHelloMessage.create(settings['default_hello_version'],
'01234567890123456789012345678901',
DEFAULT_CIPHERS)
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=hello.bytes,
length=0x0001)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
sock.write(self.make_record_length_overflow())
class RecordLengthUnderflow(Probe):
'''Make the record shorter than the specified length'''
def make_record_length_underflow(self):
hello = ClientHelloMessage.create(settings['default_hello_version'],
'01234567890123456789012345678901',
DEFAULT_CIPHERS)
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=hello.bytes,
length=0xffff)
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending Client Hello...')
try:
sock.write(self.make_record_length_underflow())
except socket.timeout, e:
result = 'writeerror:timeout'
return result
except socket.error, e:
result = 'writeerror:%s|' % errno.errorcode[e.errno]
return result
class EmptyRecord(NormalHandshake):
'''Send an empty record then the hello'''
def make_empty_record(self):
record = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message='')
#hexdump(record.bytes)
return record.bytes
def test(self, sock):
logging.debug('Sending empty record...')
sock.write(self.make_empty_record())
logging.debug('Sending Client Hello...')
sock.write(self.make_hello())
class EmptyRecord12(NormalHandshake12, EmptyRecord):
'''Send an empty record then TLSv1.2 hello'''
pass
class EmptyRecord12PFS(NormalHandshake12PFS, EmptyRecord):
'''Send and empty record then PFS TLSv1.2 hello'''
pass
class TwoInvalidPackets(Probe):
'''Send two invalid messages'''
def test(self, sock):
logging.debug('Sending split hello...')
part_one = '<tls.record.TLSRecord object at 0x7fd2dc0906d0>'
part_two = '<tls.record.TLSRecord object at 0x7fd2dc090690>'
sock.write(part_one)
try:
sock.write(part_two)
except socket.timeout, e:
result = 'writeerror:timeout'
return result
except socket.error, e:
result = 'writeerror:%s|' % errno.errorcode[e.errno]
return result
class SplitHelloRecords(Probe):
'''Split the hello over two records'''
def make_split_hello(self):
hello = ClientHelloMessage.create(settings['default_hello_version'],
'01234567890123456789012345678901',
DEFAULT_CIPHERS)
first = hello.bytes[:10]
second = hello.bytes[10:]
record_one = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=first)
record_two = TLSRecord.create(content_type=TLSRecord.Handshake,
version=0x301,
message=second)
#hexdump(record.bytes)
return record_one.bytes, record_two.bytes
def test(self, sock):
logging.debug('Sending split hello...')
part_one, part_two = self.make_split_hello()
sock.write(part_one)
try:
sock.write(part_two)
except socket.timeout, e:
result = 'writeerror:timeout'
return result
except socket.error, e:
result = 'writeerror:%s|' % errno.errorcode[e.errno]
return result
class SplitHelloRecords12(SplitHelloRecords):
'''Split the TLS1.2 hello over two records'''
def make_split_hello(self):
hello = ClientHelloMessage.create(TLSRecord.TLS1_2,
'01234567890123456789012345678901',
DEFAULT_12_CIPHERS)
first = hello.bytes[:10]
second = hello.bytes[10:]
record_one = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=first)
record_two = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=second)
#hexdump(record.bytes)
return record_one.bytes, record_two.bytes
class SplitHelloRecords12PFS(SplitHelloRecords):
'''Split the TLS1.2 PFS hello over two records'''
def make_split_hello(self):
hello = ClientHelloMessage.create(TLSRecord.TLS1_2,
'01234567890123456789012345678901',
DEFAULT_PFS_CIPHERS)
first = hello.bytes[:10]
second = hello.bytes[10:]
record_one = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=first)
record_two = TLSRecord.create(content_type=TLSRecord.Handshake,
version=settings['default_record_version'],
message=second)
#hexdump(record.bytes)
return record_one.bytes, record_two.bytes
class SplitHelloPackets(NormalHandshake):
'''Split the hello over two packets'''
def test(self, sock):
logging.debug('Sending Client Hello part one...')
record = self.make_hello()
sock.write(record[:10])
sock.flush()
logging.debug('Sending Client Hello part two...')
sock.write(record[10:])
class SplitHelloPackets12(SplitHelloPackets, NormalHandshake12):
'''Split the TLS1.2 hello over two packets'''
pass
class SplitHelloPackets12PFS(SplitHelloPackets, NormalHandshake12PFS):
'''Split the TLS1.2 PFS hello over two packets'''
pass