Last active
October 17, 2015 23:35
-
-
Save 0xbb/ffe58d173ab5edf2d91d to your computer and use it in GitHub Desktop.
Sends a TLS 1.2 Client Hello and extracts the resulting random bytes from the Server Hello
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Usage: ./tlsrand server port | |
import socket | |
import sys | |
hello = bytearray([3, 3]) # Version: TLS 1.2 | |
hello += bytearray([0]*32) # Random | |
hello += bytearray([ | |
0, # Session ID Length | |
0, 6, # Cipher Suites Length | |
0xc0, 0x2f, # TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 | |
0, 0x2f, # TLS_RSA_WITH_AES_128_CBC_SHA | |
0, 0x39, # TLS_DHE_RSA_WITH_AES_256_CBC_SHA | |
1, # Compression Methods Length: 1 | |
0, # Compression Method: null | |
0, 0 # Extensions Length | |
]) | |
msg = bytearray([1]) # Handshake Type: Client Hello | |
msg += bytearray([0, 0, len(hello)]) + hello | |
record = bytearray([ | |
0x16, # Content Type: Handshake | |
3, 3 # Version TLS 1.2 | |
]) | |
record += bytearray([0, len(msg)]) + msg | |
s = socket.socket() | |
s.connect((sys.argv[1], int(sys.argv[2]))) | |
s.sendall(record) | |
buf = s.recv(4096) | |
s.close() | |
if buf[0] == 0x16 and buf[5] == 2: # Response is: Handshake + Server Hello | |
sys.stdout.buffer.write(buf[15:15+28]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment