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

@ -95,8 +95,8 @@ def main():
if filename[:-3] in sys.modules:
del sys.modules[filename[:-3]]
module = __import__(filename[:-3].encode(sys.getfilesystemencoding() or "utf8"))
except ImportError, msg:
exit(colorize("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], msg)))
except ImportError as ex:
exit(colorize("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], ex)))
_ = dict(inspect.getmembers(module))
if "detect" not in _:

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 "

View File

@ -897,8 +897,8 @@ def cmdLineParser(argv=None):
return args
except (OptionError, TypeError), e:
parser.error(e)
except (OptionError, TypeError) as ex:
parser.error(ex)
except SystemExit:
# Protection against Windows dummy double clicking

View File

@ -141,8 +141,8 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
try:
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
except urllib2.HTTPError, e:
result = e
except urllib2.HTTPError as ex:
result = ex
# Dirty hack for http://bugs.python.org/issue15701
try:
@ -154,7 +154,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
if not hasattr(result, "read"):
def _(self, length=None):
return e.msg
return ex.msg
result.read = types.MethodType(_, result)
if not getattr(result, "url", None):

View File

@ -88,12 +88,12 @@ def _search(dork):
responseMsg += "%s\n%s\n" % (responseHeaders, page)
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
except urllib2.HTTPError, e:
except urllib2.HTTPError as ex:
try:
page = e.read()
except Exception as ex:
page = ex.read()
except Exception as _:
warnMsg = "problem occurred while trying to get "
warnMsg += "an error page information (%s)" % getSafeExString(ex)
warnMsg += "an error page information (%s)" % getSafeExString(_)
logger.critical(warnMsg)
return None
except (urllib2.URLError, httplib.error, socket.error, socket.timeout, socks.ProxyError):
@ -150,13 +150,13 @@ def _search(dork):
responseMsg += "%s\n%s\n" % (responseHeaders, page)
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, responseMsg)
except urllib2.HTTPError, e:
except urllib2.HTTPError as ex:
try:
page = e.read()
page = decodePage(page, e.headers.get("Content-Encoding"), e.headers.get("Content-Type"))
page = ex.read()
page = decodePage(page, ex.headers.get("Content-Encoding"), ex.headers.get("Content-Type"))
except socket.timeout:
warnMsg = "connection timed out while trying "
warnMsg += "to get error page information (%d)" % e.code
warnMsg += "to get error page information (%d)" % ex.code
logger.critical(warnMsg)
return None
except:

View File

@ -43,8 +43,8 @@ class Connector(GenericConnector):
try:
self.connector = pyodbc.connect('Driver={Microsoft Access Driver (*.mdb)};Dbq=%s;Uid=Admin;Pwd=;' % self.db)
except (pyodbc.Error, pyodbc.OperationalError), msg:
raise SqlmapConnectionException(getSafeExString(msg))
except (pyodbc.Error, pyodbc.OperationalError) as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
@ -52,17 +52,17 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except pyodbc.ProgrammingError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except pyodbc.ProgrammingError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
return None
def execute(self, query):
try:
self.cursor.execute(query)
except (pyodbc.OperationalError, pyodbc.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except pyodbc.Error, msg:
raise SqlmapConnectionException(getSafeExString(msg))
except (pyodbc.OperationalError, pyodbc.ProgrammingError) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
except pyodbc.Error as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.commit()

View File

@ -35,8 +35,8 @@ class Connector(GenericConnector):
try:
database = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % (self.db, self.hostname, self.port)
self.connector = ibm_db_dbi.connect(database, self.user, self.password)
except ibm_db_dbi.OperationalError, msg:
raise SqlmapConnectionException(msg)
except ibm_db_dbi.OperationalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
@ -44,17 +44,17 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except ibm_db_dbi.ProgrammingError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except ibm_db_dbi.ProgrammingError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
return None
def execute(self, query):
try:
self.cursor.execute(query)
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except ibm_db_dbi.InternalError, msg:
raise SqlmapConnectionException(getSafeExString(msg))
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
except ibm_db_dbi.InternalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.commit()

View File

@ -35,8 +35,8 @@ class Connector(GenericConnector):
try:
database = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % (self.db, self.hostname, self.port)
self.connector = ibm_db_dbi.connect(database, self.user, self.password)
except ibm_db_dbi.OperationalError, msg:
raise SqlmapConnectionException(getSafeExString(msg))
except ibm_db_dbi.OperationalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
@ -44,17 +44,17 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except ibm_db_dbi.ProgrammingError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except ibm_db_dbi.ProgrammingError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
return None
def execute(self, query):
try:
self.cursor.execute(query)
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except ibm_db_dbi.InternalError, msg:
raise SqlmapConnectionException(getSafeExString(msg))
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
except ibm_db_dbi.InternalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.commit()

View File

@ -13,6 +13,7 @@ except:
import logging
from lib.core.common import getSafeExString
from lib.core.convert import utf8encode
from lib.core.data import conf
from lib.core.data import logger
@ -41,8 +42,8 @@ class Connector(GenericConnector):
try:
self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout)
except (pymssql.Error, _mssql.MssqlDatabaseException), msg:
raise SqlmapConnectionException(msg)
except (pymssql.Error, _mssql.MssqlDatabaseException) as ex:
raise SqlmapConnectionException(getSafeExString(ex))
except ValueError:
raise SqlmapConnectionException
@ -52,8 +53,8 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except (pymssql.Error, _mssql.MssqlDatabaseException), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
except (pymssql.Error, _mssql.MssqlDatabaseException) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex).replace("\n", " "))
return None
def execute(self, query):
@ -62,10 +63,10 @@ class Connector(GenericConnector):
try:
self.cursor.execute(utf8encode(query))
retVal = True
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
except pymssql.InternalError, msg:
raise SqlmapConnectionException(msg)
except (pymssql.OperationalError, pymssql.ProgrammingError) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex).replace("\n", " "))
except pymssql.InternalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
return retVal

