Skip to content

Commit 2f53014

Browse files
committed
God help us all with this Python3 non-sense
1 parent 2dbd026 commit 2f53014

File tree

23 files changed

+118
-201
lines changed

23 files changed

+118
-201
lines changed

lib/controller/checks.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""
77

88
import copy
9-
import httplib
109
import logging
1110
import os
1211
import random
@@ -106,6 +105,7 @@
106105
from lib.request.templates import getPageTemplate
107106
from lib.techniques.union.test import unionTest
108107
from lib.techniques.union.use import configUnion
108+
from thirdparty.six.moves import http_client as _http_client
109109

110110
def checkSqlInjection(place, parameter, value):
111111
# Store here the details about boundaries and payload used to
@@ -1337,7 +1337,7 @@ def checkWaf():
13371337
if any((conf.string, conf.notString, conf.regexp, conf.dummy, conf.offline, conf.skipWaf)):
13381338
return None
13391339

1340-
if kb.originalCode == httplib.NOT_FOUND:
1340+
if kb.originalCode == _http_client.NOT_FOUND:
13411341
return None
13421342

13431343
_ = hashDBRetrieve(HASHDB_KEYS.CHECK_WAF_RESULT, True)
@@ -1623,7 +1623,7 @@ def checkConnection(suppressOutput=False):
16231623
warnMsg += "any addressing issues"
16241624
singleTimeWarnMessage(warnMsg)
16251625

1626-
if any(code in kb.httpErrorCodes for code in (httplib.NOT_FOUND, )):
1626+
if any(code in kb.httpErrorCodes for code in (_http_client.NOT_FOUND, )):
16271627
errMsg = getSafeExString(ex)
16281628
logger.critical(errMsg)
16291629

lib/core/common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@
6161
from lib.core.dicts import DBMS_DICT
6262
from lib.core.dicts import DEFAULT_DOC_ROOTS
6363
from lib.core.dicts import DEPRECATED_OPTIONS
64-
from lib.core.dicts import HTTP_RESPONSES
6564
from lib.core.dicts import SQL_STATEMENTS
6665
from lib.core.enums import ADJUST_TIME_DELAY
6766
from lib.core.enums import CONTENT_STATUS
@@ -174,6 +173,7 @@
174173
from thirdparty.magic import magic
175174
from thirdparty.odict import OrderedDict
176175
from thirdparty.six.moves import configparser as _configparser
176+
from thirdparty.six.moves import http_client as _http_client
177177
from thirdparty.six.moves import urllib as _urllib
178178
from thirdparty.termcolor.termcolor import colored
179179

@@ -3301,9 +3301,9 @@ def showHttpErrorCodes():
33013301

33023302
if kb.httpErrorCodes:
33033303
warnMsg = "HTTP error codes detected during run:\n"
3304-
warnMsg += ", ".join("%d (%s) - %d times" % (code, HTTP_RESPONSES[code] if code in HTTP_RESPONSES else '?', count) for code, count in kb.httpErrorCodes.items())
3304+
warnMsg += ", ".join("%d (%s) - %d times" % (code, _http_client.responses[code] if code in _http_client.responses else '?', count) for code, count in kb.httpErrorCodes.items())
33053305
logger.warn(warnMsg)
3306-
if any((str(_).startswith('4') or str(_).startswith('5')) and _ != 500 and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()):
3306+
if any((str(_).startswith('4') or str(_).startswith('5')) and _ != _http_client.INTERNAL_SERVER_ERROR and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()):
33073307
msg = "too many 4xx and/or 5xx HTTP error codes "
33083308
msg += "could mean that some kind of protection is involved (e.g. WAF)"
33093309
logger.debug(msg)

