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

Skip to content

Commit afdca09

Browse files
committed
Minor patches (proper user warnings in case of output directory permissions)
1 parent ac89ee7 commit afdca09

2 files changed

Lines changed: 26 additions & 20 deletions

File tree

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.127"
22+
VERSION = "1.0.5.128"
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: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from lib.core.common import normalizeUnicode
2222
from lib.core.common import openFile
2323
from lib.core.common import paramToDict
24+
from lib.core.common import randomStr
2425
from lib.core.common import readInput
2526
from lib.core.common import resetCookieJar
2627
from lib.core.common import urldecode
@@ -604,28 +605,33 @@ def _createTargetDirs():
604605
Create the output directory.
605606
"""
606607

607-
if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH):
608-
try:
609-
if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH):
610-
os.makedirs(paths.SQLMAP_OUTPUT_PATH, 0755)
611-
warnMsg = "using '%s' as the output directory" % paths.SQLMAP_OUTPUT_PATH
612-
logger.warn(warnMsg)
613-
except (OSError, IOError), ex:
614-
try:
615-
tempDir = tempfile.mkdtemp(prefix="sqlmapoutput")
616-
except Exception, _:
617-
errMsg = "unable to write to the temporary directory ('%s'). " % _
618-
errMsg += "Please make sure that your disk is not full and "
619-
errMsg += "that you have sufficient write permissions to "
620-
errMsg += "create temporary files and/or directories"
621-
raise SqlmapSystemException(errMsg)
608+
try:
609+
if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH):
610+
os.makedirs(paths.SQLMAP_OUTPUT_PATH, 0755)
622611

623-
warnMsg = "unable to create regular output directory "
624-
warnMsg += "'%s' (%s). " % (paths.SQLMAP_OUTPUT_PATH, getUnicode(ex))
625-
warnMsg += "Using temporary directory '%s' instead" % getUnicode(tempDir)
612+
_ = os.path.join(paths.SQLMAP_OUTPUT_PATH, randomStr())
613+
open(_, "w+b").close()
614+
os.remove(_)
615+
616+
if conf.outputDir:
617+
warnMsg = "using '%s' as the output directory" % paths.SQLMAP_OUTPUT_PATH
626618
logger.warn(warnMsg)
619+
except (OSError, IOError), ex:
620+
try:
621+
tempDir = tempfile.mkdtemp(prefix="sqlmapoutput")
622+
except Exception, _:
623+
errMsg = "unable to write to the temporary directory ('%s'). " % _
624+
errMsg += "Please make sure that your disk is not full and "
625+
errMsg += "that you have sufficient write permissions to "
626+
errMsg += "create temporary files and/or directories"
627+
raise SqlmapSystemException(errMsg)
628+
629+
warnMsg = "unable to %s output directory " % ("create" if not os.path.isdir(paths.SQLMAP_OUTPUT_PATH) else "write to the")
630+
warnMsg += "'%s' (%s). " % (paths.SQLMAP_OUTPUT_PATH, getUnicode(ex))
631+
warnMsg += "Using temporary directory '%s' instead" % getUnicode(tempDir)
632+
logger.warn(warnMsg)
627633

628-
paths.SQLMAP_OUTPUT_PATH = tempDir
634+
paths.SQLMAP_OUTPUT_PATH = tempDir
629635

630636
conf.outputPath = os.path.join(getUnicode(paths.SQLMAP_OUTPUT_PATH), normalizeUnicode(getUnicode(conf.hostname)))
631637

0 commit comments

Comments
 (0)