Skip to content

Commit 0c79504

Browse files
committed
Switching from WAF scripts to identYwaf (avoiding redundant work from my side)
1 parent ef7d4bb commit 0c79504

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+1529
-2114
lines changed

doc/THIRD-PARTY.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,8 @@ be bound by the terms and conditions of this License Agreement.
276276

277277
* The `bottle` web framework library located under `thirdparty/bottle/`.
278278
Copyright (C) 2012, Marcel Hellkamp.
279+
* The `identYwaf` library located under `thirdparty/identywaf/`.
280+
Copyright (C) 2019, Miroslav Stampar.
279281
* The `ordereddict` library located under `thirdparty/odict/`.
280282
Copyright (C) 2009, Raymond Hettinger.
281283
* The `six` Python 2 and 3 compatibility library located under `thirdparty/six/`.

lib/controller/checks.py

Lines changed: 35 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
from lib.techniques.union.test import unionTest
109109
from lib.techniques.union.use import configUnion
110110
from thirdparty import six
111+
from thirdparty.identywaf import identYwaf
111112
from thirdparty.six.moves import http_client as _http_client
112113

113114
def checkSqlInjection(place, parameter, value):
@@ -1402,116 +1403,51 @@ def checkWaf():
14021403
kb.resendPostOnRedirect = popValue()
14031404
kb.redirectChoice = popValue()
14041405

1406+
# TODO: today
14051407
if retVal:
1406-
warnMsg = "heuristics detected that the target "
1407-
warnMsg += "is protected by some kind of WAF/IPS"
1408-
logger.critical(warnMsg)
1409-
1410-
if not conf.identifyWaf:
1411-
message = "do you want sqlmap to try to detect backend "
1412-
message += "WAF/IPS? [y/N] "
1413-
1414-
if readInput(message, default='N', boolean=True):
1415-
conf.identifyWaf = True
1416-
1417-
if conf.timeout == defaults.timeout:
1418-
logger.warning("dropping timeout to %d seconds (i.e. '--timeout=%d')" % (IDS_WAF_CHECK_TIMEOUT, IDS_WAF_CHECK_TIMEOUT))
1419-
conf.timeout = IDS_WAF_CHECK_TIMEOUT
1420-
1421-
hashDBWrite(HASHDB_KEYS.CHECK_WAF_RESULT, retVal, True)
1422-
1423-
return retVal
1424-
1425-
@stackedmethod
1426-
def identifyWaf():
1427-
if not conf.identifyWaf:
1428-
return None
1429-
1430-
if not kb.wafFunctions:
1431-
setWafFunctions()
1432-
1433-
kb.testMode = True
1434-
1435-
infoMsg = "using WAF scripts to detect "
1436-
infoMsg += "backend WAF/IPS protection"
1437-
logger.info(infoMsg)
1438-
1439-
@cachedmethod
1440-
def _(*args, **kwargs):
1441-
page, headers, code = None, None, None
1442-
try:
1443-
pushValue(kb.redirectChoice)
1444-
pushValue(kb.resendPostOnRedirect)
1445-
1446-
kb.redirectChoice = REDIRECTION.YES
1447-
kb.resendPostOnRedirect = True
1448-
1449-
if kwargs.get("get"):
1450-
kwargs["get"] = urlencode(kwargs["get"])
1451-
kwargs["raise404"] = False
1452-
kwargs["silent"] = True
1453-
kwargs["finalCode"] = True
1454-
1455-
page, headers, code = Request.getPage(*args, **kwargs)
1456-
except Exception:
1457-
pass
1458-
finally:
1459-
kb.resendPostOnRedirect = popValue()
1460-
kb.redirectChoice = popValue()
1408+
pass
1409+
# identYwaf
1410+
#if conf.timeout == defaults.timeout:
1411+
#logger.warning("dropping timeout to %d seconds (i.e. '--timeout=%d')" % (IDS_WAF_CHECK_TIMEOUT, IDS_WAF_CHECK_TIMEOUT))
1412+
#conf.timeout = IDS_WAF_CHECK_TIMEOUT
14611413

1462-
return page or "", headers or {}, code
1414+
# identYwaf
14631415

1464-
retVal = []
1416+
#def _(*args, **kwargs):
1417+
#page, headers, code = None, None, None
1418+
#try:
1419+
#pushValue(kb.redirectChoice)
1420+
#pushValue(kb.resendPostOnRedirect)
14651421

1466-
for function, product in kb.wafFunctions:
1467-
if retVal and "unknown" in product.lower():
1468-
continue
1422+
#kb.redirectChoice = REDIRECTION.YES
1423+
#kb.resendPostOnRedirect = True
14691424

1470-
try:
1471-
logger.debug("checking for WAF/IPS product '%s'" % product)
1472-
found = function(_)
1473-
except Exception as ex:
1474-
errMsg = "exception occurred while running "
1475-
errMsg += "WAF script for '%s' ('%s')" % (product, getSafeExString(ex))
1476-
logger.critical(errMsg)
1425+
#if kwargs.get("get"):
1426+
#kwargs["get"] = urlencode(kwargs["get"])
1427+
#kwargs["raise404"] = False
1428+
#kwargs["silent"] = True
1429+
#kwargs["finalCode"] = True
14771430

1478-
found = False
1431+
#page, headers, code = Request.getPage(*args, **kwargs)
1432+
#except Exception:
1433+
#pass
1434+
#finally:
1435+
#kb.resendPostOnRedirect = popValue()
1436+
#kb.redirectChoice = popValue()
14791437

1480-
if found:
1481-
errMsg = "WAF/IPS identified as '%s'" % product
1482-
logger.critical(errMsg)
14831438

1484-
retVal.append(product)
1439+
#message = "are you sure that you want to "
1440+
#message += "continue with further target testing? [y/N] "
1441+
#choice = readInput(message, default='N', boolean=True)
14851442

1486-
if retVal:
1487-
if kb.wafSpecificResponse and "You don't have permission to access" not in kb.wafSpecificResponse and len(retVal) == 1 and "unknown" in retVal[0].lower():
1488-
handle, filename = tempfile.mkstemp(prefix=MKSTEMP_PREFIX.SPECIFIC_RESPONSE)
1489-
os.close(handle)
1490-
with openFile(filename, "w+b") as f:
1491-
f.write(kb.wafSpecificResponse)
1492-
1493-
message = "WAF/IPS specific response can be found in '%s'. " % filename
1494-
message += "If you know the details on used protection please "
1495-
message += "report it along with specific response "
1496-
message += "to '%s'" % DEV_EMAIL_ADDRESS
1497-
logger.warn(message)
1498-
1499-
message = "are you sure that you want to "
1500-
message += "continue with further target testing? [y/N] "
1501-
choice = readInput(message, default='N', boolean=True)
1502-
1503-
if not conf.tamper:
1504-
warnMsg = "please consider usage of tamper scripts (option '--tamper')"
1505-
singleTimeWarnMessage(warnMsg)
1443+
#if not conf.tamper:
1444+
#warnMsg = "please consider usage of tamper scripts (option '--tamper')"
1445+
#singleTimeWarnMessage(warnMsg)
15061446

1507-
if not choice:
1508-
raise SqlmapUserQuitException
1509-
else:
1510-
warnMsg = "WAF/IPS product hasn't been identified"
1511-
logger.warn(warnMsg)
1447+
#if not choice:
1448+
#raise SqlmapUserQuitException
15121449

1513-
kb.testType = None
1514-
kb.testMode = False
1450+
hashDBWrite(HASHDB_KEYS.CHECK_WAF_RESULT, retVal, True)
15151451

15161452
return retVal
15171453

@@ -1666,6 +1602,3 @@ def checkInternet():
16661602

16671603
def setVerbosity(): # Cross-referenced function
16681604
raise NotImplementedError
1669-
1670-
def setWafFunctions(): # Cross-referenced function
1671-
raise NotImplementedError

lib/controller/controller.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
from lib.controller.checks import checkNullConnection
2121
from lib.controller.checks import checkWaf
2222
from lib.controller.checks import heuristicCheckSqlInjection
23-
from lib.controller.checks import identifyWaf
2423
from lib.core.agent import agent
2524
from lib.core.common import dataToStdout
2625
from lib.core.common import extractRegexResult
@@ -423,9 +422,6 @@ def start():
423422

424423
checkWaf()
425424

426-
if conf.identifyWaf:
427-
identifyWaf()
428-
429425
if conf.nullConnection:
430426
checkNullConnection()
431427

lib/core/option.py

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -904,42 +904,6 @@ def _setPreprocessFunctions():
904904
errMsg += "(Note: find template script at '%s')" % filename
905905
raise SqlmapGenericException(errMsg)
906906

907-
def _setWafFunctions():
908-
"""
909-
Loads WAF/IPS detecting functions from script(s)
910-
"""
911-
912-
if conf.identifyWaf:
913-
for found in glob.glob(os.path.join(paths.SQLMAP_WAF_PATH, "*.py")):
914-
dirname, filename = os.path.split(found)
915-
dirname = os.path.abspath(dirname)
916-
917-
if filename == "__init__.py":
918-
continue
919-
920-
debugMsg = "loading WAF script '%s'" % filename[:-3]
921-
logger.debug(debugMsg)
922-
923-
if dirname not in sys.path:
924-
sys.path.insert(0, dirname)
925-
926-
try:
927-
if filename[:-3] in sys.modules:
928-
del sys.modules[filename[:-3]]
929-
module = __import__(safeFilepathEncode(filename[:-3]))
930-
except ImportError as ex:
931-
raise SqlmapSyntaxException("cannot import WAF script '%s' (%s)" % (getUnicode(filename[:-3]), getSafeExString(ex)))
932-
933-
_ = dict(inspect.getmembers(module))
934-
if "detect" not in _:
935-
errMsg = "missing function 'detect(get_page)' "
936-
errMsg += "in WAF script '%s'" % found
937-
raise SqlmapGenericException(errMsg)
938-
else:
939-
kb.wafFunctions.append((_["detect"], _.get("__product__", filename[:-3])))
940-
941-
kb.wafFunctions = sorted(kb.wafFunctions, key=lambda _: "generic" in _[1].lower())
942-
943907
def _setThreads():
944908
if not isinstance(conf.threads, int) or conf.threads <= 0:
945909
conf.threads = 1
@@ -2394,10 +2358,6 @@ def _basicOptionValidation():
23942358
errMsg = "option '-d' is incompatible with option '--dbms'"
23952359
raise SqlmapSyntaxException(errMsg)
23962360

2397-
if conf.identifyWaf and conf.skipWaf:
2398-
errMsg = "switch '--identify-waf' is incompatible with switch '--skip-waf'"
2399-
raise SqlmapSyntaxException(errMsg)
2400-
24012361
if conf.titles and conf.nullConnection:
24022362
errMsg = "switch '--titles' is incompatible with switch '--null-connection'"
24032363
raise SqlmapSyntaxException(errMsg)
@@ -2630,7 +2590,6 @@ def init():
26302590
_listTamperingFunctions()
26312591
_setTamperingFunctions()
26322592
_setPreprocessFunctions()
2633-
_setWafFunctions()
26342593
_setTrafficOutputFP()
26352594
_setupHTTPCollector()
26362595
_setHttpChunked()

lib/core/optiondict.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,6 @@
229229
"dependencies": "boolean",
230230
"disableColoring": "boolean",
231231
"googlePage": "integer",
232-
"identifyWaf": "boolean",
233232
"listTampers": "boolean",
234233
"mobile": "boolean",
235234
"offline": "boolean",

lib/core/patch.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
from lib.core.convert import stdoutEncode
2929
from lib.core.option import _setHTTPHandlers
3030
from lib.core.option import setVerbosity
31-
from lib.core.option import _setWafFunctions
3231
from lib.core.settings import IS_WIN
3332
from thirdparty.six.moves import http_client as _http_client
3433

@@ -70,7 +69,6 @@ def resolveCrossReferences():
7069
lib.request.connect.setHTTPHandlers = _setHTTPHandlers
7170
lib.utils.search.setHTTPHandlers = _setHTTPHandlers
7271
lib.controller.checks.setVerbosity = setVerbosity
73-
lib.controller.checks.setWafFunctions = _setWafFunctions
7472
lib.utils.sqlalchemy.getSafeExString = getSafeExString
7573
thirdparty.ansistrm.ansistrm.stdoutEncode = stdoutEncode
7674

lib/core/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from thirdparty.six import unichr as _unichr
1919

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

lib/parse/cmdline.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,9 +652,6 @@ def cmdLineParser(argv=None):
652652
miscellaneous.add_option("--gpage", dest="googlePage", type="int",
653653
help="Use Google dork results from specified page number")
654654

655-
miscellaneous.add_option("--identify-waf", dest="identifyWaf", action="store_true",
656-
help="Make a thorough testing for a WAF/IPS protection")
657-
658655
miscellaneous.add_option("--list-tampers", dest="listTampers", action="store_true",
659656
help="Display list of available tamper scripts")
660657

sqlmap.conf

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -788,10 +788,6 @@ disableColoring = False
788788
# Default: 1
789789
googlePage = 1
790790

791-
# Make a thorough testing for a WAF/IPS protection.
792-
# Valid: True or False
793-
identifyWaf = False
794-
795791
# Display list of available tamper scripts
796792
# Valid: True or False
797793
listTampers = False

swagger.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,6 @@ paths:
270270
tmpPath: null
271271
titles: false
272272
getSchema: false
273-
identifyWaf: false
274273
paramDel: null
275274
safeReqFile: null
276275
regKey: null

0 commit comments

Comments
 (0)