Class: Yawast::Scanner::SslLabs

Inherits:
Object
  • Object
show all
Defined in:
lib/scanner/ssl_labs.rb

Class Method Summary collapse

Class Method Details

.cipher_suite_secure?(suite) ⇒ Boolean

Returns:

  • (Boolean)


472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File 'lib/scanner/ssl_labs.rb', line 472

def self.cipher_suite_secure?(suite)
  secure = suite.secure?
  # check for weak DH
  if suite.dh_strength != nil && suite.dh_strength < 2048
    secure = false
  end
  # check for RC4
  if suite.name.include? 'RC4'
    secure = false
  end
  # check for weak suites
  if suite.cipher_strength < 112
    secure = false
  end

  secure
end

.get_cert_info(ep) ⇒ Object



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
# File 'lib/scanner/ssl_labs.rb', line 63

def self.get_cert_info (ep)
  # get the ChainCert info for the server cert - needed for extra details
  cert = nil
  ossl_cert = nil
  ep.details.chain.certs.each do |c|
    if c.subject == ep.details.cert.subject
      cert = c
      ossl_cert = OpenSSL::X509::Certificate.new cert.raw
    end
  end

  puts "\tCertificate Information:"
  unless ep.details.cert.valid?
    Yawast::Utilities.puts_vuln "\t\tCertificate Has Issues - Not Valid"

    if ep.details.cert.issues & 1 != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: no chain of trust"
    end

    if ep.details.cert.issues & (1<<1) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: certificate not yet valid"
    end

    if ep.details.cert.issues & (1<<2) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: certificate expired"
    end

    if ep.details.cert.issues & (1<<3) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: hostname mismatch"
    end

    if ep.details.cert.issues & (1<<4) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: revoked"
    end

    if ep.details.cert.issues & (1<<5) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: bad common name"
    end

    if ep.details.cert.issues & (1<<6) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: self-signed"
    end

    if ep.details.cert.issues & (1<<7) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: blacklisted"
    end

    if ep.details.cert.issues & (1<<8) != 0
      Yawast::Utilities.puts_vuln "\t\tCertificate Issue: insecure signature"
    end
  end

  Yawast::Utilities.puts_info "\t\tSubject: #{ep.details.cert.subject}"
  Yawast::Utilities.puts_info "\t\tCommon Names: #{ep.details.cert.common_names}"

  Yawast::Utilities.puts_info "\t\tAlternative names:"
  ep.details.cert.alt_names.each do |name|
    Yawast::Utilities.puts_info "\t\t\t#{name}"
  end

  # here we divide the time by 1000 to strip the fractions of a second off.
  Yawast::Utilities.puts_info "\t\tNot Before: #{Time.at(ep.details.cert.not_before / 1000).utc.to_datetime}"
  Yawast::Utilities.puts_info "\t\tNot After: #{Time.at(ep.details.cert.not_after / 1000).utc.to_datetime}"

  if cert.key_alg == 'EC'
    Yawast::Utilities.puts_info "\t\tKey: #{cert.key_alg} #{cert.key_size} (RSA equivalent: #{cert.key_strength})"
  else
    if cert.key_size < 2048
      Yawast::Utilities.puts_vuln "\t\tKey: #{cert.key_alg} #{cert.key_size}"
    else
      Yawast::Utilities.puts_info "\t\tKey: #{cert.key_alg} #{cert.key_size}"
    end
  end

  Yawast::Utilities.puts_info "\t\tPublic Key Hash: #{Digest::SHA1.hexdigest(ossl_cert.public_key.to_s)}"

  Yawast::Utilities.puts_info "\t\tVersion: #{ossl_cert.version}"

  Yawast::Utilities.puts_info "\t\tSerial: #{ossl_cert.serial}"

  Yawast::Utilities.puts_info "\t\tIssuer: #{ep.details.cert.issuer_label}"

  if ep.details.cert.sig_alg.include?('SHA1') || ep.details.cert.sig_alg.include?('MD5')
    Yawast::Utilities.puts_vuln "\t\tSignature algorithm: #{ep.details.cert.sig_alg}"
  else
    Yawast::Utilities.puts_info "\t\tSignature algorithm: #{ep.details.cert.sig_alg}"
  end

  #todo - figure out what the options for this value are
  if ep.details.cert.validation_type == 'E'
    Yawast::Utilities.puts_info "\t\tExtended Validation: Yes"
  elsif ep.details.cert.validation_type == 'D'
    Yawast::Utilities.puts_info "\t\tExtended Validation: No (Domain Control)"
  else
    Yawast::Utilities.puts_info "\t\tExtended Validation: No"
  end

  if ep.details.cert.sct?
    # check the first bit, SCT in cert
    if ep.details.has_sct & 1 != 0
      Yawast::Utilities.puts_info "\t\tCertificate Transparency: SCT in certificate"
    end

    # check second bit, SCT in stapled OSCP response
    if ep.details.has_sct & (1<<1) != 0
      Yawast::Utilities.puts_info "\t\tCertificate Transparency: SCT in the stapled OCSP response"
    end

    # check third bit, SCT in the TLS extension
    if ep.details.has_sct & (1<<2) != 0
      Yawast::Utilities.puts_info "\t\tCertificate Transparency: SCT in the TLS extension (ServerHello)"
    end
  else
    Yawast::Utilities.puts_info "\t\tCertificate Transparency: No"
  end

  case ep.details.cert.must_staple
    when 0
      Yawast::Utilities.puts_info "\t\tOCSP Must Staple: No"
    when 1
      Yawast::Utilities.puts_warn "\t\tOCSP Must Staple: Supported, but OCSP response is not stapled"
    when 2
      Yawast::Utilities.puts_info "\t\tOCSP Must Staple: OCSP response is stapled"
    else
      Yawast::Utilities.puts_error "\t\tOCSP Must Staple: Unknown Response #{ep.details.cert.must_staple}"
  end

  if ep.details.cert.revocation_info & 1 != 0
    Yawast::Utilities.puts_info "\t\tRevocation information: CRL information available"
  end
  if ep.details.cert.revocation_info & (1<<1) != 0
    Yawast::Utilities.puts_info "\t\tRevocation information: OCSP information available"
  end

  case ep.details.cert.revocation_status
    when 0
      Yawast::Utilities.puts_info "\t\tRevocation status: not checked"
    when 1
      Yawast::Utilities.puts_vuln "\t\tRevocation status: certificate revoked"
    when 2
      Yawast::Utilities.puts_info "\t\tRevocation status: certificate not revoked"
    when 3
      Yawast::Utilities.puts_error "\t\tRevocation status: revocation check error"
    when 4
      Yawast::Utilities.puts_info "\t\tRevocation status: no revocation information"
    when 5
      Yawast::Utilities.puts_error "\t\tRevocation status: SSL Labs internal error"
    else
      Yawast::Utilities.puts_error "\t\tRevocation status: Unknown response #{ep.details.cert.revocation_status}"
  end

  Yawast::Utilities.puts_info "\t\tExtensions:"
  ossl_cert.extensions.each { |ext| Yawast::Utilities.puts_info "\t\t\t#{ext}" unless ext.oid == 'subjectAltName' }

  hash = Digest::SHA1.hexdigest(ossl_cert.to_der)
  Yawast::Utilities.puts_info "\t\tHash: #{hash}"
  puts "\t\t\thttps://censys.io/certificates?q=#{hash}"
  puts "\t\t\thttps://crt.sh/?q=#{hash}"

  puts
