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

Skip to content

Commit 52351e5

Browse files
committed
Update for an Issue #161 (now detecting format error messages too)
1 parent dbbfee6 commit 52351e5

2 files changed

Lines changed: 28 additions & 20 deletions

File tree

lib/controller/checks.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from lib.core.exception import sqlmapSilentQuitException
5454
from lib.core.exception import sqlmapUserQuitException
5555
from lib.core.settings import CONSTANT_RATIO
56+
from lib.core.settings import FORMAT_EXCEPTION_STRINGS
5657
from lib.core.settings import UNKNOWN_DBMS_VERSION
5758
from lib.core.settings import LOWER_RATIO_BOUND
5859
from lib.core.settings import UPPER_RATIO_BOUND
@@ -620,6 +621,8 @@ def heuristicCheckSqlInjection(place, parameter):
620621
logger.debug(debugMsg)
621622
return None
622623

624+
origValue = conf.paramDict[place][parameter]
625+
623626
prefix = ""
624627
suffix = ""
625628

@@ -640,38 +643,40 @@ def heuristicCheckSqlInjection(place, parameter):
640643
infoMsg = "heuristic test shows that %s " % place
641644
infoMsg += "parameter '%s' might " % parameter
642645

643-
casting = False
644-
if not result and kb.dynamicParameter:
645-
origValue = conf.paramDict[place][parameter]
646+
def _(page):
647+
return any(_ in (page or "") for _ in FORMAT_EXCEPTION_STRINGS)
646648

647-
if origValue and origValue.isdigit():
648-
randInt = int(randomInt())
649-
payload = "%s%s%s" % (prefix, "%d-%d" % (int(origValue) + randInt, randInt), suffix)
650-
payload = agent.payload(place, parameter, newValue=payload, where=PAYLOAD.WHERE.REPLACE)
651-
result = Request.queryPage(payload, place, raise404=False)
649+
casting = _(page) and not _(kb.originalPage)
652650

653-
if not result:
654-
randStr = randomStr()
655-
payload = "%s%s%s" % (prefix, "%s%s" % (origValue, randStr), suffix)
656-
payload = agent.payload(place, parameter, newValue=payload, where=PAYLOAD.WHERE.REPLACE)
657-
casting = Request.queryPage(payload, place, raise404=False)
651+
if not casting and not result and kb.dynamicParameter and origValue.isdigit():
652+
randInt = int(randomInt())
653+
payload = "%s%s%s" % (prefix, "%d-%d" % (int(origValue) + randInt, randInt), suffix)
654+
payload = agent.payload(place, parameter, newValue=payload, where=PAYLOAD.WHERE.REPLACE)
655+
result = Request.queryPage(payload, place, raise404=False)
658656

659-
if result:
660-
infoMsg += "be injectable (possible DBMS: %s)" % (Format.getErrorParsedDBMSes() or UNKNOWN_DBMS_VERSION)
661-
logger.info(infoMsg)
662-
else:
663-
infoMsg += "not be injectable"
664-
logger.warn(infoMsg)
657+
if not result:
658+
randStr = randomStr()
659+
payload = "%s%s%s" % (prefix, "%s%s" % (origValue, randStr), suffix)
660+
payload = agent.payload(place, parameter, newValue=payload, where=PAYLOAD.WHERE.REPLACE)
661+
casting = Request.queryPage(payload, place, raise404=False)
665662

666663
if casting:
667-
errMsg = "possible integer casting "
664+
errMsg = "possible %scasting " % ("integer " if origValue.isdigit() else "")
668665
errMsg += "detected (e.g. %s=(int)$_REQUEST('%s')) " % (parameter, parameter)
669666
errMsg += "at the back-end web application"
670667
logger.error(errMsg)
671668

672669
message = "do you want to skip those kind of cases (and save scanning time)? [Y/n] "
673670
kb.ignoreCasted = readInput(message, default='Y').upper() != 'N'
674671

672+
elif result:
673+
infoMsg += "be injectable (possible DBMS: %s)" % (Format.getErrorParsedDBMSes() or UNKNOWN_DBMS_VERSION)
674+
logger.info(infoMsg)
675+
676+
else:
677+
infoMsg += "not be injectable"
678+
logger.warn(infoMsg)
679+
675680
kb.heuristicTest = HEURISTIC_TEST.CASTED if casting else HEURISTIC_TEST.NEGATIVE if not result else HEURISTIC_TEST.POSITIVE
676681

677682
return kb.heuristicTest

lib/core/settings.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,3 +452,6 @@
452452

453453
# Maximum length of a help part containing switch/option name(s)
454454
MAX_HELP_OPTION_LENGTH = 18
455+
456+
# Strings for detecting formatting errors
457+
FORMAT_EXCEPTION_STRINGS = ("Type mismatch", "System.FormatException", "java.lang.NumberFormatException")

0 commit comments

Comments
 (0)