5353from lib .core .exception import sqlmapSilentQuitException
5454from lib .core .exception import sqlmapUserQuitException
5555from lib .core .settings import CONSTANT_RATIO
56+ from lib .core .settings import FORMAT_EXCEPTION_STRINGS
5657from lib .core .settings import UNKNOWN_DBMS_VERSION
5758from lib .core .settings import LOWER_RATIO_BOUND
5859from 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
0 commit comments