#!/usr/bin/env python"""Copyright (c) 2006-2022 sqlmap developers (https://sqlmap.org/)See the file 'LICENSE' for copying permission"""import reimport socketfrom lib.core.common import filterNonefrom lib.core.common import getSafeExStringfrom lib.core.compat import LooseVersionfrom lib.core.compat import xrangefrom lib.core.data import conffrom lib.core.data import kbfrom lib.core.data import loggerfrom lib.core.exception import SqlmapConnectionExceptionfrom lib.core.settings import PYVERSIONfrom thirdparty.six.moves import http_client as _http_clientfrom thirdparty.six.moves import urllib as _urllibssl = Nonetry:import ssl as _sslssl = _sslexcept ImportError:pass_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):"""Connection class that enables usage of newer SSL protocols.Reference: http://bugs.python.org/msg128686"""def __init__(self, *args, **kwargs):# NOTE: Dirty patch for https://bugs.python.org/issue38251 / https://github.com/sqlmapproject/sqlmap/issues/4158if hasattr(ssl, "_create_default_https_context"):if None not in _contexts:_contexts[None] = ssl._create_default_https_context()kwargs["context"] = _contexts[None]self.retrying = False_http_client.HTTPSConnection.__init__(self, *args, **kwargs)def connect(self):def create_sock():sock = socket.create_connection((self.host, self.port), self.timeout)if getattr(self, "_tunnel_host", None):self.sock = sockself._tunnel()return socksuccess = False# Reference(s): https://docs.python.org/2/library/ssl.html#ssl.SSLContext# https://www.mnot.net/blog/2014/12/27/python_2_and_tls_sniif re.search(r"\A[\d.]+\Z", conf.hostname or "") is None and kb.tlsSNI.get(conf.hostname) is not False and hasattr(ssl, "SSLContext"):for protocol in (_ for _ in _protocols if _ >= ssl.PROTOCOL_TLSv1):try:sock = create_sock()if protocol not in _contexts:_contexts[protocol] = ssl.SSLContext(protocol)try:# Reference(s): https://askubuntu.com/a/1263098# https://askubuntu.com/a/1250807_contexts[protocol].set_ciphers("DEFAULT@SECLEVEL=1")except ssl.SSLError:passresult = _contexts[protocol].wrap_socket(sock, do_handshake_on_connect=True, server_hostname=conf.hostname)if result:success = Trueself.sock = result_protocols.remove(protocol)_protocols.insert(0, protocol)breakelse:sock.close()except (ssl.SSLError, socket.error, _http_client.BadStatusLine) as ex:self._tunnel_host = Nonelogger.debug("SSL connection error occurred for '%s' ('%s')" % (_lut[protocol], getSafeExString(ex)))if kb.tlsSNI.get(conf.hostname) is None:kb.tlsSNI[conf.hostname] = successif not success:for protocol in _protocols:try:sock = create_sock()_ = ssl.wrap_socket(sock, self.key_file, self.cert_file, ssl_version=protocol)if _:success = Trueself.sock = __protocols.remove(protocol)_protocols.insert(0, protocol)breakelse:sock.close()except (ssl.SSLError, socket.error, _http_client.BadStatusLine) as ex:self._tunnel_host = Nonelogger.debug("SSL connection error occurred for '%s' ('%s')" % (_lut[protocol], getSafeExString(ex)))if not success:errMsg = "can't establish SSL connection"# Reference: https://docs.python.org/2/library/ssl.htmlif LooseVersion(PYVERSION) < LooseVersion("2.7.9"):errMsg += " (please retry with Python >= 2.7.9)"if kb.sslSuccess and not self.retrying:self.retrying = Truefor _ in xrange(conf.retries):try:self.connect()except SqlmapConnectionException:passelse:returnraise SqlmapConnectionException(errMsg)else:kb.sslSuccess = Trueclass HTTPSHandler(_urllib.request.HTTPSHandler):def https_open(self, req):return self.do_open(HTTPSConnection if ssl else _http_client.HTTPSConnection, req)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。