From ce9285381d0355416c19dccd2b476435b00eb0ca Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 7 Apr 2020 02:07:54 +0200 Subject: [PATCH] Fixes #4158 --- lib/core/settings.py | 2 +- lib/request/httpshandler.py | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index 4d1889693..1a4596cc9 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.4.4.0" +VERSION = "1.4.4.1" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) diff --git a/lib/request/httpshandler.py b/lib/request/httpshandler.py index c7cb41abe..854cbe1a7 100644 --- a/lib/request/httpshandler.py +++ b/lib/request/httpshandler.py @@ -27,6 +27,7 @@ except ImportError: _protocols = filterNone(getattr(ssl, _, None) for _ in ("PROTOCOL_TLSv1_2", "PROTOCOL_TLSv1_1", "PROTOCOL_TLSv1", "PROTOCOL_SSLv3", "PROTOCOL_SSLv23", "PROTOCOL_SSLv2")) _lut = dict((getattr(ssl, _), _) for _ in dir(ssl) if _.startswith("PROTOCOL_")) +_contexts = {} class HTTPSConnection(_http_client.HTTPSConnection): """ @@ -36,6 +37,12 @@ class HTTPSConnection(_http_client.HTTPSConnection): """ def __init__(self, *args, **kwargs): + # NOTE: Dirty patch for https://bugs.python.org/issue38251 / https://github.com/sqlmapproject/sqlmap/issues/4158 + if hasattr(ssl, "_create_default_https_context"): + if None not in _contexts: + _contexts[None] = ssl._create_default_https_context() + kwargs["context"] = _contexts[None] + _http_client.HTTPSConnection.__init__(self, *args, **kwargs) def connect(self): @@ -54,11 +61,12 @@ class HTTPSConnection(_http_client.HTTPSConnection): for protocol in [_ for _ in _protocols if _ >= ssl.PROTOCOL_TLSv1]: try: sock = create_sock() - context = ssl.SSLContext(protocol) - _ = context.wrap_socket(sock, do_handshake_on_connect=True, server_hostname=self.host) - if _: + if protocol not in _contexts: + _contexts[protocol] = ssl.SSLContext(protocol) + result = _contexts[protocol].wrap_socket(sock, do_handshake_on_connect=True, server_hostname=self.host) + if result: success = True - self.sock = _ + self.sock = result _protocols.remove(protocol) _protocols.insert(0, protocol) break