Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 74d2b60

Browse files
committed
Minor colorization of WAF Detectify
1 parent 9e892e9 commit 74d2b60

4 files changed

Lines changed: 25 additions & 14 deletions

File tree

extra/wafdetectify/wafdetectify.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@
1919

2020
sys.dont_write_bytecode = True
2121

22-
NAME, VERSION, AUTHOR = "WAF Detectify", "0.1", "Miroslav Stampar (@stamparm)"
22+
NAME, VERSION, AUTHOR = "WAF Detectify", "0.1", "sqlmap developers (@sqlmap)"
2323
TIMEOUT = 10
2424
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"}
2525
SQLMAP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
2626
SCRIPTS_DIR = os.path.join(SQLMAP_DIR, "waf")
27+
LEVEL_COLORS = {"o": "\033[00;94m", "x": "\033[00;91m", "!": "\033[00;93m", "i": "\033[00;92m"}
2728
CACHE = {}
2829
WAF_FUNCTIONS = []
2930

@@ -41,7 +42,9 @@ def get_page(get=None, url=None, host=None, data=None):
4142

4243
try:
4344
req = urllib2.Request("".join(url[_].replace(' ', "%20") if _ > url.find('?') else url[_] for _ in xrange(len(url))), data, HEADERS)
44-
page = urllib2.urlopen(req, timeout=TIMEOUT).read()
45+
conn = urllib2.urlopen(req, timeout=TIMEOUT)
46+
page = conn.read()
47+
headers = conn.info()
4548
except Exception, ex:
4649
code = getattr(ex, "code", None)
4750
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):
5053

5154
return result
5255

56+
def colorize(message):
57+
if not subprocess.mswindows:
58+
message = re.sub(r"\[(.)\]", lambda match: "[%s%s\033[00;49m]" % (LEVEL_COLORS[match.group(1)], match.group(1)), message)
59+
message = message.replace("@sqlmap", "\033[00;96m@sqlmap\033[00;49m")
60+
message = message.replace(NAME, "\033[00;93m%s\033[00;49m" % NAME)
61+
62+
return message
63+
5364
def main():
5465
global WAF_FUNCTIONS
5566

56-
print "%s #v%s\n by: %s\n" % (NAME, VERSION, AUTHOR)
67+
print colorize("%s #v%s\n by: %s\n" % (NAME, VERSION, AUTHOR))
5768

5869
if len(sys.argv) < 2:
59-
exit("[x] usage: python %s <hostname>" % os.path.split(__file__)[-1])
70+
exit(colorize("[x] usage: python %s <hostname>" % os.path.split(__file__)[-1]))
6071

