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

Skip to content

Commit 6b2981e

Browse files
committed
Update for an Issue #290 (adding tamper-like scripts into (new) directory waf)
1 parent f593e1d commit 6b2981e

8 files changed

Lines changed: 93 additions & 0 deletions

File tree

lib/controller/checks.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,37 @@ def checkWaf():
10371037

10381038
return retVal
10391039

1040+
def identifyWaf():
1041+
if not conf.identifyWaf:
1042+
return None
1043+
1044+
infoMsg = "using WAF scripts to detect "
1045+
infoMsg += "backend WAF/IPS/IDS protection"
1046+
logger.info(infoMsg)
1047+
1048+
retVal = False
1049+
page, headers, code = Request.getPage()
1050+
1051+
for function, product, request in kb.wafFunctions:
1052+
found = False
1053+
if not request:
1054+
found = function(page or "", headers or {}, code)
1055+
else:
1056+
pass
1057+
if found:
1058+
retVal = product
1059+
break
1060+
1061+
if retVal:
1062+
warnMsg = "WAF/IDS/IPS identified ('%s'). Please " % retVal
1063+
warnMsg += "consider usage of tamper scripts (option '--tamper')"
1064+
logger.critical(warnMsg)
1065+
else:
1066+
warnMsg = "no WAF/IDS/IPS were identified"
1067+
logger.warn(warnMsg)
1068+
1069+
return retVal
1070+
10401071
def checkNullConnection():
10411072
"""
10421073
Reference: http://www.wisec.it/sectou.php?id=472f952d79293

lib/controller/controller.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from lib.controller.checks import checkNullConnection
1919
from lib.controller.checks import checkWaf
2020
from lib.controller.checks import heuristicCheckSqlInjection
21+
from lib.controller.checks import identifyWaf
2122
from lib.core.agent import agent
2223
from lib.core.common import extractRegexResult
2324
from lib.core.common import getFilteredPageContent
@@ -360,6 +361,9 @@ def start():
360361
if conf.checkWaf:
361362
checkWaf()
362363

364+
if conf.identifyWaf:
365+
identifyWaf()
366+
363367
if conf.nullConnection:
364368
checkNullConnection()
365369

lib/core/common.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ def setPaths():
973973
paths.SQLMAP_PROCS_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "procs")
974974
paths.SQLMAP_SHELL_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "shell")
975975
paths.SQLMAP_TAMPER_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "tamper")
976+
paths.SQLMAP_WAF_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "waf")
976977
paths.SQLMAP_TXT_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "txt")
977978
paths.SQLMAP_UDF_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "udf")
978979
paths.SQLMAP_XML_PATH = os.path.join(paths.SQLMAP_ROOT_PATH, "xml")

lib/core/enums.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class HTTPHEADER:
152152
REFERER = "Referer"
153153
USER_AGENT = "User-Agent"
154154

155+
class WAF_REQUEST:
156+
GET = 1
157+
POST = 2
158+
HEADERS = 3
159+
155160
class EXPECTED:
156161
BOOL = "bool"
157162
INT = "int"

lib/core/option.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77

88
import cookielib
9+
import glob
910
import inspect
1011
import logging
1112
import os
@@ -894,6 +895,35 @@ def _setTamperingFunctions():
894895
for _, function in priorities:
895896
kb.tamperFunctions.append(function)
896897

898+
def _setWafFunctions():
899+
"""
900+
Loads WAF/IDS/IPS detecting functions from script(s)
901+
"""
902+
903+
if conf.identifyWaf:
904+
for found in glob.glob(os.path.join(paths.SQLMAP_WAF_PATH, "*.py")):
905+
dirname, filename = os.path.split(found)
906+
dirname = os.path.abspath(dirname)
907+
908+
debugMsg = "loading WAF script '%s'" % filename[:-3]
909+
logger.debug(debugMsg)
910+
911+
if dirname not in sys.path:
912+
sys.path.insert(0, dirname)
913+
914+
try:
915+
module = __import__(filename[:-3])
916+
except ImportError, msg:
917+
raise SqlmapSyntaxException("cannot import WAF script '%s' (%s)" % (filename[:-3], msg))
918+
919+
_ = dict(inspect.getmembers(module))
920+
if "detect" not in _:
921+
errMsg = "missing function 'detect(page, headers, code)' "
922+
errMsg += "in WAF script '%s'" % found
923+
raise SqlmapGenericException(errMsg)
924+
else:
925+
kb.wafFunctions.append((_["detect"], _.get("__product__", filename[:-3]), _.get("__request__")))
926+
897927
def _setThreads():
898928
if not isinstance(conf.threads, int) or conf.threads <= 0:
899929
conf.threads = 1
@@ -1611,6 +1641,7 @@ def _setKnowledgeBaseAttributes(flushAll=True):
16111641
kb.userAgents = None
16121642
kb.vainRun = True
16131643
kb.vulnHosts = set()
1644+
kb.wafFunctions = []
16141645
kb.wordlists = None
16151646

16161647
def _useWizardInterface():
@@ -2080,6 +2111,7 @@ def init():
20802111
_adjustLoggingFormatter()
20812112
_setMultipleTargets()
20822113
_setTamperingFunctions()
2114+
_setWafFunctions()
20832115
_setTrafficOutputFP()
20842116
_resolveCrossReferences()
20852117

lib/core/optiondict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@
214214
"profile": "boolean",
215215
"cpuThrottle": "integer",
216216
"forceDns": "boolean",
217+
"identifyWaf": "boolean",
217218
"smokeTest": "boolean",
218219
"liveTest": "boolean",
219220
"stopFail": "boolean",

lib/parse/cmdline.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,9 @@ def cmdLineParser():
674674
parser.add_option("--force-dns", dest="forceDns", action="store_true",
675675
help=SUPPRESS_HELP)
676676

677+
parser.add_option("--identify-waf", dest="identifyWaf", action="store_true",
678+
help=SUPPRESS_HELP)
679+
677680
parser.add_option("--smoke-test", dest="smokeTest", action="store_true",
678681
help=SUPPRESS_HELP)
679682

waf/f5asm.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
"""
4+
Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/)
5+
See the file 'doc/COPYING' for copying permission
6+
"""
7+
8+
import re
9+
10+
from lib.core.enums import HTTPHEADER
11+
12+
__product__ = "F5 Networks BIG-IP Application Security Manager (ASM)"
13+
__request__ = ()
14+
15+
def detect(page, headers, code):
16+
return re.search(r"^TS[a-zA-Z0-9]{3,6}=", headers.get(HTTPHEADER.SET_COOKIE, "")) is not None

0 commit comments

Comments
 (0)