fix regarding proper string isinstance checking (including unicode)

This commit is contained in:
Miroslav Stampar 2010-05-25 10:09:35 +00:00
parent d2c03c12fd
commit dc83f794ea
13 changed files with 30 additions and 30 deletions

View File

@ -149,7 +149,7 @@ def formatDBMSfp(versions=None):
if ( not versions or versions == [None] ) and kb.dbmsVersion and kb.dbmsVersion[0] != "Unknown": if ( not versions or versions == [None] ) and kb.dbmsVersion and kb.dbmsVersion[0] != "Unknown":
versions = kb.dbmsVersion versions = kb.dbmsVersion
if isinstance(versions, str): if isinstance(versions, basestring):
return "%s %s" % (kb.dbms, versions) return "%s %s" % (kb.dbms, versions)
elif isinstance(versions, (list, set, tuple)): elif isinstance(versions, (list, set, tuple)):
return "%s %s" % (kb.dbms, " and ".join([version for version in versions])) return "%s %s" % (kb.dbms, " and ".join([version for version in versions]))
@ -848,7 +848,7 @@ def parseUnionPage(output, expression, partial=False, condition=None, sort=True)
else: else:
data = output data = output
if len(data) == 1 and isinstance(data[0], str): if len(data) == 1 and isinstance(data[0], basestring):
data = data[0] data = data[0]
return data return data
@ -1019,7 +1019,7 @@ def normalizePath(path):
def safeStringFormat(formatStr, params): def safeStringFormat(formatStr, params):
retVal = formatStr.replace("%d", "%s") retVal = formatStr.replace("%d", "%s")
if isinstance(params, str): if isinstance(params, basestring):
retVal = retVal.replace("%s", params) retVal = retVal.replace("%s", params)
else: else:
count = 0 count = 0

View File

@ -90,7 +90,7 @@ class Dump:
pass pass
for element in elements: for element in elements:
if isinstance(element, str): if isinstance(element, basestring):
self.__write("[*] %s" % element) self.__write("[*] %s" % element)
elif isinstance(element, (list, tuple, set)): elif isinstance(element, (list, tuple, set)):
self.__write("[*] " + ", ".join(str(e) for e in element)) self.__write("[*] " + ", ".join(str(e) for e in element))

View File

@ -1011,7 +1011,7 @@ def __saveCmdline():
elif datatype == "string": elif datatype == "string":
value = "" value = ""
if isinstance(value, str): if isinstance(value, basestring):
value = value.replace("\n", "\n ") value = value.replace("\n", "\n ")
config.set(family, option, value) config.set(family, option, value)

View File

@ -193,7 +193,7 @@ def setStacked():
not kb.resumedQueries[conf.url].has_key("Stacked queries") ) not kb.resumedQueries[conf.url].has_key("Stacked queries") )
) )
if not isinstance(kb.stackedTest, str): if not isinstance(kb.stackedTest, basestring):
return return
if condition: if condition:

View File

@ -45,7 +45,7 @@ def queriesForAutoCompletion():
autoComplQueries = {} autoComplQueries = {}
for _, query in queries[kb.dbms].items(): for _, query in queries[kb.dbms].items():
if isinstance(query, str) and len(query) > 1: if isinstance(query, basestring) and len(query) > 1:
autoComplQuery = query autoComplQuery = query
elif isinstance(query, dict) and "inband" in query: elif isinstance(query, dict) and "inband" in query:
autoComplQuery = query["inband"]["query"] autoComplQuery = query["inband"]["query"]

View File

