From dc3df1b8323a2c6476a90238c9269274f76431ba Mon Sep 17 00:00:00 2001 From: ctshanghai Date: Mon, 3 Aug 2015 21:10:44 +0800 Subject: [PATCH 1/4] Added --crawl-file option Added --crawl-file option to specify the output file for crawler results. --- lib/parse/cmdline.py | 3 +++ lib/utils/crawler.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 154c5d7e3..05fbf99b0 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -610,6 +610,9 @@ def cmdLineParser(): help="Log all HTTP traffic into a " "textual file") + general.add_option("--crawl-file", dest="batchCrawlFile", action="store", + help="Destination file for crawled links") + general.add_option("--batch", dest="batch", action="store_true", help="Never ask for user input, use the default behaviour") diff --git a/lib/utils/crawler.py b/lib/utils/crawler.py index be47608e1..539b53252 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -186,12 +186,14 @@ def storeResultsToFile(results): test = readInput(message, default="N") kb.storeCrawlingChoice = test[0] in ("y", "Y") - if kb.storeCrawlingChoice: - handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt") - os.close(handle) - - infoMsg = "writing crawling results to a temporary file '%s' " % filename - logger.info(infoMsg) + if kb.storeCrawlingChoice or conf.batchCrawlFile: + if conf.batchCrawlFile: + filename = conf.batchCrawlFile + else: + handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt") + os.close(handle) + infoMsg = "writing crawling results to a temporary file '%s' " % filename + logger.info(infoMsg) with openFile(filename, "w+b") as f: if conf.forms: From 1ae29629c802c0da240d3d13d356793862b16366 Mon Sep 17 00:00:00 2001 From: ctshanghai Date: Mon, 3 Aug 2015 21:10:44 +0800 Subject: [PATCH 2/4] Added --crawl-file option Added --crawl-file option to specify the output file for crawler results. --- lib/parse/cmdline.py | 3 +++ lib/utils/crawler.py | 14 ++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 154c5d7e3..05fbf99b0 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -610,6 +610,9 @@ def cmdLineParser(): help="Log all HTTP traffic into a " "textual file") + general.add_option("--crawl-file", dest="batchCrawlFile", action="store", + help="Destination file for crawled links") + general.add_option("--batch", dest="batch", action="store_true", help="Never ask for user input, use the default behaviour") diff --git a/lib/utils/crawler.py b/lib/utils/crawler.py index be47608e1..539b53252 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -186,12 +186,14 @@ def storeResultsToFile(results): test = readInput(message, default="N") kb.storeCrawlingChoice = test[0] in ("y", "Y") - if kb.storeCrawlingChoice: - handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt") - os.close(handle) - - infoMsg = "writing crawling results to a temporary file '%s' " % filename - logger.info(infoMsg) + if kb.storeCrawlingChoice or conf.batchCrawlFile: + if conf.batchCrawlFile: + filename = conf.batchCrawlFile + else: + handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt") + os.close(handle) + infoMsg = "writing crawling results to a temporary file '%s' " % filename + logger.info(infoMsg) with openFile(filename, "w+b") as f: if conf.forms: From 62e02cb730502f852da0d542cffd58220c1a58e0 Mon Sep 17 00:00:00 2001 From: ctshanghai Date: Mon, 3 Aug 2015 21:22:21 +0800 Subject: [PATCH 3/4] Added --crawl-file option Added --crawl-file option to specify the output file for crawler results. --- lib/parse/cmdline.py | 2 +- lib/utils/crawler.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 05fbf99b0..3a218bc21 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -610,7 +610,7 @@ def cmdLineParser(): help="Log all HTTP traffic into a " "textual file") - general.add_option("--crawl-file", dest="batchCrawlFile", action="store", + general.add_option("--crawl-file", dest="crawlFile", action="store", help="Destination file for crawled links") general.add_option("--batch", dest="batch", diff --git a/lib/utils/crawler.py b/lib/utils/crawler.py index 539b53252..c42d25319 100644 --- a/lib/utils/crawler.py +++ b/lib/utils/crawler.py @@ -186,9 +186,9 @@ def storeResultsToFile(results): test = readInput(message, default="N") kb.storeCrawlingChoice = test[0] in ("y", "Y") - if kb.storeCrawlingChoice or conf.batchCrawlFile: - if conf.batchCrawlFile: - filename = conf.batchCrawlFile + if kb.storeCrawlingChoice or conf.crawlFile: + if conf.crawlFile: + filename = conf.crawlFile else: handle, filename = tempfile.mkstemp(prefix="sqlmapcrawling-", suffix=".csv" if conf.forms else ".txt") os.close(handle) From c924582df31d529065ee825c96da08c2304af395 Mon Sep 17 00:00:00 2001 From: ctshanghai Date: Mon, 3 Aug 2015 21:55:07 +0800 Subject: [PATCH 4/4] Added --results-file to control results ouput file Added the ability to explicitly set the results file output name to ease integration with some external tooling. --- lib/core/target.py | 4 +++- lib/parse/cmdline.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/core/target.py b/lib/core/target.py index c1bf921bd..c33c99d65 100644 --- a/lib/core/target.py +++ b/lib/core/target.py @@ -508,7 +508,9 @@ def _setResultsFile(): return if not conf.resultsFP: - conf.resultsFilename = os.path.join(paths.SQLMAP_OUTPUT_PATH, time.strftime(RESULTS_FILE_FORMAT).lower()) + if not len(conf.resultsFilename): + conf.resultsFilename = os.path.join(paths.SQLMAP_OUTPUT_PATH, time.strftime(RESULTS_FILE_FORMAT).lower()) + try: conf.resultsFP = openFile(conf.resultsFilename, "w+", UNICODE_ENCODING, buffering=0) except (OSError, IOError), ex: diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 3a218bc21..28040e785 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -613,6 +613,9 @@ def cmdLineParser(): general.add_option("--crawl-file", dest="crawlFile", action="store", help="Destination file for crawled links") + general.add_option("--results-file", dest="resultsFilename", action="store", + help="Destination file for results in multi-target mode") + general.add_option("--batch", dest="batch", action="store_true", help="Never ask for user input, use the default behaviour")