text stringlengths 1 93.6k |
|---|
def colorize(message):
|
if COLORIZE:
|
message = re.sub(r"\[(.)\]", lambda match: "[%s%s\033[00;49m]" % (LEVEL_COLORS[match.group(1)], match.group(1)), message)
|
if any(_ in message for _ in ("rejected summary", "challenge detected")):
|
for match in re.finditer(r"[^\w]'([^)]+)'" if "rejected summary" in message else r"\('(.+)'\)", message):
|
message = message.replace("'%s'" % match.group(1), "'\033[37m%s\033[00;49m'" % match.group(1), 1)
|
else:
|
for match in re.finditer(r"[^\w]'([^']+)'", message):
|
message = message.replace("'%s'" % match.group(1), "'\033[37m%s\033[00;49m'" % match.group(1), 1)
|
if "blind match" in message:
|
for match in re.finditer(r"\(((\d+)%)\)", message):
|
message = message.replace(match.group(1), "\033[%dm%s\033[00;49m" % (92 if int(match.group(2)) >= 95 else (93 if int(match.group(2)) > 80 else 90), match.group(1)))
|
if "hardness" in message:
|
for match in re.finditer(r"\(((\d+)%)\)", message):
|
message = message.replace(match.group(1), "\033[%dm%s\033[00;49m" % (95 if " insane " in message else (91 if " hard " in message else (93 if " moderate " in message else 92)), match.group(1)))
|
return message
|
def parse_args():
|
global options
|
parser = optparse.OptionParser(version=VERSION)
|
parser.add_option("--delay", dest="delay", type=int, help="Delay (sec) between tests (default: 0)")
|
parser.add_option("--timeout", dest="timeout", type=int, help="Response timeout (sec) (default: 10)")
|
parser.add_option("--proxy", dest="proxy", help="HTTP proxy address (e.g. \"http://127.0.0.1:8080\")")
|
parser.add_option("--proxy-file", dest="proxy_file", help="Load (rotating) HTTP(s) proxy list from a file")
|
parser.add_option("--random-agent", dest="random_agent", action="store_true", help="Use random HTTP User-Agent header value")
|
parser.add_option("--code", dest="code", type=int, help="Expected HTTP code in rejected responses")
|
parser.add_option("--string", dest="string", help="Expected string in rejected responses")
|
parser.add_option("--post", dest="post", action="store_true", help="Use POST body for sending payloads")
|
parser.add_option("--debug", dest="debug", action="store_true", help=optparse.SUPPRESS_HELP)
|
parser.add_option("--fast", dest="fast", action="store_true", help=optparse.SUPPRESS_HELP)
|
parser.add_option("--lock", dest="lock", action="store_true", help=optparse.SUPPRESS_HELP)
|
# Dirty hack(s) for help message
|
def _(self, *args):
|
retval = parser.formatter._format_option_strings(*args)
|
if len(retval) > MAX_HELP_OPTION_LENGTH:
|
retval = ("%%.%ds.." % (MAX_HELP_OPTION_LENGTH - parser.formatter.indent_increment)) % retval
|
return retval
|
parser.usage = "python %s <host|url>" % parser.usage
|
parser.formatter._format_option_strings = parser.formatter.format_option_strings
|
parser.formatter.format_option_strings = type(parser.formatter.format_option_strings)(_, parser)
|
for _ in ("-h", "--version"):
|
option = parser.get_option(_)
|
option.help = option.help.capitalize()
|
try:
|
options, _ = parser.parse_args()
|
except SystemExit:
|
raise
|
if len(sys.argv) > 1:
|
url = sys.argv[-1]
|
if not url.startswith("http"):
|
url = "http://%s" % url
|
options.url = url
|
else:
|
parser.print_help()
|
raise SystemExit
|
for key in DEFAULTS:
|
if getattr(options, key, None) is None:
|
setattr(options, key, DEFAULTS[key])
|
def load_data():
|
global WAF_RECOGNITION_REGEX
|
if os.path.isfile(DATA_JSON_FILE):
|
with codecs.open(DATA_JSON_FILE, "rb", encoding="utf8") as f:
|
DATA_JSON.update(json.load(f))
|
WAF_RECOGNITION_REGEX = ""
|
for waf in DATA_JSON["wafs"]:
|
if DATA_JSON["wafs"][waf]["regex"]:
|
WAF_RECOGNITION_REGEX += "%s|" % ("(?P<waf_%s>%s)" % (waf, DATA_JSON["wafs"][waf]["regex"]))
|
for signature in DATA_JSON["wafs"][waf]["signatures"]:
|
SIGNATURES[signature] = waf
|
WAF_RECOGNITION_REGEX = WAF_RECOGNITION_REGEX.strip('|')
|
flags = "".join(set(_ for _ in "".join(re.findall(r"\(\?(\w+)\)", WAF_RECOGNITION_REGEX))))
|
WAF_RECOGNITION_REGEX = "(?%s)%s" % (flags, re.sub(r"\(\?\w+\)", "", WAF_RECOGNITION_REGEX)) # patch for "DeprecationWarning: Flags not at the start of the expression" in Python3.7
|
else:
|
exit(colorize("[x] file '%s' is missing" % DATA_JSON_FILE))
|
def init():
|
os.chdir(os.path.abspath(os.path.dirname(__file__)))
|
# Reference: http://blog.mathieu-leplatre.info/python-utf-8-print-fails-when-redirecting-stdout.html
|
if not PY3 and not IS_TTY:
|
sys.stdout = codecs.getwriter(locale.getpreferredencoding())(sys.stdout)
|
print(colorize("[o] initializing handlers..."))
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.