Minor refactoring for an Issue #295

This commit is contained in:
Miroslav Stampar 2013-01-08 10:23:02 +01:00
parent c155c6df84
commit ad85c4c964
2 changed files with 20 additions and 9 deletions

View File

@ -22,6 +22,7 @@ import socket
import string import string
import struct import struct
import sys import sys
import tempfile
import time import time
import urllib import urllib
import urlparse import urlparse
@ -38,6 +39,7 @@ from subprocess import Popen as execute
from xml.dom import minidom from xml.dom import minidom
from xml.sax import parse from xml.sax import parse
from extra.cloak.cloak import decloak
from extra.safe2bin.safe2bin import safecharencode from extra.safe2bin.safe2bin import safecharencode
from lib.core.bigarray import BigArray from lib.core.bigarray import BigArray
from lib.core.data import conf from lib.core.data import conf
@ -3260,6 +3262,21 @@ def resetCookieJar(cookieJar):
errMsg += "cookies file ('%s')" % msg errMsg += "cookies file ('%s')" % msg
raise SqlmapGenericException(errMsg) 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): def prioritySortColumns(columns):
""" """
Sorts given column names by length in ascending order while those containing Sorts given column names by length in ascending order while those containing

View File

@ -8,10 +8,10 @@ See the file 'doc/COPYING' for copying permission
import os import os
import tempfile import tempfile
from extra.cloak.cloak import decloak
from lib.core.agent import agent from lib.core.agent import agent
from lib.core.common import dataToOutFile from lib.core.common import dataToOutFile
from lib.core.common import Backend from lib.core.common import Backend
from lib.core.common import decloakToTemp
from lib.core.common import decodeHexValue from lib.core.common import decodeHexValue
from lib.core.common import isNumPosStrValue from lib.core.common import isNumPosStrValue
from lib.core.common import isListLike from lib.core.common import isListLike
@ -253,14 +253,8 @@ class Filesystem:
def writeFile(self, localFile, remoteFile, fileType=None): def writeFile(self, localFile, remoteFile, fileType=None):
self.checkDbmsOs() self.checkDbmsOs()
if localFile.endswith("_"): if localFile.endswith('_'):
content = decloak(localFile) localFile = decloakToTemp(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 conf.direct or isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED): if conf.direct or isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED): if isTechniqueAvailable(PAYLOAD.TECHNIQUE.STACKED):