This repository has been archived by the owner on Dec 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 137
/
sslyze.py
975 lines (819 loc) · 33.3 KB
/
sslyze.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
###
# Inspect a site's TLS configuration using sslyze.
#
# If data exists for a domain from `pshtt`, will check results
# and only process domains with valid HTTPS, or broken chains.
#
# Supported options:
#
# --sslyze-serial - If set, will use a synchronous (single-threaded
# in-process) scanner. Defaults to true.
# --sslyze-certs - If set, will use the CertificateInfoScanner and
# return certificate info. Defaults to true.
###
import logging
import datetime
from typing import Any
from sslyze.server_connectivity_tester import ServerConnectivityTester, ServerConnectivityError
from sslyze.synchronous_scanner import SynchronousScanner
from sslyze.concurrent_scanner import ConcurrentScanner, PluginRaisedExceptionScanResult
from sslyze.plugins.openssl_cipher_suites_plugin import Tlsv10ScanCommand, Tlsv11ScanCommand, Tlsv12ScanCommand, Tlsv13ScanCommand, Sslv20ScanCommand, Sslv30ScanCommand
from sslyze.plugins.certificate_info_plugin import CertificateInfoScanCommand, _SymantecDistructTester
from sslyze.plugins.session_renegotiation_plugin import SessionRenegotiationScanCommand
from sslyze.ssl_settings import TlsWrappedProtocolEnum
import idna
import cryptography
import cryptography.hazmat.backends.openssl
from cryptography.hazmat.primitives.serialization import Encoding
from cryptography.hazmat.primitives.asymmetric import ec, dsa, rsa
from utils import FAST_CACHE_KEY, utils
# Number of seconds to wait during sslyze connection check.
# Not much patience here, and very willing to move on.
network_timeout = 5
# Advertise Lambda support
lambda_support = True
# File with custom root and intermediate certs that should be trusted
# for verifying the cert chain
CA_FILE = None
# If we have pshtt data, use it to skip some domains, and to adjust
# scan hostnames to canonical URLs where we can.
#
# If we have trustymail data, use it to identify any mail servers that
# support STARTTLS so we can scan them.
#
# Check the fastcache to determine if we have already tested any of
# the mail servers when scanning other domains.
def init_domain(domain, environment, options):
hosts_to_scan = []
cached_data = []
cache_dir = options.get('_', {}).get('cache_dir', './cache')
# If we have pshtt data, skip domains which pshtt saw as not
# supporting HTTPS at all.
if utils.domain_doesnt_support_https(domain, cache_dir=cache_dir):
logging.warning('\tHTTPS not supported for {}'.format(domain))
else:
# If we have pshtt data and it says canonical endpoint uses
# www and the given domain is bare, add www.
if utils.domain_uses_www(domain, cache_dir=cache_dir):
hostname = 'www.%s' % domain
else:
hostname = domain
hosts_to_scan.append({
'hostname': hostname,
'port': 443,
'starttls_smtp': False
})
# If we have trustymail data, see if there are any mail servers
# that support STARTTLS that we should scan
mail_servers_to_test = utils.domain_mail_servers_that_support_starttls(domain, cache_dir=cache_dir)
for mail_server in mail_servers_to_test:
# Check if we already have results for this mail server,
# possibly from a different domain.
#
# I have found that SMTP servers (as compared to HTTP/HTTPS
# servers) are MUCH more sensitive to having multiple
# connections made to them. In testing the various cyphers we
# make a lot of connections, and multiple government domains
# often use the same SMTP servers, so it makes sense to check
# if we have already hit this mail server when testing a
# different domain.
cached_value = None
if FAST_CACHE_KEY in environment:
cached_value = environment[FAST_CACHE_KEY].get(mail_server, None)
if cached_value is None:
logging.debug('Adding {} to list to be scanned'.format(mail_server))
hostname_and_port = mail_server.split(':')
hosts_to_scan.append({
'hostname': hostname_and_port[0],
'port': int(hostname_and_port[1]),
'starttls_smtp': True
})
else:
logging.debug('Using cached data for {}'.format(mail_server))
cached_data.append(cached_value)
if not hosts_to_scan:
logging.warning('\tNo hosts to scan for {}'.format(domain))
return {
'hosts_to_scan': hosts_to_scan,
'cached_data': cached_data
}
# Run sslyze on the given domain.
def scan(domain, environment, options):
# Allow hostnames to be adjusted by init_domain
default_host = {
'hostname': domain,
'port': 443,
'starttls_smtp': False
}
retVal = []
for host_to_scan in environment.get('hosts_to_scan', [default_host]):
data = {
'hostname': host_to_scan.get('hostname'),
'port': host_to_scan.get('port'),
'starttls_smtp': host_to_scan.get('starttls_smtp'),
'protocols': {},
'config': {},
'certs': {},
'errors': []
}
# Run the SSLyze scan on the given hostname.
response = run_sslyze(data, environment, options)
# Error condition.
if response is None:
error = "No valid target for scanning, couldn't connect."
logging.warning(error)
data['errors'].append(error)
# Join all errors into a string before returning.
data['errors'] = ' '.join(data['errors'])
retVal.append(data)
# Return the scan results together with the already-cached results
# (if there were any)
retVal.extend(environment['cached_data'])
return retVal
def post_scan(domain: str, data: Any, environment: dict, options: dict):
"""Post-scan hook for sslyze
Add SMTP results to the fast cache, keyed by the concatenation of
the mail server and port. Do not update if an appropriate cache
entry appeared while we were running, since the earlier entry is
more likely to be correct because it is less likely to have
triggered any defenses that are in place.
Parameters
----------
domain : str
The domain being scanned.
data : Any
The result returned by the scan function for the domain
currently being scanned.
environment: dict
The environment data structure associated with the scan that
produced the results in data.
options: dict
The CLI options.
"""
# Make sure fast caching hasn't been disabled
if not options['no_fast_cache'] and data is not None:
if FAST_CACHE_KEY not in environment:
environment[FAST_CACHE_KEY] = {}
fast_cache = environment[FAST_CACHE_KEY]
# Add the SMTP host results to the fast cache
for record in data:
if record['starttls_smtp']:
key = '{}:{}'.format(record['hostname'],
record['port'])
# Avoid overwriting the cached data if someone
# else wrote it while we were running
if key not in fast_cache:
fast_cache[key] = record
# Given a response dict, turn it into CSV rows.
def to_rows(data):
retVal = []
for row in data:
ev = row.get('certs', {}).get('ev', {})
retVal.append([
row['hostname'],
row['port'],
row['starttls_smtp'],
row['protocols'].get('sslv2'), row['protocols'].get('sslv3'),
row['protocols'].get('tlsv1.0'), row['protocols'].get('tlsv1.1'),
row['protocols'].get('tlsv1.2'), row['protocols'].get('tlsv1.3'),
row['config'].get('any_dhe'), row['config'].get('all_dhe'),
row['config'].get('any_rc4'), row['config'].get('all_rc4'),
row['config'].get('any_3des'),
row['certs'].get('key_type'), row['certs'].get('key_length'),
row['certs'].get('leaf_signature'),
row['certs'].get('any_sha1_served'),
row['certs'].get('any_sha1_constructed'),
row['certs'].get('not_before'), row['certs'].get('not_after'),
row['certs'].get('served_issuer'), row['certs'].get('constructed_issuer'),
ev.get('asserted'), ev.get('trusted'),
str.join(", ", ev.get('trusted_oids', [])),
str.join(", ", ev.get('trusted_browsers', [])),
row['certs'].get('is_symantec_cert'),
row['certs'].get('symantec_distrust_date'),
row['config'].get('any_export'),
row['config'].get('any_NULL'),
row['config'].get('any_MD5'),
row['config'].get('any_less_than_128_bits'),
row['config'].get('insecure_renegotiation'),
row['certs'].get('certificate_less_than_2048'),
row['certs'].get('md5_signed_certificate'),
row['certs'].get('sha1_signed_certificate'),
row['certs'].get('expired_certificate'),
str.join(', ', row.get('ciphers', [])),
row.get('errors')
])
return retVal
headers = [
"Scanned Hostname",
"Scanned Port",
"STARTTLS SMTP",
"SSLv2", "SSLv3", "TLSv1.0", "TLSv1.1", "TLSv1.2", "TLSv1.3",
"Any Forward Secrecy", "All Forward Secrecy",
"Any RC4", "All RC4",
"Any 3DES",
"Key Type", "Key Length",
"Signature Algorithm",
"SHA-1 in Served Chain",
"SHA-1 in Constructed Chain",
"Not Before", "Not After",
"Highest Served Issuer", "Highest Constructed Issuer",
"Asserts EV", "Trusted for EV",
"EV Trusted OIDs", "EV Trusted Browsers",
"Is Symantec Cert", "Symantec Distrust Date",
"Any Export", "Any NULL", "Any MD5", "Any Less Than 128 Bits",
"Insecure Renegotiation",
"Certificate Less Than 2048",
"MD5 Signed Certificate", "SHA-1 Signed Certificate",
"Expired Certificate",
"Accepted Ciphers",
"Errors"
]
# Get the relevant fields out of sslyze's JSON format.
#
# Certificate PEM data must be separately parsed using
# the Python cryptography module.
def run_sslyze(data, environment, options):
# Each sslyze worker can use a sync or parallel mode.
#
# SynchronousScanner can show memory leaks when parsing certs,
# so local scanning defaults to using ConcurrentScanner.
#
# And Lambda can't use multiprocessing.Queue, so in the cloud,
# this default cannot be overridden.
scan_method = environment.get("scan_method", "local")
if scan_method == "lambda":
sync = True
else:
sync = options.get("sslyze_serial", True)
# Initialize either a synchronous or concurrent scanner.
server_info, scanner = init_sslyze(data['hostname'], data['port'], data['starttls_smtp'], options, sync=sync)
if server_info is None:
data['errors'].append("Connectivity not established.")
return data
# Whether sync or concurrent, get responses for all scans.
if sync:
sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3, certs, reneg = scan_serial(scanner, server_info, data, options)
else:
sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3, certs, reneg = scan_parallel(scanner, server_info, data, options)
# Only analyze protocols if all the scanners functioned.
# Very difficult to draw conclusions if some worked and some did not.
if sslv2 and sslv3 and tlsv1 and tlsv1_1 and tlsv1_2 and tlsv1_3:
analyze_protocols_and_ciphers(data, sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3)
if certs:
data['certs'] = analyze_certs(certs)
if reneg:
analyze_reneg(data, reneg)
return data
def analyze_protocols_and_ciphers(data, sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3):
data['protocols'] = {
'sslv2': supported_protocol(sslv2),
'sslv3': supported_protocol(sslv3),
'tlsv1.0': supported_protocol(tlsv1),
'tlsv1.1': supported_protocol(tlsv1_1),
'tlsv1.2': supported_protocol(tlsv1_2),
'tlsv1.3': supported_protocol(tlsv1_3)
}
accepted_ciphers = (
(sslv2.accepted_cipher_list or []) +
(sslv3.accepted_cipher_list or []) +
(tlsv1.accepted_cipher_list or []) +
(tlsv1_1.accepted_cipher_list or []) +
(tlsv1_2.accepted_cipher_list or []) +
(tlsv1_3.accepted_cipher_list or [])
)
data['ciphers'] = [cipher.name for cipher in accepted_ciphers]
if len(accepted_ciphers) > 0:
# Look at accepted cipher suites for RC4 or DHE.
# This is imperfect, as the advertising of RC4 could discriminate based on client.
# DHE and ECDHE may not remain the only forward secret options for TLS.
any_rc4 = False
any_dhe = False
all_rc4 = True
all_dhe = True
any_3des = False
any_export = False
any_NULL = False
any_MD5 = False
any_less_than_128_bits = False
for cipher in accepted_ciphers:
name = cipher.openssl_name
if "RC4" in name:
any_rc4 = True
else:
all_rc4 = False
if ("3DES" in name) or ("DES-CBC3" in name):
any_3des = True
if name.startswith("DHE-") or name.startswith("ECDHE-"):
any_dhe = True
else:
all_dhe = False
if ("EXPORT" in name):
any_export = True
if ("NULL" in name):
any_NULL = True
if ("MD5" in name):
any_MD5 = True
parts = name.split('_')
for p in parts:
if (p.isdigit()) and (int(p) < 128):
any_less_than_128_bits = True
data['config']['any_rc4'] = any_rc4
data['config']['all_rc4'] = all_rc4
data['config']['any_dhe'] = any_dhe
data['config']['all_dhe'] = all_dhe
data['config']['any_3des'] = any_3des
data['config']['any_export'] = any_export
data['config']['any_NULL'] = any_NULL
data['config']['any_MD5'] = any_MD5
data['config']['any_less_than_128_bits'] = any_less_than_128_bits
def analyze_certs(certs):
data = {'certs': {}}
# Served chain.
served_chain = certs.received_certificate_chain
# Constructed chain may not be there if it didn't validate.
constructed_chain = certs.verified_certificate_chain
highest_served = parse_cert(served_chain[-1])
issuer = cert_issuer_name(highest_served)
if issuer:
data['certs']['served_issuer'] = issuer
else:
data['certs']['served_issuer'] = "(None found)"
if (constructed_chain and (len(constructed_chain) > 0)):
highest_constructed = parse_cert(constructed_chain[-1])
issuer = cert_issuer_name(highest_constructed)
if issuer:
data['certs']['constructed_issuer'] = issuer
else:
data['certs']['constructed_issuer'] = "(None constructed)"
leaf = parse_cert(served_chain[0])
leaf_key = leaf.public_key()
if hasattr(leaf_key, "key_size"):
data['certs']['key_length'] = leaf_key.key_size
elif hasattr(leaf_key, "curve"):
data['certs']['key_length'] = leaf_key.curve.key_size
else:
data['certs']['key_length'] = None
if(data['certs']['key_length'] < 2048):
data['certs']['certificate_less_than_2048'] = True
else:
data['certs']['certificate_less_than_2048'] = False
if isinstance(leaf_key, rsa.RSAPublicKey):
leaf_key_type = "RSA"
elif isinstance(leaf_key, dsa.DSAPublicKey):
leaf_key_type = "DSA"
elif isinstance(leaf_key, ec.EllipticCurvePublicKey):
leaf_key_type = "ECDSA"
else:
leaf_key_type == str(leaf_key.__class__)
data['certs']['key_type'] = leaf_key_type
# Signature of the leaf certificate only.
data['certs']['leaf_signature'] = leaf.signature_hash_algorithm.name
if(leaf.signature_hash_algorithm.name == "MD5"):
data['certs']['md5_signed_certificate'] = True
else:
data['certs']['md5_signed_certificate'] = False
if(leaf.signature_hash_algorithm.name == "SHA1"):
data['certs']['sha1_signed_certificate'] = True
else:
data['certs']['sha1_signed_certificate'] = False
# Beginning and expiration dates of the leaf certificate
data['certs']['not_before'] = leaf.not_valid_before
data['certs']['not_after'] = leaf.not_valid_after
now = datetime.datetime.now()
if (now < leaf.not_valid_before) or (now > leaf.not_valid_after):
data['certs']['expired_certificate'] = True
else:
data['certs']['expired_certificate'] = False
any_sha1_served = False
for cert in served_chain:
if parse_cert(cert).signature_hash_algorithm.name == "sha1":
any_sha1_served = True
data['certs']['any_sha1_served'] = any_sha1_served
if data['certs'].get('constructed_issuer'):
data['certs']['any_sha1_constructed'] = certs.verified_chain_has_sha1_signature
extensions = leaf.extensions
oids = []
try:
ext = extensions.get_extension_for_class(cryptography.x509.extensions.CertificatePolicies)
policies = ext.value
for policy in policies:
oids.append(policy.policy_identifier.dotted_string)
except cryptography.x509.ExtensionNotFound:
# If not found, just move on.
pass
data['certs']['ev'] = {
'asserted': False,
'trusted': False,
'trusted_oids': [],
'trusted_browsers': []
}
for oid in oids:
# If it matches the generic EV OID, the certifciate is
# asserting that it was issued following the EV guidelines.
data['certs']['ev']['asserted'] = (oid == evg_oid)
# Check which browsers for which the cert is marked as EV.
browsers = []
if oid in mozilla_ev:
browsers.append("Mozilla")
if oid in google_ev:
browsers.append("Google")
if oid in microsoft_ev:
browsers.append("Microsoft")
if oid in apple_ev:
browsers.append("Apple")
if len(browsers) > 0:
data['certs']['ev']['trusted'] = True
# Log each new OID we observe as marked for EV.
if oid not in data['certs']['ev']['trusted_oids']:
data['certs']['ev']['trusted_oids'].append(oid)
# For all matching browsers, log each new one.
for browser in browsers:
if browser not in data['certs']['ev']['trusted_browsers']:
data['certs']['ev']['trusted_browsers'].append(browser)
# Is this cert issued by Symantec?
is_symantec_cert = certs.verified_chain_has_legacy_symantec_anchor
data['certs']['is_symantec_cert'] = is_symantec_cert
if is_symantec_cert:
# The distrust date is no longer passed down from when this
# test is originally run, so we have to repeat the test here
# to determine it. It shouldn't get run that often.
distrust_timeline = _SymantecDistructTester.get_distrust_timeline(constructed_chain)
data['certs']['symantec_distrust_date'] = distrust_timeline.name
else:
data['certs']['symantec_distrust_date'] = None
return data['certs']
# Given the cert sub-obj from the sslyze JSON, use
# the cryptography module to parse its PEM contents.
def parse_cert(cert):
backend = cryptography.hazmat.backends.openssl.backend
pem_bytes = cert.public_bytes(Encoding.PEM).decode('ascii').encode('utf-8')
return cryptography.x509.load_pem_x509_certificate(pem_bytes, backend)
# Given a parsed cert from the cryptography module,
# get the issuer name as best as possible
def cert_issuer_name(parsed):
attrs = parsed.issuer.get_attributes_for_oid(cryptography.x509.oid.NameOID.COMMON_NAME)
if len(attrs) == 0:
attrs = parsed.issuer.get_attributes_for_oid(cryptography.x509.oid.NameOID.ORGANIZATIONAL_UNIT_NAME)
if len(attrs) == 0:
return None
return attrs[0].value
# Analyze the results of a renegotiation test
def analyze_reneg(data, reneg):
if (reneg.accepts_client_renegotiation is True) and (reneg.supports_secure_renegotiation is False):
data['config']['insecure_renegotiation'] = True
else:
data['config']['insecure_renegotiation'] = False
# Given CipherSuiteScanResult, whether the protocol is supported
def supported_protocol(result):
return (len(result.accepted_cipher_list) > 0)
# SSlyze initialization boilerplate
def init_sslyze(hostname, port, starttls_smtp, options, sync=False):
global network_timeout, CA_FILE
network_timeout = int(options.get("network_timeout", network_timeout))
if options.get('ca_file'):
CA_FILE = options['ca_file']
tls_wrapped_protocol = TlsWrappedProtocolEnum.PLAIN_TLS
if starttls_smtp:
tls_wrapped_protocol = TlsWrappedProtocolEnum.STARTTLS_SMTP
try:
# logging.debug("\tTesting connectivity with timeout of %is." % network_timeout)
server_tester = ServerConnectivityTester(hostname=hostname, port=port, tls_wrapped_protocol=tls_wrapped_protocol)
server_info = server_tester.perform(network_timeout=network_timeout)
except ServerConnectivityError:
logging.exception("\tServer connectivity not established during test.")
return None, None
except Exception as err:
utils.notify(err)
logging.exception("\tUnknown exception when performing server connectivity info.")
return None, None
if sync:
scanner = SynchronousScanner(network_timeout=network_timeout)
else:
scanner = ConcurrentScanner(network_timeout=network_timeout)
return server_info, scanner
# Run each scan in-process, one at a time.
# Takes longer, but no multi-process funny business.
def scan_serial(scanner, server_info, data, options):
errors = 0
def run_scan(scan_type, command, errors):
if(errors >= 2):
return None, errors
logging.debug("\t\t{} scan.".format(scan_type))
result = None
try:
result = scanner.run_scan_command(server_info, command)
except Exception as err:
logging.exception("{}: Error during {} scan.".format(server_info.hostname, scan_type))
logging.debug("{}: Exception during {} scan: {}".format(server_info.hostname, scan_type, err))
errors = errors + 1
return result, errors
logging.debug("\tRunning scans in serial.")
sslv2, errors = run_scan("SSLv2", Sslv20ScanCommand(), errors)
sslv3, errors = run_scan("SSLv3", Sslv30ScanCommand(), errors)
tlsv1, errors = run_scan("TLSv1.0", Tlsv10ScanCommand(), errors)
tlsv1_1, errors = run_scan("TLSv1.1", Tlsv11ScanCommand(), errors)
tlsv1_2, errors = run_scan("TLSv1.2", Tlsv12ScanCommand(), errors)
tlsv1_3, errors = run_scan("TLSv1.3", Tlsv13ScanCommand(), errors)
certs = None
if errors < 2 and options.get("sslyze_certs", True) is True:
try:
logging.debug("\t\tCertificate information scan.")
certs = scanner.run_scan_command(server_info, CertificateInfoScanCommand(ca_file=CA_FILE))
except idna.core.InvalidCodepoint:
logging.exception(utils.format_last_exception())
data['errors'].append("Invalid certificate/OCSP for this domain.")
certs = None
except Exception as err:
logging.exception("{}: Error during certificate information scan.".format(server_info.hostname))
logging.debug("{}: Exception during certificate information scan: {}".format(server_info.hostname, err))
else:
certs = None
reneg = None
if options.get("sslyze_reneg", True) is True:
reneg, errors = run_scan("Renegotiation", SessionRenegotiationScanCommand(), errors)
else:
reneg = None
logging.debug("\tDone scanning.")
return sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3, certs, reneg
# Run each scan in parallel, using multi-processing.
# Faster, but can generate many processes.
def scan_parallel(scanner, server_info, data, options):
logging.debug("\tRunning scans in parallel.")
def queue(command):
try:
return scanner.queue_scan_command(server_info, command)
except OSError:
text = ("OSError - likely too many processes and open files.")
data['errors'].append(text)
logging.exception("%s\n%s" % (text, utils.format_last_exception()))
return None, None, None, None, None, None, None
except Exception:
text = ("Unknown exception queueing sslyze command.\n%s" % utils.format_last_exception())
data['errors'].append(text)
logging.exception(text)
return None, None, None, None, None, None, None
# Initialize commands and result containers
sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3, certs, reneg = None, None, None, None, None, None, None, None
# Queue them all up
queue(Sslv20ScanCommand())
queue(Sslv30ScanCommand())
queue(Tlsv10ScanCommand())
queue(Tlsv11ScanCommand())
queue(Tlsv12ScanCommand())
queue(Tlsv13ScanCommand())
if options.get("sslyze-certs", True) is True:
queue(CertificateInfoScanCommand())
if options.get("sslyze-reneg", True) is True:
queue(CertificateInfoScanCommand())
# Reassign them back to predictable places after they're all done
was_error = False
for result in scanner.get_results():
try:
if isinstance(result, PluginRaisedExceptionScanResult):
error = ("Scan command failed: %s" % result.as_text())
logging.warning(error)
data['errors'].append(error)
return None, None, None, None, None, None, None
if type(result.scan_command) == Sslv20ScanCommand:
sslv2 = result
elif type(result.scan_command) == Sslv30ScanCommand:
sslv3 = result
elif type(result.scan_command) == Tlsv10ScanCommand:
tlsv1 = result
elif type(result.scan_command) == Tlsv11ScanCommand:
tlsv1_1 = result
elif type(result.scan_command) == Tlsv12ScanCommand:
tlsv1_2 = result
elif type(result.scan_command) == Tlsv13ScanCommand:
tlsv1_3 = result
elif type(result.scan_command) == CertificateInfoScanCommand:
certs = result
elif type(result.scan_command) == SessionRenegotiationScanCommand:
reneg = result
else:
error = "Couldn't match scan result with command! %s" % result
logging.warning("\t%s" % error)
data['errors'].append(error)
was_error = True
except Exception:
was_error = True
text = ("Exception inside async scanner result processing.\n%s" % utils.format_last_exception())
data['errors'].append(text)
logging.exception("\t%s" % text)
# There was an error during async processing.
if was_error:
return None, None, None, None, None, None, None, None
logging.debug("\tDone scanning.")
return sslv2, sslv3, tlsv1, tlsv1_1, tlsv1_2, tlsv1_3, certs, reneg
# EV Guidelines OID
evg_oid = "2.23.140.1.1"
# Google source:
# https://cs.chromium.org/chromium/src/net/cert/ev_root_ca_metadata.cc?sq=package:chromium&dr=C
google_ev = [
"1.2.392.200091.100.721.1",
"1.2.616.1.113527.2.5.1.1",
"1.3.159.1.17.1",
"1.3.171.1.1.10.5.2",
"1.3.6.1.4.1.13177.10.1.3.10",
"1.3.6.1.4.1.14370.1.6",
"1.3.6.1.4.1.14777.6.1.1",
"1.3.6.1.4.1.14777.6.1.2",
"1.3.6.1.4.1.17326.10.14.2.1.2",
"1.3.6.1.4.1.17326.10.14.2.2.2",
"1.3.6.1.4.1.17326.10.8.12.1.2",
"1.3.6.1.4.1.17326.10.8.12.2.2",
"1.3.6.1.4.1.22234.2.5.2.3.1",
"1.3.6.1.4.1.23223.1.1.1",
"1.3.6.1.4.1.29836.1.10",
"1.3.6.1.4.1.34697.2.1",
"1.3.6.1.4.1.34697.2.2",
"1.3.6.1.4.1.34697.2.3",
"1.3.6.1.4.1.34697.2.4",
"1.3.6.1.4.1.40869.1.1.22.3",
"1.3.6.1.4.1.4146.1.1",
"1.3.6.1.4.1.4788.2.202.1",
"1.3.6.1.4.1.6334.1.100.1",
"1.3.6.1.4.1.6449.1.2.1.5.1",
"1.3.6.1.4.1.782.1.2.1.8.1",
"1.3.6.1.4.1.7879.13.24.1",
"1.3.6.1.4.1.8024.0.2.100.1.2",
"2.16.156.112554.3",
"2.16.528.1.1003.1.2.7",
"2.16.578.1.26.1.3.3",
"2.16.756.1.83.21.0",
"2.16.756.1.89.1.2.1.1",
"2.16.756.5.14.7.4.8",
"2.16.792.3.0.4.1.1.4",
"2.16.840.1.113733.1.7.23.6",
"2.16.840.1.113733.1.7.48.1",
"2.16.840.1.114028.10.1.2",
"2.16.840.1.114171.500.9",
"2.16.840.1.114404.1.1.2.4.1",
"2.16.840.1.114412.2.1",
"2.16.840.1.114413.1.7.23.3",
"2.16.840.1.114414.1.7.23.3",
"2.16.840.1.114414.1.7.24.3"
]
# Mozilla source:
# https://dxr.mozilla.org/mozilla-central/source/security/certverifier/ExtendedValidation.cpp
mozilla_ev = [
"1.2.156.112559.1.1.6.1",
"1.2.392.200091.100.721.1",
"1.2.616.1.113527.2.5.1.1",
"1.3.159.1.17.1",
"1.3.171.1.1.10.5.2",
"1.3.6.1.4.1.13177.10.1.3.10",
"1.3.6.1.4.1.14370.1.6",
"1.3.6.1.4.1.14777.6.1.1",
"1.3.6.1.4.1.14777.6.1.2",
"1.3.6.1.4.1.17326.10.14.2.1.2",
"1.3.6.1.4.1.17326.10.8.12.1.2",
"1.3.6.1.4.1.22234.2.14.3.11",
"1.3.6.1.4.1.22234.2.5.2.3.1",
"1.3.6.1.4.1.22234.3.5.3.1",
"1.3.6.1.4.1.22234.3.5.3.2",
"1.3.6.1.4.1.34697.2.1",
"1.3.6.1.4.1.34697.2.2",
"1.3.6.1.4.1.34697.2.3",
"1.3.6.1.4.1.34697.2.4",
"1.3.6.1.4.1.40869.1.1.22.3",
"1.3.6.1.4.1.4146.1.1",
"1.3.6.1.4.1.4788.2.202.1",
"1.3.6.1.4.1.6334.1.100.1",
"1.3.6.1.4.1.6449.1.2.1.5.1",
"1.3.6.1.4.1.782.1.2.1.8.1",
"1.3.6.1.4.1.7879.13.24.1",
"1.3.6.1.4.1.8024.0.2.100.1.2",
"2.16.156.112554.3",
"2.16.528.1.1003.1.2.7",
"2.16.578.1.26.1.3.3",
"2.16.756.1.89.1.2.1.1",
"2.16.756.5.14.7.4.8",
"2.16.792.3.0.4.1.1.4",
"2.16.840.1.113733.1.7.23.6",
"2.16.840.1.113733.1.7.48.1",
"2.16.840.1.114028.10.1.2",
"2.16.840.1.114404.1.1.2.4.1",
"2.16.840.1.114412.2.1",
"2.16.840.1.114413.1.7.23.3",
"2.16.840.1.114414.1.7.23.3"
]
# Microsoft source:
# https://github.com/PeculiarVentures/tl-create
# Filtered to --microsoft with --for of SERVER_AUTH.
microsoft_ev = [
"0.4.0.2042.1.4",
"0.4.0.2042.1.5",
"1.2.156.112559.1.1.6.1",
"1.2.156.112559.1.1.7.1",
"1.2.156.112570.1.1.3",
"1.2.392.200091.100.721.1",
"1.2.40.0.17.1.22",
"1.2.616.1.113527.2.5.1.1",
"1.2.616.1.113527.2.5.1.7",
"1.3.159.1.17.1",
"1.3.171.1.1.1.10.5",
"1.3.171.1.1.10.5.2",
"1.3.6.1.4.1.13177.10.1.3.10",
"1.3.6.1.4.1.14370.1.6",
"1.3.6.1.4.1.14777.6.1.1",
"1.3.6.1.4.1.14777.6.1.2",
"1.3.6.1.4.1.15096.1.3.1.51.2",
"1.3.6.1.4.1.15096.1.3.1.51.4",
"1.3.6.1.4.1.17326.10.14.2.1.2",
"1.3.6.1.4.1.17326.10.16.3.6.1.3.2.1",
"1.3.6.1.4.1.17326.10.16.3.6.1.3.2.2",
"1.3.6.1.4.1.17326.10.8.12.1.1",
"1.3.6.1.4.1.17326.10.8.12.1.2",
"1.3.6.1.4.1.18332.55.1.1.2.12",
"1.3.6.1.4.1.18332.55.1.1.2.22",
"1.3.6.1.4.1.22234.2.14.3.11",
"1.3.6.1.4.1.22234.2.5.2.3.1",
"1.3.6.1.4.1.22234.3.5.3.1",
"1.3.6.1.4.1.22234.3.5.3.2",
"1.3.6.1.4.1.23223.1.1.1",
"1.3.6.1.4.1.29836.1.10",
"1.3.6.1.4.1.311.94.1.1",
"1.3.6.1.4.1.34697.2.1",
"1.3.6.1.4.1.34697.2.2",
"1.3.6.1.4.1.34697.2.3",
"1.3.6.1.4.1.34697.2.4",
"1.3.6.1.4.1.36305.2",
"1.3.6.1.4.1.38064.1.1.1.0",
"1.3.6.1.4.1.40869.1.1.22.3",
"1.3.6.1.4.1.4146.1.1",
"1.3.6.1.4.1.4146.1.2",
"1.3.6.1.4.1.4788.2.202.1",
"1.3.6.1.4.1.6334.1.100.1",
"1.3.6.1.4.1.6449.1.2.1.5.1",
"1.3.6.1.4.1.782.1.2.1.8.1",
"1.3.6.1.4.1.7879.13.24.1",
"1.3.6.1.4.1.8024.0.2.100.1.2",
"2.16.156.112554.3",
"2.16.528.1.1003.1.2.7",
"2.16.578.1.26.1.3.3",
"2.16.756.1.17.3.22.32",
"2.16.756.1.17.3.22.34",
"2.16.756.1.83.21.0",
"2.16.756.1.89.1.2.1.1",
"2.16.792.3.0.4.1.1.4",
"2.16.840.1.113733.1.7.23.6",
"2.16.840.1.113733.1.7.48.1",
"2.16.840.1.113839.0.6.9",
"2.16.840.1.114028.10.1.2",
"2.16.840.1.114404.1.1.2.4.1",
"2.16.840.1.114412.2.1",
"2.16.840.1.114413.1.7.23.3",
"2.16.840.1.114414.1.7.23.3",
"2.16.840.1.114414.1.7.24.2",
"2.16.840.1.114414.1.7.24.3"
]
# Apple source:
# https://github.com/PeculiarVentures/tl-create
# Filtered to --apple with a --for of SERVER_AUTH.
apple_ev = [
"1.2.250.1.177.1.18.2.2",
"1.2.392.200091.100.721.1",
"1.2.616.1.113527.2.5.1.1",
"1.3.159.1.17.1",
"1.3.6.1.4.1.13177.10.1.3.10",
"1.3.6.1.4.1.14370.1.6",
"1.3.6.1.4.1.14777.6.1.1",
"1.3.6.1.4.1.14777.6.1.2",
"1.3.6.1.4.1.17326.10.14.2.1.2",
"1.3.6.1.4.1.17326.10.8.12.1.2",
"1.3.6.1.4.1.18332.55.1.1.2.22",
"1.3.6.1.4.1.22234.2.14.3.11",
"1.3.6.1.4.1.22234.2.5.2.3.1",
"1.3.6.1.4.1.22234.3.5.3.1",
"1.3.6.1.4.1.23223.1.1.1",
"1.3.6.1.4.1.23223.2",
"1.3.6.1.4.1.34697.2.1",
"1.3.6.1.4.1.34697.2.2",
"1.3.6.1.4.1.34697.2.3",
"1.3.6.1.4.1.34697.2.4",
"1.3.6.1.4.1.40869.1.1.22.3",
"1.3.6.1.4.1.4146.1.1",
"1.3.6.1.4.1.4788.2.202.1",
"1.3.6.1.4.1.6334.1.100.1",
"1.3.6.1.4.1.6449.1.2.1.5.1",
"1.3.6.1.4.1.782.1.2.1.8.1",
"1.3.6.1.4.1.7879.13.24.1",
"1.3.6.1.4.1.8024.0.2.100.1.2",
"2.16.156.112554.3",
"2.16.528.1.1003.1.2.7",
"2.16.578.1.26.1.3.3",
"2.16.756.1.83.21.0",
"2.16.756.1.89.1.2.1.1",
"2.16.756.5.14.7.4.8",
"2.16.792.3.0.4.1.1.4",
"2.16.840.1.113733.1.7.23.6",
"2.16.840.1.113733.1.7.48.1",
"2.16.840.1.114028.10.1.2",
"2.16.840.1.114404.1.1.2.4.1",
"2.16.840.1.114412.1.3.0.2",
"2.16.840.1.114412.2.1",
"2.16.840.1.114413.1.7.23.3",
"2.16.840.1.114414.1.7.23.3",
"2.16.840.1.114414.1.7.24.3"
]