2020from lib .core .common import popValue
2121from lib .core .common import pushValue
2222from lib .core .common import randomInt
23+ from lib .core .common import randomStr
2324from lib .core .common import readInput
2425from lib .core .common import safeStringFormat
2526from lib .core .common import safeSQLIdentificatorNaming
2627from lib .core .data import conf
2728from lib .core .data import kb
2829from lib .core .data import logger
2930from lib .core .enums import DBMS
31+ from lib .core .exception import sqlmapDataException
3032from lib .core .exception import sqlmapMissingMandatoryOptionException
3133from lib .core .exception import sqlmapThreadException
3234from lib .core .settings import MAX_NUMBER_OF_THREADS
3335from lib .core .settings import METADB_SUFFIX
36+ from lib .core .settings import BRUTE_COLUMN_EXISTS_TEMPLATE
37+ from lib .core .settings import BRUTE_TABLE_EXISTS_TEMPLATE
3438from lib .core .session import safeFormatString
3539from lib .core .threads import getCurrentThreadData
3640from lib .core .threads import runThreads
@@ -52,6 +56,13 @@ def __addPageTextWords():
5256 return wordsList
5357
5458def tableExists (tableFile , regex = None ):
59+ result = inject .checkBooleanExpression ("%s" % safeStringFormat (BRUTE_TABLE_EXISTS_TEMPLATE , (randomInt (1 ), randomStr ())))
60+ if result :
61+ errMsg = "can't use table existence check because of detected invalid results "
62+ errMsg += "(most probably caused by inability of the used injection "
63+ errMsg += "to distinguish errornous results)"
64+ raise sqlmapDataException , errMsg
65+
5566 tables = getFileItems (tableFile , lowercase = Backend .getIdentifiedDbms () in (DBMS .ACCESS ), unique = True )
5667
5768 infoMsg = "checking table existence using items from '%s'" % tableFile
@@ -84,7 +95,7 @@ def tableExistsThread():
8495 else :
8596 fullTableName = table
8697
87- result = inject .checkBooleanExpression ("%s" % safeStringFormat ("EXISTS(SELECT %d FROM %s)" , (randomInt (1 ), fullTableName )))
98+ result = inject .checkBooleanExpression ("%s" % safeStringFormat (BRUTE_TABLE_EXISTS_TEMPLATE , (randomInt (1 ), fullTableName )))
8899
89100 kb .locks .ioLock .acquire ()
90101
@@ -135,6 +146,13 @@ def columnExists(columnFile, regex=None):
135146 errMsg = "missing table parameter"
136147 raise sqlmapMissingMandatoryOptionException , errMsg
137148
149+ result = inject .checkBooleanExpression (safeStringFormat (BRUTE_COLUMN_EXISTS_TEMPLATE , (randomStr (), randomStr ())))
150+ if result :
151+ errMsg = "can't use column existence check because of detected invalid results "
152+ errMsg += "(most probably caused by inability of the used injection "
153+ errMsg += "to distinguish errornous results)"
154+ raise sqlmapDataException , errMsg
155+
138156 infoMsg = "checking column existence using items from '%s'" % columnFile
139157 logger .info (infoMsg )
140158
@@ -169,7 +187,7 @@ def columnExistsThread():
169187 kb .locks .countLock .release ()
170188 break
171189
172- result = inject .checkBooleanExpression ("%s" % safeStringFormat ("EXISTS(SELECT %s FROM %s)" , (column , table )))
190+ result = inject .checkBooleanExpression (safeStringFormat (BRUTE_COLUMN_EXISTS_TEMPLATE , (column , table )))
173191
174192 kb .locks .ioLock .acquire ()
175193
0 commit comments