Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ce92853

Browse files
committed
Fixes #4158
1 parent dad4879 commit ce92853

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.4.4.0"
21+
VERSION = "1.4.4.1"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/request/httpshandler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
_protocols = filterNone(getattr(ssl, _, None) for _ in ("PROTOCOL_TLSv1_2", "PROTOCOL_TLSv1_1", "PROTOCOL_TLSv1", "PROTOCOL_SSLv3", "PROTOCOL_SSLv23", "PROTOCOL_SSLv2"))
2929
_lut = dict((getattr(ssl, _), _) for _ in dir(ssl) if _.startswith("PROTOCOL_"))
30+
_contexts = {}
3031

3132
class HTTPSConnection(_http_client.HTTPSConnection):
3233
"""
@@ -36,6 +37,12 @@ class HTTPSConnection(_http_client.HTTPSConnection):
3637
"""
3738

3839
def __init__(self, *args, **kwargs):
40+
# NOTE: Dirty patch for https://bugs.python.org/issue38251 / https://github.com/sqlmapproject/sqlmap/issues/4158
41+
if hasattr(ssl, "_create_default_https_context"):
42+
if None not in _contexts:
43+
_contexts[None] = ssl._create_default_https_context()
44+
kwargs["context"] = _contexts[None]
45+
3946
_http_client.HTTPSConnection.__init__(self, *args, **kwargs)
4047

4148
def connect(self):
@@ -54,11 +61,12 @@ def create_sock():
5461
for protocol in [_ for _ in _protocols if _ >= ssl.PROTOCOL_TLSv1]:
5562
try:
5663
sock = create_sock()
57-
context = ssl.SSLContext(protocol)
58-
_ = context.wrap_socket(sock, do_handshake_on_connect=True, server_hostname=self.host)
59-
if _:
64+
if protocol not in _contexts:
65+
_contexts[protocol] = ssl.SSLContext(protocol)
66+
result = _contexts[protocol].wrap_socket(sock, do_handshake_on_connect=True, server_hostname=self.host)
67+
if result:
6068
success = True
61-
self.sock = _
69+
self.sock = result
6270
_protocols.remove(protocol)
6371
_protocols.insert(0, protocol)
6472
break

0 commit comments

Comments
 (0)