end

.get_config_info(ep) ⇒ Object



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
# File 'lib/scanner/ssl_labs.rb', line 225

def self.get_config_info(ep)
  puts "\tConfiguration Information:"

  puts "\t\tProtocol Support:"
  ep.details.protocols.each do |proto|
    if proto.name == 'SSL'
      Yawast::Utilities.puts_vuln "\t\t\t#{proto.name} #{proto.version}"
    else
      Yawast::Utilities.puts_info "\t\t\t#{proto.name} #{proto.version}"
    end
  end
  puts

  puts "\t\tCipher Suite Support:"
  if ep.details.suites.list != nil
    ep.details.suites.list.each do |suite|
      ke = nil
      if suite.ecdh_bits != nil || suite.dh_strength != nil
        if suite.name.include? 'ECDHE'
          ke = "ECDHE-#{suite.ecdh_bits}-bits"
        elsif suite.name.include? 'ECDH'
          ke = "ECDH-#{suite.ecdh_bits}"
        elsif suite.name.include? 'DHE'
          ke = "DHE-#{suite.dh_strength}-bits"
        elsif suite.name.include? 'DH'
          ke = "DH-#{suite.dh_strength}-bits"
        end
      end

      strength = suite.cipher_strength
      if suite.name.include? '3DES'
        # in this case, the effective strength is only 112 bits,
        #  which is what we want to report. So override SSL Labs
        strength = 112
      end

      suite_info = nil
      if ke != nil
        suite_info = "#{suite.name.ljust(50)} - #{strength}-bits - #{ke}"
      else
        suite_info = "#{suite.name.ljust(50)} - #{strength}-bits"
      end

      if cipher_suite_secure? suite
        if strength >= 128
          Yawast::Utilities.puts_info "\t\t\t#{suite_info}"
        else
          Yawast::Utilities.puts_warn "\t\t\t#{suite_info}"
        end
      else
        Yawast::Utilities.puts_vuln "\t\t\t#{suite_info}"
      end
    end
  else
    Yawast::Utilities.puts_error "\t\t\tInformation Not Available"
  end

  puts

  puts "\t\tHandshake Simulation:"
  if ep.details.sims.results != nil
    ep.details.sims.results.each do |sim|
      name = "#{sim.client.name} #{sim.client.version}"
      if sim.client.platform != nil
        name += " / #{sim.client.platform}"
      end
      name = name.ljust(28)

      if sim.success?
        protocol = nil
        ep.details.protocols.each do |proto|
          if sim.protocol_id == proto.id
            protocol = "#{proto.name} #{proto.version}"
          end
        end

        suite_name = nil
        secure = true
        ep.details.suites.list.each do |suite|
          if sim.suite_id == suite.id
            suite_name = suite.name
            secure = cipher_suite_secure? suite
          end
        end

        if secure
          Yawast::Utilities.puts_info "\t\t\t#{name} - #{protocol} - #{suite_name}"
        else
          Yawast::Utilities.puts_vuln "\t\t\t#{name} - #{protocol} - #{suite_name}"
        end
      else
        Yawast::Utilities.puts_error "\t\t\t#{name} - Simulation Failed"
      end
    end
  else
    Yawast::Utilities.puts_error "\t\t\tInformation Not Available"
  end

  puts
