@@ -38,56 +38,65 @@ def run_host(ip)
38
38
39
39
connect ( true , { "SSL" => true } ) #Force SSL
40
40
41
- cert = OpenSSL ::X509 ::Certificate . new ( sock . peer_cert )
41
+ if sock . respond_to? :peer_cert
42
+ cert = OpenSSL ::X509 ::Certificate . new ( sock . peer_cert )
43
+ end
42
44
43
45
disconnect
44
46
45
47
if cert
46
- print_status ( "#{ ip } :#{ rport } Subject: #{ cert . subject } " )
47
- print_status ( "#{ ip } :#{ rport } Issuer: #{ cert . issuer } " )
48
- print_status ( "#{ ip } :#{ rport } Signature Alg: #{ cert . signature_algorithm } " )
49
- public_key_size = cert . public_key . n . num_bytes * 8
50
- print_status ( "#{ ip } :#{ rport } Public Key Size: #{ public_key_size } bits" )
51
- print_status ( "#{ ip } :#{ rport } Not Valid Before: #{ cert . not_before } " )
52
- print_status ( "#{ ip } :#{ rport } Not Valid After: #{ cert . not_after } " )
48
+ print_status ( "Subject: #{ cert . subject } " )
49
+ print_status ( "Issuer: #{ cert . issuer } " )
50
+ print_status ( "Signature Alg: #{ cert . signature_algorithm } " )
51
+
52
+ # If we use ECDSA rather than RSA, our metrics for key size are different
53
+ public_key_size = 0
54
+ if cert . public_key . respond_to? :n
55
+ public_key_size = cert . public_key . n . num_bytes * 8
56
+ print_status ( "Public Key Size: #{ public_key_size } bits" )
57
+ end
58
+ print_status ( "Not Valid Before: #{ cert . not_before } " )
59
+ print_status ( "Not Valid After: #{ cert . not_after } " )
53
60
54
61
# Checks for common properties of self signed certificates
55
62
caissuer = ( /CA Issuers - URI:(.*?),/i ) . match ( cert . extensions . to_s )
56
63
57
64
if caissuer . to_s . empty?
58
- print_good ( "#{ ip } : #{ rport } Certificate contains no CA Issuers extension... possible self signed certificate" )
65
+ print_good ( "Certificate contains no CA Issuers extension... possible self signed certificate" )
59
66
else
60
- print_status ( " #{ ip } : #{ rport } " + caissuer . to_s [ 0 ..-2 ] )
67
+ print_status ( caissuer . to_s [ 0 ..-2 ] )
61
68
end
62
69
63
70
if cert . issuer . to_s == cert . subject . to_s
64
- print_good ( "#{ ip } : #{ rport } Certificate Subject and Issuer match... possible self signed certificate" )
71
+ print_good ( "Certificate Subject and Issuer match... possible self signed certificate" )
65
72
end
66
73
67
74
alg = cert . signature_algorithm
68
75
69
76
if alg . downcase . include? "md5"
70
- print_status ( "#{ ip } : #{ rport } WARNING: Signature algorithm using MD5 (#{ alg } )" )
77
+ print_status ( "WARNING: Signature algorithm using MD5 (#{ alg } )" )
71
78
end
72
79
73
80
vhostn = nil
74
81
cert . subject . to_a . each do |n |
75
82
vhostn = n [ 1 ] if n [ 0 ] == 'CN'
76
83
end
77
- if public_key_size == 1024
78
- print_status ( "#{ ip } :#{ rport } WARNING: Public Key only 1024 bits" )
79
- elsif public_key_size < 1024
80
- print_status ( "#{ ip } :#{ rport } WARNING: Weak Public Key: #{ public_key_size } bits" )
84
+ if public_key_size > 0
85
+ if public_key_size == 1024
86
+ print_status ( "WARNING: Public Key only 1024 bits" )
87
+ elsif public_key_size < 1024
88
+ print_status ( "WARNING: Weak Public Key: #{ public_key_size } bits" )
89
+ end
81
90
end
82
91
if cert . not_after < Time . now
83
- print_status ( "#{ ip } : #{ rport } WARNING: Certificate not valid anymore" )
92
+ print_status ( "WARNING: Certificate not valid anymore" )
84
93
end
85
94
if cert . not_before > Time . now
86
- print_status ( "#{ ip } : #{ rport } WARNING: Certificate not valid yet" )
95
+ print_status ( "WARNING: Certificate not valid yet" )
87
96
end
88
97
89
98
if vhostn
90
- print_status ( "#{ ip } : #{ rport } has common name #{ vhostn } " )
99
+ print_status ( "Has common name #{ vhostn } " )
91
100
92
101
# Store the virtual hostname for HTTP
93
102
report_note (
@@ -125,7 +134,7 @@ def run_host(ip)
125
134
126
135
end
127
136
else
128
- print_status ( "#{ ip } : #{ rport } ] No certificate subject or common name found" )
137
+ print_status ( "No certificate subject or common name found" )
129
138
end
130
139
rescue ::Rex ::ConnectionRefused , ::Rex ::HostUnreachable , ::Rex ::ConnectionTimeout
131
140
rescue ::Timeout ::Error , ::Errno ::EPIPE
0 commit comments