str() -> unicode()

This commit is contained in:
Miroslav Stampar 2010-05-28 13:05:02 +00:00
parent f24187f251
commit a3db3c03c1
17 changed files with 31 additions and 31 deletions

View File

@ -257,7 +257,7 @@ def checkDynParam(place, parameter, value):
logger.info(infoMsg) logger.info(infoMsg)
randInt = randomInt() randInt = randomInt()
payload = agent.payload(place, parameter, value, str(randInt)) payload = agent.payload(place, parameter, value, unicode(randInt))
dynResult1 = Request.queryPage(payload, place) dynResult1 = Request.queryPage(payload, place)
if True == dynResult1: if True == dynResult1:
@ -395,7 +395,7 @@ def checkConnection():
conf.seqMatcher.set_seq1(page) conf.seqMatcher.set_seq1(page)
except sqlmapConnectionException, errMsg: except sqlmapConnectionException, errMsg:
errMsg = str(errMsg) errMsg = unicode(errMsg)
raise sqlmapConnectionException, errMsg raise sqlmapConnectionException, errMsg
return True return True

View File

@ -155,7 +155,7 @@ def start():
if not conf.dropSetCookie: if not conf.dropSetCookie:
for _, cookie in enumerate(conf.cj): for _, cookie in enumerate(conf.cj):
cookie = str(cookie) cookie = unicode(cookie)
index = cookie.index(" for ") index = cookie.index(" for ")
cookieStr += "%s;" % cookie[8:index] cookieStr += "%s;" % cookie[8:index]
@ -267,7 +267,7 @@ def start():
action() action()
except exceptionsTuple, e: except exceptionsTuple, e:
e = str(e) e = unicode(e)
if conf.multipleTargets: if conf.multipleTargets:
e += ", skipping to next url" e += ", skipping to next url"

View File

@ -451,7 +451,7 @@ def readInput(message, default=None):
message += "\n> " message += "\n> "
if conf.batch and default: if conf.batch and default:
infoMsg = "%s%s" % (message, str(default)) infoMsg = "%s%s" % (message, unicode(default))
logger.info(infoMsg) logger.info(infoMsg)
debugMsg = "used the default behaviour, running in batch mode" debugMsg = "used the default behaviour, running in batch mode"
@ -517,7 +517,7 @@ def sanitizeStr(inpStr):
@rtype: C{str} @rtype: C{str}
""" """
cleanString = str(inpStr) cleanString = unicode(inpStr)
cleanString = cleanString.replace("\n", " ").replace("\r", "") cleanString = cleanString.replace("\n", " ").replace("\r", "")
return cleanString return cleanString
@ -638,8 +638,8 @@ def parseTargetDirect():
conf.dbmsUser = details.group('user') conf.dbmsUser = details.group('user')
conf.dbmsPass = details.group('pass') conf.dbmsPass = details.group('pass')
else: else:
conf.dbmsUser = str() conf.dbmsUser = unicode()
conf.dbmsPass = str() conf.dbmsPass = unicode()
if not conf.dbmsPass: if not conf.dbmsPass:
conf.dbmsPass = None conf.dbmsPass = None
@ -1032,7 +1032,7 @@ def safeStringFormat(formatStr, params):
if index != -1: if index != -1:
if count < len(params): if count < len(params):
retVal = retVal[:index] + str(params[count]) + retVal[index+2:] retVal = retVal[:index] + unicode(params[count]) + retVal[index+2:]
else: else:
raise sqlmapNoneDataException, "wrong number of parameters during string formatting" raise sqlmapNoneDataException, "wrong number of parameters during string formatting"
count += 1 count += 1
@ -1107,7 +1107,7 @@ def profile(profileOutputFile=None, dotOutputFile=None, imageOutputFile=None):
import gtk import gtk
import pydot import pydot
except ImportError, e: except ImportError, e:
errMsg = "profiling requires third-party libraries (%s)" % str(e) errMsg = "profiling requires third-party libraries (%s)" % unicode(e)
logger.error(errMsg) logger.error(errMsg)
return return
@ -1343,7 +1343,7 @@ def getCommonStart(strings=[]):
if len(strings) == 1: if len(strings) == 1:
return strings[0] return strings[0]
retVal = str() retVal = unicode()
maxCount = min(len(string) for string in strings) maxCount = min(len(string) for string in strings)
count = 0 count = 0

View File

