diff --git a/lib/core/common.py b/lib/core/common.py index 873821b0e..62292b370 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -22,6 +22,7 @@ import socket import string import struct import sys +import tempfile import time import urllib import urlparse @@ -38,6 +39,7 @@ from subprocess import Popen as execute from xml.dom import minidom from xml.sax import parse +from extra.cloak.cloak import decloak from extra.safe2bin.safe2bin import safecharencode from lib.core.bigarray import BigArray from lib.core.data import conf @@ -3260,6 +3262,21 @@ def resetCookieJar(cookieJar): errMsg += "cookies file ('%s')" % msg raise SqlmapGenericException(errMsg) +def decloakToTemp(filename): + """ + Decloaks content of a given file to a temporary file with similar name and extension + """ + + content = decloak(filename) + _ = os.path.split(filename[:-1])[-1] + prefix, suffix = os.path.splitext(_) + prefix = prefix.split(os.extsep)[0] + handle, filename = tempfile.mkstemp(prefix=prefix, suffix=suffix) + os.close(handle) + with open(filename, "w+b") as f: + f.write(content) + return filename + def prioritySortColumns(columns): """ Sorts given column names by length in ascending order while those containing diff --git a/plugins/generic/filesystem.py b/plugins/generic/filesystem.py index 176f48e95..6c5d27e75 100644 --- a/plugins/generic/filesystem.py +++ b/plugins/generic/filesystem.py @@ -8,10 +8,10 @@ See the file 'doc/COPYING' for copying permission import os import tempfile -from extra.cloak.cloak import decloak from lib.core.agent import agent from lib.core.common import dataToOutFile from lib.core.common import Backend +from lib.core.common import decloakToTemp from lib.core.common import decodeHexValue from lib.core.common import isNumPosStrValue from lib.core.common import isListLike @@ -253,14 +253,8 @@ class Filesystem: def writeFile(self, localFile, remoteFile, fileType=None): self.checkDbmsOs() - if localFile.endswith("_"): - content = decloak(localFile) - _ = os.path.split(localFile[:-1])[-1] - prefix, suffix = os.path.splitext(_) - handle, localFile = tempfile.mkstemp(prefix=prefix, suffix=suffix) - os.close(handle) - with open(localFile, "w+b") as f: - f.write(content) + if localFile.endswith('_'): + localFile = decloakToTemp(localFile) if conf.direct or isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED): if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):