added support for proper unicode session(s) storage/retrieval

This commit is contained in:
Miroslav Stampar 2010-05-24 11:00:49 +00:00
parent f34e6badfd
commit e9be60e1ac
5 changed files with 24 additions and 16 deletions

View File

@ -22,6 +22,7 @@ with sqlmap; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
""" """
import codecs
import cProfile import cProfile
import os import os
import random import random
@ -351,8 +352,11 @@ def filePathToString(filePath):
return strRepl return strRepl
def dataToStdout(data): def dataToStdout(data):
sys.stdout.write(data) try:
sys.stdout.flush() sys.stdout.write(data)
sys.stdout.flush()
except UnicodeEncodeError:
print data.encode("utf8")
def dataToSessionFile(data): def dataToSessionFile(data):
if not conf.sessionFile: if not conf.sessionFile:
@ -371,7 +375,7 @@ def dataToOutFile(data):
rFile = filePathToString(conf.rFile) rFile = filePathToString(conf.rFile)
rFilePath = "%s%s%s" % (conf.filePath, os.sep, rFile) rFilePath = "%s%s%s" % (conf.filePath, os.sep, rFile)
rFileFP = open(rFilePath, "wb") rFileFP = codecs.open(rFilePath, "wb", "utf-8")
rFileFP.write(data) rFileFP.write(data)
rFileFP.flush() rFileFP.flush()
@ -412,7 +416,7 @@ def fileToStr(fileName):
@rtype: C{str} @rtype: C{str}
""" """
filePointer = open(fileName, "r") filePointer = codecs.open(fileName, "r", "utf-8")
fileText = filePointer.read() fileText = filePointer.read()
return fileText.replace(" ", "").replace("\t", "").replace("\r", "").replace("\n", " ") return fileText.replace(" ", "").replace("\t", "").replace("\r", "").replace("\n", " ")

View File

@ -22,8 +22,9 @@ with sqlmap; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
""" """
import os import codecs
import re import re
import os
from lib.core.common import dataToDumpFile from lib.core.common import dataToDumpFile
from lib.core.data import conf from lib.core.data import conf
@ -54,7 +55,7 @@ class Dump:
def setOutputFile(self): def setOutputFile(self):
self.__outputFile = "%s%slog" % (conf.outputPath, os.sep) self.__outputFile = "%s%slog" % (conf.outputPath, os.sep)
self.__outputFP = open(self.__outputFile, "a") self.__outputFP = codecs.open(self.__outputFile, "a", "utf-8")
def string(self, header, data, sort=True): def string(self, header, data, sort=True):
if isinstance(data, (list, tuple, set)): if isinstance(data, (list, tuple, set)):
@ -267,7 +268,7 @@ class Dump:
os.makedirs(dumpDbPath, 0755) os.makedirs(dumpDbPath, 0755)
dumpFileName = "%s%s%s.csv" % (dumpDbPath, os.sep, table) dumpFileName = "%s%s%s.csv" % (dumpDbPath, os.sep, table)
dumpFP = open(dumpFileName, "w") dumpFP = codecs.open(dumpFileName, "w", "utf-8")
count = int(tableValues["__infos__"]["count"]) count = int(tableValues["__infos__"]["count"])
separator = "" separator = ""
@ -319,13 +320,14 @@ class Dump:
for column in columns: for column in columns:
if column != "__infos__": if column != "__infos__":
info = tableValues[column] info = tableValues[column]
value = info["values"][i]
if re.search("^[\ *]*$", str(value)): value = unicode(info["values"][i]) if type(info["values"][i]) != unicode else info["values"][i]
if re.search("^[\ *]*$", value):
value = "NULL" value = "NULL"
maxlength = int(info["length"]) maxlength = int(info["length"])
blank = " " * (maxlength - len(str(value))) blank = " " * (maxlength - len(value))
self.__write("| %s%s" % (value, blank), n=False) self.__write("| %s%s" % (value, blank), n=False)
if not conf.multipleTargets and field == fields: if not conf.multipleTargets and field == fields:

View File

@ -22,6 +22,7 @@ with sqlmap; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
""" """
import codecs
import cookielib import cookielib
import ctypes import ctypes
import difflib import difflib
@ -96,7 +97,7 @@ def __urllib2Opener():
urllib2.install_opener(opener) urllib2.install_opener(opener)
def __feedTargetsDict(reqFile, addedTargetUrls): def __feedTargetsDict(reqFile, addedTargetUrls):
fp = open(reqFile, "r") fp = codecs.open(reqFile, "r", "utf-8")
fread = fp.read() fread = fp.read()
fread = fread.replace("\r", "") fread = fread.replace("\r", "")

View File

@ -22,6 +22,7 @@ with sqlmap; if not, write to the Free Software Foundation, Inc., 51
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
""" """
import codecs
import os import os
import time import time
@ -121,11 +122,11 @@ def __setOutputResume():
if os.path.exists(conf.sessionFile): if os.path.exists(conf.sessionFile):
if not conf.flushSession: if not conf.flushSession:
readSessionFP = open(conf.sessionFile, "r") readSessionFP = codecs.open(conf.sessionFile, "r", "utf-8")
__url_cache = set() __url_cache = set()
__expression_cache = {} __expression_cache = {}
for line in readSessionFP.xreadlines(): for line in readSessionFP.readlines(): #xreadlines doesn't return unicode strings when codec.open used
if line.count("][") == 4: if line.count("][") == 4:
line = line.split("][") line = line.split("][")
@ -170,7 +171,7 @@ def __setOutputResume():
raise sqlmapFilePathException, errMsg raise sqlmapFilePathException, errMsg
try: try:
conf.sessionFP = open(conf.sessionFile, "a") conf.sessionFP = codecs.open(conf.sessionFile, "a", "utf-8")
dataToSessionFile("\n[%s]\n" % time.strftime("%X %x")) dataToSessionFile("\n[%s]\n" % time.strftime("%X %x"))
except IOError: except IOError:
errMsg = "unable to write on the session file specified" errMsg = "unable to write on the session file specified"

View File

@ -194,10 +194,10 @@ def bisection(payload, expression, length=None, charsetType=None, firstChar=None
minValue = charTbl[0] minValue = charTbl[0]
else: else:
retVal = minValue + 1 retVal = minValue + 1
if retVal < 256: if retVal < 128:
return chr(retVal) return chr(retVal)
else: else:
return unichr(retVal) return unichr(retVal) #test value 50089
def etaProgressUpdate(charTime, index): def etaProgressUpdate(charTime, index):
if len(progressTime) <= ( (length * 3) / 100 ): if len(progressTime) <= ( (length * 3) / 100 ):