Skip to content

Commit 85def6a

Browse files
committed
Adding new option --results-file (thank you Hyundai)
1 parent fdfcbb9 commit 85def6a

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

lib/controller/controller.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def _saveToResultsFile():
263263

264264
conf.resultsFP.flush()
265265
except IOError as ex:
266-
errMsg = "unable to write to the results file '%s' ('%s'). " % (conf.resultsFilename, getSafeExString(ex))
266+
errMsg = "unable to write to the results file '%s' ('%s'). " % (conf.resultsFile, getSafeExString(ex))
267267
raise SqlmapSystemException(errMsg)
268268

269269
@stackedmethod
@@ -738,9 +738,9 @@ def start():
738738
logger.info("fetched data logged to text files under '%s'" % conf.outputPath)
739739

740740
if conf.multipleTargets:
741-
if conf.resultsFilename:
741+
if conf.resultsFile:
742742
infoMsg = "you can find results of scanning in multiple targets "
743-
infoMsg += "mode inside the CSV file '%s'" % conf.resultsFilename
743+
infoMsg += "mode inside the CSV file '%s'" % conf.resultsFile
744744
logger.info(infoMsg)
745745

746746
return True

lib/core/option.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,6 @@ def _setConfAttributes():
18331833
conf.path = None
18341834
conf.port = None
18351835
conf.proxyList = None
1836-
conf.resultsFilename = None
18371836
conf.resultsFP = None
18381837
conf.scheme = None
18391838
conf.tests = []

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@
238238
"listTampers": "boolean",
239239
"offline": "boolean",
240240
"purge": "boolean",
241+
"resultsFile": "string",
241242
"tmpDir": "string",
242243
"unstable": "boolean",
243244
"updateAll": "boolean",

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

2020
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
21-
VERSION = "1.3.10.41"
21+
VERSION = "1.3.11.0"
2222
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2323
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2424
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

lib/core/target.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -561,16 +561,18 @@ def _setResultsFile():
561561
return
562562

563563
if not conf.resultsFP:
564-
conf.resultsFilename = os.path.join(paths.SQLMAP_OUTPUT_PATH, time.strftime(RESULTS_FILE_FORMAT).lower())
564+
conf.resultsFile = conf.resultsFile or os.path.join(paths.SQLMAP_OUTPUT_PATH, time.strftime(RESULTS_FILE_FORMAT).lower())
565+
found = os.path.exists(conf.resultsFile)
566+
565567
try:
566-
conf.resultsFP = openFile(conf.resultsFilename, "a", UNICODE_ENCODING, buffering=0)
568+
conf.resultsFP = openFile(conf.resultsFile, "a", UNICODE_ENCODING, buffering=0)
567569
except (OSError, IOError) as ex:
568570
try:
569-
warnMsg = "unable to create results file '%s' ('%s'). " % (conf.resultsFilename, getUnicode(ex))
570-
handle, conf.resultsFilename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.RESULTS, suffix=".csv")
571+
warnMsg = "unable to create results file '%s' ('%s'). " % (conf.resultsFile, getUnicode(ex))
572+
handle, conf.resultsFile = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.RESULTS, suffix=".csv")
571573
os.close(handle)
572-
conf.resultsFP = openFile(conf.resultsFilename, "w+", UNICODE_ENCODING, buffering=0)
573-
warnMsg += "Using temporary file '%s' instead" % conf.resultsFilename
574+
conf.resultsFP = openFile(conf.resultsFile, "w+", UNICODE_ENCODING, buffering=0)
575+
warnMsg += "Using temporary file '%s' instead" % conf.resultsFile
574576
logger.warn(warnMsg)
575577
except IOError as _:
576578
errMsg = "unable to write to the temporary directory ('%s'). " % _
@@ -579,9 +581,10 @@ def _setResultsFile():
579581
errMsg += "create temporary files and/or directories"
580582
raise SqlmapSystemException(errMsg)
581583

582-
conf.resultsFP.writelines("Target URL,Place,Parameter,Technique(s),Note(s)%s" % os.linesep)
584+
if not found:
585+
conf.resultsFP.writelines("Target URL,Place,Parameter,Technique(s),Note(s)%s" % os.linesep)
583586

584-
logger.info("using '%s' as the CSV results file in multiple targets mode" % conf.resultsFilename)
587+
logger.info("using '%s' as the CSV results file in multiple targets mode" % conf.resultsFile)
585588

586589
def _createFilesDir():
587590
"""

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,9 @@ def cmdLineParser(argv=None):
728728
miscellaneous.add_argument("--purge", dest="purge", action="store_true",
729729
help="Safely remove all content from sqlmap data directory")
730730

731+
miscellaneous.add_argument("--results-file", dest="resultsFile",
732+
help="Location of CSV results file in multiple targets mode")
733+
731734
miscellaneous.add_argument("--sqlmap-shell", dest="sqlmapShell", action="store_true",
732735
help="Prompt for an interactive sqlmap shell")
733736

sqlmap.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,9 @@ listTampers = False
822822
# Valid: True or False
823823
offline = False
824824

825+
# Location of CSV results file in multiple targets mode.
826+
resultsFile =
827+
825828
# Local directory for storing temporary files.
826829
tmpDir =
827830

0 commit comments

Comments
 (0)