diff --git a/lib/request/proxy.py b/lib/request/proxy.py index 018430679..e52d6700e 100644 --- a/lib/request/proxy.py +++ b/lib/request/proxy.py @@ -7,14 +7,12 @@ See the file 'doc/COPYING' for copying permission import httplib import socket +import ssl import urllib import urllib2 from lib.core.exception import SqlmapUnsupportedFeatureException -from lib.core.settings import PYVERSION -if PYVERSION >= "2.6": - import ssl class ProxyHTTPConnection(httplib.HTTPConnection): _ports = {"http": 80, "https": 443} @@ -82,12 +80,8 @@ class ProxyHTTPSConnection(ProxyHTTPConnection): ProxyHTTPConnection.connect(self) # Make the sock ssl-aware - if PYVERSION >= "2.6": - sslobj = ssl.wrap_socket(self.sock, self.key_file, self.cert_file) - self.sock = sslobj - else: - sslobj = socket.ssl(self.sock, self.key_file, self.cert_file) - self.sock = httplib.FakeSocket(self.sock, sslobj) + sslobj = ssl.wrap_socket(self.sock, self.key_file, self.cert_file) + self.sock = sslobj class ProxyHTTPHandler(urllib2.HTTPHandler): def __init__(self, proxy=None, debuglevel=0): @@ -101,20 +95,14 @@ class ProxyHTTPHandler(urllib2.HTTPHandler): return urllib2.HTTPHandler.do_open(self, ProxyHTTPConnection, req) -if PYVERSION >= "2.6": - class ProxyHTTPSHandler(urllib2.HTTPSHandler): - def __init__(self, proxy=None, debuglevel=0): - self.proxy = proxy +class ProxyHTTPSHandler(urllib2.HTTPSHandler): + def __init__(self, proxy=None, debuglevel=0): + self.proxy = proxy - urllib2.HTTPSHandler.__init__(self, debuglevel) + urllib2.HTTPSHandler.__init__(self, debuglevel) - def do_open(self, http_class, req): - if self.proxy is not None: - req.set_proxy(self.proxy, "https") + def do_open(self, http_class, req): + if self.proxy is not None: + req.set_proxy(self.proxy, "https") - return urllib2.HTTPSHandler.do_open(self, ProxyHTTPSConnection, req) -else: - class ProxyHTTPSHandler: - def __init__(self, *args, **kwargs): - errMsg = "unsupported feature on versions of Python before 2.6" - raise SqlmapUnsupportedFeatureException(errMsg) + return urllib2.HTTPSHandler.do_open(self, ProxyHTTPSConnection, req)