diff --git a/lib/core/bigarray.py b/lib/core/bigarray.py index 01b45992a..08b621433 100644 --- a/lib/core/bigarray.py +++ b/lib/core/bigarray.py @@ -17,7 +17,6 @@ import tempfile from lib.core.exception import SqlmapSystemException from lib.core.settings import BIGARRAY_CHUNK_SIZE -from lib.core.settings import BIGARRAY_TEMP_PREFIX DEFAULT_SIZE_OF = sys.getsizeof(object()) @@ -92,7 +91,7 @@ class BigArray(list): def _dump(self, chunk): try: - handle, filename = tempfile.mkstemp(prefix=BIGARRAY_TEMP_PREFIX) + handle, filename = tempfile.mkstemp() self.filenames.add(filename) os.close(handle) with open(filename, "w+b") as fp: diff --git a/lib/core/option.py b/lib/core/option.py index bc5f68768..b51622641 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -15,6 +15,7 @@ import re import socket import string import sys +import tempfile import threading import time import urllib2 @@ -1437,6 +1438,17 @@ def _checkDependencies(): if conf.dependencies: checkDependencies() +def _createTemporaryDirectory(): + """ + Creates temporary directory for this run. + """ + + if not os.path.isdir(tempfile.gettempdir()): + os.makedirs(tempfile.gettempdir()) + tempfile.tempdir = tempfile.mkdtemp(prefix="sqlmap", suffix=str(os.getpid())) + if not os.path.isdir(tempfile.tempdir): + os.makedirs(tempfile.tempdir) + def _cleanupOptions(): """ Cleanup configuration attributes. @@ -2332,6 +2344,7 @@ def init(): _cleanupOptions() _purgeOutput() _checkDependencies() + _createTemporaryDirectory() _basicOptionValidation() _setProxyList() _setTorProxySettings() diff --git a/lib/core/settings.py b/lib/core/settings.py index 3d1460c3b..b91a36f38 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -446,9 +446,6 @@ ROTATING_CHARS = ('\\', '|', '|', '/', '-') # Approximate chunk length (in bytes) used by BigArray objects (only last chunk and cached one are held in memory) BIGARRAY_CHUNK_SIZE = 1024 * 1024 -# Prefix used for storing dumped chunks in BigArray objects -BIGARRAY_TEMP_PREFIX = "sqlmapba-%d-" % os.getpid() - # Only console display last n table rows TRIM_STDOUT_DUMP_SIZE = 256 diff --git a/sqlmap.py b/sqlmap.py index 1c949f95c..0c20bb1eb 100755 --- a/sqlmap.py +++ b/sqlmap.py @@ -6,11 +6,11 @@ See the file 'doc/COPYING' for copying permission """ import bdb -import glob import inspect import logging import os import re +import shutil import sys import tempfile import time @@ -44,7 +44,6 @@ from lib.core.exception import SqlmapUserQuitException from lib.core.option import initOptions from lib.core.option import init from lib.core.profiling import profile -from lib.core.settings import BIGARRAY_TEMP_PREFIX from lib.core.settings import LEGAL_DISCLAIMER from lib.core.testing import smokeTest from lib.core.testing import liveTest @@ -154,11 +153,7 @@ def main(): if conf.get("showTime"): dataToStdout("\n[*] shutting down at %s\n\n" % time.strftime("%X"), forceOutput=True) - for filename in glob.glob("%s*" % os.path.join(tempfile.gettempdir(), BIGARRAY_TEMP_PREFIX)): - try: - os.remove(filename) - except: - pass + shutil.rmtree(tempfile.tempdir, ignore_errors=True) kb.threadContinue = False kb.threadException = True