diff --git a/lib/core/common.py b/lib/core/common.py index 08e6cc46e..91029490b 100755 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -3285,7 +3285,7 @@ def expandMnemonics(mnemonics, parser, args): pointer = pointer.next[char] pointer.current.append(option) - for mnemonic in mnemonics.split(','): + for mnemonic in (mnemonics or "").split(','): found = None name = mnemonic.split('=')[0].replace("-", "").strip() value = mnemonic.split('=')[1] if len(mnemonic.split('=')) > 1 else None diff --git a/lib/core/option.py b/lib/core/option.py index db7cb8c44..7097b9ac6 100644 --- a/lib/core/option.py +++ b/lib/core/option.py @@ -1339,6 +1339,9 @@ def _setHTTPExtraHeaders(): conf.headers = conf.headers.split("\n") if "\n" in conf.headers else conf.headers.split("\\n") for headerValue in conf.headers: + if not headerValue.strip(): + continue + if headerValue.count(':') >= 1: header, value = (_.lstrip() for _ in headerValue.split(":", 1)) diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index c2933ad1a..a374b4fa5 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -114,7 +114,7 @@ def cmdLineParser(): action="store_true", help="Ignore Set-Cookie header from response") - request.add_option("-H", "--user-agent", dest="agent", + request.add_option("--user-agent", dest="agent", help="HTTP User-Agent header value") request.add_option("--random-agent", dest="randomAgent", @@ -127,6 +127,9 @@ def cmdLineParser(): request.add_option("--referer", dest="referer", help="HTTP Referer header value") + request.add_option("-H", "--header", dest="header", + help="Extra header (e.g. \"X-Forwarded-For: 127.0.0.1\")") + request.add_option("--headers", dest="headers", help="Extra headers (e.g. \"Accept-Language: fr\\nETag: 123\")") @@ -799,6 +802,7 @@ def cmdLineParser(): argv = [] prompt = False advancedHelp = True + extraHeaders = [] for arg in sys.argv: argv.append(getUnicode(arg, encoding=sys.getfilesystemencoding())) @@ -860,6 +864,9 @@ def cmdLineParser(): for i in xrange(len(argv)): if argv[i] == "-hh": argv[i] = "-h" + elif argv[i] == "-H": + if i + 1 < len(argv): + extraHeaders.append(argv[i + 1]) elif re.match(r"\A\d+!\Z", argv[i]) and argv[max(0, i - 1)] == "--threads" or re.match(r"\A--threads.+\d+!\Z", argv[i]): argv[i] = argv[i][:-1] conf.skipThreadCheck = True @@ -888,6 +895,12 @@ def cmdLineParser(): print "\n[!] to see full list of options run with '-hh'" raise + if extraHeaders: + if not args.headers: + args.headers = "" + delimiter = "\\n" if "\\n" in args.headers else "\n" + args.headers += delimiter + delimiter.join(extraHeaders) + # Expand given mnemonic options (e.g. -z "ign,flu,bat") for i in xrange(len(argv) - 1): if argv[i] == "-z":