View File

@ -38,8 +38,8 @@ class Connector(GenericConnector):
try:
self.connector = pymysql.connect(host=self.hostname, user=self.user, passwd=self.password, db=self.db, port=self.port, connect_timeout=conf.timeout, use_unicode=True)
except (pymysql.OperationalError, pymysql.InternalError, pymysql.ProgrammingError, struct.error), msg:
raise SqlmapConnectionException(getSafeExString(msg))
except (pymysql.OperationalError, pymysql.InternalError, pymysql.ProgrammingError, struct.error) as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
@ -47,8 +47,8 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except pymysql.ProgrammingError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except pymysql.ProgrammingError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
return None
def execute(self, query):
@ -57,10 +57,10 @@ class Connector(GenericConnector):
try:
self.cursor.execute(query)
retVal = True
except (pymysql.OperationalError, pymysql.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(msg))
except pymysql.InternalError, msg:
raise SqlmapConnectionException(getSafeExString(msg))
except (pymysql.OperationalError, pymysql.ProgrammingError) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
except pymysql.InternalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.commit()

View File

@ -14,6 +14,7 @@ import logging
import os
import re
from lib.core.common import getSafeExString
from lib.core.convert import utf8encode
from lib.core.data import conf
from lib.core.data import logger
@ -44,16 +45,16 @@ class Connector(GenericConnector):
self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password, mode=cx_Oracle.SYSDBA)
logger.info("successfully connected as SYSDBA")
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError) as ex:
if "Oracle Client library" in str(ex):
msg = re.sub(r"DPI-\d+:\s+", "", str(ex))
if "Oracle Client library" in getSafeExString(ex):
msg = re.sub(r"DPI-\d+:\s+", "", getSafeExString(ex))
msg = re.sub(r': ("[^"]+")', r" (\g<1>)", msg)
msg = re.sub(r". See (http[^ ]+)", r'. See "\g<1>"', msg)
raise SqlmapConnectionException(msg)
try:
self.connector = cx_Oracle.connect(dsn=self.__dsn, user=self.user, password=self.password)
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError), msg:
raise SqlmapConnectionException(msg)
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError) as ex:
raise SqlmapConnectionException(ex)
self.initCursor()
self.printConnected()
@ -61,8 +62,8 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except cx_Oracle.InterfaceError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg)
except cx_Oracle.InterfaceError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
return None
def execute(self, query):
@ -71,8 +72,8 @@ class Connector(GenericConnector):
try:
self.cursor.execute(utf8encode(query))
retVal = True
except cx_Oracle.DatabaseError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg)
except cx_Oracle.DatabaseError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
self.connector.commit()

View File

@ -13,6 +13,7 @@ try:
except:
pass
from lib.core.common import getSafeExString
from lib.core.data import logger
from lib.core.exception import SqlmapConnectionException
from plugins.generic.connector import Connector as GenericConnector
@ -36,8 +37,8 @@ class Connector(GenericConnector):
try:
self.connector = psycopg2.connect(host=self.hostname, user=self.user, password=self.password, database=self.db, port=self.port)
except psycopg2.OperationalError, msg:
raise SqlmapConnectionException(msg)
except psycopg2.OperationalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.set_client_encoding('UNICODE')
@ -47,8 +48,8 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except psycopg2.ProgrammingError, msg:
logger.warn(msg)
except psycopg2.ProgrammingError as ex:
logger.warn(getSafeExString(ex))
return None
def execute(self, query):
@ -57,10 +58,10 @@ class Connector(GenericConnector):
try:
self.cursor.execute(query)
retVal = True
except (psycopg2.OperationalError, psycopg2.ProgrammingError), msg:
logger.warn(("(remote) %s" % msg).strip())
except psycopg2.InternalError, msg:
raise SqlmapConnectionException(msg)
except (psycopg2.OperationalError, psycopg2.ProgrammingError) as ex:
logger.warn(("(remote) '%s'" % getSafeExString(ex)).strip())
except psycopg2.InternalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.commit()

View File

@ -12,6 +12,7 @@ except:
import logging
from lib.core.common import getSafeExString
from lib.core.convert import utf8encode
from lib.core.data import conf
from lib.core.data import logger
@ -45,7 +46,7 @@ class Connector(GenericConnector):
cursor.execute("SELECT * FROM sqlite_master")
cursor.close()
except (self.__sqlite.DatabaseError, self.__sqlite.OperationalError), msg:
except (self.__sqlite.DatabaseError, self.__sqlite.OperationalError):
warnMsg = "unable to connect using SQLite 3 library, trying with SQLite 2"
logger.warn(warnMsg)
@ -59,8 +60,8 @@ class Connector(GenericConnector):
self.__sqlite = sqlite
self.connector = self.__sqlite.connect(database=self.db, check_same_thread=False, timeout=conf.timeout)
except (self.__sqlite.DatabaseError, self.__sqlite.OperationalError), msg:
raise SqlmapConnectionException(msg[0])
except (self.__sqlite.DatabaseError, self.__sqlite.OperationalError) as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.initCursor()
self.printConnected()
@ -68,17 +69,17 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except self.__sqlite.OperationalError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[0])
except self.__sqlite.OperationalError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
return None
def execute(self, query):
try:
self.cursor.execute(utf8encode(query))
except self.__sqlite.OperationalError, msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[0])
except self.__sqlite.DatabaseError, msg:
raise SqlmapConnectionException(msg[0])
except self.__sqlite.OperationalError as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
except self.__sqlite.DatabaseError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
self.connector.commit()

View File

@ -13,6 +13,7 @@ except:
import logging
from lib.core.common import getSafeExString
from lib.core.convert import utf8encode
from lib.core.data import conf
from lib.core.data import logger
@ -41,8 +42,8 @@ class Connector(GenericConnector):
try:
self.connector = pymssql.connect(host="%s:%d" % (self.hostname, self.port), user=self.user, password=self.password, database=self.db, login_timeout=conf.timeout, timeout=conf.timeout)
except (pymssql.Error, _mssql.MssqlDatabaseException), msg:
raise SqlmapConnectionException(msg)
except (pymssql.Error, _mssql.MssqlDatabaseException) as ex:
raise SqlmapConnectionException(ex)
except ValueError:
raise SqlmapConnectionException
@ -52,8 +53,8 @@ class Connector(GenericConnector):
def fetchall(self):
try:
return self.cursor.fetchall()
except (pymssql.Error, _mssql.MssqlDatabaseException), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
except (pymssql.Error, _mssql.MssqlDatabaseException) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex).replace("\n", " "))
return None
def execute(self, query):
@ -62,10 +63,10 @@ class Connector(GenericConnector):
try:
self.cursor.execute(utf8encode(query))
retVal = True
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
except pymssql.InternalError, msg:
raise SqlmapConnectionException(msg)
except (pymssql.OperationalError, pymssql.ProgrammingError) as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex).replace("\n", " "))
except pymssql.InternalError as ex:
raise SqlmapConnectionException(getSafeExString(ex))
return retVal

View File