lib/core/dicts.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -330,47 +330,3 @@
330330
"osCmd": CONTENT_TYPE.OS_CMD,
331331
"regRead": CONTENT_TYPE.REG_READ
332332
}
333-
334-
HTTP_RESPONSES = {
335-
200: "OK",
336-
201: "Created",
337-
202: "Accepted",
338-
203: "Non-Authoritative Information",
339-
204: "No Content",
340-
205: "Reset Content",
341-
206: "Partial Content",
342-
100: "Continue",
343-
101: "Switching Protocols",
344-
300: "Multiple Choices",
345-
301: "Moved Permanently",
346-
302: "Found",
347-
303: "See Other",
348-
304: "Not Modified",
349-
305: "Use Proxy",
350-
306: "(Unused)",
351-
307: "Temporary Redirect",
352-
400: "Bad Request",
353-
401: "Unauthorized",
354-
402: "Payment Required",
355-
403: "Forbidden",
356-
404: "Not Found",
357-
405: "Method Not Allowed",
358-
406: "Not Acceptable",
359-
407: "Proxy Authentication Required",
360-
408: "Request Timeout",
361-
409: "Conflict",
362-
410: "Gone",
363-
411: "Length Required",
364-
412: "Precondition Failed",
365-
413: "Request Entity Too Large",
366-
414: "Request-URI Too Long",
367-
415: "Unsupported Media Type",
368-
416: "Requested Range Not Satisfiable",
369-
417: "Expectation Failed",
370-
500: "Internal Server Error",
371-
501: "Not Implemented",
372-
502: "Bad Gateway",
373-
503: "Service Unavailable",
374-
504: "Gateway Timeout",
375-
505: "HTTP Version Not Supported"
376-
}

lib/core/option.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8-
import cookielib
98
import glob
10-
import httplib
119
import inspect
1210
import logging
1311
import os
@@ -19,7 +17,6 @@
1917
import threading
2018
import time
2119
import urllib2
22-
import urlparse
2320

2421
import lib.controller.checks
2522
import lib.core.common
@@ -153,14 +150,17 @@
153150
from thirdparty.keepalive import keepalive
154151
from thirdparty.multipart import multipartpost
155152
from thirdparty.oset.pyoset import oset
153+
from thirdparty.six.moves import http_client as _http_client
154+
from thirdparty.six.moves import http_cookiejar as _http_cookiejar
155+
from thirdparty.six.moves import urllib as _urllib
156156
from thirdparty.socks import socks
157157
from xml.etree.ElementTree import ElementTree
158158

159-
authHandler = urllib2.BaseHandler()
159+
authHandler = _urllib.request.BaseHandler()
160160
chunkedHandler = ChunkedHandler()
161161
httpsHandler = HTTPSHandler()
162162
keepAliveHandler = keepalive.HTTPHandler()
163-
proxyHandler = urllib2.ProxyHandler()
163+
proxyHandler = _urllib.request.ProxyHandler()
164164
redirectHandler = SmartRedirectHandler()
165165
rangeHandler = HTTPRangeHandler()
166166
multipartPostHandler = multipartpost.MultipartPostHandler()
@@ -1053,7 +1053,7 @@ def _setHTTPHandlers():
10531053
logger.debug(debugMsg)
10541054

10551055
try:
1056-
_ = urlparse.urlsplit(conf.proxy)
1056+
_ = _urllib.parse.urlsplit(conf.proxy)
10571057
except Exception as ex:
10581058
errMsg = "invalid proxy address '%s' ('%s')" % (conf.proxy, getSafeExString(ex))
10591059
raise SqlmapSyntaxException(errMsg)
@@ -1090,9 +1090,9 @@ def _setHTTPHandlers():
10901090
proxyHandler.proxies = {}
10911091

10921092
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 if scheme == PROXY_TYPE.SOCKS5 else socks.PROXY_TYPE_SOCKS4, hostname, port, username=username, password=password)
1093-
socks.wrapmodule(urllib2)
1093+
socks.wrapmodule(_http_client)
10941094
else:
1095-
socks.unwrapmodule(urllib2)
1095+
socks.unwrapmodule(_http_client)
10961096

10971097
if conf.proxyCred:
10981098
# Reference: http://stackoverflow.com/questions/34079/how-to-specify-an-authenticated-proxy-for-a-python-http-connection
@@ -1112,12 +1112,12 @@ def _setHTTPHandlers():
11121112

11131113
if not conf.dropSetCookie:
11141114
if not conf.loadCookies:
1115-
conf.cj = cookielib.CookieJar()
1115+
conf.cj = _http_cookiejar.CookieJar()
11161116
else:
1117-
conf.cj = cookielib.MozillaCookieJar()
1117+
conf.cj = _http_cookiejar.MozillaCookieJar()
11181118
resetCookieJar(conf.cj)
11191119

