Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 26d4dec

Browse files
committed
Minor refactoring
1 parent cf31d12 commit 26d4dec

9 files changed

Lines changed: 24 additions & 8 deletions

File tree

lib/core/bigarray.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import tempfile
1717

18+
from lib.core.enums import MKSTEMP_PREFIX
1819
from lib.core.exception import SqlmapSystemException
1920
from lib.core.settings import BIGARRAY_CHUNK_SIZE
2021

@@ -91,7 +92,7 @@ def index(self, value):
9192

9293
def _dump(self, chunk):
9394
try:
94-
handle, filename = tempfile.mkstemp()
95+
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.BIG_ARRAY)
9596
self.filenames.add(filename)
9697
os.close(handle)
9798
with open(filename, "w+b") as fp:

lib/core/common.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
from lib.core.enums import HEURISTIC_TEST
7373
from lib.core.enums import HTTP_HEADER
7474
from lib.core.enums import HTTPMETHOD
75+
from lib.core.enums import MKSTEMP_PREFIX
7576
from lib.core.enums import OS
7677
from lib.core.enums import PLACE
7778
from lib.core.enums import PAYLOAD
@@ -3976,7 +3977,7 @@ def resetCookieJar(cookieJar):
39763977

39773978
content = readCachedFileContent(conf.loadCookies)
39783979
lines = filter(None, (line.strip() for line in content.split("\n") if not line.startswith('#')))
3979-
handle, filename = tempfile.mkstemp(prefix="sqlmapcj-")
3980+
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.COOKIE_JAR)
39803981
os.close(handle)
39813982

39823983
# Reference: http://www.hashbangcode.com/blog/netscape-http-cooke-file-parser-php-584.html

lib/core/enums.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,12 @@ class AUTOCOMPLETE_TYPE:
355355

356356
class NOTE:
357357
FALSE_POSITIVE_OR_UNEXPLOITABLE = "false positive or unexploitable"
358+
359+
class MKSTEMP_PREFIX:
360+
HASHES = "sqlmaphashes-"
361+
CRAWLER = "sqlmapcrawler-"
362+
IPC = "sqlmapipc-"
363+
TESTING = "sqlmaptesting-"
364+
RESULTS = "sqlmapresults-"
365+
COOKIE_JAR = "sqlmapcookiejar-"
366+
BIG_ARRAY = "sqlmapbigarray-"

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.revision import getRevisionNumber
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.0.5.124"
22+
VERSION = "1.0.5.125"
2323
REVISION = getRevisionNumber()
2424
STABLE = VERSION.count('.') <= 2
2525
VERSION_STRING = "sqlmap/%s#%s" % (VERSION, "stable" if STABLE else "dev")

lib/core/target.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from lib.core.enums import HASHDB_KEYS
3636
from lib.core.enums import HTTP_HEADER
3737
from lib.core.enums import HTTPMETHOD
38+
from lib.core.enums import MKSTEMP_PREFIX
3839
from lib.core.enums import PLACE
3940
from lib.core.enums import POST_HINT
4041
from lib.core.exception import SqlmapFilePathException
@@ -531,7 +532,7 @@ def _setResultsFile():
531532
except (OSError, IOError), ex:
532533
try:
533534
warnMsg = "unable to create results file '%s' ('%s'). " % (conf.resultsFilename, getUnicode(ex))
534-
conf.resultsFilename = tempfile.mkstemp(prefix="sqlmapresults-", suffix=".csv")[1]
535+
conf.resultsFilename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.RESULTS, suffix=".csv")[1]
535536
conf.resultsFP = openFile(conf.resultsFilename, "w+", UNICODE_ENCODING, buffering=0)
536537
warnMsg += "Using temporary file '%s' instead" % conf.resultsFilename
537538
logger.warn(warnMsg)

lib/core/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from lib.core.data import conf
2626
from lib.core.data import logger
2727
from lib.core.data import paths
28+
from lib.core.enums import MKSTEMP_PREFIX
2829
from lib.core.exception import SqlmapBaseException
2930
from lib.core.exception import SqlmapNotVulnerableException
3031
from lib.core.log import LOGGER_HANDLER
@@ -235,7 +236,7 @@ def initCase(switches, count):
235236
Failures.failedParseOn = None
236237
Failures.failedTraceBack = None
237238

238-
paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp(prefix="sqlmaptest-%d-" % count)
239+
paths.SQLMAP_OUTPUT_PATH = tempfile.mkdtemp(prefix="%s%d-" % (MKSTEMP_PREFIX.TESTING, count))
239240
paths.SQLMAP_DUMP_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "dump")
240241
paths.SQLMAP_FILES_PATH = os.path.join(paths.SQLMAP_OUTPUT_PATH, "%s", "files")
241242

lib/utils/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from lib.core.datatype import AttribDict
3232
from lib.core.defaults import _defaults
3333
from lib.core.enums import CONTENT_STATUS
34+
from lib.core.enums import MKSTEMP_PREFIX
3435
from lib.core.enums import PART_RUN_CONTENT_TYPES
3536
from lib.core.exception import SqlmapConnectionException
3637
from lib.core.log import LOGGER_HANDLER
@@ -643,7 +644,7 @@ def server(host=RESTAPI_DEFAULT_ADDRESS, port=RESTAPI_DEFAULT_PORT, adapter=REST
643644
REST-JSON API server
644645
"""
645646
DataStore.admin_id = hexencode(os.urandom(16))
646-
Database.filepath = tempfile.mkstemp(prefix="sqlmapipc-", text=False)[1]
647+
Database.filepath = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.IPC, text=False)[1]
647648

648649
logger.info("Running REST-JSON API server at '%s:%d'.." % (host, port))
649650
logger.info("Admin ID: %s" % DataStore.admin_id)

lib/utils/crawler.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from lib.core.data import conf
2323
from lib.core.data import kb
2424
from lib.core.data import logger
25+
from lib.core.enums import MKSTEMP_PREFIX
2526
from lib.core.exception import SqlmapConnectionException
2627
from lib.core.exception import SqlmapSyntaxException
2728
from lib.core.settings import CRAWL_EXCLUDE_EXTENSIONS
@@ -198,7 +199,7 @@ def storeResultsToFile(results):
198199
kb.storeCrawlingChoice = test[0] in ("y", "Y")
199200

200201
if kb.storeCrawlingChoice:
201-
handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt")
202+
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.CRAWLER, suffix=".csv" if conf.forms else ".txt")
202203
os.close(handle)
203204

204205
infoMsg = "writing crawling results to a temporary file '%s' " % filename

lib/utils/hash.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from lib.core.data import logger
6363
from lib.core.enums import DBMS
6464
from lib.core.enums import HASH
65+
from lib.core.enums import MKSTEMP_PREFIX
6566
from lib.core.exception import SqlmapDataException
6667
from lib.core.exception import SqlmapUserQuitException
6768
from lib.core.settings import COMMON_PASSWORD_SUFFIXES
@@ -387,7 +388,7 @@ def storeHashesToFile(attack_dict):
387388
if not kb.storeHashesChoice:
388389
return
389390

390-
handle, filename = tempfile.mkstemp(prefix="sqlmaphashes-", suffix=".txt")
391+
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.HASHES, suffix=".txt")
391392
os.close(handle)
392393

393394
infoMsg = "writing hashes to a temporary file '%s' " % filename

0 commit comments

Comments
 (0)