mirror of
https://github.com/sqlmapproject/sqlmap.git
synced 2025-07-29 01:19:47 +03:00
Refactoring for compatible with Python 3
* transformation: except
This commit is contained in:
parent
9e75bb7f68
commit
1f5a8d4068
|
@ -59,7 +59,7 @@ def main():
|
|||
if not args.inputFile:
|
||||
parser.error('Missing the input file, -h for help')
|
||||
|
||||
except (OptionError, TypeError), e:
|
||||
except (OptionError, TypeError) as e:
|
||||
parser.error(e)
|
||||
|
||||
if not os.path.isfile(args.inputFile):
|
||||
|
|
|
@ -86,7 +86,7 @@ if __name__ == "__main__":
|
|||
if not args.inputFile:
|
||||
parser.error("Missing the input file, -h for help")
|
||||
|
||||
except (OptionError, TypeError), e:
|
||||
except (OptionError, TypeError) as e:
|
||||
parser.error(e)
|
||||
|
||||
inputFile = args.inputFile
|
||||
|
|
|
@ -108,7 +108,7 @@ def main():
|
|||
if not args.inputFile:
|
||||
parser.error('Missing the input file, -h for help')
|
||||
|
||||
except (OptionError, TypeError), e:
|
||||
except (OptionError, TypeError) as e:
|
||||
parser.error(e)
|
||||
|
||||
if not os.path.isfile(args.inputFile):
|
||||
|
|
|
@ -56,7 +56,7 @@ def send_email(msg):
|
|||
s.sendmail(FROM, TO, msg.as_string())
|
||||
s.quit()
|
||||
# Catch all for SMTP exceptions
|
||||
except smtplib.SMTPException, e:
|
||||
except smtplib.SMTPException as e:
|
||||
print "Failure to send email: %s" % str(e)
|
||||
|
||||
def failure_email(msg):
|
||||
|
@ -157,7 +157,7 @@ if __name__ == "__main__":
|
|||
|
||||
try:
|
||||
main()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
log_fd.write("An exception has occurred:\n%s" % str(traceback.format_exc()))
|
||||
|
||||
log_fd.write("Regression test finished at %s\n\n" % time.strftime("%H:%M:%S %d-%m-%Y", time.gmtime()))
|
||||
|
|
|
@ -75,7 +75,7 @@ def main():
|
|||
except KeyboardInterrupt:
|
||||
raise
|
||||
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
print msg
|
||||
|
||||
if abort:
|
||||
|
@ -118,7 +118,7 @@ def main():
|
|||
except KeyboardInterrupt:
|
||||
raise
|
||||
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
print msg
|
||||
|
||||
else:
|
||||
|
|
|
@ -75,7 +75,7 @@ def action():
|
|||
if conf.getPasswordHashes:
|
||||
try:
|
||||
conf.dumper.userSettings("database management system users password hashes", conf.dbmsHandler.getPasswordHashes(), "password hash", CONTENT_TYPE.PASSWORDS)
|
||||
except SqlmapNoneDataException, ex:
|
||||
except SqlmapNoneDataException as ex:
|
||||
logger.critical(ex)
|
||||
except:
|
||||
raise
|
||||
|
@ -83,7 +83,7 @@ def action():
|
|||
if conf.getPrivileges:
|
||||
try:
|
||||
conf.dumper.userSettings("database management system users privileges", conf.dbmsHandler.getPrivileges(), "privilege", CONTENT_TYPE.PRIVILEGES)
|
||||
except SqlmapNoneDataException, ex:
|
||||
except SqlmapNoneDataException as ex:
|
||||
logger.critical(ex)
|
||||
except:
|
||||
raise
|
||||
|
@ -91,7 +91,7 @@ def action():
|
|||
if conf.getRoles:
|
||||
try:
|
||||
conf.dumper.userSettings("database management system users roles", conf.dbmsHandler.getRoles(), "role", CONTENT_TYPE.ROLES)
|
||||
except SqlmapNoneDataException, ex:
|
||||
except SqlmapNoneDataException as ex:
|
||||
logger.critical(ex)
|
||||
except:
|
||||
raise
|
||||
|
|
|
@ -602,7 +602,7 @@ def checkSqlInjection(place, parameter, value):
|
|||
|
||||
injectable = True
|
||||
|
||||
except SqlmapConnectionException, msg:
|
||||
except SqlmapConnectionException as msg:
|
||||
debugMsg = "problem occurred most likely because the "
|
||||
debugMsg += "server hasn't recovered as expected from the "
|
||||
debugMsg += "error-based payload used ('%s')" % msg
|
||||
|
@ -1405,7 +1405,7 @@ def identifyWaf():
|
|||
try:
|
||||
logger.debug("checking for WAF/IPS/IDS product '%s'" % product)
|
||||
found = function(_)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "exception occurred while running "
|
||||
errMsg += "WAF script for '%s' ('%s')" % (product, getSafeExString(ex))
|
||||
logger.critical(errMsg)
|
||||
|
@ -1506,7 +1506,7 @@ def checkConnection(suppressOutput=False):
|
|||
except socket.gaierror:
|
||||
errMsg = "host '%s' does not exist" % conf.hostname
|
||||
raise SqlmapConnectionException(errMsg)
|
||||
except socket.error, ex:
|
||||
except socket.error as ex:
|
||||
errMsg = "problem occurred while "
|
||||
errMsg += "resolving a host name '%s' ('%s')" % (conf.hostname, getSafeExString(ex))
|
||||
raise SqlmapConnectionException(errMsg)
|
||||
|
@ -1537,7 +1537,7 @@ def checkConnection(suppressOutput=False):
|
|||
else:
|
||||
kb.errorIsNone = True
|
||||
|
||||
except SqlmapConnectionException, ex:
|
||||
except SqlmapConnectionException as ex:
|
||||
if conf.ipv6:
|
||||
warnMsg = "check connection to a provided "
|
||||
warnMsg += "IPv6 address with a tool like ping6 "
|
||||
|
|
|
@ -672,7 +672,7 @@ def start():
|
|||
except SqlmapSilentQuitException:
|
||||
raise
|
||||
|
||||
except SqlmapBaseException, ex:
|
||||
except SqlmapBaseException as ex:
|
||||
errMsg = getSafeExString(ex)
|
||||
|
||||
if conf.multipleTargets:
|
||||
|
|
|
@ -87,7 +87,7 @@ class BigArray(list):
|
|||
try:
|
||||
with open(self.chunks[-1], "rb") as f:
|
||||
self.chunks[-1] = pickle.loads(bz2.decompress(f.read()))
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "exception occurred while retrieving data "
|
||||
errMsg += "from a temporary file ('%s')" % ex.message
|
||||
raise SqlmapSystemException, errMsg
|
||||
|
@ -109,7 +109,7 @@ class BigArray(list):
|
|||
with open(filename, "w+b") as f:
|
||||
f.write(bz2.compress(pickle.dumps(chunk, pickle.HIGHEST_PROTOCOL), BIGARRAY_COMPRESS_LEVEL))
|
||||
return filename
|
||||
except (OSError, IOError), ex:
|
||||
except (OSError, IOError) as ex:
|
||||
errMsg = "exception occurred while storing data "
|
||||
errMsg += "to a temporary file ('%s'). Please " % ex.message
|
||||
errMsg += "make sure that there is enough disk space left. If problem persists, "
|
||||
|
@ -126,7 +126,7 @@ class BigArray(list):
|
|||
try:
|
||||
with open(self.chunks[index], "rb") as f:
|
||||
self.cache = Cache(index, pickle.loads(bz2.decompress(f.read())), False)
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "exception occurred while retrieving data "
|
||||
errMsg += "from a temporary file ('%s')" % ex.message
|
||||
raise SqlmapSystemException, errMsg
|
||||
|
|
|
@ -924,7 +924,7 @@ def dataToTrafficFile(data):
|
|||
try:
|
||||
conf.trafficFP.write(data)
|
||||
conf.trafficFP.flush()
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "something went wrong while trying "
|
||||
errMsg += "to write to the traffic file '%s' ('%s')" % (conf.trafficFile, getSafeExString(ex))
|
||||
raise SqlmapSystemException(errMsg)
|
||||
|
@ -933,7 +933,7 @@ def dataToDumpFile(dumpFile, data):
|
|||
try:
|
||||
dumpFile.write(data)
|
||||
dumpFile.flush()
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
if "No space left" in getUnicode(ex):
|
||||
errMsg = "no space left on output device"
|
||||
logger.error(errMsg)
|
||||
|
@ -953,7 +953,7 @@ def dataToOutFile(filename, data):
|
|||
try:
|
||||
with open(retVal, "w+b") as f: # has to stay as non-codecs because data is raw ASCII encoded data
|
||||
f.write(unicodeencode(data))
|
||||
except UnicodeEncodeError, ex:
|
||||
except UnicodeEncodeError as ex:
|
||||
_ = normalizeUnicode(filename)
|
||||
if filename != _:
|
||||
filename = _
|
||||
|
@ -961,7 +961,7 @@ def dataToOutFile(filename, data):
|
|||
errMsg = "couldn't write to the "
|
||||
errMsg += "output file ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapGenericException(errMsg)
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "something went wrong while trying to write "
|
||||
errMsg += "to the output file ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
@ -1410,7 +1410,7 @@ def parseTargetUrl():
|
|||
|
||||
try:
|
||||
urlSplit = urlparse.urlsplit(conf.url)
|
||||
except ValueError, ex:
|
||||
except ValueError as ex:
|
||||
errMsg = "invalid URL '%s' has been given ('%s'). " % (conf.url, getSafeExString(ex))
|
||||
errMsg += "Please be sure that you don't have any leftover characters (e.g. '[' or ']') "
|
||||
errMsg += "in the hostname part"
|
||||
|
@ -1982,7 +1982,7 @@ def parseXmlFile(xmlFile, handler):
|
|||
try:
|
||||
with contextlib.closing(StringIO(readCachedFileContent(xmlFile))) as stream:
|
||||
parse(stream, handler)
|
||||
except (SAXParseException, UnicodeError), ex:
|
||||
except (SAXParseException, UnicodeError) as ex:
|
||||
errMsg = "something appears to be wrong with "
|
||||
errMsg += "the file '%s' ('%s'). Please make " % (xmlFile, getSafeExString(ex))
|
||||
errMsg += "sure that you haven't made any changes to it"
|
||||
|
@ -2042,7 +2042,7 @@ def readCachedFileContent(filename, mode='rb'):
|
|||
try:
|
||||
with openFile(filename, mode) as f:
|
||||
kb.cache.content[filename] = f.read()
|
||||
except (IOError, OSError, MemoryError), ex:
|
||||
except (IOError, OSError, MemoryError) as ex:
|
||||
errMsg = "something went wrong while trying "
|
||||
errMsg += "to read the content of file '%s' ('%s')" % (filename, getSafeExString(ex))
|
||||
raise SqlmapSystemException(errMsg)
|
||||
|
@ -2156,7 +2156,7 @@ def getFileItems(filename, commentPrefix='#', unicode_=True, lowercase=False, un
|
|||
retVal[line] = True
|
||||
else:
|
||||
retVal.append(line)
|
||||
except (IOError, OSError, MemoryError), ex:
|
||||
except (IOError, OSError, MemoryError) as ex:
|
||||
errMsg = "something went wrong while trying "
|
||||
errMsg += "to read the content of file '%s' ('%s')" % (filename, getSafeExString(ex))
|
||||
raise SqlmapSystemException(errMsg)
|
||||
|
@ -2289,7 +2289,7 @@ def getUnicode(value, encoding=None, noneToNull=False):
|
|||
while True:
|
||||
try:
|
||||
return unicode(value, encoding or (kb.get("pageEncoding") if kb.get("originalPage") else None) or UNICODE_ENCODING)
|
||||
except UnicodeDecodeError, ex:
|
||||
except UnicodeDecodeError as ex:
|
||||
try:
|
||||
return unicode(value, UNICODE_ENCODING)
|
||||
except:
|
||||
|
@ -2345,7 +2345,7 @@ def pushValue(value):
|
|||
getCurrentThreadData().valueStack.append(copy.deepcopy(value))
|
||||
success = True
|
||||
break
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
_ = ex
|
||||
|
||||
if not success:
|
||||
|
@ -3033,7 +3033,7 @@ def saveConfig(conf, filename):
|
|||
with openFile(filename, "wb") as f:
|
||||
try:
|
||||
config.write(f)
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "something went wrong while trying "
|
||||
errMsg += "to write to the configuration file '%s' ('%s')" % (filename, getSafeExString(ex))
|
||||
raise SqlmapSystemException(errMsg)
|
||||
|
@ -3361,7 +3361,7 @@ def createGithubIssue(errMsg, excMsg):
|
|||
|
||||
try:
|
||||
content = urllib2.urlopen(req).read()
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
content = None
|
||||
|
||||
issueUrl = re.search(r"https://github.com/sqlmapproject/sqlmap/issues/\d+", content or "")
|
||||
|
@ -3971,7 +3971,7 @@ def findPageForms(content, url, raise_=False, addToTargets=False):
|
|||
continue
|
||||
|
||||
request = form.click()
|
||||
except (ValueError, TypeError), ex:
|
||||
except (ValueError, TypeError) as ex:
|
||||
errMsg = "there has been a problem while "
|
||||
errMsg += "processing page forms ('%s')" % getSafeExString(ex)
|
||||
if raise_:
|
||||
|
@ -4092,7 +4092,7 @@ def evaluateCode(code, variables=None):
|
|||
exec(code, variables)
|
||||
except KeyboardInterrupt:
|
||||
raise
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "an error occurred while evaluating provided code ('%s') " % getSafeExString(ex)
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
||||
|
@ -4299,7 +4299,7 @@ def resetCookieJar(cookieJar):
|
|||
errMsg = "no valid cookies found"
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
||||
except cookielib.LoadError, msg:
|
||||
except cookielib.LoadError as msg:
|
||||
errMsg = "there was a problem loading "
|
||||
errMsg += "cookies file ('%s')" % re.sub(r"(cookies) file '[^']+'", "\g<1>", str(msg))
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
|
|
@ -77,7 +77,7 @@ class Dump(object):
|
|||
|
||||
try:
|
||||
self._outputFP.write(text)
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "error occurred while writing to log file ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
||||
|
@ -97,7 +97,7 @@ class Dump(object):
|
|||
self._outputFile = os.path.join(conf.outputPath, "log")
|
||||
try:
|
||||
self._outputFP = openFile(self._outputFile, "ab" if not conf.flushSession else "wb")
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
errMsg = "error occurred while opening log file ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
||||
|
@ -424,10 +424,10 @@ class Dump(object):
|
|||
if not os.path.isdir(dumpDbPath):
|
||||
try:
|
||||
os.makedirs(dumpDbPath, 0755)
|
||||
except Exception, ex:
|
||||
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 "
|
||||
|
@ -621,7 +621,7 @@ class Dump(object):
|
|||
with open(filepath, "wb") as f:
|
||||
_ = safechardecode(value, True)
|
||||
f.write(_)
|
||||
except magic.MagicException, err:
|
||||
except magic.MagicException as err:
|
||||
logger.debug(str(err))
|
||||
|
||||
if conf.dumpFormat == DUMP_FORMAT.CSV:
|
||||
|
|
|
@ -353,7 +353,7 @@ def _feedTargetsDict(reqFile, addedTargetUrls):
|
|||
try:
|
||||
with openFile(reqFile, "rb") as f:
|
||||
content = f.read()
|
||||
except (IOError, OSError, MemoryError), ex:
|
||||
except (IOError, OSError, MemoryError) as ex:
|
||||
errMsg = "something went wrong while trying "
|
||||
errMsg += "to read the content of file '%s' ('%s')" % (reqFile, getSafeExString(ex))
|
||||
raise SqlmapSystemException(errMsg)
|
||||
|
@ -398,7 +398,7 @@ def _loadQueries():
|
|||
tree = ElementTree()
|
||||
try:
|
||||
tree.parse(paths.QUERIES_XML)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "something appears to be wrong with "
|
||||
errMsg += "the file '%s' ('%s'). Please make " % (paths.QUERIES_XML, getSafeExString(ex))
|
||||
errMsg += "sure that you haven't made any changes to it"
|
||||
|
@ -514,7 +514,7 @@ def _setCrawler():
|
|||
if conf.verbose in (1, 2):
|
||||
status = "%d/%d links visited (%d%%)" % (i + 1, len(targets), round(100.0 * (i + 1) / len(targets)))
|
||||
dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status), True)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "problem occurred while crawling at '%s' ('%s')" % (target, getSafeExString(ex))
|
||||
logger.error(errMsg)
|
||||
|
||||
|
@ -650,7 +650,7 @@ def _findPageForms():
|
|||
dataToStdout("\r[%s] [INFO] %s" % (time.strftime("%X"), status), True)
|
||||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "problem occurred while searching for forms at '%s' ('%s')" % (target, getSafeExString(ex))
|
||||
logger.error(errMsg)
|
||||
|
||||
|
@ -931,7 +931,7 @@ def _setTamperingFunctions():
|
|||
|
||||
try:
|
||||
module = __import__(filename[:-3].encode(sys.getfilesystemencoding() or UNICODE_ENCODING))
|
||||
except (ImportError, SyntaxError), ex:
|
||||
except (ImportError, SyntaxError) as ex:
|
||||
raise SqlmapSyntaxException("cannot import tamper script '%s' (%s)" % (filename[:-3], getSafeExString(ex)))
|
||||
|
||||
priority = PRIORITY.NORMAL if not hasattr(module, "__priority__") else module.__priority__
|
||||
|
@ -1004,7 +1004,7 @@ 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:
|
||||
except ImportError as msg:
|
||||
raise SqlmapSyntaxException("cannot import WAF script '%s' (%s)" % (filename[:-3], msg))
|
||||
|
||||
_ = dict(inspect.getmembers(module))
|
||||
|
@ -1126,7 +1126,7 @@ def _setHTTPHandlers():
|
|||
|
||||
try:
|
||||
_ = urlparse.urlsplit(conf.proxy)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "invalid proxy address '%s' ('%s')" % (conf.proxy, getSafeExString(ex))
|
||||
raise SqlmapSyntaxException, errMsg
|
||||
|
||||
|
@ -1577,7 +1577,7 @@ def _createTemporaryDirectory():
|
|||
|
||||
warnMsg = "using '%s' as the temporary directory" % conf.tmpDir
|
||||
logger.warn(warnMsg)
|
||||
except (OSError, IOError), ex:
|
||||
except (OSError, IOError) as ex:
|
||||
errMsg = "there has been a problem while accessing "
|
||||
errMsg += "temporary directory location(s) ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapSystemException, errMsg
|
||||
|
@ -1585,7 +1585,7 @@ def _createTemporaryDirectory():
|
|||
try:
|
||||
if not os.path.isdir(tempfile.gettempdir()):
|
||||
os.makedirs(tempfile.gettempdir())
|
||||
except (OSError, IOError, WindowsError), ex:
|
||||
except (OSError, IOError, WindowsError) as ex:
|
||||
warnMsg = "there has been a problem while accessing "
|
||||
warnMsg += "system's temporary directory location(s) ('%s'). Please " % getSafeExString(ex)
|
||||
warnMsg += "make sure that there is enough disk space left. If problem persists, "
|
||||
|
@ -1604,7 +1604,7 @@ def _createTemporaryDirectory():
|
|||
if not os.path.isdir(tempfile.tempdir):
|
||||
try:
|
||||
os.makedirs(tempfile.tempdir)
|
||||
except (OSError, IOError, WindowsError), ex:
|
||||
except (OSError, IOError, WindowsError) as ex:
|
||||
errMsg = "there has been a problem while setting "
|
||||
errMsg += "temporary directory location ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapSystemException, errMsg
|
||||
|
@ -2269,7 +2269,7 @@ def _setDNSServer():
|
|||
try:
|
||||
conf.dnsServer = DNSServer()
|
||||
conf.dnsServer.run()
|
||||
except socket.error, msg:
|
||||
except socket.error as msg:
|
||||
errMsg = "there was an error while setting up "
|
||||
errMsg += "DNS server instance ('%s')" % msg
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
@ -2456,14 +2456,14 @@ def _basicOptionValidation():
|
|||
if conf.regexp:
|
||||
try:
|
||||
re.compile(conf.regexp)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "invalid regular expression '%s' ('%s')" % (conf.regexp, getSafeExString(ex))
|
||||
raise SqlmapSyntaxException(errMsg)
|
||||
|
||||
if conf.crawlExclude:
|
||||
try:
|
||||
re.compile(conf.crawlExclude)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "invalid regular expression '%s' ('%s')" % (conf.crawlExclude, getSafeExString(ex))
|
||||
raise SqlmapSyntaxException(errMsg)
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
|
|||
import gobject
|
||||
import gtk
|
||||
import pydot
|
||||
except ImportError, e:
|
||||
except ImportError as e:
|
||||
errMsg = "profiling requires third-party libraries ('%s') " % getUnicode(e, UNICODE_ENCODING)
|
||||
errMsg += "(Hint: 'sudo apt-get install python-pydot python-pyparsing python-profiler graphviz')"
|
||||
logger.error(errMsg)
|
||||
|
|
|
@ -27,7 +27,7 @@ class Replication(object):
|
|||
self.connection = sqlite3.connect(dbpath)
|
||||
self.connection.isolation_level = None
|
||||
self.cursor = self.connection.cursor()
|
||||
except sqlite3.OperationalError, ex:
|
||||
except sqlite3.OperationalError as ex:
|
||||
errMsg = "error occurred while opening a replication "
|
||||
errMsg += "file '%s' ('%s')" % (self.filepath, getSafeExString(ex))
|
||||
raise SqlmapConnectionException(errMsg)
|
||||
|
@ -63,7 +63,7 @@ class Replication(object):
|
|||
self.execute('CREATE TABLE "%s" (%s)' % (self.name, ','.join('"%s" %s' % (unsafeSQLIdentificatorNaming(colname), coltype) for colname, coltype in self.columns)))
|
||||
else:
|
||||
self.execute('CREATE TABLE "%s" (%s)' % (self.name, ','.join('"%s"' % unsafeSQLIdentificatorNaming(colname) for colname in self.columns)))
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "problem occurred ('%s') while initializing the sqlite database " % getSafeExString(ex, UNICODE_ENCODING)
|
||||
errMsg += "located at '%s'" % self.parent.dbpath
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
@ -82,7 +82,7 @@ class Replication(object):
|
|||
def execute(self, sql, parameters=[]):
|
||||
try:
|
||||
self.parent.cursor.execute(sql, parameters)
|
||||
except sqlite3.OperationalError, ex:
|
||||
except sqlite3.OperationalError as ex:
|
||||
errMsg = "problem occurred ('%s') while accessing sqlite database " % getSafeExString(ex, UNICODE_ENCODING)
|
||||
errMsg += "located at '%s'. Please make sure that " % self.parent.dbpath
|
||||
errMsg += "it's not used by some other program"
|
||||
|
|
|
@ -72,7 +72,7 @@ def saveHistory(completion=None):
|
|||
readline.set_history_length(MAX_HISTORY_LENGTH)
|
||||
try:
|
||||
readline.write_history_file(historyPath)
|
||||
except IOError, msg:
|
||||
except IOError as msg:
|
||||
warnMsg = "there was a problem writing the history file '%s' (%s)" % (historyPath, msg)
|
||||
logger.warn(warnMsg)
|
||||
|
||||
|
@ -92,7 +92,7 @@ def loadHistory(completion=None):
|
|||
if os.path.exists(historyPath):
|
||||
try:
|
||||
readline.read_history_file(historyPath)
|
||||
except IOError, msg:
|
||||
except IOError as msg:
|
||||
warnMsg = "there was a problem loading the history file '%s' (%s)" % (historyPath, msg)
|
||||
logger.warn(warnMsg)
|
||||
|
||||
|
|
|
@ -37,7 +37,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
|
||||
|
@ -58,7 +58,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:
|
||||
|
@ -101,7 +101,7 @@ class Popen(subprocess.Popen):
|
|||
(errCode, written) = WriteFile(x, input)
|
||||
except ValueError:
|
||||
return self._close('stdin')
|
||||
except (subprocess.pywintypes.error, Exception), why:
|
||||
except (subprocess.pywintypes.error, Exception) as why:
|
||||
if why[0] in (109, errno.ESHUTDOWN):
|
||||
return self._close('stdin')
|
||||
raise
|
||||
|
@ -122,7 +122,7 @@ class Popen(subprocess.Popen):
|
|||
(errCode, read) = ReadFile(x, nAvail, None)
|
||||
except (ValueError, NameError):
|
||||
return self._close(which)
|
||||
except (subprocess.pywintypes.error, Exception), why:
|
||||
except (subprocess.pywintypes.error, Exception) as why:
|
||||
if why[0] in (109, errno.ESHUTDOWN):
|
||||
return self._close(which)
|
||||
raise
|
||||
|
@ -140,7 +140,7 @@ class Popen(subprocess.Popen):
|
|||
|
||||
try:
|
||||
written = os.write(self.stdin.fileno(), input)
|
||||
except OSError, why:
|
||||
except OSError as why:
|
||||
if why[0] == errno.EPIPE: # broken pipe
|
||||
return self._close('stdin')
|
||||
raise
|
||||
|
|
|
@ -422,7 +422,7 @@ def _setHashDB():
|
|||
try:
|
||||
os.remove(conf.hashDBFile)
|
||||
logger.info("flushing session file")
|
||||
except OSError, msg:
|
||||
except OSError as msg:
|
||||
errMsg = "unable to flush the session file (%s)" % msg
|
||||
raise SqlmapFilePathException(errMsg)
|
||||
|
||||
|
@ -550,7 +550,7 @@ def _setResultsFile():
|
|||
conf.resultsFilename = os.path.join(paths.SQLMAP_OUTPUT_PATH, time.strftime(RESULTS_FILE_FORMAT).lower())
|
||||
try:
|
||||
conf.resultsFP = openFile(conf.resultsFilename, "a", UNICODE_ENCODING, buffering=0)
|
||||
except (OSError, IOError), ex:
|
||||
except (OSError, IOError) as ex:
|
||||
try:
|
||||
warnMsg = "unable to create results file '%s' ('%s'). " % (conf.resultsFilename, getUnicode(ex))
|
||||
handle, conf.resultsFilename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.RESULTS, suffix=".csv")
|
||||
|
@ -558,7 +558,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 "
|
||||
|
@ -582,7 +582,7 @@ def _createFilesDir():
|
|||
if not os.path.isdir(conf.filePath):
|
||||
try:
|
||||
os.makedirs(conf.filePath, 0755)
|
||||
except OSError, ex:
|
||||
except OSError as ex:
|
||||
tempDir = tempfile.mkdtemp(prefix="sqlmapfiles")
|
||||
warnMsg = "unable to create files directory "
|
||||
warnMsg += "'%s' (%s). " % (conf.filePath, getUnicode(ex))
|
||||
|
@ -604,7 +604,7 @@ def _createDumpDir():
|
|||
if not os.path.isdir(conf.dumpPath):
|
||||
try:
|
||||
os.makedirs(conf.dumpPath, 0755)
|
||||
except OSError, ex:
|
||||
except OSError as ex:
|
||||
tempDir = tempfile.mkdtemp(prefix="sqlmapdump")
|
||||
warnMsg = "unable to create dump directory "
|
||||
warnMsg += "'%s' (%s). " % (conf.dumpPath, getUnicode(ex))
|
||||
|
@ -633,10 +633,10 @@ def _createTargetDirs():
|
|||
if conf.outputDir:
|
||||
warnMsg = "using '%s' as the output directory" % paths.SQLMAP_OUTPUT_PATH
|
||||
logger.warn(warnMsg)
|
||||
except (OSError, IOError), ex:
|
||||
except (OSError, IOError) as ex:
|
||||
try:
|
||||
tempDir = tempfile.mkdtemp(prefix="sqlmapoutput")
|
||||
except Exception, _:
|
||||
except Exception 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 "
|
||||
|
@ -655,10 +655,10 @@ def _createTargetDirs():
|
|||
try:
|
||||
if not os.path.isdir(conf.outputPath):
|
||||
os.makedirs(conf.outputPath, 0755)
|
||||
except (OSError, IOError, TypeError), ex:
|
||||
except (OSError, IOError, TypeError) as ex:
|
||||
try:
|
||||
tempDir = tempfile.mkdtemp(prefix="sqlmapoutput")
|
||||
except Exception, _:
|
||||
except Exception 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 "
|
||||
|
@ -679,7 +679,7 @@ def _createTargetDirs():
|
|||
f.write(" # %s" % getUnicode(subprocess.list2cmdline(sys.argv), encoding=sys.stdin.encoding))
|
||||
if conf.data:
|
||||
f.write("\n\n%s" % getUnicode(conf.data))
|
||||
except IOError, ex:
|
||||
except IOError as ex:
|
||||
if "denied" in getUnicode(ex):
|
||||
errMsg = "you don't have enough permissions "
|
||||
else:
|
||||
|
|
|
@ -71,7 +71,7 @@ def smokeTest():
|
|||
try:
|
||||
__import__(path)
|
||||
module = sys.modules[path]
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
retVal = False
|
||||
dataToStdout("\r")
|
||||
errMsg = "smoke test failed at importing module '%s' (%s):\n%s" % (path, os.path.join(root, filename), msg)
|
||||
|
@ -271,9 +271,9 @@ def runCase(parse):
|
|||
result = start()
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
except SqlmapBaseException, e:
|
||||
except SqlmapBaseException as e:
|
||||
handled_exception = e
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
unhandled_exception = e
|
||||
finally:
|
||||
sys.stdout.seek(0)
|
||||
|
|
|
@ -91,7 +91,7 @@ def exceptionHandledFunction(threadFunction, silent=False):
|
|||
kb.threadContinue = False
|
||||
kb.threadException = True
|
||||
raise
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
if not silent:
|
||||
logger.error("thread %s: %s" % (threading.currentThread().getName(), ex.message))
|
||||
|
||||
|
@ -150,7 +150,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
|||
|
||||
try:
|
||||
thread.start()
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "error occurred while starting new thread ('%s')" % ex.message
|
||||
logger.critical(errMsg)
|
||||
break
|
||||
|
@ -166,7 +166,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
|||
alive = True
|
||||
time.sleep(0.1)
|
||||
|
||||
except (KeyboardInterrupt, SqlmapUserQuitException), ex:
|
||||
except (KeyboardInterrupt, SqlmapUserQuitException) as ex:
|
||||
print
|
||||
kb.threadContinue = False
|
||||
kb.threadException = True
|
||||
|
@ -183,7 +183,7 @@ def runThreads(numThreads, threadFunction, cleanupFunction=None, forwardExceptio
|
|||
if forwardException:
|
||||
raise
|
||||
|
||||
except (SqlmapConnectionException, SqlmapValueException), ex:
|
||||
except (SqlmapConnectionException, SqlmapValueException) as ex:
|
||||
print
|
||||
kb.threadException = True
|
||||
logger.error("thread %s: %s" % (threading.currentThread().getName(), ex.message))
|
||||
|
|
|
@ -46,7 +46,7 @@ def update():
|
|||
pollProcess(process, True)
|
||||
stdout, stderr = process.communicate()
|
||||
success = not process.returncode
|
||||
except (IOError, OSError), ex:
|
||||
except (IOError, OSError) as ex:
|
||||
success = False
|
||||
stderr = getSafeExString(ex)
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ class Wordlist(object):
|
|||
if os.path.splitext(self.current)[1].lower() == ".zip":
|
||||
try:
|
||||
_ = zipfile.ZipFile(self.current, 'r')
|
||||
except zipfile.error, ex:
|
||||
except zipfile.error as ex:
|
||||
errMsg = "something appears to be wrong with "
|
||||
errMsg += "the file '%s' ('%s'). Please make " % (self.current, getSafeExString(ex))
|
||||
errMsg += "sure that you haven't made any changes to it"
|
||||
|
@ -69,7 +69,7 @@ class Wordlist(object):
|
|||
self.counter += 1
|
||||
try:
|
||||
retVal = self.iter.next().rstrip()
|
||||
except zipfile.error, ex:
|
||||
except zipfile.error as ex:
|
||||
errMsg = "something appears to be wrong with "
|
||||
errMsg += "the file '%s' ('%s'). Please make " % (self.current, getSafeExString(ex))
|
||||
errMsg += "sure that you haven't made any changes to it"
|
||||
|
|
|
@ -908,7 +908,7 @@ def cmdLineParser(argv=None):
|
|||
try:
|
||||
for arg in shlex.split(command):
|
||||
argv.append(getUnicode(arg, encoding=sys.stdin.encoding))
|
||||
except ValueError, ex:
|
||||
except ValueError as ex:
|
||||
raise SqlmapSyntaxException, "something went wrong during command line parsing ('%s')" % ex.message
|
||||
|
||||
for i in xrange(len(argv)):
|
||||
|
@ -954,7 +954,7 @@ def cmdLineParser(argv=None):
|
|||
|
||||
try:
|
||||
(args, _) = parser.parse_args(argv)
|
||||
except UnicodeEncodeError, ex:
|
||||
except UnicodeEncodeError as ex:
|
||||
dataToStdout("\n[!] %s\n" % ex.object.encode("unicode-escape"))
|
||||
raise SystemExit
|
||||
except SystemExit:
|
||||
|
@ -985,7 +985,7 @@ def cmdLineParser(argv=None):
|
|||
|
||||
return args
|
||||
|
||||
except (OptionError, TypeError), e:
|
||||
except (OptionError, TypeError) as e:
|
||||
parser.error(e)
|
||||
|
||||
except SystemExit:
|
||||
|
|
|
@ -39,7 +39,7 @@ def configFileProxy(section, option, datatype):
|
|||
value = config.getfloat(section, option) if config.get(section, option) else 0.0
|
||||
else:
|
||||
value = config.get(section, option)
|
||||
except ValueError, ex:
|
||||
except ValueError as ex:
|
||||
errMsg = "error occurred while processing the option "
|
||||
errMsg += "'%s' in provided configuration file ('%s')" % (option, getUnicode(ex))
|
||||
raise SqlmapSyntaxException(errMsg)
|
||||
|
@ -71,7 +71,7 @@ def configFileParser(configFile):
|
|||
try:
|
||||
config = UnicodeRawConfigParser()
|
||||
config.readfp(configFP)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "you have provided an invalid and/or unreadable configuration file ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapSyntaxException(errMsg)
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ def parseXmlNode(node):
|
|||
def loadBoundaries():
|
||||
try:
|
||||
doc = et.parse(paths.BOUNDARIES_XML)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "something appears to be wrong with "
|
||||
errMsg += "the file '%s' ('%s'). Please make " % (paths.BOUNDARIES_XML, getSafeExString(ex))
|
||||
errMsg += "sure that you haven't made any changes to it"
|
||||
|
@ -89,7 +89,7 @@ def loadPayloads():
|
|||
|
||||
try:
|
||||
doc = et.parse(payloadFilePath)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "something appears to be wrong with "
|
||||
errMsg += "the file '%s' ('%s'). Please make " % (payloadFilePath, getSafeExString(ex))
|
||||
errMsg += "sure that you haven't made any changes to it"
|
||||
|
|
|
@ -283,7 +283,7 @@ def decodePage(page, contentEncoding, contentType):
|
|||
raise Exception("size too large")
|
||||
|
||||
page = data.read()
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
if "<html" not in page: # in some cases, invalid "Content-Encoding" appears for plain HTML (should be ignored)
|
||||
errMsg = "detected invalid data for declared content "
|
||||
errMsg += "encoding '%s' ('%s')" % (contentEncoding, msg)
|
||||
|
|
|
@ -540,11 +540,11 @@ class Connect(object):
|
|||
if hasattr(conn.fp, '_sock'):
|
||||
conn.fp._sock.close()
|
||||
conn.close()
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
warnMsg = "problem occurred during connection closing ('%s')" % getSafeExString(ex)
|
||||
logger.warn(warnMsg)
|
||||
|
||||
except SqlmapConnectionException, ex:
|
||||
except SqlmapConnectionException as ex:
|
||||
if conf.proxyList and not kb.threadException:
|
||||
warnMsg = "unable to connect to the target URL ('%s')" % ex
|
||||
logger.critical(warnMsg)
|
||||
|
@ -553,7 +553,7 @@ class Connect(object):
|
|||
else:
|
||||
raise
|
||||
|
||||
except urllib2.HTTPError, ex:
|
||||
except urllib2.HTTPError as ex:
|
||||
page = None
|
||||
responseHeaders = None
|
||||
|
||||
|
@ -817,7 +817,7 @@ class Connect(object):
|
|||
for function in kb.tamperFunctions:
|
||||
try:
|
||||
payload = function(payload=payload, headers=auxHeaders)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "error occurred while running tamper "
|
||||
errMsg += "function '%s' ('%s')" % (function.func_name, getSafeExString(ex))
|
||||
raise SqlmapGenericException(errMsg)
|
||||
|
@ -1058,7 +1058,7 @@ class Connect(object):
|
|||
while True:
|
||||
try:
|
||||
compiler.parse(unicodeencode(conf.evalCode.replace(';', '\n')))
|
||||
except SyntaxError, ex:
|
||||
except SyntaxError as ex:
|
||||
if ex.text:
|
||||
original = replacement = ex.text.strip()
|
||||
if '=' in original:
|
||||
|
|
|
@ -149,7 +149,7 @@ if __name__ == "__main__":
|
|||
|
||||
time.sleep(1)
|
||||
|
||||
except socket.error, ex:
|
||||
except socket.error as ex:
|
||||
if 'Permission' in str(ex):
|
||||
print "[x] Please run with sudo/Administrator privileges"
|
||||
else:
|
||||
|
|
|
@ -62,7 +62,7 @@ class HTTPSConnection(httplib.HTTPSConnection):
|
|||
break
|
||||
else:
|
||||
sock.close()
|
||||
except (ssl.SSLError, socket.error, httplib.BadStatusLine), ex:
|
||||
except (ssl.SSLError, socket.error, httplib.BadStatusLine) as ex:
|
||||
self._tunnel_host = None
|
||||
logger.debug("SSL connection error occurred ('%s')" % getSafeExString(ex))
|
||||
|
||||
|
@ -82,7 +82,7 @@ class HTTPSConnection(httplib.HTTPSConnection):
|
|||
break
|
||||
else:
|
||||
sock.close()
|
||||
except (ssl.SSLError, socket.error, httplib.BadStatusLine), ex:
|
||||
except (ssl.SSLError, socket.error, httplib.BadStatusLine) as ex:
|
||||
self._tunnel_host = None
|
||||
logger.debug("SSL connection error occurred ('%s')" % getSafeExString(ex))
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
|||
|
||||
try:
|
||||
content = fp.read(MAX_CONNECTION_TOTAL_SIZE)
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
dbgMsg = "there was a problem while retrieving "
|
||||
dbgMsg += "redirect response content (%s)" % msg
|
||||
logger.debug(dbgMsg)
|
||||
|
@ -132,7 +132,7 @@ class SmartRedirectHandler(urllib2.HTTPRedirectHandler):
|
|||
req.headers[HTTP_HEADER.COOKIE] = re.sub(r"%s{2,}" % delimiter, delimiter, ("%s%s%s" % (re.sub(r"\b%s=[^%s]*%s?" % (re.escape(_.split('=')[0]), delimiter, delimiter), "", req.headers[HTTP_HEADER.COOKIE]), delimiter, _)).strip(delimiter))
|
||||
try:
|
||||
result = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
|
||||
except urllib2.HTTPError, e:
|
||||
except urllib2.HTTPError as e:
|
||||
result = e
|
||||
|
||||
# Dirty hack for http://bugs.python.org/issue15701
|
||||
|
|
|
@ -93,7 +93,7 @@ class Database(object):
|
|||
self.cursor.execute(statement, arguments)
|
||||
else:
|
||||
self.cursor.execute(statement)
|
||||
except sqlite3.OperationalError, ex:
|
||||
except sqlite3.OperationalError as ex:
|
||||
if not "locked" in getSafeExString(ex):
|
||||
raise
|
||||
else:
|
||||
|
@ -276,7 +276,7 @@ def setRestAPILog():
|
|||
try:
|
||||
conf.databaseCursor = Database(conf.database)
|
||||
conf.databaseCursor.connect("client")
|
||||
except sqlite3.OperationalError, ex:
|
||||
except sqlite3.OperationalError as ex:
|
||||
raise SqlmapConnectionException, "%s ('%s')" % (ex, conf.database)
|
||||
|
||||
# Set a logging handler that writes log messages to a IPC database
|
||||
|
@ -699,7 +699,7 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, adapter=REST
|
|||
eventlet.monkey_patch()
|
||||
logger.debug("Using adapter '%s' to run bottle" % adapter)
|
||||
run(host=host, port=port, quiet=True, debug=True, server=adapter)
|
||||
except socket.error, ex:
|
||||
except socket.error as ex:
|
||||
if "already in use" in getSafeExString(ex):
|
||||
logger.error("Address already in use ('%s:%s')" % (host, port))
|
||||
else:
|
||||
|
@ -753,7 +753,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
|
|||
|
||||
try:
|
||||
_client(addr)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
if not isinstance(ex, urllib2.HTTPError) or ex.code == httplib.UNAUTHORIZED:
|
||||
errMsg = "There has been a problem while connecting to the "
|
||||
errMsg += "REST-JSON API server at '%s' " % addr
|
||||
|
@ -805,7 +805,7 @@ def client(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, username=Non
|
|||
|
||||
try:
|
||||
argv = ["sqlmap.py"] + shlex.split(command)[1:]
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
logger.error("Error occurred while parsing arguments ('%s')" % ex)
|
||||
taskid = None
|
||||
continue
|
||||
|
|
|
@ -63,14 +63,14 @@ def crawl(target):
|
|||
try:
|
||||
if current:
|
||||
content = Request.getPage(url=current, crawling=True, raise404=False)[0]
|
||||
except SqlmapConnectionException, ex:
|
||||
except SqlmapConnectionException as ex:
|
||||
errMsg = "connection exception detected ('%s'). skipping " % getSafeExString(ex)
|
||||
errMsg += "URL '%s'" % current
|
||||
logger.critical(errMsg)
|
||||
except SqlmapSyntaxException:
|
||||
errMsg = "invalid URL detected. skipping '%s'" % current
|
||||
logger.critical(errMsg)
|
||||
except httplib.InvalidURL, ex:
|
||||
except httplib.InvalidURL as ex:
|
||||
errMsg = "invalid URL detected ('%s'). skipping " % getSafeExString(ex)
|
||||
errMsg += "URL '%s'" % current
|
||||
logger.critical(errMsg)
|
||||
|
@ -138,7 +138,7 @@ def crawl(target):
|
|||
url = urlparse.urljoin(target, "/sitemap.xml")
|
||||
try:
|
||||
items = parseSitemap(url)
|
||||
except SqlmapConnectionException, ex:
|
||||
except SqlmapConnectionException as ex:
|
||||
if "page not found" in getSafeExString(ex):
|
||||
found = False
|
||||
logger.warn("'sitemap.xml' not found")
|
||||
|
|
|
@ -767,7 +767,7 @@ def _bruteProcessVariantA(attack_info, hash_regex, suffix, retVal, proc_id, proc
|
|||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
pass # ignore possible encoding problems caused by some words in custom dictionaries
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
warnMsg = "there was a problem while hashing entry: %s (%s). " % (repr(word), e)
|
||||
warnMsg += "Please report by e-mail to '%s'" % DEV_EMAIL_ADDRESS
|
||||
logger.critical(warnMsg)
|
||||
|
@ -843,7 +843,7 @@ def _bruteProcessVariantB(user, hash_, kwargs, hash_regex, suffix, retVal, found
|
|||
except (UnicodeEncodeError, UnicodeDecodeError):
|
||||
pass # ignore possible encoding problems caused by some words in custom dictionaries
|
||||
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
warnMsg = "there was a problem while hashing entry: %s (%s). " % (repr(word), e)
|
||||
warnMsg += "Please report by e-mail to '%s'" % DEV_EMAIL_ADDRESS
|
||||
logger.critical(warnMsg)
|
||||
|
@ -994,7 +994,7 @@ def dictionaryAttack(attack_dict):
|
|||
|
||||
kb.wordlists = dictPaths
|
||||
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
warnMsg = "there was a problem while loading dictionaries"
|
||||
warnMsg += " ('%s')" % getSafeExString(ex)
|
||||
logger.critical(warnMsg)
|
||||
|
|
|
@ -41,7 +41,7 @@ class HashDB(object):
|
|||
threadData.hashDBCursor = connection.cursor()
|
||||
threadData.hashDBCursor.execute("CREATE TABLE IF NOT EXISTS storage (id INTEGER PRIMARY KEY, value TEXT)")
|
||||
connection.commit()
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "error occurred while opening a session "
|
||||
errMsg += "file '%s' ('%s')" % (self.filepath, getSafeExString(ex))
|
||||
raise SqlmapConnectionException(errMsg)
|
||||
|
@ -81,7 +81,7 @@ class HashDB(object):
|
|||
try:
|
||||
for row in self.cursor.execute("SELECT value FROM storage WHERE id=?", (hash_,)):
|
||||
retVal = row[0]
|
||||
except sqlite3.OperationalError, ex:
|
||||
except sqlite3.OperationalError as ex:
|
||||
if any(_ in getSafeExString(ex) for _ in ("locked", "no such table")):
|
||||
warnMsg = "problem occurred while accessing session file '%s' ('%s')" % (self.filepath, getSafeExString(ex))
|
||||
singleTimeWarnMessage(warnMsg)
|
||||
|
@ -89,7 +89,7 @@ class HashDB(object):
|
|||
break
|
||||
else:
|
||||
raise
|
||||
except sqlite3.DatabaseError, ex:
|
||||
except sqlite3.DatabaseError as ex:
|
||||
errMsg = "error occurred while accessing session file '%s' ('%s'). " % (self.filepath, getSafeExString(ex))
|
||||
errMsg += "If the problem persists please rerun with `--flush-session`"
|
||||
raise SqlmapConnectionException, errMsg
|
||||
|
@ -141,7 +141,7 @@ class HashDB(object):
|
|||
self.cursor.execute("INSERT INTO storage VALUES (?, ?)", (hash_, value,))
|
||||
except sqlite3.IntegrityError:
|
||||
self.cursor.execute("UPDATE storage SET value=? WHERE id=?", (value, hash_,))
|
||||
except sqlite3.DatabaseError, ex:
|
||||
except sqlite3.DatabaseError as ex:
|
||||
if not os.path.exists(self.filepath):
|
||||
debugMsg = "session file '%s' does not exist" % self.filepath
|
||||
logger.debug(debugMsg)
|
||||
|
|
|
@ -174,7 +174,7 @@ def pivotDumpTable(table, colList, count=None, blind=True):
|
|||
warnMsg += "will display partial output"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
except SqlmapConnectionException, e:
|
||||
except SqlmapConnectionException as e:
|
||||
errMsg = "connection exception detected. sqlmap "
|
||||
errMsg += "will display partial output"
|
||||
errMsg += "'%s'" % e
|
||||
|
|
|
@ -79,5 +79,5 @@ def purge(directory):
|
|||
|
||||
try:
|
||||
shutil.rmtree(directory)
|
||||
except OSError, ex:
|
||||
except OSError as ex:
|
||||
logger.error("problem occurred while removing directory '%s' ('%s')" % (directory, getSafeExString(ex)))
|
||||
|
|
|
@ -53,7 +53,7 @@ def _search(dork):
|
|||
try:
|
||||
req = urllib2.Request("https://www.google.com/ncr", headers=headers)
|
||||
conn = urllib2.urlopen(req)
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
errMsg = "unable to connect to Google ('%s')" % getSafeExString(ex)
|
||||
raise SqlmapConnectionException(errMsg)
|
||||
|
||||
|
@ -87,10 +87,10 @@ 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 e:
|
||||
try:
|
||||
page = e.read()
|
||||
except Exception, ex:
|
||||
except Exception as ex:
|
||||
warnMsg = "problem occurred while trying to get "
|
||||
warnMsg += "an error page information (%s)" % getSafeExString(ex)
|
||||
logger.critical(warnMsg)
|
||||
|
@ -149,7 +149,7 @@ 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 e:
|
||||
try:
|
||||
page = e.read()
|
||||
except socket.timeout:
|
||||
|
@ -171,7 +171,7 @@ def search(dork):
|
|||
|
||||
try:
|
||||
return _search(dork)
|
||||
except SqlmapBaseException, ex:
|
||||
except SqlmapBaseException as ex:
|
||||
if conf.proxyList:
|
||||
logger.critical(getSafeExString(ex))
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ class SQLAlchemy(GenericConnector):
|
|||
raise
|
||||
except SqlmapFilePathException:
|
||||
raise
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
raise SqlmapConnectionException("SQLAlchemy connection issue ('%s')" % msg[0])
|
||||
|
||||
self.printConnected()
|
||||
|
@ -86,16 +86,16 @@ class SQLAlchemy(GenericConnector):
|
|||
for row in self.cursor.fetchall():
|
||||
retVal.append(tuple(row))
|
||||
return retVal
|
||||
except _sqlalchemy.exc.ProgrammingError, msg:
|
||||
except _sqlalchemy.exc.ProgrammingError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg.message if hasattr(msg, "message") else msg)
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor = self.connector.execute(query)
|
||||
except (_sqlalchemy.exc.OperationalError, _sqlalchemy.exc.ProgrammingError), msg:
|
||||
except (_sqlalchemy.exc.OperationalError, _sqlalchemy.exc.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg.message if hasattr(msg, "message") else msg)
|
||||
except _sqlalchemy.exc.InternalError, msg:
|
||||
except _sqlalchemy.exc.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
def select(self, query):
|
||||
|
|
|
@ -22,7 +22,7 @@ def timeout(func, args=(), kwargs={}, duration=1, default=None):
|
|||
try:
|
||||
self.result = func(*args, **kwargs)
|
||||
self.timeout_state = TIMEOUT_STATE.NORMAL
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, msg)
|
||||
self.result = default
|
||||
self.timeout_state = TIMEOUT_STATE.EXCEPTION
|
||||
|
|
|
@ -42,7 +42,7 @@ 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:
|
||||
except (pyodbc.Error, pyodbc.OperationalError) as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.initCursor()
|
||||
|
@ -51,16 +51,16 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except pyodbc.ProgrammingError, msg:
|
||||
except pyodbc.ProgrammingError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor.execute(query)
|
||||
except (pyodbc.OperationalError, pyodbc.ProgrammingError), msg:
|
||||
except (pyodbc.OperationalError, pyodbc.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
except pyodbc.Error, msg:
|
||||
except pyodbc.Error as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -34,7 +34,7 @@ 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:
|
||||
except ibm_db_dbi.OperationalError as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
|
||||
|
@ -44,16 +44,16 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except ibm_db_dbi.ProgrammingError, msg:
|
||||
except ibm_db_dbi.ProgrammingError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor.execute(query)
|
||||
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError), msg:
|
||||
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
except ibm_db_dbi.InternalError, msg:
|
||||
except ibm_db_dbi.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -41,7 +41,7 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.connector = kinterbasdb.connect(host=self.hostname.encode(UNICODE_ENCODING), database=self.db.encode(UNICODE_ENCODING), \
|
||||
user=self.user.encode(UNICODE_ENCODING), password=self.password.encode(UNICODE_ENCODING), charset="UTF8") # Reference: http://www.daniweb.com/forums/thread248499.html
|
||||
except kinterbasdb.OperationalError, msg:
|
||||
except kinterbasdb.OperationalError as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.initCursor()
|
||||
|
@ -50,16 +50,16 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except kinterbasdb.OperationalError, msg:
|
||||
except kinterbasdb.OperationalError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor.execute(query)
|
||||
except kinterbasdb.OperationalError, msg:
|
||||
except kinterbasdb.OperationalError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
except kinterbasdb.Error, msg:
|
||||
except kinterbasdb.Error as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -41,7 +41,7 @@ class Connector(GenericConnector):
|
|||
args = "-Djava.class.path=%s" % jar
|
||||
jvm_path = jpype.getDefaultJVMPath()
|
||||
jpype.startJVM(jvm_path, args)
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
raise SqlmapConnectionException(msg[0])
|
||||
|
||||
try:
|
||||
|
@ -51,7 +51,7 @@ class Connector(GenericConnector):
|
|||
connection_string,
|
||||
str(self.user),
|
||||
str(self.password))
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
raise SqlmapConnectionException(msg[0])
|
||||
|
||||
self.initCursor()
|
||||
|
@ -60,7 +60,7 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
return None
|
||||
|
||||
|
@ -70,7 +70,7 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.cursor.execute(query)
|
||||
retVal = True
|
||||
except Exception, msg: #todo fix with specific error
|
||||
except Exception as msg: #todo fix with specific error
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -34,7 +34,7 @@ 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:
|
||||
except ibm_db_dbi.OperationalError as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
|
||||
|
@ -44,16 +44,16 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except ibm_db_dbi.ProgrammingError, msg:
|
||||
except ibm_db_dbi.ProgrammingError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor.execute(query)
|
||||
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError), msg:
|
||||
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
except ibm_db_dbi.InternalError, msg:
|
||||
except ibm_db_dbi.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -41,7 +41,7 @@ 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:
|
||||
except (pymssql.Error, _mssql.MssqlDatabaseException) as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
self.initCursor()
|
||||
|
@ -50,7 +50,7 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except (pymssql.Error, _mssql.MssqlDatabaseException), msg:
|
||||
except (pymssql.Error, _mssql.MssqlDatabaseException) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
|
||||
return None
|
||||
|
||||
|
@ -60,9 +60,9 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.cursor.execute(utf8encode(query))
|
||||
retVal = True
|
||||
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
|
||||
except (pymssql.OperationalError, pymssql.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
|
||||
except pymssql.InternalError, msg:
|
||||
except pymssql.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
return retVal
|
||||
|
|
|
@ -37,9 +37,9 @@ 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), msg:
|
||||
except (pymysql.OperationalError, pymysql.InternalError) as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
except struct.error, msg:
|
||||
except struct.error as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
self.initCursor()
|
||||
|
@ -48,7 +48,7 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except pymysql.ProgrammingError, msg:
|
||||
except pymysql.ProgrammingError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
return None
|
||||
|
||||
|
@ -58,9 +58,9 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.cursor.execute(query)
|
||||
retVal = True
|
||||
except (pymysql.OperationalError, pymysql.ProgrammingError), msg:
|
||||
except (pymysql.OperationalError, pymysql.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
||||
except pymysql.InternalError, msg:
|
||||
except pymysql.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg[1])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -43,7 +43,7 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
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), ex:
|
||||
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))
|
||||
msg = re.sub(r': ("[^"]+")', r" (\g<1>)", msg)
|
||||
|
@ -52,7 +52,7 @@ class Connector(GenericConnector):
|
|||
|
||||
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:
|
||||
except (cx_Oracle.OperationalError, cx_Oracle.DatabaseError, cx_Oracle.InterfaceError) as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
self.initCursor()
|
||||
|
@ -61,7 +61,7 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except cx_Oracle.InterfaceError, msg:
|
||||
except cx_Oracle.InterfaceError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg)
|
||||
return None
|
||||
|
||||
|
@ -71,7 +71,7 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.cursor.execute(utf8encode(query))
|
||||
retVal = True
|
||||
except cx_Oracle.DatabaseError, msg:
|
||||
except cx_Oracle.DatabaseError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg)
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -36,7 +36,7 @@ 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:
|
||||
except psycopg2.OperationalError as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
self.connector.set_client_encoding('UNICODE')
|
||||
|
@ -47,7 +47,7 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except psycopg2.ProgrammingError, msg:
|
||||
except psycopg2.ProgrammingError as msg:
|
||||
logger.warn(msg)
|
||||
return None
|
||||
|
||||
|
@ -57,9 +57,9 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.cursor.execute(query)
|
||||
retVal = True
|
||||
except (psycopg2.OperationalError, psycopg2.ProgrammingError), msg:
|
||||
except (psycopg2.OperationalError, psycopg2.ProgrammingError) as msg:
|
||||
logger.warn(("(remote) %s" % msg).strip())
|
||||
except psycopg2.InternalError, msg:
|
||||
except psycopg2.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -46,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) as msg:
|
||||
warnMsg = "unable to connect using SQLite 3 library, trying with SQLite 2"
|
||||
logger.warn(warnMsg)
|
||||
|
||||
|
@ -60,7 +60,7 @@ 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:
|
||||
except (self.__sqlite.DatabaseError, self.__sqlite.OperationalError) as msg:
|
||||
raise SqlmapConnectionException(msg[0])
|
||||
|
||||
self.initCursor()
|
||||
|
@ -69,16 +69,16 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except self.__sqlite.OperationalError, msg:
|
||||
except self.__sqlite.OperationalError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[0])
|
||||
return None
|
||||
|
||||
def execute(self, query):
|
||||
try:
|
||||
self.cursor.execute(utf8encode(query))
|
||||
except self.__sqlite.OperationalError, msg:
|
||||
except self.__sqlite.OperationalError as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[0])
|
||||
except self.__sqlite.DatabaseError, msg:
|
||||
except self.__sqlite.DatabaseError as msg:
|
||||
raise SqlmapConnectionException(msg[0])
|
||||
|
||||
self.connector.commit()
|
||||
|
|
|
@ -41,7 +41,7 @@ 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:
|
||||
except (pymssql.Error, _mssql.MssqlDatabaseException) as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
self.initCursor()
|
||||
|
@ -50,7 +50,7 @@ class Connector(GenericConnector):
|
|||
def fetchall(self):
|
||||
try:
|
||||
return self.cursor.fetchall()
|
||||
except (pymssql.Error, _mssql.MssqlDatabaseException), msg:
|
||||
except (pymssql.Error, _mssql.MssqlDatabaseException) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
|
||||
return None
|
||||
|
||||
|
@ -60,9 +60,9 @@ class Connector(GenericConnector):
|
|||
try:
|
||||
self.cursor.execute(utf8encode(query))
|
||||
retVal = True
|
||||
except (pymssql.OperationalError, pymssql.ProgrammingError), msg:
|
||||
except (pymssql.OperationalError, pymssql.ProgrammingError) as msg:
|
||||
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % str(msg).replace("\n", " "))
|
||||
except pymssql.InternalError, msg:
|
||||
except pymssql.InternalError as msg:
|
||||
raise SqlmapConnectionException(msg)
|
||||
|
||||
return retVal
|
||||
|
|
|
@ -50,7 +50,7 @@ class Connector:
|
|||
self.cursor.close()
|
||||
if self.connector:
|
||||
self.connector.close()
|
||||
except Exception, msg:
|
||||
except Exception as msg:
|
||||
logger.debug(msg)
|
||||
finally:
|
||||
self.closed()
|
||||
|
|
|
@ -70,7 +70,7 @@ class Custom:
|
|||
|
||||
output = NULL
|
||||
|
||||
except SqlmapNoneDataException, ex:
|
||||
except SqlmapNoneDataException as ex:
|
||||
logger.warn(ex)
|
||||
|
||||
return output
|
||||
|
|
|
@ -424,13 +424,13 @@ class Entries:
|
|||
"db": safeSQLIdentificatorNaming(conf.db)}
|
||||
try:
|
||||
attackDumpedTable()
|
||||
except (IOError, OSError), ex:
|
||||
except (IOError, OSError) as ex:
|
||||
errMsg = "an error occurred while attacking "
|
||||
errMsg += "table dump ('%s')" % getSafeExString(ex)
|
||||
logger.critical(errMsg)
|
||||
conf.dumper.dbTableValues(kb.data.dumpedTable)
|
||||
|
||||
except SqlmapConnectionException, ex:
|
||||
except SqlmapConnectionException as ex:
|
||||
errMsg = "connection exception detected in dumping phase "
|
||||
errMsg += "('%s')" % getSafeExString(ex)
|
||||
logger.critical(errMsg)
|
||||
|
|
Loading…
Reference in New Issue
Block a user