end

.get_proto_info(ep) ⇒ Object



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
# File 'lib/scanner/ssl_labs.rb', line 326

def self.get_proto_info(ep)
  puts "\t\tProtocol & Vulnerability Information:"

  if ep.details.drown_vulnerable?
    Yawast::Utilities.puts_vuln "\t\t\tDROWN: Vulnerable"

    ep.details.drown_hosts.each do |dh|
      Yawast::Utilities.puts_vuln "\t\t\t\t#{dh['ip']}:#{dh['port']} - #{dh['status']}"
      puts "\t\t\t\thttps://test.drownattack.com/?site=#{dh['ip']}"
    end
  else
    Yawast::Utilities.puts_info "\t\t\tDROWN: No"
  end

  if ep.details.reneg_support & 1 != 0
    Yawast::Utilities.puts_vuln "\t\t\tSecure Renegotiation: insecure client-initiated renegotiation supported"
  end
  if ep.details.reneg_support & (1<<1) != 0
    Yawast::Utilities.puts_info "\t\t\tSecure Renegotiation: secure renegotiation supported"
  end
  if ep.details.reneg_support & (1<<2) != 0
    Yawast::Utilities.puts_info "\t\t\tSecure Renegotiation: secure client-initiated renegotiation supported"
  end
  if ep.details.reneg_support & (1<<3) != 0
    Yawast::Utilities.puts_info "\t\t\tSecure Renegotiation: server requires secure renegotiation support"
  end

  if ep.details.poodle?
    Yawast::Utilities.puts_vuln "\t\t\tPOODLE (SSL): Vulnerable"
  else
    Yawast::Utilities.puts_info "\t\t\tPOODLE (SSL): No"
  end

  case ep.details.poodle_tls
    when -3
      Yawast::Utilities.puts_info "\t\t\tPOODLE (TLS): Inconclusive (Timeout)"
    when -2
      Yawast::Utilities.puts_info "\t\t\tPOODLE (TLS): TLS Not Supported"
    when -1
      Yawast::Utilities.puts_error "\t\t\tPOODLE (TLS): Test Failed"
    when 0
      Yawast::Utilities.puts_error "\t\t\tPOODLE (TLS): Test Failed (Unknown)"
    when 1
      Yawast::Utilities.puts_info "\t\t\tPOODLE (TLS): No"
    when 2
      Yawast::Utilities.puts_vuln "\t\t\tPOODLE (TLS): Vulnerable"
    else
      Yawast::Utilities.puts_error "\t\t\tPOODLE (TLS): Unknown Response #{ep.details.poodle_tls}"
  end

  if ep.details.fallback_scsv?
    Yawast::Utilities.puts_info "\t\t\tDowngrade Prevention: Yes"
  else
    Yawast::Utilities.puts_warn "\t\t\tDowngrade Prevention: No"
  end

  if ep.details.compression_methods & 1 != 0
    Yawast::Utilities.puts_warn "\t\t\tCompression: DEFLATE"
  else
    Yawast::Utilities.puts_info "\t\t\tCompression: No"
  end

  if ep.details.heartbleed?
    Yawast::Utilities.puts_vuln "\t\t\tHeartbleed: Vulnerable"
  else
    Yawast::Utilities.puts_info "\t\t\tHeartbleed: No"
  end

  case ep.details.open_ssl_ccs
    when -1
      Yawast::Utilities.puts_error "\t\t\tOpenSSL CCS (CVE-2014-0224): Test Failed"
    when 0
      Yawast::Utilities.puts_error "\t\t\tOpenSSL CCS (CVE-2014-0224): Test Failed (Unknown)"
    when 1
      Yawast::Utilities.puts_info "\t\t\tOpenSSL CCS (CVE-2014-0224): No"
    when 2
      Yawast::Utilities.puts_vuln "\t\t\tOpenSSL CCS (CVE-2014-0224): Vulnerable - Not Exploitable"
    when 3
      Yawast::Utilities.puts_vuln "\t\t\tOpenSSL CCS (CVE-2014-0224): Vulnerable"
    else
      Yawast::Utilities.puts_error "\t\t\tOpenSSL CCS (CVE-2014-0224): Unknown Response #{ep.details.open_ssl_ccs}"
  end

  case ep.details.open_ssl_lucky_minus20
    when -1
      Yawast::Utilities.puts_error "\t\t\tOpenSSL Padding Oracle (CVE-2016-2107): Test Failed"
    when 0
      Yawast::Utilities.puts_error "\t\t\tOpenSSL Padding Oracle (CVE-2016-2107): Test Failed (Unknown)"
    when 1
      Yawast::Utilities.puts_info "\t\t\tOpenSSL Padding Oracle (CVE-2016-2107): No"
    when 2
      Yawast::Utilities.puts_vuln "\t\t\tOpenSSL Padding Oracle (CVE-2016-2107): Vulnerable"
    else
      Yawast::Utilities.puts_error "\t\t\tOpenSSL Padding Oracle (CVE-2016-2107): Unknown Response #{ep.details.open_ssl_lucky_minus20}"
  end

  if ep.details.forward_secrecy & (1<<2) != 0
    Yawast::Utilities.puts_info "\t\t\tForward Secrecy: Yes (all simulated clients)"
  elsif ep.details.forward_secrecy & (1<<1) != 0
    Yawast::Utilities.puts_info "\t\t\tForward Secrecy: Yes (modern clients)"
  elsif ep.details.forward_secrecy & 1 != 0
    Yawast::Utilities.puts_warn "\t\t\tForward Secrecy: Yes (limited support)"
  else
    Yawast::Utilities.puts_vuln "\t\t\tForward Secrecy: No"
  end

  if ep.details.ocsp_stapling?
    Yawast::Utilities.puts_info "\t\t\tOCSP Stapling: Yes"
  else
    Yawast::Utilities.puts_warn "\t\t\tOCSP Stapling: No"
  end

  if ep.details.freak?
    Yawast::Utilities.puts_vuln "\t\t\tFREAK: Vulnerable"
  else
    Yawast::Utilities.puts_info "\t\t\tFREAK: No"
  end

  if ep.details.logjam?
    Yawast::Utilities.puts_vuln "\t\t\tLogjam: Vulnerable"
  else
    Yawast::Utilities.puts_info "\t\t\tLogjam: No"
  end

  case ep.details.dh_uses_known_primes
    when 0
      Yawast::Utilities.puts_info "\t\t\tUses common DH primes: No"
    when 1
      Yawast::Utilities.puts_warn "\t\t\tUses common DH primes: Yes (not weak)"
    when 2
      Yawast::Utilities.puts_vuln "\t\t\tUses common DH primes: Yes (weak)"
    else
      unless ep.details.dh_uses_known_primes == nil
        Yawast::Utilities.puts_error "\t\t\tUses common DH primes: Unknown Response #{ep.details.dh_uses_known_primes}"
      end
  end

  if ep.details.dh_ys_reuse?
    Yawast::Utilities.puts_vuln "\t\t\tDH public server param (Ys) reuse: Yes"
  else
    Yawast::Utilities.puts_info "\t\t\tDH public server param (Ys) reuse: No"
  end

  puts
