|
59 | 59 | from lib.core.exception import SqlmapNoneDataException |
60 | 60 | from lib.core.exception import SqlmapSilentQuitException |
61 | 61 | from lib.core.exception import SqlmapUserQuitException |
| 62 | +from lib.core.settings import DEFAULT_GET_POST_DELIMITER |
62 | 63 | from lib.core.settings import DUMMY_XSS_CHECK_APPENDIX |
63 | 64 | from lib.core.settings import FORMAT_EXCEPTION_STRINGS |
64 | 65 | from lib.core.settings import HEURISTIC_CHECK_ALPHABET |
|
68 | 69 | from lib.core.settings import LOWER_RATIO_BOUND |
69 | 70 | from lib.core.settings import UPPER_RATIO_BOUND |
70 | 71 | from lib.core.settings import IDS_WAF_CHECK_PAYLOAD |
| 72 | +from lib.core.settings import IDS_WAF_CHECK_RATIO |
71 | 73 | from lib.core.threads import getCurrentThreadData |
72 | 74 | from lib.request.connect import Connect as Request |
73 | 75 | from lib.request.inject import checkBooleanExpression |
@@ -1094,56 +1096,32 @@ def checkWaf(): |
1094 | 1096 | Reference: http://seclists.org/nmap-dev/2011/q2/att-1005/http-waf-detect.nse |
1095 | 1097 | """ |
1096 | 1098 |
|
1097 | | - if not conf.checkWaf: |
1098 | | - return False |
1099 | | - |
1100 | 1099 | infoMsg = "heuristically checking if the target is protected by " |
1101 | 1100 | infoMsg += "some kind of WAF/IPS/IDS" |
1102 | 1101 | logger.info(infoMsg) |
1103 | 1102 |
|
1104 | 1103 | retVal = False |
1105 | | - |
1106 | 1104 | backup = dict(conf.parameters) |
1107 | | - |
1108 | 1105 | payload = "%d %s" % (randomInt(), IDS_WAF_CHECK_PAYLOAD) |
1109 | 1106 |
|
1110 | 1107 | 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 |
1112 | 1109 | conf.parameters[PLACE.GET] += "%s=%s" % (randomStr(), payload) |
1113 | 1110 |
|
1114 | 1111 | logger.log(CUSTOM_LOGGING.PAYLOAD, payload) |
1115 | 1112 |
|
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 |
1129 | 1119 | 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) |
1142 | 1120 |
|
1143 | 1121 | if retVal: |
1144 | 1122 | warnMsg = "it appears that the target is protected. Please " |
1145 | 1123 | warnMsg += "consider usage of tamper scripts (option '--tamper')" |
1146 | | - logger.warn(warnMsg) |
| 1124 | + logger.critical(warnMsg) |
1147 | 1125 | else: |
1148 | 1126 | infoMsg = "it appears that the target is not protected" |
1149 | 1127 | logger.info(infoMsg) |
|
0 commit comments