1120-
handlers.append(urllib2.HTTPCookieProcessor(conf.cj))
1120+
handlers.append(_urllib.request.HTTPCookieProcessor(conf.cj))
11211121

11221122
# Reference: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html
11231123
if conf.keepAlive:
@@ -1133,8 +1133,8 @@ def _setHTTPHandlers():
11331133
else:
11341134
handlers.append(keepAliveHandler)
11351135

1136-
opener = urllib2.build_opener(*handlers)
1137-
urllib2.install_opener(opener)
1136+
opener = _urllib.request.build_opener(*handlers)
1137+
_urllib.request.install_opener(opener)
11381138

11391139
def _setSafeVisit():
11401140
"""
@@ -1166,7 +1166,7 @@ def _setSafeVisit():
11661166
if value.endswith(":443"):
11671167
scheme = "https"
11681168
value = "%s://%s" % (scheme, value)
1169-
kb.safeReq.url = urlparse.urljoin(value, kb.safeReq.url)
1169+
kb.safeReq.url = _urllib.parse.urljoin(value, kb.safeReq.url)
11701170
else:
11711171
break
11721172

@@ -1289,15 +1289,15 @@ def _setHTTPAuthentication():
12891289
conf.authUsername = aCredRegExp.group(1)
12901290
conf.authPassword = aCredRegExp.group(2)
12911291

1292-
kb.passwordMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
1292+
kb.passwordMgr = _urllib.request.HTTPPasswordMgrWithDefaultRealm()
12931293

12941294
_setAuthCred()
12951295

12961296
if authType == AUTH_TYPE.BASIC:
12971297
authHandler = SmartHTTPBasicAuthHandler(kb.passwordMgr)
12981298

12991299
elif authType == AUTH_TYPE.DIGEST:
1300-
authHandler = urllib2.HTTPDigestAuthHandler(kb.passwordMgr)
1300+
authHandler = _urllib.request.HTTPDigestAuthHandler(kb.passwordMgr)
13011301

13021302
elif authType == AUTH_TYPE.NTLM:
13031303
try:
@@ -1459,7 +1459,7 @@ def _setHostname():
14591459

14601460
if conf.url:
14611461
try:
1462-
conf.hostname = urlparse.urlsplit(conf.url).netloc.split(':')[0]
1462+
conf.hostname = _urllib.parse.urlsplit(conf.url).netloc.split(':')[0]
14631463
except ValueError as ex:
14641464
errMsg = "problem occurred while "
14651465
errMsg += "parsing an URL '%s' ('%s')" % (conf.url, getSafeExString(ex))
@@ -1783,8 +1783,8 @@ def _cleanupEnvironment():
17831783
Cleanup environment (e.g. from leftovers after --sqlmap-shell).
17841784
"""
17851785

1786-
if issubclass(urllib2.socket.socket, socks.socksocket):
1787-
socks.unwrapmodule(urllib2)
1786+
if issubclass(_http_client.socket.socket, socks.socksocket):
1787+
socks.unwrapmodule(_http_client)
17881788

17891789
if hasattr(socket, "_ready"):
17901790
socket._ready.clear()
@@ -2312,11 +2312,11 @@ def _setTorSocksProxySettings():
23122312

23132313
# SOCKS5 to prevent DNS leaks (http://en.wikipedia.org/wiki/Tor_%28anonymity_network%29)
23142314
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5 if conf.torType == PROXY_TYPE.SOCKS5 else socks.PROXY_TYPE_SOCKS4, LOCALHOST, port)
2315-
socks.wrapmodule(urllib2)
2315+
socks.wrapmodule(_http_client)
23162316

23172317
def _setHttpChunked():
23182318
if conf.chunked and conf.data:
2319-
httplib.HTTPConnection._set_content_length = lambda self, a, b: None
2319+
_http_client.HTTPConnection._set_content_length = lambda self, a, b: None
23202320

23212321
def _checkWebSocket():
23222322
if conf.url and (conf.url.startswith("ws:/") or conf.url.startswith("wss:/")):

