I want to know if the following Python code is vulnerable to end-to-end eavesdropping attacks when the url points to a https:// site but this one does not support SSL encryption.
Why I'm in doubt? because Mechanize internally uses urllib2 but HTTPS requests do not do any verification of the server’s certificate in urllib2
Plus I do not know how to verify if we are actually using a https or http connection with Urllib2/Mechanize. AFAIK Mechanize behaves as a browser, so I don't know if it fallback to http when SSL is not supported by server, or if it performs an insecure https implementation.
How can I check if I'm getting out of Tor circuit unencrypted?
The code:
import socks
import socket
def create_connection(address, timeout=None, source_address=None):
sock = socks.socksocket()
sock.connect(address)
return sock
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, "127.0.0.1", 9050)
# patch the socket module
socket.socket = socks.socksocket
socket.create_connection = create_connection
import urllib2
print "urllib2.urlopen(): ",urllib2.urlopen('https://icanhazip.com').read()
import mechanize
from mechanize import Browser
br = Browser()
print "Mechanize Browser.open(): ", br.open('https://icanhazip.com').read()
print "Mechanize Browser.open(): ", br.open('https://check.torproject.org/').read()