diff --git a/lib/core/xmldump.py b/lib/core/xmldump.py index 14e86ab33..7635df19f 100644 --- a/lib/core/xmldump.py +++ b/lib/core/xmldump.py @@ -32,7 +32,7 @@ DB_TABLE_ELEM_NAME = "DBTable" IS_DBA_ELEM_NAME = "isDBA" FILE_CONTENT_ELEM_NAME = "FileContent" DB_ATTR = "db" -UNKNOWN_COLUMN_TYPE= "unknown" +UNKNOWN_COLUMN_TYPE = "unknown" USER_SETTINGS_ELEM_NAME = "UserSettings" USER_SETTING_ELEM_NAME = "UserSetting" USERS_ELEM_NAME = "Users" @@ -72,7 +72,7 @@ XMLNS_ATTR = "xmlns:xsi" SCHEME_NAME = "sqlmap.xsd" SCHEME_NAME_ATTR = "xsi:noNamespaceSchemaLocation" CHARACTERS_TO_ENCODE = range(32) + range(127, 256) -ENTITIES = {'"':'"',"'":"'"} +ENTITIES = {'"': '"', "'": "'"} class XMLDump: ''' @@ -86,7 +86,7 @@ class XMLDump: self.__root = None self.__doc = Document() - def __addToRoot(self,element): + def __addToRoot(self, element): ''' Adds element to the root element ''' @@ -105,36 +105,36 @@ class XMLDump: kb.dataOutputFlag = True - def __getRootChild(self,elemName): + def __getRootChild(self, elemName): ''' Returns the child of the root with the described name ''' elements = self.__root.getElementsByTagName(elemName) - if elements : + if elements: return elements[0] return elements - def __createTextNode(self,data): + def __createTextNode(self, data): ''' Creates a text node with utf8 data inside. The text is escaped to an fit the xml text Format. ''' - if data is None : + if data is None: return self.__doc.createTextNode(u'') - else : + else: escaped_data = saxutils.escape(data, ENTITIES) return self.__doc.createTextNode(escaped_data) - def __createAttribute(self,attrName,attrValue): + def __createAttribute(self, attrName, attrValue): ''' Creates an attribute node with utf8 data inside. The text is escaped to an fit the xml text Format. ''' attr = self.__doc.createAttribute(attrName) - if attrValue is None : + if attrValue is None: attr.nodeValue = u'' - else : + else: attr.nodeValue = getUnicode(attrValue) return attr @@ -153,7 +153,7 @@ class XMLDump: if data: data = self.__formatString(data) - else : + else: data = "" elem = self.__doc.createElement(MESSAGE_ELEM) @@ -168,7 +168,6 @@ class XMLDump: lstElem = self.__doc.createElement(LST_ELEM_NAME) lstElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, header)) if elements: - if sort: try: elements = set(elements) @@ -185,7 +184,7 @@ class XMLDump: memberElem.appendChild(self.__createTextNode(element)) elif isinstance(element, (list, tuple, set)): memberElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, "list")) - for e in element : + for e in element: memberElemStr = self.__doc.createElement(MEMBER_ELEM) memberElemStr.setAttributeNode(self.__createAttribute(TYPE_ATTR, "string")) memberElemStr.appendChild(self.__createTextNode(getUnicode(e))) @@ -196,7 +195,7 @@ class XMLDump: self.__addToRoot(listsElem) listsElem.appendChild(lstElem) - def technic(self,technicType,data): + def technic(self, technicType, data): ''' Adds information about the technic used to extract data from the db ''' @@ -210,7 +209,7 @@ class XMLDump: self.__addToRoot(technicsElem) technicsElem.appendChild(technicElem) - def banner(self,data): + def banner(self, data): ''' Adds information about the database banner to the xml. The banner contains information about the type and the version of the database. @@ -219,7 +218,7 @@ class XMLDump: bannerElem.appendChild(self.__createTextNode(data)) self.__addToRoot(bannerElem) - def currentUser(self,data): + def currentUser(self, data): ''' Adds information about the current database user to the xml ''' @@ -228,7 +227,7 @@ class XMLDump: currentUserElem.appendChild(textNode) self.__addToRoot(currentUserElem) - def currentDb(self,data): + def currentDb(self, data): ''' Adds information about the current database is use to the xml ''' @@ -237,7 +236,7 @@ class XMLDump: currentDBElem.appendChild(textNode) self.__addToRoot(currentDBElem) - def dba(self,isDBA): + def dba(self, isDBA): ''' Adds information to the xml that indicates whether the user has DBA privileges ''' @@ -245,7 +244,7 @@ class XMLDump: isDBAElem.setAttributeNode(self.__createAttribute(VALUE_ATTR, getUnicode(isDBA))) self.__addToRoot(isDBAElem) - def users(self,users): + def users(self, users): ''' Adds a list of the existing users to the xml ''' @@ -325,7 +324,7 @@ class XMLDump: for db, tables in dbTables.items(): tables.sort(key=lambda x: x.lower()) dbElem = self.__doc.createElement(DATABASE_ELEM_NAME) - dbElem.setAttributeNode(self.__createAttribute(NAME_ATTR,db)) + dbElem.setAttributeNode(self.__createAttribute(NAME_ATTR, db)) dbTablesElem.appendChild(dbElem) for table in tables: tableElem = self.__doc.createElement(DB_TABLE_ELEM_NAME) @@ -361,7 +360,7 @@ class XMLDump: colElem = self.__doc.createElement(COLUMN_ELEM_NAME) if colType is not None: colElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, colType)) - else : + else: colElem.setAttributeNode(self.__createAttribute(TYPE_ATTR, UNKNOWN_COLUMN_TYPE)) colElem.appendChild(self.__createTextNode(column)) tableElem.appendChild(colElem) @@ -426,16 +425,16 @@ class XMLDump: if tbl in printDbs[db]: printDbs[db][tbl][col] = dataType else: - printDbs[db][tbl] = { col: dataType } + printDbs[db][tbl] = {col: dataType} else: printDbs[db] = {} - printDbs[db][tbl] = { col: dataType } + printDbs[db][tbl] = {col: dataType} continue self.dbTableColumns(printDbs) - def query(self,query,queryRes): + def query(self, query, queryRes): ''' Adds details of an executed query to the xml. The query details are the query itself and it's results. @@ -449,7 +448,7 @@ class XMLDump: self.__addToRoot(queriesElem) queriesElem.appendChild(queryElem) - def registerValue(self,registerData): + def registerValue(self, registerData): ''' Adds information about an extracted registry key to the xml ''' @@ -474,8 +473,8 @@ class XMLDump: ''' Initiates the xml file from the configuration. ''' - if (conf.xmlFile) : - try : + if (conf.xmlFile): + try: self.__outputFile = conf.xmlFile self.__root = None @@ -490,8 +489,8 @@ class XMLDump: if self.__root is None: self.__root = self.__doc.createElementNS(NAME_SPACE_ATTR, RESULTS_ELEM_NAME) - self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR,NAME_SPACE_ATTR)) - self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR,SCHEME_NAME)) + self.__root.setAttributeNode(self.__createAttribute(XMLNS_ATTR, NAME_SPACE_ATTR)) + self.__root.setAttributeNode(self.__createAttribute(SCHEME_NAME_ATTR, SCHEME_NAME)) self.__doc.appendChild(self.__root) except IOError: raise sqlmapFilePathException("Wrong filename provided for saving the xml file: %s" % conf.xmlFile) @@ -508,7 +507,7 @@ class XMLDump: ''' if ((self.__outputFP is not None) and not(self.__outputFP.closed)): statusElem = self.__doc.createElement(STATUS_ELEM_NAME) - statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR,getUnicode(resultStatus))) + statusElem.setAttributeNode(self.__createAttribute(SUCESS_ATTR, getUnicode(resultStatus))) if not resultStatus: errorElem = self.__doc.createElement(ERROR_ELEM_NAME) @@ -525,6 +524,7 @@ class XMLDump: self.__write(prettyprint.formatXML(self.__doc, encoding=UNICODE_ENCODING)) self.__outputFP.close() + def closeDumper(status, msg=""): """ Closes the dumper of the session diff --git a/lib/request/rangehandler.py b/lib/request/rangehandler.py index 7fe23d5b2..bd3aa4758 100644 --- a/lib/request/rangehandler.py +++ b/lib/request/rangehandler.py @@ -18,7 +18,7 @@ class HTTPRangeHandler(urllib2.BaseHandler): This was extremely simple. The Range header is a HTTP feature to begin with so all this class does is tell urllib2 that the - "206 Partial Content" reponse from the HTTP server is what we + "206 Partial Content" response from the HTTP server is what we expected. Example: diff --git a/lib/utils/deps.py b/lib/utils/deps.py index 7c895b5dd..451ec63d7 100644 --- a/lib/utils/deps.py +++ b/lib/utils/deps.py @@ -39,7 +39,7 @@ def checkDependencies(): import pyodbc elif dbmsName == DBMS.FIREBIRD: import kinterbasdb - except ImportError, _: + except ImportError: warnMsg = "sqlmap requires '%s' third-party library " % data[1] warnMsg += "in order to directly connect to the database " warnMsg += "%s. Download from %s" % (dbmsName, data[2]) @@ -55,7 +55,7 @@ def checkDependencies(): import impacket debugMsg = "'python-impacket' third-party library is found" logger.debug(debugMsg) - except ImportError, _: + except ImportError: warnMsg = "sqlmap requires 'python-impacket' third-party library for " warnMsg += "out-of-band takeover feature. Download from " warnMsg += "http://code.google.com/p/impacket/" @@ -66,7 +66,7 @@ def checkDependencies(): import ntlm debugMsg = "'python-ntlm' third-party library is found" logger.debug(debugMsg) - except ImportError, _: + except ImportError: warnMsg = "sqlmap requires 'python-ntlm' third-party library for " warnMsg += "if you plan to attack a web application behind NTLM " warnMsg += "authentication. Download from http://code.google.com/p/python-ntlm/" @@ -78,7 +78,7 @@ def checkDependencies(): import pyreadline debugMsg = "'python-pyreadline' third-party library is found" logger.debug(debugMsg) - except ImportError, _: + except ImportError: warnMsg = "sqlmap requires 'pyreadline' third-party library to " warnMsg += "be able to take advantage of the sqlmap TAB " warnMsg += "completion and history support features in the SQL " diff --git a/lib/utils/hash.py b/lib/utils/hash.py index f925c5e1a..b1feed7d9 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: from crypt import crypt -except ImportError, _: +except ImportError: from thirdparty.fcrypt.fcrypt import crypt _multiprocessing = None diff --git a/plugins/dbms/access/connector.py b/plugins/dbms/access/connector.py index 0910b63a5..8fd84f780 100644 --- a/plugins/dbms/access/connector.py +++ b/plugins/dbms/access/connector.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: import pyodbc -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/dbms/db2/__init__.py b/plugins/dbms/db2/__init__.py index 5c20f0117..a50b7b70f 100644 --- a/plugins/dbms/db2/__init__.py +++ b/plugins/dbms/db2/__init__.py @@ -1,8 +1,6 @@ #!/usr/bin/env python """ -$Id$ - Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ diff --git a/plugins/dbms/db2/connector.py b/plugins/dbms/db2/connector.py index e486ce088..66869c738 100644 --- a/plugins/dbms/db2/connector.py +++ b/plugins/dbms/db2/connector.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: import ibm_db_dbi -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/dbms/db2/enumeration.py b/plugins/dbms/db2/enumeration.py index d195d3a32..0484eedd6 100644 --- a/plugins/dbms/db2/enumeration.py +++ b/plugins/dbms/db2/enumeration.py @@ -1,8 +1,6 @@ #!/usr/bin/env python """ -$Id$ - Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ diff --git a/plugins/dbms/db2/syntax.py b/plugins/dbms/db2/syntax.py index 6b03af591..a3778c6b4 100644 --- a/plugins/dbms/db2/syntax.py +++ b/plugins/dbms/db2/syntax.py @@ -1,8 +1,6 @@ #!/usr/bin/env python """ -$Id$ - Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ diff --git a/plugins/dbms/firebird/connector.py b/plugins/dbms/firebird/connector.py index 86fc7edb1..c6e714208 100644 --- a/plugins/dbms/firebird/connector.py +++ b/plugins/dbms/firebird/connector.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: import kinterbasdb -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/dbms/mssqlserver/connector.py b/plugins/dbms/mssqlserver/connector.py index c34554ef7..71e311aa0 100644 --- a/plugins/dbms/mssqlserver/connector.py +++ b/plugins/dbms/mssqlserver/connector.py @@ -8,7 +8,7 @@ See the file 'doc/COPYING' for copying permission try: import _mssql import pymssql -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/dbms/mysql/connector.py b/plugins/dbms/mysql/connector.py index ce19ce79b..02251ecf5 100644 --- a/plugins/dbms/mysql/connector.py +++ b/plugins/dbms/mysql/connector.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: import pymysql -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/dbms/oracle/connector.py b/plugins/dbms/oracle/connector.py index 195b9aa34..9c3f16164 100644 --- a/plugins/dbms/oracle/connector.py +++ b/plugins/dbms/oracle/connector.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: import cx_Oracle -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/dbms/oracle/enumeration.py b/plugins/dbms/oracle/enumeration.py index da95f1828..df7d63996 100644 --- a/plugins/dbms/oracle/enumeration.py +++ b/plugins/dbms/oracle/enumeration.py @@ -164,4 +164,4 @@ class Enumeration(GenericEnumeration): errMsg += "for the database users" raise sqlmapNoneDataException, errMsg - return ( kb.data.cachedUsersRoles, areAdmins ) + return kb.data.cachedUsersRoles, areAdmins diff --git a/plugins/dbms/postgresql/connector.py b/plugins/dbms/postgresql/connector.py index ebf3bebe4..f2f11d528 100644 --- a/plugins/dbms/postgresql/connector.py +++ b/plugins/dbms/postgresql/connector.py @@ -10,7 +10,7 @@ try: import psycopg2.extensions psycopg2.extensions.register_type(psycopg2.extensions.UNICODE) psycopg2.extensions.register_type(psycopg2.extensions.UNICODEARRAY) -except ImportError, _: +except ImportError: pass from lib.core.data import logger diff --git a/plugins/dbms/sqlite/connector.py b/plugins/dbms/sqlite/connector.py index 298d4e295..435a74a48 100644 --- a/plugins/dbms/sqlite/connector.py +++ b/plugins/dbms/sqlite/connector.py @@ -7,7 +7,7 @@ See the file 'doc/COPYING' for copying permission try: import sqlite3 -except ImportError, _: +except ImportError: pass import logging @@ -53,7 +53,7 @@ class Connector(GenericConnector): try: try: import sqlite - except ImportError, _: + except ImportError: errMsg = "sqlmap requires 'python-sqlite2' third-party library " errMsg += "in order to directly connect to the database '%s'" % self.db raise sqlmapMissingDependence, errMsg diff --git a/plugins/dbms/sybase/connector.py b/plugins/dbms/sybase/connector.py index 81fa3ced9..8fc31d34b 100644 --- a/plugins/dbms/sybase/connector.py +++ b/plugins/dbms/sybase/connector.py @@ -8,7 +8,7 @@ See the file 'doc/COPYING' for copying permission try: import _mssql import pymssql -except ImportError, _: +except ImportError: pass import logging diff --git a/plugins/generic/takeover.py b/plugins/generic/takeover.py index 443f3fb97..54bd7b884 100644 --- a/plugins/generic/takeover.py +++ b/plugins/generic/takeover.py @@ -129,7 +129,7 @@ class Takeover(Abstraction, Metasploit, ICMPsh, Registry, Miscellaneous): try: from impacket import ImpactDecoder from impacket import ImpactPacket - except ImportError, _: + except ImportError: errMsg = "sqlmap requires 'impacket' third-party library " errMsg += "in order to run icmpsh master. Download from " errMsg += "http://oss.coresecurity.com/projects/impacket.html"