Skip to content

Instantly share code, notes, and snippets.

@andresriancho
Created January 30, 2015 22:09
Show Gist options
  • Save andresriancho/77d1d163c9987966ce77 to your computer and use it in GitHub Desktop.
Save andresriancho/77d1d163c9987966ce77 to your computer and use it in GitHub Desktop.
tls
import socket
import ssl
sock = socket.create_connection(('dadario.com.br', 443))
sock = ssl.wrap_socket(sock, None, None, ssl_version=ssl.PROTOCOL_TLSv1)
@andresriancho
Copy link
Author

If you've got a couple of minutes help me out by running this code and storing the result, more info here

@andresriancho
Copy link
Author

Seems like the issue was the lacking SNI support in python 2.7 ssl module. This code works (after installing new dependency, see notes below):

import socket
import ssl

from ssl_sni.openssl import wrap_socket

hostname = 'dadario.com.br'

sock = socket.create_connection((hostname, 443))
sock = wrap_socket(sock, None, None, ssl_version=ssl.PROTOCOL_TLSv1, server_hostname=hostname)

sock.write('GET / HTTP/1.1\r\n')
sock.write('Host: %s\r\n' % hostname)
sock.write('\r\n')
sock.write('\r\n')

print sock.read(850)
sudo apt-get install libffi-dev
pip install ssl_sni

@andresriancho
Copy link
Author

This is a nightmare! Now it doesn't work with w3af because of the timeout 👎

import socket
import ssl

from ssl_sni.openssl import wrap_socket

hostname = 'dadario.com.br'

socket.setdefaulttimeout(1)
sock = socket.create_connection((hostname, 443))
sock = wrap_socket(sock, None, None, ssl_version=ssl.PROTOCOL_TLSv1, server_hostname=hostname)

sock.write('GET / HTTP/1.1\r\n')
sock.write('Host: %s\r\n' % hostname)
sock.write('\r\n')
sock.write('\r\n')

print(sock.read(850))

@andresriancho
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment