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

Skip to content

Commit 6fc41ca

Browse files
committed
Heuristically checking for WAF/IDS/IPS by default
1 parent cd7d9ed commit 6fc41ca

6 files changed

Lines changed: 14 additions & 43 deletions

File tree

lib/controller/checks.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
from lib.core.exception import SqlmapNoneDataException
6060
from lib.core.exception import SqlmapSilentQuitException
6161
from lib.core.exception import SqlmapUserQuitException
62+
from lib.core.settings import DEFAULT_GET_POST_DELIMITER
6263
from lib.core.settings import DUMMY_XSS_CHECK_APPENDIX
6364
from lib.core.settings import FORMAT_EXCEPTION_STRINGS
6465
from lib.core.settings import HEURISTIC_CHECK_ALPHABET
@@ -68,6 +69,7 @@
6869
from lib.core.settings import LOWER_RATIO_BOUND
6970
from lib.core.settings import UPPER_RATIO_BOUND
7071
from lib.core.settings import IDS_WAF_CHECK_PAYLOAD
72+
from lib.core.settings import IDS_WAF_CHECK_RATIO
7173
from lib.core.threads import getCurrentThreadData
7274
from lib.request.connect import Connect as Request
7375
from lib.request.inject import checkBooleanExpression
@@ -1094,56 +1096,32 @@ def checkWaf():
10941096
Reference: http://seclists.org/nmap-dev/2011/q2/att-1005/http-waf-detect.nse
10951097
"""
10961098

1097-
if not conf.checkWaf:
1098-
return False
1099-
11001099
infoMsg = "heuristically checking if the target is protected by "
11011100
infoMsg += "some kind of WAF/IPS/IDS"
11021101
logger.info(infoMsg)
11031102

11041103
retVal = False
1105-
11061104
backup = dict(conf.parameters)
1107-
11081105
payload = "%d %s" % (randomInt(), IDS_WAF_CHECK_PAYLOAD)
11091106

11101107
conf.parameters = dict(backup)
1111-
conf.parameters[PLACE.GET] = "" if not conf.parameters.get(PLACE.GET) else conf.parameters[PLACE.GET] + "&"
1108+
conf.parameters[PLACE.GET] = "" if not conf.parameters.get(PLACE.GET) else conf.parameters[PLACE.GET] + DEFAULT_GET_POST_DELIMITER
11121109
conf.parameters[PLACE.GET] += "%s=%s" % (randomStr(), payload)
11131110

11141111
logger.log(CUSTOM_LOGGING.PAYLOAD, payload)
11151112

1116-
kb.matchRatio = None
1117-
Request.queryPage()
1118-
1119-
if kb.errorIsNone and kb.matchRatio is None:
1120-
kb.matchRatio = LOWER_RATIO_BOUND
1121-
1122-
conf.parameters = dict(backup)
1123-
conf.parameters[PLACE.GET] = "" if not conf.parameters.get(PLACE.GET) else conf.parameters[PLACE.GET] + "&"
1124-
conf.parameters[PLACE.GET] += "%s=%d" % (randomStr(), randomInt())
1125-
1126-
trueResult = Request.queryPage()
1127-
1128-
if trueResult:
1113+
try:
1114+
retVal = Request.queryPage(getRatioValue=True, noteResponseTime=False, silent=True)[1] < IDS_WAF_CHECK_RATIO
1115+
except SqlmapConnectionException:
1116+
retVal = True
1117+
finally:
1118+
kb.matchRatio = None
11291119
conf.parameters = dict(backup)
1130-
conf.parameters[PLACE.GET] = "" if not conf.parameters.get(PLACE.GET) else conf.parameters[PLACE.GET] + "&"
1131-
conf.parameters[PLACE.GET] += "%s=%d %s" % (randomStr(), randomInt(), IDS_WAF_CHECK_PAYLOAD)
1132-
1133-
try:
1134-
falseResult = Request.queryPage()
1135-
except SqlmapConnectionException:
1136-
falseResult = None
1137-
1138-
if not falseResult:
1139-
retVal = True
1140-
1141-
conf.parameters = dict(backup)
11421120

11431121
if retVal:
11441122
warnMsg = "it appears that the target is protected. Please "
11451123
warnMsg += "consider usage of tamper scripts (option '--tamper')"
1146-
logger.warn(warnMsg)
1124+
logger.critical(warnMsg)
11471125
else:
11481126
infoMsg = "it appears that the target is not protected"
11491127
logger.info(infoMsg)

lib/controller/controller.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,7 @@ def start():
372372
if not checkConnection(suppressOutput=conf.forms) or not checkString() or not checkRegexp():
373373
continue
374374

375-
if conf.checkWaf:
376-
checkWaf()
375+
checkWaf()
377376

378377
if conf.identifyWaf:
379378
identifyWaf()

lib/core/optiondict.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@
209209
"alert": "string",
210210
"answers": "string",
211211
"beep": "boolean",
212-
"checkWaf": "boolean",
213212
"cleanup": "boolean",
214213
"dependencies": "boolean",
215214
"disableColoring": "boolean",

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
DIFF_TOLERANCE = 0.05
4141
CONSTANT_RATIO = 0.9
4242

43+
# Ratio used in heuristic check for WAF/IDS/IPS protected targets
44+
IDS_WAF_CHECK_RATIO = 0.5
45+
4346
# Lower and upper values for match ratio in case of stable page
4447
LOWER_RATIO_BOUND = 0.02
4548
UPPER_RATIO_BOUND = 0.98

lib/parse/cmdline.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,10 +676,6 @@ def cmdLineParser():
676676
miscellaneous.add_option("--beep", dest="beep", action="store_true",
677677
help="Make a beep sound when SQL injection is found")
678678

679-
miscellaneous.add_option("--check-waf", dest="checkWaf",
680-
action="store_true",
681-
help="Heuristically check for WAF/IPS/IDS protection")
682-
683679
miscellaneous.add_option("--cleanup", dest="cleanup",
684680
action="store_true",
685681
help="Clean up the DBMS from sqlmap specific "

sqlmap.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,10 +718,6 @@ beep = False
718718
# Valid: True or False
719719
checkPayload = False
720720

721-
# Heuristically check for WAF/IPS/IDS protection.
722-
# Valid: True or False
723-
checkWaf = False
724-
725721
# Clean up the DBMS from sqlmap specific UDF and tables.
726722
# Valid: True or False
727723
cleanup = False

0 commit comments

Comments
 (0)