6172
cookie_jar = cookielib.CookieJar()
6273
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
@@ -79,29 +90,29 @@ def main():
7990
del sys.modules[filename[:-3]]
8091
module = __import__(filename[:-3].encode(sys.getfilesystemencoding() or "utf8"))
8192
except ImportError, msg:
82-
exit("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], msg))
93+
exit(colorize("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], msg)))
8394

8495
_ = dict(inspect.getmembers(module))
8596
if "detect" not in _:
86-
exit("[x] missing function 'detect(get_page)' in WAF script '%s'" % found)
97+
exit(colorize("[x] missing function 'detect(get_page)' in WAF script '%s'" % found))
8798
else:
8899
WAF_FUNCTIONS.append((_["detect"], _.get("__product__", filename[:-3])))
89100

90101
WAF_FUNCTIONS = sorted(WAF_FUNCTIONS, key=lambda _: "generic" in _[1].lower())
91102

92-
print "[i] %d (sqlmap's) WAF scripts loaded" % len(WAF_FUNCTIONS)
103+
print colorize("[i] %d WAF scripts loaded" % len(WAF_FUNCTIONS))
93104

94105
found = False
95106
for function, product in WAF_FUNCTIONS:
96107
if found and "unknown" in product.lower():
97108
continue
98109

99110
if function(get_page):
100-
print "[!] WAF/IPS/IDS identified as '%s'" % product
111+
print colorize("[!] WAF/IPS/IDS identified as '%s'" % product)
101112
found = True
102113

103114
if not found:
104-
print "[o] nothing found"
115+
print colorize("[o] nothing found")
105116

106117
if __name__ == "__main__":
107118
main()

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from lib.core.enums import OS
2020

2121
# sqlmap version (<major>.<minor>.<month>.<monthly commit>)
22-
VERSION = "1.2.8.24"
22+
VERSION = "1.2.8.25"
2323
TYPE = "dev" if VERSION.count('.') > 2 and VERSION.split('.')[-1] != '0' else "stable"
2424
TYPE_COLORS = {"dev": 33, "stable": 90, "pip": 34}
2525
VERSION_STRING = "sqlmap/%s#%s" % ('.'.join(VERSION.split('.')[:-1]) if VERSION.count('.') > 2 and VERSION.split('.')[-1] == '0' else VERSION, TYPE)

txt/checksum.md5

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ e4805169a081b834ca51a60a150c7247 extra/shutils/newlines.py
2222
1e5532ede194ac9c083891c2f02bca93 extra/sqlharvest/__init__.py
2323
b3e60ea4e18a65c48515d04aab28ff68 extra/sqlharvest/sqlharvest.py
2424
1e5532ede194ac9c083891c2f02bca93 extra/wafdetectify/__init__.py
25-
cf646f49087ff56d752dc831d2245a51 extra/wafdetectify/wafdetectify.py
25+
85ca5478dc2bd9db40772e52dad2f84a extra/wafdetectify/wafdetectify.py
2626
3459c562a6abb9b4bdcc36925f751f3e lib/controller/action.py
2727
7493c782345a60f6c00c9281d51a494e lib/controller/checks.py
2828
c414cecdb0472c92cf50ed5b01e4438c lib/controller/controller.py
@@ -50,7 +50,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
5050
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
5151
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5252
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
53-
4ecbe8858ce030877cb3e00f437ac87a lib/core/settings.py
53+
13758369fddb4d7e791e989966908ee6 lib/core/settings.py
5454
dd68a9d02fccb4fa1428b20e15b0db5d lib/core/shell.py
5555
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5656
815d1cf27f0f8738d81531e73149867d lib/core/target.py
@@ -415,7 +415,7 @@ aade02eb8f6a4a214a53db0fd0f2aae6 waf/dosarrest.py
415415
7ec3f2a90914b501100685aa66aadf02 waf/edgecast.py
416416
954bebd4a246d8b88794de00ccaecd3b waf/expressionengine.py
417417
a2ce6cde682f78e1fd561dc40611877e waf/fortiweb.py
418-
eb56ac34775cc3c5f721ec967d04b283 waf/generic.py
418+
ade1299c435db7b9e35cf1166ed9d859 waf/generic.py
419419
1c70655551b8296ceeb19292a342e620 waf/hyperguard.py
420420
51aed66945f95641cb45c840e7132e3b waf/incapsula.py
421421
1e5532ede194ac9c083891c2f02bca93 waf/__init__.py

waf/generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def detect(get_page):
2626

2727
if code >= 400 or (IDS_WAF_CHECK_PAYLOAD in vector and (code is None or re.search(GENERIC_PROTECTION_REGEX, page or "") and not re.search(GENERIC_PROTECTION_REGEX, original or ""))):
2828
if code is not None:
29-
kb.wafSpecificResponse = "HTTP/1.1 %s\n%s\n%s" % (code, "".join(_ for _ in headers.headers or [] if not _.startswith("URI")), page)
29+
kb.wafSpecificResponse = "HTTP/1.1 %s\n%s\n%s" % (code, "".join(_ for _ in (headers.headers if headers else {}) or [] if not _.startswith("URI")), page)
3030

3131
retval = True
3232
break

0 commit comments

Comments
 (0)