From a77b7f00d92edbaa3eeccd219d5380572d9d680e Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sun, 23 Dec 2012 19:34:35 +0100 Subject: [PATCH] Fix for an Issue #323 --- lib/takeover/metasploit.py | 3 +-- plugins/dbms/mssqlserver/filesystem.py | 7 ++----- plugins/generic/filesystem.py | 4 +--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/takeover/metasploit.py b/lib/takeover/metasploit.py index 473605f7d..8bf89f854 100644 --- a/lib/takeover/metasploit.py +++ b/lib/takeover/metasploit.py @@ -5,7 +5,6 @@ Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ -import codecs import os import re import sys @@ -531,7 +530,7 @@ class Metasploit: errMsg = "failed to create the shellcode (%s)" % payloadStderr.replace("\n", " ").replace("\r", "") raise SqlmapFilePathException, errMsg - self._shellcodeFP = codecs.open(self._shellcodeFilePath, "rb", UNICODE_ENCODING) + self._shellcodeFP = open(self._shellcodeFilePath, "rb") self.shellcodeString = self._shellcodeFP.read() self._shellcodeFP.close() diff --git a/plugins/dbms/mssqlserver/filesystem.py b/plugins/dbms/mssqlserver/filesystem.py index 2e01e01f0..be9d000ea 100644 --- a/plugins/dbms/mssqlserver/filesystem.py +++ b/plugins/dbms/mssqlserver/filesystem.py @@ -5,7 +5,6 @@ Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ -import codecs import ntpath import os @@ -23,7 +22,6 @@ from lib.core.enums import EXPECTED from lib.core.enums import PAYLOAD from lib.core.exception import SqlmapNoneDataException from lib.core.exception import SqlmapUnsupportedFeatureException -from lib.core.settings import UNICODE_ENCODING from lib.request import inject from plugins.generic.filesystem import Filesystem as GenericFilesystem @@ -338,9 +336,8 @@ class Filesystem(GenericFilesystem): tmpPath = posixToNtSlashes(conf.tmpPath) dFile = posixToNtSlashes(dFile) - wFilePointer = codecs.open(wFile, "rb", UNICODE_ENCODING) - wFileContent = wFilePointer.read() - wFilePointer.close() + with open(wFile, "rb") as f: + wFileContent = f.read() self._stackedWriteFileVbs(tmpPath, wFileContent, dFile, fileType) diff --git a/plugins/generic/filesystem.py b/plugins/generic/filesystem.py index 950f5f85f..36f80eafe 100644 --- a/plugins/generic/filesystem.py +++ b/plugins/generic/filesystem.py @@ -5,7 +5,6 @@ Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/) See the file 'doc/COPYING' for copying permission """ -import codecs import os from lib.core.agent import agent @@ -25,7 +24,6 @@ from lib.core.enums import CHARSET_TYPE from lib.core.enums import EXPECTED from lib.core.enums import PAYLOAD from lib.core.exception import SqlmapUndefinedMethod -from lib.core.settings import UNICODE_ENCODING from lib.request import inject class Filesystem: @@ -113,7 +111,7 @@ class Filesystem: """ retVal = [] - with codecs.open(fileName, "rb", UNICODE_ENCODING) as f: + with open(fileName, "rb") as f: content = f.read().encode(encoding).replace("\n", "") if not single: