From 2bf22df53aad1f25486bbca3a7289cc6845b11d1 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Wed, 14 Oct 2020 11:34:52 +0200 Subject: [PATCH] Implementing support for piped input of targets --- lib/controller/controller.py | 2 +- lib/core/option.py | 49 +++++++++++++++++++++++------------- lib/core/settings.py | 2 +- lib/parse/cmdline.py | 3 +++ 4 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/controller/controller.py b/lib/controller/controller.py index 608d9df54..4fe4e2d71 100644 --- a/lib/controller/controller.py +++ b/lib/controller/controller.py @@ -291,7 +291,7 @@ def start(): logger.error(errMsg) return False - if kb.targets and len(kb.targets) > 1: + if kb.targets and isListLike(kb.targets) and len(kb.targets) > 1: infoMsg = "found a total of %d targets" % len(kb.targets) logger.info(infoMsg) diff --git a/lib/core/option.py b/lib/core/option.py index 7512cb116..147c5138d 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -8,6 +8,7 @@ See the file 'LICENSE' for copying permission from __future__ import division import codecs +import collections import functools import glob import inspect @@ -416,28 +417,39 @@ def _setBulkMultipleTargets(): if not conf.bulkFile: return - conf.bulkFile = safeExpandUser(conf.bulkFile) + if isinstance(conf.bulkFile, collections.Iterable): + def _(): + for line in conf.bulkFile: + if line: + match = re.search(r"\bhttps?://[^\s'\"]+", line, re.I) + if match: + yield (match.group(0), conf.method, conf.data, conf.cookie, None) + else: + break + kb.targets = _() + else: + conf.bulkFile = safeExpandUser(conf.bulkFile) - infoMsg = "parsing multiple targets list from '%s'" % conf.bulkFile - logger.info(infoMsg) + infoMsg = "parsing multiple targets list from '%s'" % conf.bulkFile + logger.info(infoMsg) - if not checkFile(conf.bulkFile, False): - errMsg = "the specified bulk file " - errMsg += "does not exist" - raise SqlmapFilePathException(errMsg) + if not checkFile(conf.bulkFile, False): + errMsg = "the specified bulk file " + errMsg += "does not exist" + raise SqlmapFilePathException(errMsg) - found = False - for line in getFileItems(conf.bulkFile): - if conf.scope and not re.search(conf.scope, line, re.I): - continue + found = False + for line in getFileItems(conf.bulkFile): + if conf.scope and not re.search(conf.scope, line, re.I): + continue - if re.match(r"[^ ]+\?(.+)", line, re.I) or kb.customInjectionMark in line: - found = True - kb.targets.add((line.strip(), conf.method, conf.data, conf.cookie, None)) + if re.match(r"[^ ]+\?(.+)", line, re.I) or kb.customInjectionMark in line: + found = True + kb.targets.add((line.strip(), conf.method, conf.data, conf.cookie, None)) - if not found and not conf.forms and not conf.crawlDepth: - warnMsg = "no usable links found (with GET parameters)" - logger.warn(warnMsg) + if not found and not conf.forms and not conf.crawlDepth: + warnMsg = "no usable links found (with GET parameters)" + logger.warn(warnMsg) def _findPageForms(): if not conf.forms or conf.crawlDepth: @@ -1631,7 +1643,8 @@ def _cleanupOptions(): for key, value in conf.items(): if value and any(key.endswith(_) for _ in ("Path", "File", "Dir")): - conf[key] = safeExpandUser(value) + if isinstance(value, str): + conf[key] = safeExpandUser(value) if conf.testParameter: conf.testParameter = urldecode(conf.testParameter) diff --git a/lib/core/settings.py b/lib/core/settings.py index efe598298..a08f8806b 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -18,7 +18,7 @@ from lib.core.enums import OS from thirdparty.six import unichr as _unichr # sqlmap version (...) -VERSION = "1.4.10.5" +VERSION = "1.4.10.6" TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable" TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34} VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index f6deac160..f96ec0853 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -1035,6 +1035,9 @@ def cmdLineParser(argv=None): if args.dummy: args.url = args.url or DUMMY_URL + if hasattr(sys.stdin, "fileno") and not os.isatty(sys.stdin.fileno()) and '-' not in sys.argv: + args.bulkFile = iter(sys.stdin.readline, None) + if not any((args.direct, args.url, args.logFile, args.bulkFile, args.googleDork, args.configFile, args.requestFile, args.updateAll, args.smokeTest, args.vulnTest, args.bedTest, args.fuzzTest, args.wizard, args.dependencies, args.purge, args.listTampers, args.hashFile)): errMsg = "missing a mandatory option (-d, -u, -l, -m, -r, -g, -c, --list-tampers, --wizard, --update, --purge or --dependencies). " errMsg += "Use -h for basic and -hh for advanced help\n"