@@ -153,9 +153,11 @@ def oracle(target, pms, cke_2nd_prefix, cipher_handshake=ch_def, messageflow=Fal
153
153
return "ConnectionResetError"
154
154
except socket .timeout :
155
155
return ("Timeout waiting for alert" )
156
- s .close ()
157
156
except Exception as e :
158
157
return str (e )
158
+ finally :
159
+ if 's' in locals ():
160
+ s .close ()
159
161
160
162
161
163
def run (args ):
@@ -172,14 +174,14 @@ def run(args):
172
174
N , e = get_rsa_from_server (target , timeout )
173
175
174
176
if not N :
175
- module .log ("{}:{} - Cannot establish SSL connection: {}" .format (* target , e ), level = 'error' )
177
+ module .log ("{}:{} - Cannot establish SSL connection: {error }" .format (* target , error = e ), level = 'error' )
176
178
return
177
179
178
180
modulus_bits = int (math .ceil (math .log (N , 2 )))
179
181
modulus_bytes = (modulus_bits + 7 ) // 8
180
- module .log ("{}:{} - RSA N: {}" .format (* target , hex (N )), level = 'debug' )
181
- module .log ("{}:{} - RSA e: {}" .format (* target , hex (e )), level = 'debug' )
182
- module .log ("{}:{} - Modulus size: {} bits, {} bytes" .format (* target , modulus_bits , modulus_bytes ), level = 'debug' )
182
+ module .log ("{}:{} - RSA N: {rsa_n }" .format (* target , rsa_n = hex (N )), level = 'debug' )
183
+ module .log ("{}:{} - RSA e: {rsa_e }" .format (* target , rsa_e = hex (e )), level = 'debug' )
184
+ module .log ("{}:{} - Modulus size: {modulus_bits } bits, {modulus_bytes } bytes" .format (* target , modulus_bits = modulus_bits , modulus_bytes = modulus_bytes ), level = 'debug' )
183
185
184
186
cke_2nd_prefix = bytearray .fromhex ("{0:0{1}x}" .format (modulus_bytes + 6 , 4 ) + "10" + "{0:0{1}x}" .format (modulus_bytes + 2 , 6 ) + "{0:0{1}x}" .format (modulus_bytes , 4 ))
185
187
# pad_len is length in hex chars, so bytelen * 2
@@ -210,14 +212,14 @@ def run(args):
210
212
oracle_bad4 = oracle (target , pms_bad4 , cke_2nd_prefix , cipher_handshake , messageflow = False , timeout = timeout )
211
213
212
214
if (oracle_good == oracle_bad1 == oracle_bad2 == oracle_bad3 == oracle_bad4 ):
213
- module .log ("{}:{} - Identical results ({}), retrying with changed messageflow" .format (* target , oracle_good ), level = 'info' )
215
+ module .log ("{}:{} - Identical results ({oracle_good }), retrying with changed messageflow" .format (* target , oracle_good = oracle_good ), level = 'info' )
214
216
oracle_good = oracle (target , pms_good , cke_2nd_prefix , cipher_handshake , messageflow = True , timeout = timeout )
215
217
oracle_bad1 = oracle (target , pms_bad1 , cke_2nd_prefix , cipher_handshake , messageflow = True , timeout = timeout )
216
218
oracle_bad2 = oracle (target , pms_bad2 , cke_2nd_prefix , cipher_handshake , messageflow = True , timeout = timeout )
217
219
oracle_bad3 = oracle (target , pms_bad3 , cke_2nd_prefix , cipher_handshake , messageflow = True , timeout = timeout )
218
220
oracle_bad4 = oracle (target , pms_bad4 , cke_2nd_prefix , cipher_handshake , messageflow = True , timeout = timeout )
219
221
if (oracle_good == oracle_bad1 == oracle_bad2 == oracle_bad3 == oracle_bad4 ):
220
- module .log ("{}:{} - Identical results ({}), no working oracle found" .format (* target , oracle_good ), level = 'info' )
222
+ module .log ("{}:{} - Identical results ({oracle_good }), no working oracle found" .format (* target , oracle_good = oracle_good ), level = 'info' )
221
223
return
222
224
else :
223
225
flow = True
@@ -265,13 +267,13 @@ def run(args):
265
267
tlsver = "TLS raw version %i/%i" % (cke_version [0 ], cke_version [1 ])
266
268
267
269
module .report_vuln (target [0 ], 'Bleichenbacher Oracle' , port = target [1 ])
268
- module .log ("{}:{} - Vulnerable: ({}) oracle found {} with {} message flow" .format (* target , oracle_strength , tlsver , flowt ), level = 'good' )
270
+ module .log ("{}:{} - Vulnerable: ({oracle_strength }) oracle found {tlsver } with {flowt } message flow" .format (* target , oracle_strength = oracle_strength , tlsver = tlsver , flowt = flowt ), level = 'good' )
269
271
270
- module .log ("{}:{} - Result of good request: {}" .format (* target , oracle_good ), level = 'debug' )
271
- module .log ("{}:{} - Result of bad request 1 (wrong first bytes): {}" .format (* target , oracle_bad1 ), level = 'debug' )
272
- module .log ("{}:{} - Result of bad request 2 (wrong 0x00 position): {}" .format (* target , oracle_bad2 ), level = 'debug' )
273
- module .log ("{}:{} - Result of bad request 3 (missing 0x00): {}" .format (* target , oracle_bad3 ), level = 'debug' )
274
- module .log ("{}:{} - Result of bad request 4 (bad TLS version): {}" .format (* target , oracle_bad4 ), level = 'debug' )
272
+ module .log ("{}:{} - Result of good request: {oracle_bad }" .format (* target , oracle_bad = oracle_good ), level = 'debug' )
273
+ module .log ("{}:{} - Result of bad request 1 (wrong first bytes): {oracle_bad }" .format (* target , oracle_bad = oracle_bad1 ), level = 'debug' )
274
+ module .log ("{}:{} - Result of bad request 2 (wrong 0x00 position): {oracle_bad }" .format (* target , oracle_bad = oracle_bad2 ), level = 'debug' )
275
+ module .log ("{}:{} - Result of bad request 3 (missing 0x00): {oracle_bad }" .format (* target , oracle_bad = oracle_bad3 ), level = 'debug' )
276
+ module .log ("{}:{} - Result of bad request 4 (bad TLS version): {oracle_bad }" .format (* target , oracle_bad = oracle_bad4 ), level = 'debug' )
275
277
276
278
277
279
if __name__ == "__main__" :
0 commit comments