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

Skip to content

Commit 35728fa

Browse files
committed
Fix (and some hidden bug fixes/improvements) regarding an Issue #317
1 parent 352e516 commit 35728fa

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

lib/core/common.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -737,13 +737,13 @@ def dataToDumpFile(dumpFile, data):
737737
dumpFile.flush()
738738

739739
def dataToOutFile(filename, data):
740-
if not data:
741-
return "No data retrieved"
740+
retVal = None
742741

743-
retVal = "%s%s%s" % (conf.filePath, os.sep, filePathToString(filename))
742+
if data:
743+
retVal = "%s%s%s" % (conf.filePath, os.sep, filePathToString(filename))
744744

745-
with codecs.open(retVal, "wb") as f:
746-
f.write(data)
745+
with codecs.open(retVal, "wb", UNICODE_ENCODING) as f:
746+
f.write(data)
747747

748748
return retVal
749749

@@ -3170,19 +3170,20 @@ def decodeHexValue(value):
31703170
retVal = value
31713171

31723172
def _(value):
3173+
retVal = value
31733174
if value and isinstance(value, basestring) and len(value) % 2 == 0:
3174-
value = hexdecode(value)
3175+
retVal = hexdecode(retVal)
31753176

3176-
if Backend.isDbms(DBMS.MSSQL):
3177+
if Backend.isDbms(DBMS.MSSQL) and value.startswith("0x"):
31773178
try:
3178-
value = value.decode("utf-16-le")
3179+
retVal = retVal.decode("utf-16-le")
31793180
except UnicodeDecodeError:
31803181
pass
31813182

3182-
if not isinstance(value, unicode):
3183-
value = getUnicode(value, "utf8")
3183+
if not isinstance(retVal, unicode):
3184+
retVal = getUnicode(retVal, "utf8")
31843185

3185-
return value
3186+
return retVal
31863187

31873188
try:
31883189
retVal = applyFunctionRecursively(value, _)

lib/takeover/metasploit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ def createMsfShellcode(self, exitfunc, format, extra, encode):
531531
errMsg = "failed to create the shellcode (%s)" % payloadStderr.replace("\n", " ").replace("\r", "")
532532
raise SqlmapFilePathException, errMsg
533533

534-
self._shellcodeFP = codecs.open(self._shellcodeFilePath, "rb")
534+
self._shellcodeFP = codecs.open(self._shellcodeFilePath, "rb", UNICODE_ENCODING)
535535
self.shellcodeString = self._shellcodeFP.read()
536536
self._shellcodeFP.close()
537537

plugins/dbms/mssqlserver/filesystem.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from lib.core.enums import PAYLOAD
2424
from lib.core.exception import SqlmapNoneDataException
2525
from lib.core.exception import SqlmapUnsupportedFeatureException
26+
from lib.core.settings import UNICODE_ENCODING
2627
from lib.request import inject
2728

2829
from plugins.generic.filesystem import Filesystem as GenericFilesystem
@@ -337,7 +338,7 @@ def stackedWriteFile(self, wFile, dFile, fileType):
337338

338339
tmpPath = posixToNtSlashes(conf.tmpPath)
339340
dFile = posixToNtSlashes(dFile)
340-
wFilePointer = codecs.open(wFile, "rb")
341+
wFilePointer = codecs.open(wFile, "rb", UNICODE_ENCODING)
341342
wFileContent = wFilePointer.read()
342343
wFilePointer.close()
343344

plugins/generic/filesystem.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lib.core.enums import EXPECTED
2626
from lib.core.enums import PAYLOAD
2727
from lib.core.exception import SqlmapUndefinedMethod
28+
from lib.core.settings import UNICODE_ENCODING
2829
from lib.request import inject
2930

3031
class Filesystem:
@@ -112,7 +113,7 @@ def fileEncode(self, fileName, encoding, single):
112113
"""
113114

114115
retVal = []
115-
with codecs.open(fileName, "rb") as f:
116+
with codecs.open(fileName, "rb", UNICODE_ENCODING) as f:
116117
content = f.read().encode(encoding).replace("\n", "")
117118

118119
if not single:
@@ -230,19 +231,24 @@ def readFile(self, remoteFiles):
230231

231232
if fileContent is not None:
232233
fileContent = decodeHexValue(fileContent)
233-
localFilePath = dataToOutFile(remoteFile, fileContent)
234234

235-
if not Backend.isDbms(DBMS.PGSQL):
236-
self.cleanup(onlyFileTbl=True)
235+
if fileContent:
236+
localFilePath = dataToOutFile(remoteFile, fileContent)
237237

238-
sameFile = self.askCheckReadFile(localFilePath, remoteFile)
238+
if not Backend.isDbms(DBMS.PGSQL):
239+
self.cleanup(onlyFileTbl=True)
239240

240-
if sameFile is True:
241-
localFilePath += " (same file)"
242-
elif sameFile is False:
243-
localFilePath += " (size differs from remote file)"
241+
sameFile = self.askCheckReadFile(localFilePath, remoteFile)
244242

245-
localFilePaths.append(localFilePath)
243+
if sameFile is True:
244+
localFilePath += " (same file)"
245+
elif sameFile is False:
246+
localFilePath += " (size differs from remote file)"
247+
248+
localFilePaths.append(localFilePath)
249+
else:
250+
errMsg = "no data retrieved"
251+
logger.error(errMsg)
246252

247253
return localFilePaths
248254

0 commit comments

Comments
 (0)