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

Skip to content

Commit ff52931

Browse files
committed
some refactoring (skipping duplicate messages in case that UNION/ERROR techniques failed and BOOLEAN/TIMED/STACKED are not available)
1 parent 1893053 commit ff52931

5 files changed

Lines changed: 35 additions & 28 deletions

File tree

lib/core/common.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ def getTechniqueData(technique=None):
24862486

24872487
return retVal
24882488

2489-
def isTechniqueAvailable(technique=None):
2489+
def isTechniqueAvailable(technique):
24902490
"""
24912491
Returns True if there is injection data which sqlmap could use for
24922492
technique specified
@@ -2497,6 +2497,9 @@ def isTechniqueAvailable(technique=None):
24972497
else:
24982498
return getTechniqueData(technique) is not None
24992499

2500+
def isInferenceAvailable():
2501+
return any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.BOOLEAN, PAYLOAD.TECHNIQUE.STACKED, PAYLOAD.TECHNIQUE.TIME))
2502+
25002503
def setOptimize():
25012504
#conf.predictOutput = True
25022505
conf.keepAlive = True

plugins/dbms/mssqlserver/enumeration.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from lib.core.common import arrayizeValue
1212
from lib.core.common import Backend
1313
from lib.core.common import getRange
14+
from lib.core.common import isInferenceAvailable
1415
from lib.core.common import isNoneValue
1516
from lib.core.common import isNumPosStrValue
1617
from lib.core.common import isTechniqueAvailable
@@ -85,7 +86,7 @@ def getTables(self):
8586

8687
rootQuery = queries[Backend.getIdentifiedDbms()].tables
8788

88-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
89+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
8990
for db in dbs:
9091
if conf.excludeSysDbs and db in self.excludeDbsList:
9192
infoMsg = "skipping system database '%s'" % db
@@ -102,7 +103,7 @@ def getTables(self):
102103
if not isNoneValue(value):
103104
kb.data.cachedTables[db] = arrayizeValue(value)
104105

105-
if not kb.data.cachedTables and not conf.direct:
106+
if not kb.data.cachedTables and isInferenceAvailable() and not conf.direct:
106107
for db in dbs:
107108
if conf.excludeSysDbs and db in self.excludeDbsList:
108109
infoMsg = "skipping system database '%s'" % db
@@ -190,7 +191,7 @@ def searchTable(self):
190191

191192
continue
192193

193-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
194+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
194195
query = rootQuery.inband.query % db
195196
query += tblQuery
196197
values = inject.getValue(query, blind=False)
@@ -283,7 +284,7 @@ def searchColumn(self):
283284

284285
continue
285286

286-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
287+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
287288
query = rootQuery.inband.query % (db, db, db, db, db, db)
288289
query += " AND %s" % colQuery.replace("[DB]", db)
289290
values = inject.getValue(query, blind=False)

plugins/dbms/oracle/enumeration.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from lib.core.agent import agent
1111
from lib.core.common import Backend
1212
from lib.core.common import getRange
13+
from lib.core.common import isInferenceAvailable
1314
from lib.core.common import isNoneValue
1415
from lib.core.common import isNumPosStrValue
1516
from lib.core.common import isTechniqueAvailable
@@ -44,7 +45,7 @@ def getRoles(self, query2=False):
4445
# Set containing the list of DBMS administrators
4546
areAdmins = set()
4647

47-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
48+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
4849
if query2:
4950
query = rootQuery.inband.query2
5051
condition = rootQuery.inband.condition2
@@ -90,7 +91,7 @@ def getRoles(self, query2=False):
9091
else:
9192
kb.data.cachedUsersRoles[user] = list(roles)
9293

93-
if not kb.data.cachedUsersRoles and not conf.direct:
94+
if not kb.data.cachedUsersRoles and isInferenceAvailable() and not conf.direct:
9495
conditionChar = "="
9596

9697
if conf.user:

plugins/dbms/sybase/enumeration.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def getUsers(self):
3636
randStr = randomStr()
3737
query = rootQuery.inband.query
3838

39-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
39+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
4040
blinds = [False, True]
4141
else:
4242
blinds = [True]
@@ -90,7 +90,7 @@ def getDbs(self):
9090
randStr = randomStr()
9191
query = rootQuery.inband.query
9292

93-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
93+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
9494
blinds = [False, True]
9595
else:
9696
blinds = [True]
@@ -130,7 +130,7 @@ def getTables(self, bruteForce=None):
130130
infoMsg += "%s: %s" % ("s" if len(dbs) > 1 else "", ", ".join(db for db in sorted(dbs)))
131131
logger.info(infoMsg)
132132

133-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
133+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
134134
blinds = [False, True]
135135
else:
136136
blinds = [True]
@@ -204,7 +204,7 @@ def getColumns(self, onlyColNames=False):
204204

205205
rootQuery = queries[Backend.getIdentifiedDbms()].columns
206206

207-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
207+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
208208
blinds = [False, True]
209209
else:
210210
blinds = [True]

plugins/generic/enumeration.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
from lib.core.common import getRange
2121
from lib.core.common import getCompiledRegex
2222
from lib.core.common import getUnicode
23+
from lib.core.common import isInferenceAvailable
2324
from lib.core.common import isNoneValue
2425
from lib.core.common import isNumPosStrValue
2526
from lib.core.common import isTechniqueAvailable
@@ -176,7 +177,7 @@ def getUsers(self):
176177
condition = ( Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")) )
177178
condition |= ( Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema )
178179

179-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
180+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
180181
if condition:
181182
query = rootQuery.inband.query2
182183
else:
@@ -186,7 +187,7 @@ def getUsers(self):
186187
if not isNoneValue(value):
187188
kb.data.cachedUsers = arrayizeValue(value)
188189

189-
if not kb.data.cachedUsers and not conf.direct:
190+
if not kb.data.cachedUsers and isInferenceAvailable() and not conf.direct:
190191
infoMsg = "fetching number of database users"
191192
logger.info(infoMsg)
192193

@@ -252,7 +253,7 @@ def getPasswordHashes(self):
252253

253254
users = filter(None, users)
254255

255-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
256+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
256257
if Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):
257258
query = rootQuery.inband.query2
258259
else:
@@ -293,7 +294,7 @@ def getPasswordHashes(self):
293294
else:
294295
kb.data.cachedUsersPasswords[user].append(password)
295296

296-
if not kb.data.cachedUsersPasswords and not conf.direct:
297+
if not kb.data.cachedUsersPasswords and isInferenceAvailable() and not conf.direct:
297298
if not len(users):
298299
users = self.getUsers()
299300

@@ -452,7 +453,7 @@ def getPrivileges(self, query2=False):
452453
# Set containing the list of DBMS administrators
453454
areAdmins = set()
454455

455-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
456+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
456457
if Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema:
457458
query = rootQuery.inband.query2
458459
condition = rootQuery.inband.condition2
@@ -537,7 +538,7 @@ def getPrivileges(self, query2=False):
537538
else:
538539
kb.data.cachedUsersPrivileges[user] = list(privileges)
539540

540-
if not kb.data.cachedUsersPrivileges and not conf.direct:
541+
if not kb.data.cachedUsersPrivileges and isInferenceAvailable() and not conf.direct:
541542
if Backend.isDbms(DBMS.MYSQL) and kb.data.has_information_schema:
542543
conditionChar = " LIKE "
543544
else:
@@ -736,7 +737,7 @@ def getDbs(self):
736737

737738
rootQuery = queries[Backend.getIdentifiedDbms()].dbs
738739

739-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
740+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
740741
if Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema:
741742
query = rootQuery.inband.query2
742743
else:
@@ -746,7 +747,7 @@ def getDbs(self):
746747
if not isNoneValue(value):
747748
kb.data.cachedDbs = arrayizeValue(value)
748749

749-
if not kb.data.cachedDbs and not conf.direct:
750+
if not kb.data.cachedDbs and isInferenceAvailable() and not conf.direct:
750751
infoMsg = "fetching number of databases"
751752
logger.info(infoMsg)
752753

@@ -870,7 +871,7 @@ def getTables(self, bruteForce=None):
870871

871872
rootQuery = queries[Backend.getIdentifiedDbms()].tables
872873

873-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
874+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
874875
query = rootQuery.inband.query
875876
condition = rootQuery.inband.condition if 'condition' in rootQuery.inband else None
876877

@@ -904,7 +905,7 @@ def getTables(self, bruteForce=None):
904905
else:
905906
kb.data.cachedTables[db].append(table)
906907

907-
if not kb.data.cachedTables and not conf.direct:
908+
if not kb.data.cachedTables and isInferenceAvailable() and not conf.direct:
908909
for db in dbs:
909910
if conf.excludeSysDbs and db in self.excludeDbsList:
910911
infoMsg = "skipping system database '%s'" % db
@@ -1087,7 +1088,7 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
10871088
rootQuery = queries[Backend.getIdentifiedDbms()].columns
10881089
condition = rootQuery.blind.condition if 'condition' in rootQuery.blind else None
10891090

1090-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
1091+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
10911092
for tbl in tblList:
10921093
if conf.db is not None and len(kb.data.cachedColumns) > 0 \
10931094
and conf.db in kb.data.cachedColumns and tbl in \
@@ -1156,7 +1157,7 @@ def getColumns(self, onlyColNames=False, colTuple=None, bruteForce=None):
11561157
table[safeSQLIdentificatorNaming(tbl, True)] = columns
11571158
kb.data.cachedColumns[safeSQLIdentificatorNaming(conf.db)] = table
11581159

1159-
if not kb.data.cachedColumns and not conf.direct:
1160+
if not kb.data.cachedColumns and isInferenceAvailable() and not conf.direct:
11601161
for tbl in tblList:
11611162
if conf.db is not None and len(kb.data.cachedColumns) > 0 \
11621163
and conf.db in kb.data.cachedColumns and tbl in \
@@ -1565,7 +1566,8 @@ def dumpTable(self, foundData=None):
15651566
or not kb.data.cachedColumns[safeSQLIdentificatorNaming(conf.db)][safeSQLIdentificatorNaming(tbl, True)]:
15661567
warnMsg = "unable to enumerate the columns for table "
15671568
warnMsg += "'%s' on database" % unsafeSQLIdentificatorNaming(tbl)
1568-
warnMsg += " '%s', skipping" % unsafeSQLIdentificatorNaming(conf.db)
1569+
warnMsg += " '%s'" % unsafeSQLIdentificatorNaming(conf.db)
1570+
warnMsg += ", skipping" if len(tblList) > 1 else ""
15691571
logger.warn(warnMsg)
15701572

15711573
continue
@@ -1660,7 +1662,7 @@ def dumpTable(self, foundData=None):
16601662

16611663
index += 1
16621664

1663-
if not kb.data.dumpedTable and not conf.direct:
1665+
if not kb.data.dumpedTable and isInferenceAvailable() and not conf.direct:
16641666
infoMsg = "fetching number of "
16651667
if conf.col:
16661668
infoMsg += "column(s) '%s' " % colString
@@ -1924,7 +1926,7 @@ def searchDb(self):
19241926
dbQuery = "%s%s" % (dbCond, dbCondParam)
19251927
dbQuery = dbQuery % unsafeSQLIdentificatorNaming(db)
19261928

1927-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
1929+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
19281930
if Backend.isDbms(DBMS.MYSQL) and not kb.data.has_information_schema:
19291931
query = rootQuery.inband.query2
19301932
else:
@@ -2044,7 +2046,7 @@ def searchTable(self):
20442046
tblQuery = "%s%s" % (tblCond, tblCondParam)
20452047
tblQuery = tblQuery % tbl
20462048

2047-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
2049+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
20482050
query = rootQuery.inband.query
20492051
query += tblQuery
20502052
query += whereDbsQuery
@@ -2213,7 +2215,7 @@ def searchColumn(self):
22132215
colQuery = "%s%s" % (colCond, colCondParam)
22142216
colQuery = colQuery % unsafeSQLIdentificatorNaming(column)
22152217

2216-
if isTechniqueAvailable(PAYLOAD.TECHNIQUE.UNION) or isTechniqueAvailable(PAYLOAD.TECHNIQUE.ERROR) or conf.direct:
2218+
if any(isTechniqueAvailable(_) for _ in (PAYLOAD.TECHNIQUE.UNION, PAYLOAD.TECHNIQUE.ERROR)) or conf.direct:
22172219
if not all((conf.db, conf.tbl)):
22182220
query = rootQuery.inband.query
22192221
query += colQuery

0 commit comments

Comments
 (0)