@ -376,7 +376,7 @@ def getValue(expression, blind=True, inband=True, fromUser=False, expected=None,
kb.unionFalseCond = oldParamFalseCond kb.unionFalseCond = oldParamFalseCond
kb.unionNegative = oldParamNegative kb.unionNegative = oldParamNegative
if value and isinstance(value, str): if value and isinstance(value, basestring):
value = value.strip() value = value.strip()
return value return value

View File

@ -179,7 +179,7 @@ class Metasploit:
return self.__skeletonSelection("SMB port", self.__msfSMBPortsList) return self.__skeletonSelection("SMB port", self.__msfSMBPortsList)
def __selectEncoder(self, encode=True): def __selectEncoder(self, encode=True):
if isinstance(encode, str): if isinstance(encode, basestring):
return encode return encode
elif kb.os == "Windows" and encode: elif kb.os == "Windows" and encode:

View File

@ -227,7 +227,7 @@ class UDF:
while True: while True:
udfCount = readInput(msg, default=1) udfCount = readInput(msg, default=1)
if isinstance(udfCount, str) and udfCount.isdigit(): if isinstance(udfCount, basestring) and udfCount.isdigit():
udfCount = int(udfCount) udfCount = int(udfCount)
if udfCount <= 0: if udfCount <= 0:
@ -267,7 +267,7 @@ class UDF:
while True: while True:
parCount = readInput(msg, default=default) parCount = readInput(msg, default=default)
if isinstance(parCount, str) and parCount.isdigit() and int(parCount) >= 0: if isinstance(parCount, basestring) and parCount.isdigit() and int(parCount) >= 0:
parCount = int(parCount) parCount = int(parCount)
break break
@ -284,7 +284,7 @@ class UDF:
while True: while True:
parType = readInput(msg, default=defaultType) parType = readInput(msg, default=defaultType)
if isinstance(parType, str) and parType.isdigit(): if isinstance(parType, basestring) and parType.isdigit():
logger.warn("you need to specify the data-type of the parameter") logger.warn("you need to specify the data-type of the parameter")
else: else:
@ -297,7 +297,7 @@ class UDF:
while True: while True:
retType = readInput(msg, default=defaultType) retType = readInput(msg, default=defaultType)
if isinstance(retType, str) and retType.isdigit(): if isinstance(retType, basestring) and retType.isdigit():
logger.warn("you need to specify the data-type of the return value") logger.warn("you need to specify the data-type of the return value")
else: else:
self.udfs[udfName]["return"] = retType self.udfs[udfName]["return"] = retType
@ -328,7 +328,7 @@ class UDF:
if choice and choice[0] in ( "q", "Q" ): if choice and choice[0] in ( "q", "Q" ):
break break
elif isinstance(choice, str) and choice.isdigit() and int(choice) > 0 and int(choice) <= len(udfList): elif isinstance(choice, basestring) and choice.isdigit() and int(choice) > 0 and int(choice) <= len(udfList):
choice = int(choice) choice = int(choice)
break break
elif isinstance(choice, int) and choice > 0 and choice <= len(udfList): elif isinstance(choice, int) and choice > 0 and choice <= len(udfList):

View File

@ -58,20 +58,20 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
if "LENGTH(" in expression or "LEN(" in expression: if "LENGTH(" in expression or "LEN(" in expression:
firstChar = 0 firstChar = 0
elif conf.firstChar is not None and ( isinstance(conf.firstChar, int) or ( isinstance(conf.firstChar, str) and conf.firstChar.isdigit() ) ): elif conf.firstChar is not None and ( isinstance(conf.firstChar, int) or ( isinstance(conf.firstChar, basestring) and conf.firstChar.isdigit() ) ):
firstChar = int(conf.firstChar) - 1 firstChar = int(conf.firstChar) - 1
elif firstChar is None: elif firstChar is None:
firstChar = 0 firstChar = 0
elif ( isinstance(firstChar, str) and firstChar.isdigit() ) or isinstance(firstChar, int): elif ( isinstance(firstChar, basestring) and firstChar.isdigit() ) or isinstance(firstChar, int):
firstChar = int(firstChar) - 1 firstChar = int(firstChar) - 1
if "LENGTH(" in expression or "LEN(" in expression: if "LENGTH(" in expression or "LEN(" in expression:
lastChar = 0 lastChar = 0
elif conf.lastChar is not None and ( isinstance(conf.lastChar, int) or ( isinstance(conf.lastChar, str) and conf.lastChar.isdigit() ) ): elif conf.lastChar is not None and ( isinstance(conf.lastChar, int) or ( isinstance(conf.lastChar, basestring) and conf.lastChar.isdigit() ) ):
lastChar = int(conf.lastChar) lastChar = int(conf.lastChar)
elif lastChar in ( None, "0" ): elif lastChar in ( None, "0" ):
lastChar = 0 lastChar = 0
elif ( isinstance(lastChar, str) and lastChar.isdigit() ) or isinstance(lastChar, int): elif ( isinstance(lastChar, basestring) and lastChar.isdigit() ) or isinstance(lastChar, int):
lastChar = int(lastChar) lastChar = int(lastChar)
if kb.dbmsDetected: if kb.dbmsDetected:
@ -335,7 +335,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
# can mean that the connection to the target url was lost # can mean that the connection to the target url was lost
if None in value: if None in value:
for v in value: for v in value:
if isinstance(v, str) and v is not None: if isinstance(v, basestring) and v is not None:
partialValue += v partialValue += v
if partialValue: if partialValue:
@ -345,7 +345,7 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
finalValue = "".join(value) finalValue = "".join(value)
infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), finalValue) infoMsg = "\r[%s] [INFO] retrieved: %s" % (time.strftime("%X"), finalValue)
if isinstance(finalValue, str) and len(finalValue) > 0: if isinstance(finalValue, basestring) and len(finalValue) > 0:
dataToSessionFile(replaceNewlineTabs(finalValue)) dataToSessionFile(replaceNewlineTabs(finalValue))
if conf.verbose >= 1 and not showEta and infoMsg: if conf.verbose >= 1 and not showEta and infoMsg:

