From 3af15327000495a2634ef1a8ee93d0968d447419 Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Tue, 3 Jul 2012 12:09:18 +0200 Subject: [PATCH] Implementation for Issue #54 --- lib/core/settings.py | 34 ++++++++++++++++++++++++++++++++++ lib/parse/cmdline.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/lib/core/settings.py b/lib/core/settings.py index a9a53f9e2..dfc818b41 100644 --- a/lib/core/settings.py +++ b/lib/core/settings.py @@ -247,6 +247,40 @@ SQL_STATEMENTS = { "rollback ", ), } +# items displayed in basic help (-h) output +BASIC_HELP_ITEMS = ( + "url", + "googleDork", + "data", + "cookie", + "randomAgent", + "proxy", + "testParameter", + "dbms", + "level", + "risk", + "tech", + "getBanner", + "getCurrentUser", + "getCurrentDb", + "getPasswordHashes", + "getTables", + "getColumns", + "getSchema", + "dumpTable", + "dumpAll", + "db", + "tbl", + "col", + "osShell", + "osPwn", + "batch", + "checkTor", + "flushSession", + "tor", + "wizard" + ) + # string representation for NULL value NULL = "NULL" diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index ac356bd5e..89781785a 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -16,6 +16,7 @@ from lib.core.common import expandMnemonics from lib.core.common import getUnicode from lib.core.data import logger from lib.core.defaults import defaults +from lib.core.settings import BASIC_HELP_ITEMS from lib.core.settings import IS_WIN from lib.core.settings import VERSION_STRING @@ -30,6 +31,10 @@ def cmdLineParser(): parser = OptionParser(usage=usage, version=VERSION_STRING) try: + parser.add_option("--hh", dest="advancedHelp", + action="store_true", + help="Show advanced help") + parser.add_option("-v", dest="verbose", type="int", help="Verbosity level: 0-6 (default %d)" % defaults.verbose) @@ -666,22 +671,42 @@ def cmdLineParser(): parser.add_option_group(general) parser.add_option_group(miscellaneous) + # Dirty hack for making a short option -hh + _ = parser.get_option("--hh") + _._short_opts = ["-hh"] + _._long_opts = [] + args = [] for arg in sys.argv: args.append(getUnicode(arg, system=True)) + # Hide non-basic options in basic help case + for i in xrange(len(sys.argv)): + if sys.argv[i] == '-hh': + sys.argv[i] = '-h' + elif sys.argv[i] == '-h': + for group in parser.option_groups[:]: + found = False + for option in group.option_list: + if option.dest not in BASIC_HELP_ITEMS: + option.help = SUPPRESS_HELP + else: + found = True + if not found: + parser.option_groups.remove(group) + (args, _) = parser.parse_args(args) - for i in xrange(len(sys.argv)-1): + # Expand given mnemonic options (e.g. -z "ign,flu,bat") + for i in xrange(len(sys.argv) - 1): if sys.argv[i] == '-z': expandMnemonics(sys.argv[i+1], parser, args) - break if not any((args.direct, args.url, args.logFile, args.bulkFile, args.googleDork, args.configFile, \ args.requestFile, args.updateAll, args.smokeTest, args.liveTest, args.realTest, args.wizard, args.dependencies, args.purgeOutput)): errMsg = "missing a mandatory option (-d, -u, -l, -m, -r, -g, -c, --wizard, --update, --purge-output or --dependencies), " - errMsg += "use -h for help" + errMsg += "use -h for basic help and -hh for advanced help" parser.error(errMsg) return args