lib/core/patch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
"""
77

88
import codecs
9-
import httplib
109

1110
from lib.core.settings import IS_WIN
11+
from thirdparty.six.moves import http_client as _http_client
1212

1313
def dirtyPatches():
1414
"""
1515
Place for "dirty" Python related patches
1616
"""
1717

1818
# accept overly long result lines (e.g. SQLi results in HTTP header responses)
19-
httplib._MAXLINE = 1 * 1024 * 1024
19+
_http_client._MAXLINE = 1 * 1024 * 1024
2020

2121
# add support for inet_pton() on Windows OS
2222
if IS_WIN:

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from lib.core.enums import OS
1818

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

lib/core/target.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import sys
1313
import tempfile
1414
import time
15-
import urlparse
1615

1716
from lib.core.common import Backend
1817
from lib.core.common import getSafeExString
@@ -74,6 +73,7 @@
7473
from lib.core.settings import XML_RECOGNITION_REGEX
7574
from lib.utils.hashdb import HashDB
7675
from thirdparty.odict import OrderedDict
76+
from thirdparty.six.moves import urllib as _urllib
7777

7878
def _setRequestParams():
7979
"""
@@ -276,7 +276,7 @@ def process(match, repl):
276276

277277
if not kb.processUserMarks:
278278
if place == PLACE.URI:
279-
query = urlparse.urlsplit(value).query
279+
query = _urllib.parse.urlsplit(value).query
280280
if query:
281281
parameters = conf.parameters[PLACE.GET] = query
282282
paramDict = paramToDict(PLACE.GET, parameters)

lib/core/threads.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import time
1414
import traceback
1515

16+
from lib.core.compat import WichmannHill
1617
from lib.core.data import conf
1718
from lib.core.data import kb
1819
from lib.core.data import logger
@@ -57,7 +58,7 @@ def reset(self):
5758
self.lastRequestMsg = None
5859
self.lastRequestUID = 0
5960
self.lastRedirectURL = None
60-
self.random = random.WichmannHill()
61+
self.random = WichmannHill()
6162
self.resumed = False
6263
self.retriesCount = 0
6364
self.seqMatcher = difflib.SequenceMatcher(None)

lib/parse/sitemap.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
See the file 'LICENSE' for copying permission
66
"""
77

8-
import httplib
98
import re
109

1110
from lib.core.common import readInput
@@ -14,6 +13,7 @@
1413
from lib.core.exception import SqlmapSyntaxException
1514
from lib.request.connect import Connect as Request
1615
from thirdparty.oset.pyoset import oset
16+
from thirdparty.six.moves import http_client as _http_client
1717

1818
abortedFlag = None
1919

@@ -30,7 +30,7 @@ def parseSitemap(url, retVal=None):
3030

3131
try:
3232
content = Request.getPage(url=url, raise404=True)[0] if not abortedFlag else ""
33-
except httplib.InvalidURL:
33+
except _http_client.InvalidURL:
3434
errMsg = "invalid URL given for sitemap ('%s')" % url
3535
raise SqlmapSyntaxException(errMsg)
3636

lib/request/basicauthhandler.py

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

8-
import urllib2
8+
from thirdparty.six.moves import urllib as _urllib
99

10-
class SmartHTTPBasicAuthHandler(urllib2.HTTPBasicAuthHandler):
10+
class SmartHTTPBasicAuthHandler(_urllib.request.HTTPBasicAuthHandler):
1111
"""
1212
Reference: http://selenic.com/hg/rev/6c51a5056020
1313
Fix for a: http://bugs.python.org/issue8797
1414
"""
1515
def __init__(self, *args, **kwargs):
16-
urllib2.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
16+
_urllib.request.HTTPBasicAuthHandler.__init__(self, *args, **kwargs)
1717
self.retried_req = set()
1818
self.retried_count = 0
1919

@@ -30,8 +30,8 @@ def http_error_auth_reqed(self, auth_header, host, req, headers):
3030
self.retried_count = 0
3131
else:
3232
if self.retried_count > 5:
33-
raise urllib2.HTTPError(req.get_full_url(), 401, "basic auth failed", headers, None)
33+
raise _urllib.error.HTTPError(req.get_full_url(), 401, "basic auth failed", headers, None)
3434
else:
3535
self.retried_count += 1
3636

37-
return urllib2.HTTPBasicAuthHandler.http_error_auth_reqed(self, auth_header, host, req, headers)
37+
return _urllib.request.HTTPBasicAuthHandler.http_error_auth_reqed(self, auth_header, host, req, headers)

0 commit comments

Comments
 (0)