Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # mark options that require arguments with :, and options that can optionally take arguments with ?
- short_opts = "hHS?A?c:d:npliP:b:B:t:U:L:I:"
- long_opts = [
- "help",
- "header",
- "scanhelp?",
- "attackhelp?",
- "conc:",
- "delay:",
- "nonhtml",
- "php",
- "listable",
- "ignored",
- "proxy:",
- "low_bound:",
- "high_bound:",
- "timeout:",
- "user-agents:",
- "listable_dict:",
- "ignore_dict:"
- ]
- # the below is a complicated procedure for mapping all passed args into positional args and
- # option value pairs. you do not need to change it to add additional options or modify
- # how options are handled once mapped, so DON'T fuck with it unless you know what you're
- # doing or you will break it. if you just want to add more options, add them in the two
- # variables short_opts and long_opts defined above. to change what happens with args once
- # they're mapped, go to the next block down.
- positional_args = []
- option_value_pairs = []
- mapped_flag = False # used to avoid handling args that were handled already by being passed to previous arg
- def get_passed(pos): # used to look for an arg that's been passed to an option
- passed = None
- if pos + 1 != len(args) and args[pos + 1][0] != "-":
- passed = args[pos + 1]
- return passed
- for argpos, arg in enumerate(args):
- # if mapped flag is on, arg was handled already and all we need to do is reset the flag
- if mapped_flag:
- mapped_flag = False
- # if arg is flagged handle as optional
- elif arg[0] == '-':
- # if arg flagged, we need to look for a matching option in short opts and long opts
- # short opts may be passed in clusters, so valid options is created as a list
- options = []
- # if long
- if arg[:2] == '--':
- for l in long_opts:
- if arg[2:] == l.replace(":","").replace("?",""):
- options.append(l)
- if len(options) == 0:
- print("Invalid option: '%s'" % arg[2:])
- usage()
- # if short
- else:
- for a in arg[1:]:
- if a in short_opts:
- i = short_opts.index(a)
- if i + 1 != len(short_opts) and short_opts[i + 1] in ":?":
- options.append(a + short_opts[i + 1])
- else:
- options.append(a)
- else:
- print("Invalid option: '%s'" % a)
- usage()
- # if we found valid options, procceed. If invalid options were found, we've already called usage()
- for o in options:
- # if option may take argument, look for one to overwrite the None value
- value = None
- if o[-1] in ":?":
- v = get_passed(argpos)
- if v == None:
- if o[-1] == ":":
- print("Option '%s' requires an argument" % o.replace(":",""))
- usage()
- else:
- mapped_flag = True
- # now create the option value pairs
- if arg[:2] == "--":
- option_value_pairs.append([arg, value])
- else:
- option_value_pairs.append(["-" + o[0], value])
- # if not mapped and not option, append to positional args
- else:
- positional_args.append(arg)
- # now we can handle our positional args and option/value pairs
- if ("-h", "") in option_value_pairs or ("--help", "") in option_value_pairs:
- usage()
- runtime_configs = default_configs
- try:
- for opt, arg in option_value_pairs:
- if opt in ["-H", "--header"]:
- runtime_configs["header"] = not runtime_configs["header"]
- elif opt in ["-c", "--conc"]:
- runtime_configs["concurrent"] = int(arg)
- elif opt in ["-d", "--delay"]:
- runtime_configs["delay"] = int(arg)
- elif opt in ["-n", "--nonhtml"]:
- runtime_configs["scan_nonhtml"] = not runtime_configs["scan_nonhtml"]
- elif opt in ["-p", "--php"]:
- runtime_configs["scan_php"] = not runtime_configs["scan_php"]
- elif opt in ["-l", "--listable"]:
- runtime_configs["scan_listable"] = not runtime_configs["scan_listable"]
- elif opt in ["-i", "--ignored"]:
- runtime_configs["scan_ignored"] = not runtime_configs["scan_ignored"]
- elif opt in ["-P", "--proxy"]:
- runtime_configs["proxy"] = arg
- elif opt in ["-b", "--lower_bound"]:
- runtime_configs["lower_status_code_bound"] = int(arg)
- elif opt in ["-B", "--upper_bound"]:
- runtime_configs["upper_status_code_bound"] = int(arg)
- elif opt in ["-t", "--timeout"]:
- runtime_configs["timeout"] = int(arg)
- elif opt in ["-U", "--user-agents"]:
- runtime_configs["user-agents"] = arg
- elif opt in ["-L", "--listable_dict"]:
- runtime_configs["listable_dict"] = arg
- elif opt in ["-I", "--ignore_dict"]:
- runtime_configs["ignore_dict"] = arg
- else:
- print("warning: unhandled option %s" % opt)
- except ValueError:
- print("option %s requires an integer\n" % opt)
- usage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement