Minor colorization of WAF Detectify

This commit is contained in:
Miroslav Stampar
2018-08-30 15:18:42 +02:00
parent 9e892e93f3
commit 74d2b60cf3
4 changed files with 25 additions and 14 deletions

View File

@@ -19,11 +19,12 @@ import urlparse
sys.dont_write_bytecode = True
NAME, VERSION, AUTHOR = "WAF Detectify", "0.1", "Miroslav Stampar (@stamparm)"
NAME, VERSION, AUTHOR = "WAF Detectify", "0.1", "sqlmap developers (@sqlmap)"
TIMEOUT = 10
HEADERS = {"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate", "Cache-Control": "max-age=0"}
SQLMAP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
SCRIPTS_DIR = os.path.join(SQLMAP_DIR, "waf")
LEVEL_COLORS = {"o": "\033[00;94m", "x": "\033[00;91m", "!": "\033[00;93m", "i": "\033[00;92m"}
CACHE = {}
WAF_FUNCTIONS = []
@@ -41,7 +42,9 @@ def get_page(get=None, url=None, host=None, data=None):
try:
req = urllib2.Request("".join(url[_].replace(' ', "%20") if _ > url.find('?') else url[_] for _ in xrange(len(url))), data, HEADERS)
page = urllib2.urlopen(req, timeout=TIMEOUT).read()
conn = urllib2.urlopen(req, timeout=TIMEOUT)
page = conn.read()
headers = conn.info()
except Exception, ex:
code = getattr(ex, "code", None)
page = ex.read() if hasattr(ex, "read") else getattr(ex, "msg", "")
@@ -50,13 +53,21 @@ def get_page(get=None, url=None, host=None, data=None):
return result
def colorize(message):
if not subprocess.mswindows:
message = re.sub(r"\[(.)\]", lambda match: "[%s%s\033[00;49m]" % (LEVEL_COLORS[match.group(1)], match.group(1)), message)
message = message.replace("@sqlmap", "\033[00;96m@sqlmap\033[00;49m")
message = message.replace(NAME, "\033[00;93m%s\033[00;49m" % NAME)
return message
def main():
global WAF_FUNCTIONS
print "%s #v%s\n by: %s\n" % (NAME, VERSION, AUTHOR)
print colorize("%s #v%s\n by: %s\n" % (NAME, VERSION, AUTHOR))
if len(sys.argv) < 2:
exit("[x] usage: python %s <hostname>" % os.path.split(__file__)[-1])
exit(colorize("[x] usage: python %s <hostname>" % os.path.split(__file__)[-1]))
cookie_jar = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
@@ -79,17 +90,17 @@ def main():
del sys.modules[filename[:-3]]
module = __import__(filename[:-3].encode(sys.getfilesystemencoding() or "utf8"))
except ImportError, msg:
exit("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], msg))
exit(colorize("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], msg)))
_ = dict(inspect.getmembers(module))
if "detect" not in _:
exit("[x] missing function 'detect(get_page)' in WAF script '%s'" % found)
exit(colorize("[x] missing function 'detect(get_page)' in WAF script '%s'" % found))
else:
WAF_FUNCTIONS.append((_["detect"], _.get("__product__", filename[:-3])))
WAF_FUNCTIONS = sorted(WAF_FUNCTIONS, key=lambda _: "generic" in _[1].lower())
print "[i] %d (sqlmap's) WAF scripts loaded" % len(WAF_FUNCTIONS)
print colorize("[i] %d WAF scripts loaded" % len(WAF_FUNCTIONS))
found = False
for function, product in WAF_FUNCTIONS:
@@ -97,11 +108,11 @@ def main():
continue
if function(get_page):
print "[!] WAF/IPS/IDS identified as '%s'" % product
print colorize("[!] WAF/IPS/IDS identified as '%s'" % product)
found = True
if not found:
print "[o] nothing found"
print colorize("[o] nothing found")
if __name__ == "__main__":
main()