Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e9be60e

Browse files
committed
added support for proper unicode session(s) storage/retrieval
1 parent f34e6ba commit e9be60e

5 files changed

Lines changed: 24 additions & 16 deletions

File tree

lib/core/common.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25+
import codecs
2526
import cProfile
2627
import os
2728
import random
@@ -351,8 +352,11 @@ def filePathToString(filePath):
351352
return strRepl
352353

353354
def dataToStdout(data):
354-
sys.stdout.write(data)
355-
sys.stdout.flush()
355+
try:
356+
sys.stdout.write(data)
357+
sys.stdout.flush()
358+
except UnicodeEncodeError:
359+
print data.encode("utf8")
356360

357361
def dataToSessionFile(data):
358362
if not conf.sessionFile:
@@ -371,7 +375,7 @@ def dataToOutFile(data):
371375

372376
rFile = filePathToString(conf.rFile)
373377
rFilePath = "%s%s%s" % (conf.filePath, os.sep, rFile)
374-
rFileFP = open(rFilePath, "wb")
378+
rFileFP = codecs.open(rFilePath, "wb", "utf-8")
375379

376380
rFileFP.write(data)
377381
rFileFP.flush()
@@ -412,7 +416,7 @@ def fileToStr(fileName):
412416
@rtype: C{str}
413417
"""
414418

415-
filePointer = open(fileName, "r")
419+
filePointer = codecs.open(fileName, "r", "utf-8")
416420
fileText = filePointer.read()
417421

418422
return fileText.replace(" ", "").replace("\t", "").replace("\r", "").replace("\n", " ")

lib/core/dump.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25-
import os
25+
import codecs
2626
import re
27+
import os
2728

2829
from lib.core.common import dataToDumpFile
2930
from lib.core.data import conf
@@ -54,7 +55,7 @@ def __write(self, data, n=True):
5455

5556
def setOutputFile(self):
5657
self.__outputFile = "%s%slog" % (conf.outputPath, os.sep)
57-
self.__outputFP = open(self.__outputFile, "a")
58+
self.__outputFP = codecs.open(self.__outputFile, "a", "utf-8")
5859

5960
def string(self, header, data, sort=True):
6061
if isinstance(data, (list, tuple, set)):
@@ -267,7 +268,7 @@ def dbTableValues(self, tableValues):
267268
os.makedirs(dumpDbPath, 0755)
268269

269270
dumpFileName = "%s%s%s.csv" % (dumpDbPath, os.sep, table)
270-
dumpFP = open(dumpFileName, "w")
271+
dumpFP = codecs.open(dumpFileName, "w", "utf-8")
271272

272273
count = int(tableValues["__infos__"]["count"])
273274
separator = ""
@@ -319,13 +320,14 @@ def dbTableValues(self, tableValues):
319320
for column in columns:
320321
if column != "__infos__":
321322
info = tableValues[column]
322-
value = info["values"][i]
323323

324-
if re.search("^[\ *]*$", str(value)):
324+
value = unicode(info["values"][i]) if type(info["values"][i]) != unicode else info["values"][i]
325+
326+
if re.search("^[\ *]*$", value):
325327
value = "NULL"
326328

327329
maxlength = int(info["length"])
328-
blank = " " * (maxlength - len(str(value)))
330+
blank = " " * (maxlength - len(value))
329331
self.__write("| %s%s" % (value, blank), n=False)
330332

331333
if not conf.multipleTargets and field == fields:

lib/core/option.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25+
import codecs
2526
import cookielib
2627
import ctypes
2728
import difflib
@@ -96,7 +97,7 @@ def __urllib2Opener():
9697
urllib2.install_opener(opener)
9798

9899
def __feedTargetsDict(reqFile, addedTargetUrls):
99-
fp = open(reqFile, "r")
100+
fp = codecs.open(reqFile, "r", "utf-8")
100101

101102
fread = fp.read()
102103
fread = fread.replace("\r", "")

lib/core/target.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
"""
2424

25+
import codecs
2526
import os
2627
import time
2728

@@ -121,11 +122,11 @@ def __setOutputResume():
121122

122123
if os.path.exists(conf.sessionFile):
123124
if not conf.flushSession:
124-
readSessionFP = open(conf.sessionFile, "r")
125+
readSessionFP = codecs.open(conf.sessionFile, "r", "utf-8")
125126
__url_cache = set()
126127
__expression_cache = {}
127128

128-
for line in readSessionFP.xreadlines():
129+
for line in readSessionFP.readlines(): #xreadlines doesn't return unicode strings when codec.open used
129130
if line.count("][") == 4:
130131
line = line.split("][")
131132

@@ -170,7 +171,7 @@ def __setOutputResume():
170171
raise sqlmapFilePathException, errMsg
171172

172173
try:
173-
conf.sessionFP = open(conf.sessionFile, "a")
174+
conf.sessionFP = codecs.open(conf.sessionFile, "a", "utf-8")
174175
dataToSessionFile("\n[%s]\n" % time.strftime("%X %x"))
175176
except IOError:
176177
errMsg = "unable to write on the session file specified"

lib/techniques/blind/inference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,10 +194,10 @@ def getChar(idx, charTbl=asciiTbl):
194194
minValue = charTbl[0]
195195
else:
196196
retVal = minValue + 1
197-
if retVal < 256:
197+
if retVal < 128:
198198
return chr(retVal)
199199
else:
200-
return unichr(retVal)
200+
return unichr(retVal) #test value 50089
201201

202202
def etaProgressUpdate(charTime, index):
203203
if len(progressTime) <= ( (length * 3) / 100 ):

0 commit comments

Comments
 (0)