diff --git a/lib/contrib/upx/windows/README.txt b/lib/contrib/upx/windows/README.txt new file mode 100644 index 000000000..a00b6a806 --- /dev/null +++ b/lib/contrib/upx/windows/README.txt @@ -0,0 +1,10 @@ +Due to the anti-virus positive detection of executable stored inside this folder, +we needed to somehow circumvent this. As from the plain sqlmap users perspective nothing +has to be done prior to its usage by sqlmap, but if you want to have access to the +original executable use the decrypt functionality of the ../../../../extra/cloak/cloak.py utility. + +To prepare the executable to the cloaked form use this command: +python ../../../../extra/cloak/cloak.py -i upx.exe + +To get back the original executable use this: +python ../../../../extra/cloak/cloak.py -d -i upx.exe_ \ No newline at end of file diff --git a/lib/contrib/upx/windows/upx.exe b/lib/contrib/upx/windows/upx.exe deleted file mode 100755 index 6266213c6..000000000 Binary files a/lib/contrib/upx/windows/upx.exe and /dev/null differ diff --git a/lib/contrib/upx/windows/upx.exe_ b/lib/contrib/upx/windows/upx.exe_ new file mode 100644 index 000000000..9c1a15940 Binary files /dev/null and b/lib/contrib/upx/windows/upx.exe_ differ diff --git a/lib/core/common.py b/lib/core/common.py index 2a598d8a6..cbf6ec9a9 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -34,6 +34,7 @@ import ntpath import posixpath from tempfile import NamedTemporaryFile +from tempfile import mkstemp from extra.cloak.cloak import decloak from lib.contrib import magic @@ -885,3 +886,10 @@ def decloakToNamedTemporaryFile(filepath, name=None): retVal.old_name = retVal.name retVal.name = name return retVal + +def decloakToMkstemp(filepath, **kwargs): + name = mkstemp(**kwargs)[1] + retVal = open(name, 'w+b') + retVal.write(decloak(filepath)) + retVal.seek(0) + return retVal diff --git a/lib/takeover/upx.py b/lib/takeover/upx.py index fb8000d26..f352b6b73 100644 --- a/lib/takeover/upx.py +++ b/lib/takeover/upx.py @@ -30,6 +30,7 @@ from subprocess import STDOUT from subprocess import Popen as execute from lib.core.common import dataToStdout +from lib.core.common import decloakToMkstemp from lib.core.common import pollProcess from lib.core.data import logger from lib.core.data import paths @@ -49,7 +50,9 @@ class UPX: self.__upxPath = "%s/upx/macosx/upx" % paths.SQLMAP_CONTRIB_PATH elif "win" in PLATFORM: - self.__upxPath = "%s\upx\windows\upx.exe" % paths.SQLMAP_CONTRIB_PATH + self.__upxTempExe = decloakToMkstemp("%s\upx\windows\upx.exe_" % paths.SQLMAP_CONTRIB_PATH, suffix=".exe") + self.__upxPath = self.__upxTempExe.name + self.__upxTempExe.close() #needed for execution rights elif "linux" in PLATFORM: self.__upxPath = "%s/upx/linux/upx" % paths.SQLMAP_CONTRIB_PATH @@ -71,6 +74,9 @@ class UPX: logger.debug("executing local command: %s" % self.__upxCmd) process = execute(self.__upxCmd, shell=True, stdout=PIPE, stderr=STDOUT) + + if (self, hasattr('__upxTempExe')): + os.remove(self.__upxTempExe.name) dataToStdout("\r[%s] [INFO] compression in progress " % time.strftime("%X")) pollProcess(process)