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

Skip to content

Commit 9e892e9

Browse files
committed
Created a WAF Detectify utility
1 parent 0bbf5f9 commit 9e892e9

4 files changed

Lines changed: 119 additions & 2 deletions

File tree

extra/wafdetectify/__init__.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)
5+
See the file 'LICENSE' for copying permission
6+
"""
7+
8+
pass

extra/wafdetectify/wafdetectify.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2018 sqlmap developers (http://sqlmap.org/)
5+
See the file 'LICENSE' for copying permission
6+
"""
7+
8+
import cookielib
9+
import glob
10+
import httplib
11+
import inspect
12+
import os
13+
import re
14+
import subprocess
15+
import sys
16+
import urllib
17+
import urllib2
18+
import urlparse
19+
20+
sys.dont_write_bytecode = True
21+
22+
NAME, VERSION, AUTHOR = "WAF Detectify", "0.1", "Miroslav Stampar (@stamparm)"
23+
TIMEOUT = 10
24+
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"}
25+
SQLMAP_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", ".."))
26+
SCRIPTS_DIR = os.path.join(SQLMAP_DIR, "waf")
27+
CACHE = {}
28+
WAF_FUNCTIONS = []
29+
30+
def get_page(get=None, url=None, host=None, data=None):
31+
key = (get, url, host, data)
32+
33+
if key in CACHE:
34+
return CACHE[key]
35+
36+
page, headers, code = None, {}, httplib.OK
37+
38+
url = url or ("%s%s%s" % (sys.argv[1], '?' if '?' not in sys.argv[1] else '&', get) if get else sys.argv[1])
39+
if not url.startswith("http"):
40+
url = "http://%s" % url
41+
42+
try:
43+
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+
except Exception, ex:
46+
code = getattr(ex, "code", None)
47+
page = ex.read() if hasattr(ex, "read") else getattr(ex, "msg", "")
48+
49+
result = CACHE[key] = page, headers, code
50+
51+
return result
52+
53+
def main():
54+
global WAF_FUNCTIONS
55+
56+
print "%s #v%s\n by: %s\n" % (NAME, VERSION, AUTHOR)
57+
58+
if len(sys.argv) < 2:
59+
exit("[x] usage: python %s <hostname>" % os.path.split(__file__)[-1])
60+
61+
cookie_jar = cookielib.CookieJar()
62+
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie_jar))
63+
urllib2.install_opener(opener)
64+
65+
sys.path.insert(0, SQLMAP_DIR)
66+
67+
for found in glob.glob(os.path.join(SCRIPTS_DIR, "*.py")):
68+
dirname, filename = os.path.split(found)
69+
dirname = os.path.abspath(dirname)
70+
71+
if filename == "__init__.py":
72+
continue
73+
74+
if dirname not in sys.path:
75+
sys.path.insert(0, dirname)
76+
77+
try:
78+
if filename[:-3] in sys.modules:
79+
del sys.modules[filename[:-3]]
80+
module = __import__(filename[:-3].encode(sys.getfilesystemencoding() or "utf8"))
81+
except ImportError, msg:
82+
exit("[x] cannot import WAF script '%s' (%s)" % (filename[:-3], msg))
83+
84+
_ = dict(inspect.getmembers(module))
85+
if "detect" not in _:
86+
exit("[x] missing function 'detect(get_page)' in WAF script '%s'" % found)
87+
else:
88+
WAF_FUNCTIONS.append((_["detect"], _.get("__product__", filename[:-3])))
89+
90+
WAF_FUNCTIONS = sorted(WAF_FUNCTIONS, key=lambda _: "generic" in _[1].lower())
91+
92+
print "[i] %d (sqlmap's) WAF scripts loaded" % len(WAF_FUNCTIONS)
93+
94+
found = False
95+
for function, product in WAF_FUNCTIONS:
96+
if found and "unknown" in product.lower():
97+
continue
98+
99+
if function(get_page):
100+
print "[!] WAF/IPS/IDS identified as '%s'" % product
101+
found = True
102+
103+
if not found:
104+
print "[o] nothing found"
105+
106+
if __name__ == "__main__":
107+
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.23"
22+
VERSION = "1.2.8.24"
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ e4805169a081b834ca51a60a150c7247 extra/shutils/newlines.py
2121
1056d1112ba5130868178cb495d22b1d extra/shutils/regressiontest.py
2222
1e5532ede194ac9c083891c2f02bca93 extra/sqlharvest/__init__.py
2323
b3e60ea4e18a65c48515d04aab28ff68 extra/sqlharvest/sqlharvest.py
24+
1e5532ede194ac9c083891c2f02bca93 extra/wafdetectify/__init__.py
25+
cf646f49087ff56d752dc831d2245a51 extra/wafdetectify/wafdetectify.py
2426
3459c562a6abb9b4bdcc36925f751f3e lib/controller/action.py
2527
7493c782345a60f6c00c9281d51a494e lib/controller/checks.py
2628
c414cecdb0472c92cf50ed5b01e4438c lib/controller/controller.py
@@ -48,7 +50,7 @@ c8c386d644d57c659d74542f5f57f632 lib/core/patch.py
4850
0c3eef46bdbf87e29a3f95f90240d192 lib/core/replication.py
4951
a7db43859b61569b601b97f187dd31c5 lib/core/revision.py
5052
fcb74fcc9577523524659ec49e2e964b lib/core/session.py
51-
b52affaeb83ecf36e15e75bd439df284 lib/core/settings.py
53+
4ecbe8858ce030877cb3e00f437ac87a lib/core/settings.py
5254
dd68a9d02fccb4fa1428b20e15b0db5d lib/core/shell.py
5355
a7edc9250d13af36ac0108f259859c19 lib/core/subprocessng.py
5456
815d1cf27f0f8738d81531e73149867d lib/core/target.py

0 commit comments

Comments
 (0)