@ -63,7 +63,7 @@ class Dump:
return return
data = str(data) data = unicode(data)
if data: if data:
data = data.replace("__NEWLINE__", "\n").replace("__TAB__", "\t") data = data.replace("__NEWLINE__", "\n").replace("__TAB__", "\t")
@ -93,7 +93,7 @@ class Dump:
if isinstance(element, basestring): 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(unicode(e) for e in element))
if elements: if elements:
self.__write("") self.__write("")

View File

@ -80,7 +80,7 @@ class ProgressBar:
" " * (allFull - numHashes)) " " * (allFull - numHashes))
# Add the percentage at the beginning of the progress bar # Add the percentage at the beginning of the progress bar
percentString = str(percentDone) + "%" percentString = unicode(percentDone) + "%"
self.__progBar = "%s %s" % (percentString, self.__progBar) self.__progBar = "%s %s" % (percentString, self.__progBar)
def draw(self, eta=0): def draw(self, eta=0):
@ -102,4 +102,4 @@ class ProgressBar:
This method returns the progress bar string This method returns the progress bar string
""" """
return str(self.__progBar) return unicode(self.__progBar)

View File

@ -214,7 +214,7 @@ def __updateSqlmap():
logger.debug(debugMsg) logger.debug(debugMsg)
def notify(event_dict): def notify(event_dict):
action = str(event_dict['action']) action = unicode(event_dict['action'])
index = action.find('_') index = action.find('_')
prefix = action[index + 1].upper() if index != -1 else action.capitalize() prefix = action[index + 1].upper() if index != -1 else action.capitalize()
@ -224,7 +224,7 @@ def __updateSqlmap():
if action.find('_completed') == -1: if action.find('_completed') == -1:
print "%s\t%s" % (prefix, event_dict['path']) print "%s\t%s" % (prefix, event_dict['path'])
else: else:
revision = str(event_dict['revision']) revision = unicode(event_dict['revision'])
index = revision.find('number ') index = revision.find('number ')
if index != -1: if index != -1:

View File

@ -94,7 +94,7 @@ def decodePage(page, encoding):
Decode gzip/deflate HTTP response Decode gzip/deflate HTTP response
""" """
if str(encoding).lower() in ('gzip', 'x-gzip', 'deflate'): if unicode(encoding).lower() in (u'gzip', u'x-gzip', u'deflate'):
if encoding == 'deflate': if encoding == 'deflate':
# http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations # http://stackoverflow.com/questions/1089662/python-inflate-and-deflate-implementations
data = StringIO.StringIO(zlib.decompress(page, -15)) data = StringIO.StringIO(zlib.decompress(page, -15))

View File

@ -163,7 +163,7 @@ class Connect:
if not cookieStr: if not cookieStr:
cookieStr = "Cookie: " cookieStr = "Cookie: "
cookie = str(cookie) cookie = unicode(cookie)
index = cookie.index(" for ") index = cookie.index(" for ")
cookieStr += "%s; " % cookie[8:index] cookieStr += "%s; " % cookie[8:index]
@ -257,7 +257,7 @@ class Connect:
responseMsg += "(%s - %d):\n" % (status, code) responseMsg += "(%s - %d):\n" % (status, code)
if conf.verbose <= 4: if conf.verbose <= 4:
responseMsg += str(responseHeaders) responseMsg += unicode(responseHeaders)
elif conf.verbose > 4: elif conf.verbose > 4:
responseMsg += "%s\n%s\n" % (responseHeaders, page) responseMsg += "%s\n%s\n" % (responseHeaders, page)

View File

@ -54,7 +54,7 @@ def direct(query, content=True):
output = base64unpickle(kb.resumedQueries[conf.hostname][query][:-1]) output = base64unpickle(kb.resumedQueries[conf.hostname][query][:-1])
infoMsg = "resumed from file '%s': " % conf.sessionFile infoMsg = "resumed from file '%s': " % conf.sessionFile
infoMsg += "%s..." % str(output)[:20] infoMsg += "%s..." % unicode(output)[:20]
logger.info(infoMsg) logger.info(infoMsg)
elif select: elif select:
output = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None) output = timeout(func=conf.dbmsConnector.select, args=(query,), duration=conf.timeout, default=None)
@ -67,7 +67,7 @@ def direct(query, content=True):
if len(output) == 1: if len(output) == 1:
if len(output[0]) == 1: if len(output[0]) == 1:
return str(list(output)[0][0]) return unicode(list(output)[0][0])
else: else:
return list(output) return list(output)
else: else:

View File

@ -156,7 +156,7 @@ class Metasploit:
if not choice: if not choice:
if lst: if lst:
choice = str(default) choice = unicode(default)
else: else:
return default return default