View File

@ -159,7 +159,7 @@ class Enumeration(GenericEnumeration):
values = inject.getValue(query, blind=False) values = inject.getValue(query, blind=False)
if values: if values:
if isinstance(values, str): if isinstance(values, basestring):
values = [ values ] values = [ values ]
for foundTbl in values: for foundTbl in values:
@ -244,7 +244,7 @@ class Enumeration(GenericEnumeration):
values = inject.getValue(query, blind=False) values = inject.getValue(query, blind=False)
if values: if values:
if isinstance(values, str): if isinstance(values, basestring):
values = [ values ] values = [ values ]
for foundTbl in values: for foundTbl in values:

View File

@ -217,7 +217,7 @@ class Enumeration(GenericEnumeration):
values = inject.getValue(query, blind=False) values = inject.getValue(query, blind=False)
if values: if values:
if isinstance(values, str): if isinstance(values, basestring):
values = [ values ] values = [ values ]
for foundTbl in values: for foundTbl in values:

View File

@ -718,7 +718,7 @@ class Enumeration:
if value: if value:
if kb.dbms == "SQLite": if kb.dbms == "SQLite":
if isinstance(value, str): if isinstance(value, basestring):
value = [[ "SQLite", value ]] value = [[ "SQLite", value ]]
elif isinstance(value, (list, tuple, set)): elif isinstance(value, (list, tuple, set)):
newValue = [] newValue = []
@ -1040,7 +1040,7 @@ class Enumeration:
entries = inject.getValue(query, blind=False, dump=True) entries = inject.getValue(query, blind=False, dump=True)
if entries: if entries:
if isinstance(entries, str): if isinstance(entries, basestring):
entries = [ entries ] entries = [ entries ]
entriesCount = len(entries) entriesCount = len(entries)
@ -1053,7 +1053,7 @@ class Enumeration:
kb.data.dumpedTable[column] = { "length": 0, "values": [] } kb.data.dumpedTable[column] = { "length": 0, "values": [] }
for entry in entries: for entry in entries:
if isinstance(entry, str): if isinstance(entry, basestring):
colEntry = entry colEntry = entry
else: else:
colEntry = entry[index] colEntry = entry[index]
@ -1295,7 +1295,7 @@ class Enumeration:
values = inject.getValue(query, blind=False) values = inject.getValue(query, blind=False)
if values: if values:
if isinstance(values, str): if isinstance(values, basestring):
values = [ values ] values = [ values ]
for value in values: for value in values:
@ -1380,7 +1380,7 @@ class Enumeration:
values = inject.getValue(query, blind=False) values = inject.getValue(query, blind=False)
if values: if values:
if isinstance(values, str): if isinstance(values, basestring):
values = [ values ] values = [ values ]
for foundDb, foundTbl in values: for foundDb, foundTbl in values:
@ -1501,7 +1501,7 @@ class Enumeration:
values = inject.getValue(query, blind=False) values = inject.getValue(query, blind=False)
if values: if values:
if isinstance(values, str): if isinstance(values, basestring):
values = [ values ] values = [ values ]
for foundDb, foundTbl in values: for foundDb, foundTbl in values:

View File

@ -114,7 +114,7 @@ class Takeover(Abstraction, Metasploit, Registry, Miscellaneous):
while True: while True:
choice = readInput(msg, default=1) choice = readInput(msg, default=1)
if isinstance(choice, str) and choice.isdigit() and int(choice) in ( 1, 2 ): if isinstance(choice, basestring) and choice.isdigit() and int(choice) in ( 1, 2 ):
choice = int(choice) choice = int(choice)
break break