Skip to content

Commit 59695af

Browse files
committed
Minor improvement of heuristic checks
1 parent 8b90d14 commit 59695af

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

lib/controller/checks.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,14 @@
6666
from lib.core.settings import DUMMY_NON_SQLI_CHECK_APPENDIX
6767
from lib.core.settings import FORMAT_EXCEPTION_STRINGS
6868
from lib.core.settings import HEURISTIC_CHECK_ALPHABET
69+
from lib.core.settings import IDS_WAF_CHECK_PAYLOAD
70+
from lib.core.settings import IDS_WAF_CHECK_RATIO
71+
from lib.core.settings import IDS_WAF_CHECK_TIMEOUT
72+
from lib.core.settings import NON_SQLI_CHECK_PREFIX_SUFFIX_LENGTH
6973
from lib.core.settings import SUHOSIN_MAX_VALUE_LENGTH
7074
from lib.core.settings import SUPPORTED_DBMS
7175
from lib.core.settings import URI_HTTP_HEADER
7276
from lib.core.settings import UPPER_RATIO_BOUND
73-
from lib.core.settings import IDS_WAF_CHECK_PAYLOAD
74-
from lib.core.settings import IDS_WAF_CHECK_RATIO
75-
from lib.core.settings import IDS_WAF_CHECK_TIMEOUT
7677
from lib.core.threads import getCurrentThreadData
7778
from lib.request.connect import Connect as Request
7879
from lib.request.inject import checkBooleanExpression
@@ -932,23 +933,25 @@ def _(page):
932933

933934
kb.heuristicMode = True
934935

935-
randStr1, randStr2 = randomStr(), randomStr()
936+
randStr1, randStr2 = randomStr(NON_SQLI_CHECK_PREFIX_SUFFIX_LENGTH), randomStr(NON_SQLI_CHECK_PREFIX_SUFFIX_LENGTH)
936937
value = "%s%s%s" % (randStr1, DUMMY_NON_SQLI_CHECK_APPENDIX, randStr2)
937938
payload = "%s%s%s" % (prefix, "'%s" % value, suffix)
938939
payload = agent.payload(place, parameter, newValue=payload)
939940
page, _ = Request.queryPage(payload, place, content=True, raise404=False)
940941

941942
paramType = conf.method if conf.method not in (None, HTTPMETHOD.GET, HTTPMETHOD.POST) else place
942943

943-
if value in (page or ""):
944+
if value.lower() in (page or "").lower():
944945
infoMsg = "heuristic (XSS) test shows that %s parameter " % paramType
945946
infoMsg += "'%s' might be vulnerable to cross-site scripting attacks" % parameter
946947
logger.info(infoMsg)
947948

948-
if re.search(r"(?i)Failed opening[^\n]+%s" % randStr1, page or ""):
949-
infoMsg = "heuristic (FI) test shows that %s parameter " % paramType
950-
infoMsg += "'%s' might be vulnerable to file inclusion attacks" % parameter
951-
logger.info(infoMsg)
949+
for match in re.finditer("(?i)[^\n]*(no such file|failed (to )?open)[^\n]*", page or ""):
950+
if randStr1.lower() in match.group(0).lower():
951+
infoMsg = "heuristic (FI) test shows that %s parameter " % paramType
952+
infoMsg += "'%s' might be vulnerable to file inclusion attacks" % parameter
953+
logger.info(infoMsg)
954+
break
952955

953956
kb.heuristicMode = False
954957

lib/core/settings.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,12 @@
548548
# Alphabet used for heuristic checks
549549
HEURISTIC_CHECK_ALPHABET = ('"', '\'', ')', '(', ',', '.')
550550

551-
# String used for dummy non-SQLi (e.g. XSS) check of a tested parameter value
551+
# String used for dummy non-SQLi (e.g. XSS) heuristic checks of a tested parameter value
552552
DUMMY_NON_SQLI_CHECK_APPENDIX = "<'\">"
553553

554+
# Length of prefix and suffix used in non-SQLI heuristic checks
555+
NON_SQLI_CHECK_PREFIX_SUFFIX_LENGTH = 6
556+
554557
# Connection chunk size (processing large responses in chunks to avoid MemoryError crashes - e.g. large table dump in full UNION injections)
555558
MAX_CONNECTION_CHUNK_SIZE = 10 * 1024 * 1024
556559

0 commit comments

Comments
 (0)