diff --git a/lib/core/bigarray.py b/lib/core/bigarray.py index f1d5dda8d..0bca3d5e6 100644 --- a/lib/core/bigarray.py +++ b/lib/core/bigarray.py @@ -15,6 +15,7 @@ import os import sys import tempfile +from lib.core.enums import MKSTEMP_PREFIX from lib.core.exception import SqlmapSystemException from lib.core.settings import BIGARRAY_CHUNK_SIZE @@ -91,7 +92,7 @@ class BigArray(list): def _dump(self, chunk): try: - handle, filename = tempfile.mkstemp() + handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.BIG_ARRAY) self.filenames.add(filename) os.close(handle) with open(filename, "w+b") as fp: diff --git a/lib/core/common.py b/lib/core/common.py index 7adbffed0..318d4b07e 100644 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -72,6 +72,7 @@ from lib.core.enums import EXPECTED from lib.core.enums import HEURISTIC_TEST from lib.core.enums import HTTP_HEADER from lib.core.enums import HTTPMETHOD +from lib.core.enums import MKSTEMP_PREFIX from lib.core.enums import OS from lib.core.enums import PLACE from lib.core.enums import PAYLOAD @@ -3976,7 +3977,7 @@ def resetCookieJar(cookieJar): content = readCachedFileContent(conf.loadCookies) lines = filter(None, (line.strip() for line in content.split("\n") if not line.startswith('#'))) - handle, filename = tempfile.mkstemp(prefix="sqlmapcj-") + handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.COOKIE_JAR) os.close(handle) # Reference: http://www.hashbangcode.com/blog/netscape-http-cooke-file-parser-php-584.html diff --git a/lib/core/enums.py b/lib/core/enums.py index a07192ac6..0a879d54b 100644 --- a/lib/core/enums.py +++ b/lib/core/enums.py @@ -355,3 +355,12 @@ class AUTOCOMPLETE_TYPE: class NOTE: FALSE_POSITIVE_OR_UNEXPLOITABLE = "false positive or unexploitable" + +class MKSTEMP_PREFIX: + HASHES = "sqlmaphashes-" + CRAWLER = "sqlmapcrawler-" + IPC = "sqlmapipc-" + TESTING = "sqlmaptesting-" + RESULTS = "sqlmapresults-" + COOKIE_JAR = "sqlmapcookiejar-" + BIG_ARRAY = "sqlmapbigarray-" diff --git a/lib/core/settings.py b/lib/core/settings.py index 048267d99..b3ec50b30 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -19,7 +19,7 @@ from lib.core.enums import OS from lib.core.revision import getRevisionNumber # sqlmap version (...) -VERSION = "1.0.5.124" +VERSION = "1.0.5.125" REVISION = getRevisionNumber() STABLE = VERSION.count('.') <= 2 VERSION_STRING = "sqlmap/%s#%s" % (VERSION, "stable" if STABLE else "dev") diff --git a/lib/core/target.py b/lib/core/target.py index 7254ad91c..de0f12084 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -35,6 +35,7 @@ from lib.core.dump import dumper from lib.core.enums import HASHDB_KEYS from lib.core.enums import HTTP_HEADER from lib.core.enums import HTTPMETHOD +from lib.core.enums import MKSTEMP_PREFIX from lib.core.enums import PLACE from lib.core.enums import POST_HINT from lib.core.exception import SqlmapFilePathException @@ -531,7 +532,7 @@ def _setResultsFile(): except (OSError, IOError), ex: try: warnMsg = "unable to create results file '%s' ('%s'). " % (conf.resultsFilename, getUnicode(ex)) - conf.resultsFilename = tempfile.mkstemp(prefix="sqlmapresults-", suffix=".csv")[1] + conf.resultsFilename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.RESULTS, suffix=".csv")[1] conf.resultsFP = openFile(conf.resultsFilename, "w+", UNICODE_ENCODING, buffering=0) warnMsg += "Using temporary file '%s' instead" % conf.resultsFilename logger.warn(warnMsg) diff --git a/lib/core/testing.py b/lib/core/testing.py index bef223513..6dec0e4c6 100644 --- a/lib/core/testing.py +++ b/lib/core/testing.py @@ -25,6 +25,7 @@ from lib.core.common import readXmlFile from lib.core.data import conf from lib.core.data import logger from lib.core.data import paths +from lib.core.enums import MKSTEMP_PREFIX from lib.core.exception import SqlmapBaseException from lib.core.exception import SqlmapNotVulnerableException from lib.core.log import LOGGER_HANDLER @@ -235,7 +236,7 @@ def initCase(switches, count): Failures.failedParseOn = None Failures.failedTraceBack = None - paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp(prefix="sqlmaptest-%d-" % count) + paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp(prefix="%s%d-" % (MKSTEMP_PREFIX.TESTING, count)) paths.SQLMAP_DUMP_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "dump") paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files") diff --git a/lib/utils/api.py b/lib/utils/api.py index 69a3efdf6..3e1b11058 100644 --- a/lib/utils/api.py +++ b/lib/utils/api.py @@ -31,6 +31,7 @@ from lib.core.data import logger from lib.core.datatype import AttribDict from lib.core.defaults import _defaults from lib.core.enums import CONTENT_STATUS +from lib.core.enums import MKSTEMP_PREFIX from lib.core.enums import PART_RUN_CONTENT_TYPES from lib.core.exception import SqlmapConnectionException from lib.core.log import LOGGER_HANDLER @@ -643,7 +644,7 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, adapter=REST REST-JSON API server """ DataStore.admin_id = hexencode(os.urandom(16)) - Database.filepath = tempfile.mkstemp(prefix="sqlmapipc-", text=False)[1] + Database.filepath = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.IPC, text=False)[1] logger.info("Running REST-JSON API server at '%s:%d'.." % (host, port)) logger.info("Admin ID: %s" % DataStore.admin_id) diff --git a/lib/utils/crawler.py b/lib/utils/crawler.py index 7241be724..67d80fa89 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -22,6 +22,7 @@ from lib.core.common import safeCSValue from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger +from lib.core.enums import MKSTEMP_PREFIX from lib.core.exception import SqlmapConnectionException from lib.core.exception import SqlmapSyntaxException from lib.core.settings import CRAWL_EXCLUDE_EXTENSIONS @@ -198,7 +199,7 @@ def storeResultsToFile(results): kb.storeCrawlingChoice = test[0] in ("y", "Y") if kb.storeCrawlingChoice: - handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt") + handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.CRAWLER, suffix=".csv" if conf.forms else ".txt") os.close(handle) infoMsg = "writing crawling results to a temporary file '%s' " % filename diff --git a/lib/utils/hash.py b/lib/utils/hash.py index 95831b235..98809d863 100644 --- a/lib/utils/hash.py +++ b/lib/utils/hash.py @@ -62,6 +62,7 @@ from lib.core.data import kb from lib.core.data import logger from lib.core.enums import DBMS from lib.core.enums import HASH +from lib.core.enums import MKSTEMP_PREFIX from lib.core.exception import SqlmapDataException from lib.core.exception import SqlmapUserQuitException from lib.core.settings import COMMON_PASSWORD_SUFFIXES @@ -387,7 +388,7 @@ def storeHashesToFile(attack_dict): if not kb.storeHashesChoice: return - handle, filename = tempfile.mkstemp(prefix="sqlmaphashes-", suffix=".txt") + handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.HASHES, suffix=".txt") os.close(handle) infoMsg = "writing hashes to a temporary file '%s' " % filename