View File

@ -227,7 +227,7 @@ def unionUse(expression, direct=False, unescape=True, resetCounter=False, nullCh
# sql injection output # sql injection output
startPosition = resultPage.index(temp.start) startPosition = resultPage.index(temp.start)
endPosition = resultPage.rindex(temp.stop) + len(temp.stop) endPosition = resultPage.rindex(temp.stop) + len(temp.stop)
value = str(resultPage[startPosition:endPosition]) value = unicode(resultPage[startPosition:endPosition])
duration = calculateDeltaSeconds(start) duration = calculateDeltaSeconds(start)

View File

@ -123,7 +123,7 @@ class Google:
responseMsg = "HTTP response (%s - %d):\n" % (status, code) responseMsg = "HTTP response (%s - %d):\n" % (status, code)
if conf.verbose <= 4: if conf.verbose <= 4:
responseMsg += str(responseHeaders) responseMsg += unicode(responseHeaders)
elif conf.verbose > 4: elif conf.verbose > 4:
responseMsg += "%s\n%s\n" % (responseHeaders, page) responseMsg += "%s\n%s\n" % (responseHeaders, page)

View File

@ -94,7 +94,7 @@ class Fingerprint(GenericFingerprint):
for i in xrange(len(table)): for i in xrange(len(table)):
version, checks = table[i] version, checks = table[i]
failed = False failed = False
check = checks[randomRange(0,len(checks)-1)].replace("%d", str(randomRange(1,100))) check = checks[randomRange(0,len(checks)-1)].replace("%d", unicode(randomRange(1,100)))
payload = agent.fullPayload(check) payload = agent.fullPayload(check)
result = Request.queryPage(payload) result = Request.queryPage(payload)
if result: if result:

View File

@ -217,7 +217,7 @@ class Fingerprint(GenericFingerprint):
for sp in sps: for sp in sps:
query = "(SELECT LEN(%s) FROM %s WHERE %s " % (self.tblField, self.fileTblName, self.tblField) query = "(SELECT LEN(%s) FROM %s WHERE %s " % (self.tblField, self.fileTblName, self.tblField)
query += "LIKE '%Service Pack " + str(sp) + "%')>0" query += "LIKE '%Service Pack " + unicode(sp) + "%')>0"
query = agent.forgeCaseStatement(query) query = agent.forgeCaseStatement(query)
if inject.getValue(query, charsetType=1) == "1": if inject.getValue(query, charsetType=1) == "1":

View File

@ -76,7 +76,7 @@ class Fingerprint(GenericFingerprint):
for version in range(element[0], element[1] + 1): for version in range(element[0], element[1] + 1):
randInt = randomInt() randInt = randomInt()
version = str(version) version = unicode(version)
query = agent.prefixQuery(" /*!%s AND %d=%d*/" % (version, randInt, randInt + 1)) query = agent.prefixQuery(" /*!%s AND %d=%d*/" % (version, randInt, randInt + 1))
query = agent.postfixQuery(query) query = agent.postfixQuery(query)
payload = agent.payload(newValue=query) payload = agent.payload(newValue=query)
@ -168,7 +168,7 @@ class Fingerprint(GenericFingerprint):
infoMsg = "testing MySQL" infoMsg = "testing MySQL"
logger.info(infoMsg) logger.info(infoMsg)
randInt = str(randomInt(1)) randInt = unicode(randomInt(1))
payload = agent.fullPayload(" AND CONNECTION_ID()=CONNECTION_ID()") payload = agent.fullPayload(" AND CONNECTION_ID()=CONNECTION_ID()")
result = Request.queryPage(payload) result = Request.queryPage(payload)

View File

@ -97,7 +97,7 @@ class Fingerprint(GenericFingerprint):
infoMsg = "testing PostgreSQL" infoMsg = "testing PostgreSQL"
logger.info(infoMsg) logger.info(infoMsg)
randInt = str(randomInt(1)) randInt = unicode(randomInt(1))
payload = agent.fullPayload(" AND %s::int=%s" % (randInt, randInt)) payload = agent.fullPayload(" AND %s::int=%s" % (randInt, randInt))
result = Request.queryPage(payload) result = Request.queryPage(payload)

View File

@ -81,7 +81,7 @@ def main():
else: else:
start() start()
except exceptionsTuple, e: except exceptionsTuple, e:
e = str(e) e = unicode(e)
logger.error(e) logger.error(e)
except KeyboardInterrupt: except KeyboardInterrupt: