mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-12-09 22:21:30 +00:00
God help us all with this Python3 non-sense
This commit is contained in:
@@ -5,15 +5,15 @@ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
import urllib2
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
class SmartHTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
|
||||
class SmartHTTPBasicAuthHandler(_urllib.request.HTTPBasicAuthHandler):
|
||||
"""
|
||||
Reference: http://selenic.com/hg/rev/6c51a5056020
|
||||
Fix for a: http://bugs.python.org/issue8797
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
|
||||
_urllib.request.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
|
||||
self.retried_req = set()
|
||||
self.retried_count = 0
|
||||
|
||||
@@ -30,8 +30,8 @@ class SmartHTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
|
||||
self.retried_count = 0
|
||||
else:
|
||||
if self.retried_count > 5:
|
||||
raise urllib2.HTTPError(req.get_full_url(), 401, "basic auth failed", headers, None)
|
||||
raise _urllib.error.HTTPError(req.get_full_url(), 401, "basic auth failed", headers, None)
|
||||
else:
|
||||
self.retried_count += 1
|
||||
|
||||
return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(self, auth_header, host, req, headers)
|
||||
return _urllib.request.HTTPBasicAuthHandler.http_error_auth_reqed(self, auth_header, host, req, headers)
|
||||
|
||||
@@ -5,37 +5,35 @@ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
import urllib2
|
||||
|
||||
from lib.core.data import conf
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
class ChunkedHandler(urllib2.HTTPHandler):
|
||||
class ChunkedHandler(_urllib.request.HTTPHandler):
|
||||
"""
|
||||
Ensures that urllib2.HTTPHandler is working properly in case of Chunked Transfer-Encoding
|
||||
Ensures that HTTPHandler is working properly in case of Chunked Transfer-Encoding
|
||||
"""
|
||||
|
||||
def _http_request(self, request):
|
||||
host = request.get_host()
|
||||
if not host:
|
||||
raise urllib2.URLError('no host given')
|
||||
raise _urllib.error.URLError("no host given")
|
||||
|
||||
if request.has_data(): # POST
|
||||
data = request.get_data()
|
||||
if not request.has_header('Content-type'):
|
||||
if not request.has_header("Content-type"):
|
||||
request.add_unredirected_header(
|
||||
'Content-type',
|
||||
'application/x-www-form-urlencoded')
|
||||
if not request.has_header('Content-length') and not conf.chunked:
|
||||
"Content-type",
|
||||
"application/x-www-form-urlencoded")
|
||||
if not request.has_header("Content-length") and not conf.chunked:
|
||||
request.add_unredirected_header(
|
||||
'Content-length', '%d' % len(data))
|
||||
"Content-length", "%d" % len(data))
|
||||
|
||||
sel_host = host
|
||||
if request.has_proxy():
|
||||
scheme, sel = urllib2.splittype(request.get_selector())
|
||||
sel_host, sel_path = urllib2.splithost(sel)
|
||||
sel_host = _urllib.parse.urlsplit(request.get_selector()).netloc
|
||||
|
||||
if not request.has_header('Host'):
|
||||
request.add_unredirected_header('Host', sel_host)
|
||||
if not request.has_header("Host"):
|
||||
request.add_unredirected_header("Host", sel_host)
|
||||
for name, value in self.parent.addheaders:
|
||||
name = name.capitalize()
|
||||
if not request.has_header(name):
|
||||
|
||||
@@ -62,7 +62,6 @@ from lib.core.data import kb
|
||||
from lib.core.data import logger
|
||||
from lib.core.datatype import AttribDict
|
||||
from lib.core.decorators import stackedmethod
|
||||
from lib.core.dicts import HTTP_RESPONSES
|
||||
from lib.core.dicts import POST_HINT_CONTENT_TYPES
|
||||
from lib.core.enums import ADJUST_TIME_DELAY
|
||||
from lib.core.enums import AUTH_TYPE
|
||||
@@ -425,7 +424,7 @@ class Connect(object):
|
||||
page = ws.recv()
|
||||
ws.close()
|
||||
code = ws.status
|
||||
status = HTTP_RESPONSES[code]
|
||||
status = _http_client.responses[code]
|
||||
|
||||
class _(dict):
|
||||
pass
|
||||
@@ -641,7 +640,7 @@ class Connect(object):
|
||||
if ignoreTimeout:
|
||||
return None if not conf.ignoreTimeouts else "", None, None
|
||||
else:
|
||||
warnMsg = "unable to connect to the target URL (%d - %s)" % (ex.code, HTTP_RESPONSES[ex.code])
|
||||
warnMsg = "unable to connect to the target URL (%d - %s)" % (ex.code, _http_client.responses[ex.code])
|
||||
if threadData.retriesCount < conf.retries and not kb.threadException:
|
||||
warnMsg += ". sqlmap is going to retry the request"
|
||||
logger.critical(warnMsg)
|
||||
|
||||
@@ -6,10 +6,8 @@ See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
import distutils.version
|
||||
import httplib
|
||||
import re
|
||||
import socket
|
||||
import urllib2
|
||||
|
||||
from lib.core.common import getSafeExString
|
||||
from lib.core.data import conf
|
||||
@@ -17,6 +15,8 @@ from lib.core.data import kb
|
||||
from lib.core.data import logger
|
||||
from lib.core.exception import SqlmapConnectionException
|
||||
from lib.core.settings import PYVERSION
|
||||
from thirdparty.six.moves import http_client as _http_client
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
ssl = None
|
||||
try:
|
||||
@@ -27,7 +27,7 @@ except ImportError:
|
||||
|
||||
_protocols = filter(None, (getattr(ssl, _, None) for _ in ("PROTOCOL_TLSv1_2", "PROTOCOL_TLSv1_1", "PROTOCOL_TLSv1", "PROTOCOL_SSLv3", "PROTOCOL_SSLv23", "PROTOCOL_SSLv2")))
|
||||
|
||||
class HTTPSConnection(httplib.HTTPSConnection):
|
||||
class HTTPSConnection(_http_client.HTTPSConnection):
|
||||
"""
|
||||
Connection class that enables usage of newer SSL protocols.
|
||||
|
||||
@@ -35,7 +35,7 @@ class HTTPSConnection(httplib.HTTPSConnection):
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
httplib.HTTPSConnection.__init__(self, *args, **kwargs)
|
||||
_http_client.HTTPSConnection.__init__(self, *args, **kwargs)
|
||||
|
||||
def connect(self):
|
||||
def create_sock():
|
||||
@@ -63,7 +63,7 @@ class HTTPSConnection(httplib.HTTPSConnection):
|
||||
break
|
||||
else:
|
||||
sock.close()
|
||||
except (ssl.SSLError, socket.error, httplib.BadStatusLine) as ex:
|
||||
except (ssl.SSLError, socket.error, _http_client.BadStatusLine) as ex:
|
||||
self._tunnel_host = None
|
||||
logger.debug("SSL connection error occurred ('%s')" % getSafeExString(ex))
|
||||
|
||||
@@ -83,7 +83,7 @@ class HTTPSConnection(httplib.HTTPSConnection):
|
||||
break
|
||||
else:
|
||||
sock.close()
|
||||
except (ssl.SSLError, socket.error, httplib.BadStatusLine) as ex:
|
||||
except (ssl.SSLError, socket.error, _http_client.BadStatusLine) as ex:
|
||||
self._tunnel_host = None
|
||||
logger.debug("SSL connection error occurred ('%s')" % getSafeExString(ex))
|
||||
|
||||
@@ -94,14 +94,14 @@ class HTTPSConnection(httplib.HTTPSConnection):
|
||||
errMsg += " (please retry with Python >= 2.7.9)"
|
||||
raise SqlmapConnectionException(errMsg)
|
||||
|
||||
class HTTPSHandler(urllib2.HTTPSHandler):
|
||||
class HTTPSHandler(_urllib.request.HTTPSHandler):
|
||||
def https_open(self, req):
|
||||
return self.do_open(HTTPSConnection if ssl else httplib.HTTPSConnection, req)
|
||||
return self.do_open(HTTPSConnection if ssl else _http_client.HTTPSConnection, req)
|
||||
|
||||
# Bug fix (http://bugs.python.org/issue17849)
|
||||
|
||||
def _(self, *args):
|
||||
return self._readline()
|
||||
|
||||
httplib.LineAndFileWrapper._readline = httplib.LineAndFileWrapper.readline
|
||||
httplib.LineAndFileWrapper.readline = _
|
||||
_http_client.LineAndFileWrapper._readline = _http_client.LineAndFileWrapper.readline
|
||||
_http_client.LineAndFileWrapper.readline = _
|
||||
|
||||
@@ -5,15 +5,15 @@ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
import urllib2
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
class MethodRequest(urllib2.Request):
|
||||
class MethodRequest(_urllib.request.Request):
|
||||
"""
|
||||
Used to create HEAD/PUT/DELETE/... requests with urllib2
|
||||
Used to create HEAD/PUT/DELETE/... requests with urllib
|
||||
"""
|
||||
|
||||
def set_method(self, method):
|
||||
self.method = method.upper()
|
||||
|
||||
def get_method(self):
|
||||
return getattr(self, 'method', urllib2.Request.get_method(self))
|
||||
return getattr(self, 'method', _urllib.request.Request.get_method(self))
|
||||
|
||||
@@ -5,16 +5,15 @@ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
import httplib
|
||||
import urllib2
|
||||
|
||||
from lib.core.data import conf
|
||||
from lib.core.common import getSafeExString
|
||||
from lib.core.exception import SqlmapConnectionException
|
||||
from thirdparty.six.moves import http_client as _http_client
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
class HTTPSPKIAuthHandler(urllib2.HTTPSHandler):
|
||||
class HTTPSPKIAuthHandler(_urllib.request.HTTPSHandler):
|
||||
def __init__(self, auth_file):
|
||||
urllib2.HTTPSHandler.__init__(self)
|
||||
_urllib.request.HTTPSHandler.__init__(self)
|
||||
self.auth_file = auth_file
|
||||
|
||||
def https_open(self, req):
|
||||
@@ -23,7 +22,7 @@ class HTTPSPKIAuthHandler(urllib2.HTTPSHandler):
|
||||
def getConnection(self, host, timeout=None):
|
||||
try:
|
||||
# Reference: https://docs.python.org/2/library/ssl.html#ssl.SSLContext.load_cert_chain
|
||||
return httplib.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=conf.timeout)
|
||||
return _http_client.HTTPSConnection(host, cert_file=self.auth_file, key_file=self.auth_file, timeout=conf.timeout)
|
||||
except IOError as ex:
|
||||
errMsg = "error occurred while using key "
|
||||
errMsg += "file '%s' ('%s')" % (self.auth_file, getSafeExString(ex))
|
||||
|
||||
@@ -5,41 +5,19 @@ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/)
|
||||
See the file 'LICENSE' for copying permission
|
||||
"""
|
||||
|
||||
import urllib
|
||||
import urllib2
|
||||
|
||||
from lib.core.exception import SqlmapConnectionException
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
class HTTPRangeHandler(urllib2.BaseHandler):
|
||||
class HTTPRangeHandler(_urllib.request.BaseHandler):
|
||||
"""
|
||||
Handler that enables HTTP Range headers.
|
||||
|
||||
Reference: http://stackoverflow.com/questions/1971240/python-seek-on-remote-file
|
||||
|
||||
This was extremely simple. The Range header is a HTTP feature to
|
||||
begin with so all this class does is tell urllib2 that the
|
||||
"206 Partial Content" response from the HTTP server is what we
|
||||
expected.
|
||||
|
||||
Example:
|
||||
import urllib2
|
||||
import byterange
|
||||
|
||||
range_handler = range.HTTPRangeHandler()
|
||||
opener = urllib2.build_opener(range_handler)
|
||||
|
||||
# install it
|
||||
urllib2.install_opener(opener)
|
||||
|
||||
# create Request and set Range header
|
||||
req = urllib2.Request('https://www.python.org/')
|
||||
req.header['Range'] = 'bytes=30-50'
|
||||
f = urllib2.urlopen(req)
|
||||
"""
|
||||
|
||||
def http_error_206(self, req, fp, code, msg, hdrs):
|
||||
# 206 Partial Content Response
|
||||
r = urllib.addinfourl(fp, hdrs, req.get_full_url())
|
||||
r = _urllib.response.addinfourl(fp, hdrs, req.get_full_url())
|
||||
r.code = code
|
||||
r.msg = msg
|
||||
return r
|
||||
|
||||
@@ -8,8 +8,6 @@ See the file 'LICENSE' for copying permission
|
||||
import io
|
||||
import time
|
||||
import types
|
||||
import urllib2
|
||||
import urlparse
|
||||
|
||||
from lib.core.data import conf
|
||||
from lib.core.data import kb
|
||||
@@ -32,8 +30,9 @@ from lib.core.settings import MAX_TOTAL_REDIRECTIONS
|
||||
from lib.core.threads import getCurrentThreadData
|
||||
from lib.request.basic import decodePage
|
||||
from lib.request.basic import parseResponse
|
||||
from thirdparty.six.moves import urllib as _urllib
|
||||
|
||||
class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||
class SmartRedirectHandler(_urllib.request.HTTPRedirectHandler):
|
||||
def _get_header_redirect(self, headers):
|
||||
retVal = None
|
||||
|
||||
@@ -66,7 +65,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||
|
||||
def _redirect_request(self, req, fp, code, msg, headers, newurl):
|
||||
newurl = newurl.replace(' ', '%20')
|
||||
return urllib2.Request(newurl, data=req.data, headers=req.headers, origin_req_host=req.get_origin_req_host())
|
||||
return _urllib.request.Request(newurl, data=req.data, headers=req.headers, origin_req_host=req.get_origin_req_host())
|
||||
|
||||
def http_error_302(self, req, fp, code, msg, headers):
|
||||
start = time.time()
|
||||
@@ -109,8 +108,8 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||
|
||||
if redurl:
|
||||
try:
|
||||
if not urlparse.urlsplit(redurl).netloc:
|
||||
redurl = urlparse.urljoin(req.get_full_url(), redurl)
|
||||
if not _urllib.parse.urlsplit(redurl).netloc:
|
||||
redurl = _urllib.parse.urljoin(req.get_full_url(), redurl)
|
||||
|
||||
self._infinite_loop_check(req)
|
||||
self._ask_redirect_choice(code, redurl, req.get_method())
|
||||
@@ -139,8 +138,8 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
||||
req.headers[HTTP_HEADER.COOKIE] = delimiter.join("%s=%s" % (key, cookies[key]) for key in cookies)
|
||||
|
||||
try:
|
||||
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
|
||||
except urllib2.HTTPError as ex:
|
||||
result = _urllib.request.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
|
||||
except _urllib.error.HTTPError as ex:
|
||||
result = ex
|
||||
|
||||
# Dirty hack for http://bugs.python.org/issue15701
|
||||
|
||||
Reference in New Issue
Block a user