Skip to content

Commit 6ef62d0

Browse files
committed
Minor improvement of PKI handler
1 parent 8c9e704 commit 6ef62d0

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

data/txt/sha256sums.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ fb0a08ac6f8bb07711e4e895eebf9fb3c8d452cc7aaebcdf78d926cdf051550d lib/core/patch
189189
73ef0895d728fe76bf9abda94d4b97951069532a088d603a064e793bb2ae45d9 lib/core/replication.py
190190
3574639db4942d16a2dc0a2f04bb7c0913c40c3862b54d34c44075a760e0c194 lib/core/revision.py
191191
888daba83fd4a34e9503fe21f01fef4cc730e5cde871b1d40e15d4cbc847d56c lib/core/session.py
192-
7dfde59e8efcd684be4cd84f93024554406d139d8604a0336cfac81f5f5008ac lib/core/settings.py
192+
4284c63fe1589282f961392380a83990d5bf1baa41d6056bc69aa2e4ec6ab8aa lib/core/settings.py
193193
cd5a66deee8963ba8e7e9af3dd36eb5e8127d4d68698811c29e789655f507f82 lib/core/shell.py
194194
00dc9e87db2c13d7eaf18edd503267430460d91baf76760350be545d4a387a9f lib/core/subprocessng.py
195195
d35650179816193164a5f177102f18379dfbe6bb6d40fbb67b78d907b41c8038 lib/core/target.py
@@ -219,7 +219,7 @@ f56fc33251bd6214e3a6316c8f843eb192b2996aa84bd4c3e98790fdcf6e8cf0 lib/request/ht
219219
1966ca704961fb987ab757f0a4afddbf841d1a880631b701487c75cef63d60c3 lib/request/__init__.py
220220
aeeeb5f0148078e30d52208184042efc3618d3f2e840d7221897aae34315824e lib/request/inject.py
221221
ada4d305d6ce441f79e52ec3f2fc23869ee2fa87c017723e8f3ed0dfa61cdab4 lib/request/methodrequest.py
222-
5c3edfca5ad58153ad6cface03777e059d3308b2aa3c38db993b5054145faa8e lib/request/pkihandler.py
222+
43a7fdf64e7ba63c6b2d641c9f999a63c12ac23b43b64fedfce4e05b863de568 lib/request/pkihandler.py
223223
4efead49b76d1237c283ecf281673d8762e09575d05af2a1e24680900ca83d0b lib/request/rangehandler.py
224224
47a97b264fb588142b102d18100030ce333ce372c677b97ed6cb04105c6c9d30 lib/request/redirecthandler.py
225225
1bf93c2c251f9c422ecf52d9cae0cd0ff4ea2e24091ee6d019c7a4f69de8e5eb lib/request/templates.py

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from thirdparty import six
2020

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

lib/request/pkihandler.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8+
ssl = None
9+
try:
10+
import ssl as _ssl
11+
ssl = _ssl
12+
except ImportError:
13+
pass
14+
815
from lib.core.data import conf
916
from lib.core.common import getSafeExString
1017
from lib.core.exception import SqlmapConnectionException
1118
from thirdparty.six.moves import http_client as _http_client
1219
from thirdparty.six.moves import urllib as _urllib
1320

21+
1422
class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler):
1523
def __init__(self, auth_file):
1624
_urllib.request.HTTPSHandler.__init__(self)
@@ -20,10 +28,24 @@ def https_open(self, req):
2028
return self.do_open(self.getConnection, req)
2129

2230
def getConnection(self, host, timeout=None):
31+
if timeout is None:
32+
timeout = conf.timeout
33+
34+
if not hasattr(_http_client, "HTTPSConnection"):
35+
raise SqlmapConnectionException("HTTPS support is not available in this Python build")
36+
2337
try:
24-
# Reference: https://docs.python.org/2/library/ssl.html#ssl.SSLContext.load_cert_chain
25-
return _http_client.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=conf.timeout)
26-
except IOError as ex:
38+
if ssl and hasattr(ssl, "SSLContext") and hasattr(ssl, "create_default_context"):
39+
ctx = ssl.create_default_context()
40+
ctx.load_cert_chain(certfile=self.auth_file, keyfile=self.auth_file)
41+
try:
42+
return _http_client.HTTPSConnection(host, timeout=timeout, context=ctx)
43+
except TypeError:
44+
pass
45+
46+
return _http_client.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=timeout)
47+
48+
except (IOError, OSError) as ex:
2749
errMsg = "error occurred while using key "
2850
errMsg += "file '%s' ('%s')" % (self.auth_file, getSafeExString(ex))
2951
raise SqlmapConnectionException(errMsg)

0 commit comments

Comments
 (0)