More refactoring like the last couple of commits

This commit is contained in:
Miroslav Stampar
2019-01-22 02:08:02 +01:00
parent fd705c3dff
commit 7074365f8e
22 changed files with 144 additions and 137 deletions

View File

@@ -4409,9 +4409,9 @@ def resetCookieJar(cookieJar):
errMsg = "no valid cookies found"
raise SqlmapGenericException(errMsg)
except cookielib.LoadError, msg:
except cookielib.LoadError as ex:
errMsg = "there was a problem loading "
errMsg += "cookies file ('%s')" % re.sub(r"(cookies) file '[^']+'", r"\g<1>", str(msg))
errMsg += "cookies file ('%s')" % re.sub(r"(cookies) file '[^']+'", r"\g<1>", getSafeExString(ex))
raise SqlmapGenericException(errMsg)
def decloakToTemp(filename):
@@ -4738,8 +4738,6 @@ def getSafeExString(ex, encoding=None):
u'foobar'
"""
retVal = ex
if getattr(ex, "message", None):
retVal = ex.message
elif getattr(ex, "msg", None):
@@ -4748,6 +4746,8 @@ def getSafeExString(ex, encoding=None):
retVal = ex[1]
elif isinstance(ex, (list, tuple)) and len(ex) > 0 and isinstance(ex[0], basestring):
retVal = ex[0]
else:
retVal = str(ex)
return getUnicode(retVal or "", encoding=encoding).strip()

View File

@@ -429,7 +429,7 @@ class Dump(object):
except Exception as ex:
try:
tempDir = tempfile.mkdtemp(prefix="sqlmapdb")
except IOError, _:
except IOError as _:
errMsg = "unable to write to the temporary directory ('%s'). " % _
errMsg += "Please make sure that your disk is not full and "
errMsg += "that you have sufficient write permissions to "

View File

@@ -846,8 +846,8 @@ def _setWafFunctions():
if filename[:-3] in sys.modules:
del sys.modules[filename[:-3]]
module = __import__(filename[:-3].encode(sys.getfilesystemencoding() or UNICODE_ENCODING))
except ImportError, msg:
raise SqlmapSyntaxException("cannot import WAF script '%s' (%s)" % (filename[:-3], msg))
except ImportError as ex:
raise SqlmapSyntaxException("cannot import WAF script '%s' (%s)" % (filename[:-3], getSafeExString(ex)))
_ = dict(inspect.getmembers(module))
if "detect" not in _:
@@ -1195,7 +1195,7 @@ def _setHTTPAuthentication():
elif authType == AUTH_TYPE.NTLM:
regExp = "^(.*\\\\.*):(.*?)$"
errMsg = "HTTP NTLM authentication credentials value must "
errMsg += "be in format 'DOMAIN\username:password'"
errMsg += "be in format 'DOMAIN\\username:password'"
elif authType == AUTH_TYPE.PKI:
errMsg = "HTTP PKI authentication require "
errMsg += "usage of option `--auth-pki`"
@@ -2136,9 +2136,9 @@ def _setDNSServer():
try:
conf.dnsServer = DNSServer()
conf.dnsServer.run()
except socket.error, msg:
except socket.error as ex:
errMsg = "there was an error while setting up "
errMsg += "DNS server instance ('%s')" % msg
errMsg += "DNS server instance ('%s')" % getSafeExString(ex)
raise SqlmapGenericException(errMsg)
else:
errMsg = "you need to run sqlmap as an administrator "

View File

@@ -9,6 +9,7 @@ import codecs
import os
import cProfile
from lib.core.common import getSafeExString
from lib.core.common import getUnicode
from lib.core.data import logger
from lib.core.data import paths
@@ -25,8 +26,8 @@ def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
from thirdparty.xdot import xdot
import gtk
import pydot
except ImportError, e:
errMsg = "profiling requires third-party libraries ('%s') " % getUnicode(e, UNICODE_ENCODING)
except ImportError as ex:
errMsg = "profiling requires third-party libraries ('%s') " % getSafeExString(ex)
errMsg += "(Hint: 'sudo apt-get install python-pydot python-pyparsing python-profiler graphviz')"
logger.error(errMsg)

View File

@@ -19,7 +19,7 @@ from lib.core.enums import DBMS_DIRECTORY_NAME
from lib.core.enums import OS
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
VERSION = "1.3.1.62"
VERSION = "1.3.1.63"
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)

View File

@@ -9,6 +9,7 @@ import atexit
import os
from lib.core import readlineng as readline
from lib.core.common import getSafeExString
from lib.core.data import logger
from lib.core.data import paths
from lib.core.enums import AUTOCOMPLETE_TYPE
@@ -75,8 +76,8 @@ def saveHistory(completion=None):
readline.set_history_length(MAX_HISTORY_LENGTH)
try:
readline.write_history_file(historyPath)
except IOError, msg:
warnMsg = "there was a problem writing the history file '%s' (%s)" % (historyPath, msg)
except IOError as ex:
warnMsg = "there was a problem writing the history file '%s' (%s)" % (historyPath, getSafeExString(ex))
logger.warn(warnMsg)
except KeyboardInterrupt:
pass
@@ -99,8 +100,8 @@ def loadHistory(completion=None):
if os.path.exists(historyPath):
try:
readline.read_history_file(historyPath)
except IOError, msg:
warnMsg = "there was a problem loading the history file '%s' (%s)" % (historyPath, msg)
except IOError as ex:
warnMsg = "there was a problem loading the history file '%s' (%s)" % (historyPath, getSafeExString(ex))
logger.warn(warnMsg)
def autoCompletion(completion=None, os=None, commands=None):

View File

@@ -31,7 +31,7 @@ def blockingReadFromFD(fd):
while True:
try:
output += os.read(fd, 8192)
except (OSError, IOError), ioe:
except (OSError, IOError) as ioe:
if ioe.args[0] in (errno.EAGAIN, errno.EINTR):
# Uncomment the following line if the process seems to
# take a huge amount of cpu time
@@ -52,7 +52,7 @@ def blockingWriteToFD(fd, data):
try:
data_length = len(data)
wrote_data = os.write(fd, data)
except (OSError, IOError), io:
except (OSError, IOError) as io:
if io.errno in (errno.EAGAIN, errno.EINTR):
continue
else:
@@ -95,8 +95,8 @@ class Popen(subprocess.Popen):
(errCode, written) = WriteFile(x, input)
except ValueError:
return self._close('stdin')
except (subprocess.pywintypes.error, Exception), why:
if why[0] in (109, errno.ESHUTDOWN):
except (subprocess.pywintypes.error, Exception) as ex:
if ex[0] in (109, errno.ESHUTDOWN):
return self._close('stdin')
raise
@@ -116,8 +116,8 @@ class Popen(subprocess.Popen):
(errCode, read) = ReadFile(x, nAvail, None)
except (ValueError, NameError):
return self._close(which)
except (subprocess.pywintypes.error, Exception), why:
if why[0] in (109, errno.ESHUTDOWN):
except (subprocess.pywintypes.error, Exception) as ex:
if ex[0] in (109, errno.ESHUTDOWN):
return self._close(which)
raise
@@ -134,8 +134,8 @@ class Popen(subprocess.Popen):
try:
written = os.write(self.stdin.fileno(), input)
except OSError, why:
if why[0] == errno.EPIPE: # broken pipe
except OSError as ex:
if ex[0] == errno.EPIPE: # broken pipe
return self._close('stdin')
raise

View File

@@ -427,8 +427,8 @@ def _setHashDB():
try:
os.remove(conf.hashDBFile)
logger.info("flushing session file")
except OSError, msg:
errMsg = "unable to flush the session file (%s)" % msg
except OSError as ex:
errMsg = "unable to flush the session file ('%s')" % getSafeExString(ex)
raise SqlmapFilePathException(errMsg)
conf.hashDB = HashDB(conf.hashDBFile)
@@ -566,7 +566,7 @@ def _setResultsFile():
conf.resultsFP = openFile(conf.resultsFilename, "w+", UNICODE_ENCODING, buffering=0)
warnMsg += "Using temporary file '%s' instead" % conf.resultsFilename
logger.warn(warnMsg)
except IOError, _:
except IOError as _:
errMsg = "unable to write to the temporary directory ('%s'). " % _
errMsg += "Please make sure that your disk is not full and "
errMsg += "that you have sufficient write permissions to "