end

.info(uri, sslsessioncount) ⇒ Object



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
# File 'lib/scanner/ssl_labs.rb', line 9

def self.info(uri, sslsessioncount)
  puts 'Beginning SSL Labs scan (this could take a minute or two)'

  api = Ssllabs::Api.new

  info = api.info

  info.messages.each do |msg|
    puts "[SSL Labs]\t#{msg}"
  end

  begin
    api.analyse(host: uri.host, publish: 'off', startNew: 'on', all: 'done', ignoreMismatch: 'on')

    status = ''
    host = nil
    until status == 'READY' || status == 'ERROR' || status == 'DNS'
      # poll for updates every 5 seconds
      # don't want to poll faster, to avoid excess load / errors
      sleep(5)

      host = api.analyse(host: uri.host, publish: 'off', all: 'done', ignoreMismatch: 'on')
      status = host.status

      print '.'
    end
    puts
    puts

    host.endpoints.each do |ep|
      Yawast::Utilities.puts_info "IP: #{ep.ip_address} - Grade: #{ep.grade}"
      puts

      begin
        if ep.status_message == 'Ready'
          get_cert_info(ep)
          get_config_info(ep)
          get_proto_info(ep)
        else
          Yawast::Utilities.puts_error "Error getting information for IP: #{ep.ip_address}: #{ep.status_message}"
        end
      rescue => e
        Yawast::Utilities.puts_error "Error getting information for IP: #{ep.ip_address}: #{e.message}"
      end

      Yawast::Scanner::Ssl.get_session_msg_count(uri) if sslsessioncount

      puts
    end
  rescue => e
    Yawast::Utilities.puts_error "SSL Labs Error: #{e.message}"
  end
end