@ -21,7 +21,7 @@ a32e12410e0f86c1d035db6daae84680 extra/shutils/duplicates.py
fb6be55d21a70765e35549af2484f762 extra/sqlharvest/__init__.py
4f82e97b09cc530cb9a92472d0835cea extra/sqlharvest/sqlharvest.py
fb6be55d21a70765e35549af2484f762 extra/wafdetectify/__init__.py
d62ae3224aca6a9496b35583db61412a extra/wafdetectify/wafdetectify.py
aec73042403993076f478da48066a79e extra/wafdetectify/wafdetectify.py
ec782b9cdb8d857a80b6ecf0f32db7f4 lib/controller/action.py
d099724a49c5fd6b0dca8c777e82604e lib/controller/checks.py
c4d559a98cfc62b401ef7e0bfab782f0 lib/controller/controller.py
@ -29,30 +29,30 @@ c1da277517c7ec4c23e953a51b51e203 lib/controller/handler.py
fb6be55d21a70765e35549af2484f762 lib/controller/__init__.py
ed7874be0d2d3802f3d20184f2b280d5 lib/core/agent.py
44ac129c1b3b6130b4f1bc7b93036278 lib/core/bigarray.py
34906c544d5c1060eecb2277b2c218d3 lib/core/common.py
981783b71439d82e84b47fb9b9a88164 lib/core/common.py
de8d27ae6241163ff9e97aa9e7c51a18 lib/core/convert.py
abcb1121eb56d3401839d14e8ed06b6e lib/core/data.py
db60c6ebb63b72ed119e304b359fc1a6 lib/core/datatype.py
b7c912e2af7a3354f6d7c04f556a80b2 lib/core/decorators.py
5f4680b769ae07f22157bd832c97cf8f lib/core/defaults.py
9dfc69ba47209a4ceca494dde9ee8183 lib/core/dicts.py
d9a9783b417a6c34f177272596904bdc lib/core/dump.py
fd5403505f76eee6829c06b9342e269c lib/core/dump.py
5c91145204092b995ed1ac641e9e291d lib/core/enums.py
84ef8f32e4582fcc294dc14e1997131d lib/core/exception.py
fb6be55d21a70765e35549af2484f762 lib/core/__init__.py
18c896b157b03af716542e5fe9233ef9 lib/core/log.py
fa9f24e88c81a6cef52da3dd5e637010 lib/core/optiondict.py
95f9836ad46146537cc16f918a002118 lib/core/option.py
3c5c2c63e67b40ca8ae9b1ffa8d7f77d lib/core/option.py
fe370021c6bc99daf44b2bfc0d1effb3 lib/core/patch.py
0f1d79ada721cf6def611b21b03d68af lib/core/profiling.py
4cfda3735871cd59b213470a0bbc8c3a lib/core/profiling.py
5e2c16a8e2daee22dd545df13386e7a3 lib/core/readlineng.py
7d8a22c582ad201f65b73225e4456170 lib/core/replication.py
3179d34f371e0295dd4604568fb30bcd lib/core/revision.py
d6269c55789f78cf707e09a0f5b45443 lib/core/session.py
0013f0712973543735d356560295a047 lib/core/settings.py
a8a7501d1e6b21669b858a62e921d191 lib/core/shell.py
5dc606fdf0afefd4b305169c21ab2612 lib/core/subprocessng.py
072c08d834d01b33e5f39320dcf67a0d lib/core/target.py
9adcbe4eb038933aa8f9ef13f288dde6 lib/core/settings.py
4483b4a5b601d8f1c4281071dff21ecc lib/core/shell.py
10fd19b0716ed261e6d04f311f6f527c lib/core/subprocessng.py
9c7b5c6397fb3da33e7a4d7876d159c6 lib/core/target.py
7857b24b7865ccb4a05283faa596974d lib/core/testing.py
203d2082929b4ac5454605c8c7c800a9 lib/core/threads.py
2c263c8610667fdc593c50a35ab20f57 lib/core/unescaper.py
@ -60,7 +60,7 @@ ff45c74515fecc95277f7b9ad945f17c lib/core/update.py
b40f4c20a38729bb4933b8221665f106 lib/core/wordlist.py
fb6be55d21a70765e35549af2484f762 lib/__init__.py
4881480d0c1778053908904e04570dc3 lib/parse/banner.py
f60469363c303b86255246e5a9604ba3 lib/parse/cmdline.py
87a1d50411e74cd0afb2d1bed30f59d4 lib/parse/cmdline.py
06ccbccb63255c8f1c35950a4c8a6f6b lib/parse/configfile.py
9b33e52f697d6e915c7a10153562ce89 lib/parse/handler.py
43deb2400e269e602e916efaec7c0903 lib/parse/headers.py
@ -80,7 +80,7 @@ fb6be55d21a70765e35549af2484f762 lib/request/__init__.py
52a067bd2fe91ea9395269a684380cbb lib/request/methodrequest.py
ac482ec52227daf48f523827dd67078f lib/request/pkihandler.py
16ff6e078819fe517b1fc0ae3cbc1aa8 lib/request/rangehandler.py
db4dc98d03d1865cc6266a79cd5c81b7 lib/request/redirecthandler.py
921db487a5879b219af1216d7eaccf74 lib/request/redirecthandler.py
1e60edebdb3997055616d12f4a932375 lib/request/templates.py
eafa28e4beb2b7492dfc8036033ac824 lib/takeover/abstraction.py
ac9efea51eba120b667b4b73536d7f1c lib/takeover/icmpsh.py
@ -114,19 +114,19 @@ fb6be55d21a70765e35549af2484f762 lib/utils/__init__.py
833b05c72c9fa60b0a25b0a26f8f31fb lib/utils/pivotdumptable.py
5a8902fd6fa94ea73cf44952f9ed5a57 lib/utils/progress.py
b79654e49850937ab2dc8e0d73625cab lib/utils/purge.py
081765fc1b3ad8a63f72e9c0e02ff00e lib/utils/search.py
503637fbdabaad5bc7f87dfcfbea4dd3 lib/utils/search.py
272a538a3d36186113191f4c543bb34b lib/utils/sqlalchemy.py
68f90f633d812ca428d2f15f016b2d96 lib/utils/timeout.py
164f830baad3e13b226ee57d44d69dfa lib/utils/versioncheck.py
1e5d24f1c629476bdf43363d2c8d8397 lib/utils/xrange.py
ab877805fe12bbcbb06b9eccfabdc4ed plugins/dbms/access/connector.py
b8656f4785d0945e68257107a171f945 plugins/dbms/access/connector.py
b0e4f4aed8504f97d4044620d3a7d27d plugins/dbms/access/enumeration.py
58d664d680087596965f95b482157320 plugins/dbms/access/filesystem.py
50e2991ae3f0a1eaf49fd10dcd041d92 plugins/dbms/access/fingerprint.py
bd8faded88ef80cde33b747d8181192d plugins/dbms/access/__init__.py
f36a8b05ea1a25254e03dc3bd44b1261 plugins/dbms/access/syntax.py
1a4e639d2a946792401cf5367ef661a5 plugins/dbms/access/takeover.py
b4bf4ef5189705945ca77424a7f42ee7 plugins/dbms/db2/connector.py
8f30dffb6cc7738adb5e83c2c6efb30f plugins/dbms/db2/connector.py
0f2e682ced8f91b1ec8bdf08c925b5a4 plugins/dbms/db2/enumeration.py
1ac13df2e0f04f312f522e9d8c13b692 plugins/dbms/db2/filesystem.py
e003fe19474305af522d8d6c6680db17 plugins/dbms/db2/fingerprint.py
@ -154,7 +154,7 @@ e4366df5a32c32f33be348e880714999 plugins/dbms/hsqldb/filesystem.py
5221fe018709e60663cae7c5d784ad60 plugins/dbms/hsqldb/__init__.py
5a1e5c46053ec1be5f536cec644949b5 plugins/dbms/hsqldb/syntax.py
e77d9be343fe7820a594d7b02f8d0b55 plugins/dbms/hsqldb/takeover.py
e7293692829fbacb63cd9f353b719ea8 plugins/dbms/informix/connector.py
f2bf868a83538168a3384904e2264419 plugins/dbms/informix/connector.py
4af6786b459ddbb666c5c765bf2a1158 plugins/dbms/informix/enumeration.py
1ac13df2e0f04f312f522e9d8c13b692 plugins/dbms/informix/filesystem.py
ed2bdb4eb574066521e88241a21f4bf7 plugins/dbms/informix/fingerprint.py
@ -169,42 +169,42 @@ ea186b97a394b61d82ecf7ed22b0cff6 plugins/dbms/maxdb/enumeration.py
8ad820fdfd2454363279eda7a9a08e6e plugins/dbms/maxdb/__init__.py
8fe248263926639acf41db3179db13d0 plugins/dbms/maxdb/syntax.py
479ce664674859d0e61c5221f9e835fd plugins/dbms/maxdb/takeover.py
1610a08c26895154287959193d8bd56f plugins/dbms/mssqlserver/connector.py
6ef95017815eb5d2d0f5645a6f5c7a79 plugins/dbms/mssqlserver/connector.py
69bfc53a409e79511802f668439bf4be plugins/dbms/mssqlserver/enumeration.py
bb02bdf47c71ed93d28d20b98ea0f8c6 plugins/dbms/mssqlserver/filesystem.py
bcabbf98e72bf3c6e971b56d8da60261 plugins/dbms/mssqlserver/fingerprint.py
6bffd484ef47111dd8a6e46e127ab5c7 plugins/dbms/mssqlserver/__init__.py
fae49b96d1422171b8f8c79f42aa56c9 plugins/dbms/mssqlserver/syntax.py
a5aa91bd7248d4f7ad508cf69f45696d plugins/dbms/mssqlserver/takeover.py
078a5399bd14d1416e2ae6fcd0445159 plugins/dbms/mysql/connector.py
dbd6121fcc92249ee0c023ee28e30274 plugins/dbms/mysql/connector.py
a94bde2f4dcf3a5f166302d07ea32907 plugins/dbms/mysql/enumeration.py
81c762ceba0892d0d6d78d70f513d20a plugins/dbms/mysql/filesystem.py
fd79ec2504b6bada7d2da233a549af53 plugins/dbms/mysql/fingerprint.py
040835bde6be85ebc1a6667dcd08940e plugins/dbms/mysql/__init__.py
dd6bd1d3d561755b96e953ede16cb8fc plugins/dbms/mysql/syntax.py
6c91ef5b5a6cd29cef4bd9bc3c369454 plugins/dbms/mysql/takeover.py
6e6c992f7fff55a8aa79d14437c648e7 plugins/dbms/oracle/connector.py
82ed71cf0e9283859b61c88325255eb2 plugins/dbms/oracle/connector.py
3266e81eb4a3c083d27c7a255be38893 plugins/dbms/oracle/enumeration.py
5bdd5288c8303ea21a5f8409332e32a1 plugins/dbms/oracle/filesystem.py
8813f44f3b67fc98024199c7b8398811 plugins/dbms/oracle/fingerprint.py
c7bb3f112aad2ea7ea92e036e9aab6a7 plugins/dbms/oracle/__init__.py
2676a1544b454f276c64f5147f03ce02 plugins/dbms/oracle/syntax.py
8da7c9ee0a0e692097757dfc2b5fefe0 plugins/dbms/oracle/takeover.py
e5e202429e9eee431c9dd39737b4b95c plugins/dbms/postgresql/connector.py
393a17dc8cb982ebb27665ead6b84bf1 plugins/dbms/postgresql/connector.py
86f0e0c9c4bc155c93277e879e3c3311 plugins/dbms/postgresql/enumeration.py
d68b5a9d6e608f15fbe2c520613ece4a plugins/dbms/postgresql/filesystem.py
2af014c49f103cb27bc547cc12641e2b plugins/dbms/postgresql/fingerprint.py
fb018fd23dcebdb36dddd22ac92efa2c plugins/dbms/postgresql/__init__.py
290ea28e1215565d9d12ede3422a4dcf plugins/dbms/postgresql/syntax.py
339bc65824b5c946ec40a12cd0257df1 plugins/dbms/postgresql/takeover.py
d2391dfe74f053eb5f31b0efad3fdda0 plugins/dbms/sqlite/connector.py
014968f7b28abe3ca8e533843a017453 plugins/dbms/sqlite/connector.py
6a0784e3ce46b6aa23dde813c6bc177f plugins/dbms/sqlite/enumeration.py
3c0adec05071fbe655a9c2c7afe52721 plugins/dbms/sqlite/filesystem.py
4d00b64bbfb2572a4a3a3330f255cc54 plugins/dbms/sqlite/fingerprint.py
582165c3e31ec5bf919db015c2e9bb2b plugins/dbms/sqlite/__init__.py
1ca5b1d7c64686827e80988933c397fa plugins/dbms/sqlite/syntax.py
224835bf71e99bac6e50b689afac5122 plugins/dbms/sqlite/takeover.py
492e2ad85f1a3a0feb2f010cb6c84eb1 plugins/dbms/sybase/connector.py
1f726d02ce4c709c0a3d327be947c72b plugins/dbms/sybase/connector.py
37a4e529dfb6bf3387c22e66cd9966f7 plugins/dbms/sybase/enumeration.py
9f16fb52a70e5fb01876f1bc5f5ef532 plugins/dbms/sybase/filesystem.py
69c104c5a2ff3e2c88a41205bb96d812 plugins/dbms/sybase/fingerprint.py