From a21cbcb665d464e310c77de03e92cd5a36744d06 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 27 Mar 2019 00:58:12 +0100 Subject: [PATCH] Some minor stuff for Py3 --- lib/core/common.py | 17 ++++++++-------- lib/core/dicts.py | 44 ++++++++++++++++++++++++++++++++++++++++++ lib/core/settings.py | 12 +++++------- lib/request/connect.py | 5 +++-- sqlmap.py | 3 +-- 5 files changed, 61 insertions(+), 20 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index d61d34ecc..4aa3133d9 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -8,12 +8,10 @@ See the file 'LICENSE' for copying permission import binascii import codecs import contextlib -import cookielib import copy import distutils import getpass import hashlib -import httplib import inspect import io import json @@ -52,10 +50,6 @@ from extra.beep.beep import beep from extra.cloak.cloak import decloak from extra.safe2bin.safe2bin import safecharencode from lib.core.bigarray import BigArray -from lib.core.data import conf -from lib.core.data import kb -from lib.core.data import logger -from lib.core.data import paths from lib.core.convert import base64pickle from lib.core.convert import base64unpickle from lib.core.convert import hexdecode @@ -63,11 +57,16 @@ from lib.core.convert import htmlunescape from lib.core.convert import stdoutencode from lib.core.convert import unicodeencode from lib.core.convert import utf8encode +from lib.core.data import conf +from lib.core.data import kb +from lib.core.data import logger +from lib.core.data import paths from lib.core.decorators import cachedmethod from lib.core.defaults import defaults from lib.core.dicts import DBMS_DICT from lib.core.dicts import DEFAULT_DOC_ROOTS from lib.core.dicts import DEPRECATED_OPTIONS +from lib.core.dicts import HTTP_RESPONSES from lib.core.dicts import SQL_STATEMENTS from lib.core.enums import ADJUST_TIME_DELAY from lib.core.enums import CONTENT_STATUS @@ -3305,9 +3304,9 @@ def showHttpErrorCodes(): if kb.httpErrorCodes: warnMsg = "HTTP error codes detected during run:\n" - warnMsg += ", ".join("%d (%s) - %d times" % (code, httplib.responses[code] if code in httplib.responses else '?', count) for code, count in kb.httpErrorCodes.items()) + warnMsg += ", ".join("%d (%s) - %d times" % (code, HTTP_RESPONSES[code] if code in HTTP_RESPONSES else '?', count) for code, count in kb.httpErrorCodes.items()) logger.warn(warnMsg) - if any((str(_).startswith('4') or str(_).startswith('5')) and _ != httplib.INTERNAL_SERVER_ERROR and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()): + if any((str(_).startswith('4') or str(_).startswith('5')) and _ != 500 and _ != kb.originalCode for _ in kb.httpErrorCodes.keys()): msg = "too many 4xx and/or 5xx HTTP error codes " msg += "could mean that some kind of protection is involved (e.g. WAF)" logger.debug(msg) @@ -4512,7 +4511,7 @@ def resetCookieJar(cookieJar): errMsg = "no valid cookies found" raise SqlmapGenericException(errMsg) - except cookielib.LoadError as ex: + except Exception as ex: errMsg = "there was a problem loading " errMsg += "cookies file ('%s')" % re.sub(r"(cookies) file '[^']+'", r"\g<1>", getSafeExString(ex)) raise SqlmapGenericException(errMsg) diff --git a/lib/core/dicts.py b/lib/core/dicts.py index 18c28d722..4019ef75c 100644 --- a/lib/core/dicts.py +++ b/lib/core/dicts.py @@ -330,3 +330,47 @@ PART_RUN_CONTENT_TYPES = { "osCmd": CONTENT_TYPE.OS_CMD, "regRead": CONTENT_TYPE.REG_READ } + +HTTP_RESPONSES = { + 200: "OK", + 201: "Created", + 202: "Accepted", + 203: "Non-Authoritative Information", + 204: "No Content", + 205: "Reset Content", + 206: "Partial Content", + 100: "Continue", + 101: "Switching Protocols", + 300: "Multiple Choices", + 301: "Moved Permanently", + 302: "Found", + 303: "See Other", + 304: "Not Modified", + 305: "Use Proxy", + 306: "(Unused)", + 307: "Temporary Redirect", + 400: "Bad Request", + 401: "Unauthorized", + 402: "Payment Required", + 403: "Forbidden", + 404: "Not Found", + 405: "Method Not Allowed", + 406: "Not Acceptable", + 407: "Proxy Authentication Required", + 408: "Request Timeout", + 409: "Conflict", + 410: "Gone", + 411: "Length Required", + 412: "Precondition Failed", + 413: "Request Entity Too Large", + 414: "Request-URI Too Long", + 415: "Unsupported Media Type", + 416: "Requested Range Not Satisfiable", + 417: "Expectation Failed", + 500: "Internal Server Error", + 501: "Not Implemented", + 502: "Bad Gateway", + 503: "Service Unavailable", + 504: "Gateway Timeout", + 505: "HTTP Version Not Supported" +} diff --git a/lib/core/settings.py b/lib/core/settings.py index 20b910fcf..261ac7db7 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -5,10 +5,10 @@ Copyright (c) 2006-2019 sqlmap developers (http://sqlmap.org/) See the file 'LICENSE' for copying permission """ +import codecs import os import random import re -import subprocess import string import sys import types @@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME from lib.core.enums import OS # sqlmap version (...) -VERSION = "1.3.3.50" +VERSION = "1.3.3.51" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) @@ -218,7 +218,7 @@ DUMMY_USER_PREFIX = "__dummy__" DEFAULT_PAGE_ENCODING = "iso-8859-1" try: - unicode(DEFAULT_PAGE_ENCODING, DEFAULT_PAGE_ENCODING) + codecs.lookup(DEFAULT_PAGE_ENCODING) except LookupError: DEFAULT_PAGE_ENCODING = "utf8" @@ -228,12 +228,10 @@ STDIN_PIPE_DASH = '-' # URL used in dummy runs DUMMY_URL = "http://foo/bar?id=1" -# System variables -IS_WIN = subprocess.mswindows - # The name of the operating system dependent module imported. The following names have currently been registered: 'posix', 'nt', 'mac', 'os2', 'ce', 'java', 'riscos' PLATFORM = os.name PYVERSION = sys.version.split()[0] +IS_WIN = PLATFORM == "nt" # DBMS system databases MSSQL_SYSTEM_DBS = ("Northwind", "master", "model", "msdb", "pubs", "tempdb") @@ -448,7 +446,7 @@ HASH_MOD_ITEM_DISPLAY = 11 HASH_EMPTY_PASSWORD_MARKER = "" # Maximum integer value -MAX_INT = sys.maxint +MAX_INT = sys.maxsize # Replacement for unsafe characters in dump table filenames UNSAFE_DUMP_FILEPATH_REPLACEMENT = '_' diff --git a/lib/request/connect.py b/lib/request/connect.py index 3de5e700e..e41beddfa 100644 --- a/lib/request/connect.py +++ b/lib/request/connect.py @@ -67,6 +67,7 @@ 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 @@ -427,7 +428,7 @@ class Connect(object): page = ws.recv() ws.close() code = ws.status - status = httplib.responses[code] + status = HTTP_RESPONSES[code] class _(dict): pass @@ -643,7 +644,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, httplib.responses[ex.code]) + warnMsg = "unable to connect to the target URL (%d - %s)" % (ex.code, HTTP_RESPONSES[ex.code]) if threadData.retriesCount < conf.retries and not kb.threadException: warnMsg += ". sqlmap is going to retry the request" logger.critical(warnMsg) diff --git a/sqlmap.py b/sqlmap.py index fd654b010..bd6133896 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -27,7 +27,6 @@ try: import re import shutil import sys - import thread import threading import time import traceback @@ -169,7 +168,7 @@ def main(): else: try: start() - except thread.error as ex: + except Exception as ex: if "can't start new thread" in getSafeExString(ex): errMsg = "unable to start new threads. Please check OS (u)limits" logger.critical(errMsg)