More code refactoring of Backend class methods used

This commit is contained in:
Bernardo Damele
2011-04-30 14:54:29 +00:00
parent 2f2758b033
commit 9a4ae7d9e2
16 changed files with 146 additions and 146 deletions

View File

@@ -282,14 +282,14 @@ class Agent:
# SQLite version 2 does not support neither CAST() nor IFNULL(),
# introduced only in SQLite version 3
if Backend.getIdentifiedDbms() == DBMS.SQLITE:
if Backend.isDbms(DBMS.SQLITE):
return field
if field.startswith("(CASE"):
nulledCastedField = field
else:
nulledCastedField = queries[Backend.getIdentifiedDbms()].cast.query % field
if Backend.getIdentifiedDbms() == DBMS.ACCESS:
if Backend.isDbms(DBMS.ACCESS):
nulledCastedField = queries[Backend.getIdentifiedDbms()].isnull.query % (nulledCastedField, nulledCastedField)
else:
nulledCastedField = queries[Backend.getIdentifiedDbms()].isnull.query % nulledCastedField
@@ -401,7 +401,7 @@ class Agent:
def simpleConcatQuery(self, query1, query2):
concatenatedQuery = ""
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
concatenatedQuery = "CONCAT(%s,%s)" % (query1, query2)
elif Backend.getIdentifiedDbms() in (DBMS.PGSQL, DBMS.ORACLE, DBMS.SQLITE):
@@ -447,7 +447,7 @@ class Agent:
else:
return query
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
if fieldsExists:
concatenatedQuery = concatenatedQuery.replace("SELECT ", "CONCAT('%s'," % kb.misc.start, 1)
concatenatedQuery += ",'%s')" % kb.misc.stop
@@ -540,7 +540,7 @@ class Agent:
if query.startswith("TOP"):
# TOP enumeration on DBMS.MSSQL is too specific and it has to go into it's own brackets
# because those NULLs cause problems with ORDER BY clause
if Backend.getIdentifiedDbms() == DBMS.MSSQL:
if Backend.isDbms(DBMS.MSSQL):
inbandQuery += ",".join(map(lambda x: char if x != position else '(SELECT %s)' % query, range(0, count)))
inbandQuery = self.suffixQuery(inbandQuery, comment, suffix)
return inbandQuery
@@ -633,11 +633,11 @@ class Agent:
limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num, 1)
limitedQuery += " %s" % limitStr
elif Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
elif Backend.isDbms(DBMS.FIREBIRD):
limitStr = queries[Backend.getIdentifiedDbms()].limit.query % (num+1, num+1)
limitedQuery += " %s" % limitStr
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
if " ORDER BY " in limitedQuery and "(SELECT " in limitedQuery:
orderBy = limitedQuery[limitedQuery.index(" ORDER BY "):]
limitedQuery = limitedQuery[:limitedQuery.index(" ORDER BY ")]
@@ -650,7 +650,7 @@ class Agent:
limitedQuery = limitedQuery % fromFrom
limitedQuery += "=%d" % (num + 1)
elif Backend.getIdentifiedDbms() == DBMS.MSSQL:
elif Backend.isDbms(DBMS.MSSQL):
forgeNotIn = True
if " ORDER BY " in limitedQuery:

View File

@@ -869,7 +869,7 @@ def parsePasswordHash(password):
if not password or password == " ":
password = "NULL"
if Backend.getIdentifiedDbms() == DBMS.MSSQL and password != "NULL" and isHexEncodedString(password):
if Backend.isDbms(DBMS.MSSQL) and password != "NULL" and isHexEncodedString(password):
hexPassword = password
password = "%s\n" % hexPassword
password += "%sheader: %s\n" % (blank, hexPassword[:6])
@@ -1194,11 +1194,11 @@ def getDelayQuery(andCond=False):
banVer = kb.bannerFp["dbmsVersion"] if 'dbmsVersion' in kb.bannerFp else None
if banVer is None or (Backend.getIdentifiedDbms() == DBMS.MYSQL and banVer >= "5.0.12") or (Backend.getIdentifiedDbms() == DBMS.PGSQL and banVer >= "8.2"):
if banVer is None or (Backend.isDbms(DBMS.MYSQL) and banVer >= "5.0.12") or (Backend.isDbms(DBMS.PGSQL) and banVer >= "8.2"):
query = queries[Backend.getIdentifiedDbms()].timedelay.query % conf.timeSec
else:
query = queries[Backend.getIdentifiedDbms()].timedelay.query2 % conf.timeSec
elif Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
elif Backend.isDbms(DBMS.FIREBIRD):
query = queries[Backend.getIdentifiedDbms()].timedelay.query
else:
query = queries[Backend.getIdentifiedDbms()].timedelay.query % conf.timeSec
@@ -1206,7 +1206,7 @@ def getDelayQuery(andCond=False):
if andCond:
if Backend.getIdentifiedDbms() in ( DBMS.MYSQL, DBMS.SQLITE ):
query = query.replace("SELECT ", "")
elif Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
elif Backend.isDbms(DBMS.FIREBIRD):
query = "(%s)>0" % query
return query

View File

@@ -104,9 +104,9 @@ class Dump:
self.string("current user", data)
def currentDb(self,data):
if Backend.getIdentifiedDbms() == DBMS.MAXDB:
if Backend.isDbms(DBMS.MAXDB):
self.string("current database (no practical usage on %s)" % Backend.getIdentifiedDbms(), data)
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
self.string("current schema (equivalent to database on %s)" % Backend.getIdentifiedDbms(), data)
else:
self.string("current database", data)

View File

@@ -97,13 +97,13 @@ def bannerParser(banner):
xmlfile = None
if Backend.getIdentifiedDbms() == DBMS.MSSQL:
if Backend.isDbms(DBMS.MSSQL):
xmlfile = paths.MSSQL_XML
elif Backend.getIdentifiedDbms() == DBMS.MYSQL:
elif Backend.isDbms(DBMS.MYSQL):
xmlfile = paths.MYSQL_XML
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
xmlfile = paths.ORACLE_XML
elif Backend.getIdentifiedDbms() == DBMS.PGSQL:
elif Backend.isDbms(DBMS.PGSQL):
xmlfile = paths.PGSQL_XML
if not xmlfile:
@@ -111,7 +111,7 @@ def bannerParser(banner):
checkFile(xmlfile)
if Backend.getIdentifiedDbms() == DBMS.MSSQL:
if Backend.isDbms(DBMS.MSSQL):
handler = MSSQLBannerHandler(banner, kb.bannerFp)
parseXmlFile(xmlfile, handler)

View File

@@ -27,7 +27,7 @@ def direct(query, content=True):
select = True
query = agent.payloadDirect(query)
if Backend.getIdentifiedDbms() == DBMS.ORACLE and query.startswith("SELECT ") and " FROM " not in query:
if Backend.isDbms(DBMS.ORACLE) and query.startswith("SELECT ") and " FROM " not in query:
query = "%s FROM DUAL" % query
for sqlTitle, sqlStatements in SQL_STATEMENTS.items():

View File

@@ -141,7 +141,7 @@ def __goInferenceProxy(expression, fromUser=False, expected=None, batch=False, r
_, _, _, _, _, expressionFieldsList, expressionFields, _ = agent.getFields(expression)
rdbRegExp = re.search("RDB\$GET_CONTEXT\([^)]+\)", expression, re.I)
if rdbRegExp and Backend.getIdentifiedDbms() == DBMS.FIREBIRD:
if rdbRegExp and Backend.isDbms(DBMS.FIREBIRD):
expressionFieldsList = [expressionFields]
if len(expressionFieldsList) > 1:
@@ -189,7 +189,7 @@ def __goInferenceProxy(expression, fromUser=False, expected=None, batch=False, r
stopLimit = int(topLimit.group(1))
limitCond = int(stopLimit) > 1
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
limitCond = False
else:
limitCond = True

View File

@@ -45,7 +45,7 @@ class Abstraction(Web, UDF, xp_cmdshell):
elif Backend.getIdentifiedDbms() in ( DBMS.MYSQL, DBMS.PGSQL ):
self.udfExecCmd(cmd, silent=silent)
elif Backend.getIdentifiedDbms() == DBMS.MSSQL:
elif Backend.isDbms(DBMS.MSSQL):
self.xpCmdshellExecCmd(cmd, silent=silent)
else:
@@ -59,7 +59,7 @@ class Abstraction(Web, UDF, xp_cmdshell):
elif Backend.getIdentifiedDbms() in ( DBMS.MYSQL, DBMS.PGSQL ):
return self.udfEvalCmd(cmd, first, last)
elif Backend.getIdentifiedDbms() == DBMS.MSSQL:
elif Backend.isDbms(DBMS.MSSQL):
return self.xpCmdshellEvalCmd(cmd, first, last)
else:
@@ -100,7 +100,7 @@ class Abstraction(Web, UDF, xp_cmdshell):
infoMsg += "command execution"
logger.info(infoMsg)
elif Backend.getIdentifiedDbms() == DBMS.MSSQL:
elif Backend.isDbms(DBMS.MSSQL):
infoMsg = "going to use xp_cmdshell extended procedure for "
infoMsg += "operating system command execution"
logger.info(infoMsg)
@@ -154,7 +154,7 @@ class Abstraction(Web, UDF, xp_cmdshell):
if Backend.getIdentifiedDbms() in ( DBMS.MYSQL, DBMS.PGSQL ):
self.udfInjectSys()
elif Backend.getIdentifiedDbms() == DBMS.MSSQL:
elif Backend.isDbms(DBMS.MSSQL):
if mandatory:
self.xpCmdshellInit()
else:

View File

@@ -189,13 +189,13 @@ class Metasploit:
if __payloadStr == "windows/vncinject":
choose = False
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
debugMsg = "by default MySQL on Windows runs as SYSTEM "
debugMsg += "user, it is likely that the the VNC "
debugMsg += "injection will be successful"
logger.debug(debugMsg)
elif Backend.getIdentifiedDbms() == DBMS.PGSQL:
elif Backend.isDbms(DBMS.PGSQL):
choose = True
warnMsg = "by default PostgreSQL on Windows runs as "
@@ -203,7 +203,7 @@ class Metasploit:
warnMsg += "injection will be successful"
logger.warn(warnMsg)
elif Backend.getIdentifiedDbms() == DBMS.MSSQL and Backend.isVersionWithin(("2005", "2008")):
elif Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):
choose = True
warnMsg = "it is unlikely that the VNC injection will be "
@@ -232,12 +232,12 @@ class Metasploit:
break
elif choice == "1":
if Backend.getIdentifiedDbms() == DBMS.PGSQL:
if Backend.isDbms(DBMS.PGSQL):
logger.warn("beware that the VNC injection might not work")
break
elif Backend.getIdentifiedDbms() == DBMS.MSSQL and Backend.isVersionWithin(("2005", "2008")):
elif Backend.isDbms(DBMS.MSSQL) and Backend.isVersionWithin(("2005", "2008")):
break
elif not choice.isdigit():

View File

@@ -144,9 +144,9 @@ class UDF:
if udf in self.udfToCreate and udf not in self.createdUdf:
self.udfCreateFromSharedLib(udf, inpRet)
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
supportTblType = "longtext"
elif Backend.getIdentifiedDbms() == DBMS.PGSQL:
elif Backend.isDbms(DBMS.PGSQL):
supportTblType = "text"
self.udfCreateSupportTbl(supportTblType)
@@ -237,9 +237,9 @@ class UDF:
else:
logger.warn("you need to specify the name of the UDF")
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
defaultType = "string"
elif Backend.getIdentifiedDbms() == DBMS.PGSQL:
elif Backend.isDbms(DBMS.PGSQL):
defaultType = "text"
self.udfs[udfName]["input"] = []

View File

@@ -57,7 +57,7 @@ def __oneShotErrorUse(expression, field):
nulledCastedField = agent.nullAndCastField(field)
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
nulledCastedField = queries[DBMS.MYSQL].substring.query % (nulledCastedField, offset, MYSQL_ERROR_CHUNK_LENGTH)
# Forge the error-based SQL injection request
@@ -101,7 +101,7 @@ def __oneShotErrorUse(expression, field):
if isinstance(output, basestring):
output = htmlunescape(output).replace("<br>", "\n")
if Backend.getIdentifiedDbms() == DBMS.MYSQL:
if Backend.isDbms(DBMS.MYSQL):
if offset == 1:
retVal = output
else:
@@ -243,7 +243,7 @@ def errorUse(expression, expected=None, resumeValue=True, dump=False):
stopLimit = int(topLimit.group(1))
limitCond = int(stopLimit) > 1
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
limitCond = False
else:
limitCond = True

View File

@@ -184,7 +184,7 @@ def unionUse(expression, unpack=True, dump=False):
stopLimit = int(topLimit.group(1))
limitCond = int(stopLimit) > 1
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
limitCond = False
else:
limitCond = True
@@ -256,7 +256,7 @@ def unionUse(expression, unpack=True, dump=False):
for num in xrange(startLimit, stopLimit):
if Backend.getIdentifiedDbms() in (DBMS.MSSQL, DBMS.SYBASE):
field = expressionFieldsList[0]
elif Backend.getIdentifiedDbms() == DBMS.ORACLE:
elif Backend.isDbms(DBMS.ORACLE):
field = expressionFieldsList
else:
field = None

View File

@@ -299,9 +299,9 @@ def hashRecognition(value):
if isinstance(value, basestring):
for name, regex in getPublicTypeMembers(HASH):
# Hashes for Oracle and old MySQL look the same hence these checks
if Backend.getIdentifiedDbms() == DBMS.ORACLE and regex == HASH.MYSQL_OLD:
if Backend.isDbms(DBMS.ORACLE) and regex == HASH.MYSQL_OLD:
continue
elif Backend.getIdentifiedDbms() == DBMS.MYSQL and regex == HASH.ORACLE_OLD:
elif Backend.isDbms(DBMS.MYSQL) and regex == HASH.ORACLE_OLD:
continue
elif regex == HASH.CRYPT_GENERIC:
if any([getCompiledRegex(GENERAL_IP_ADDRESS_REGEX).match(value), value.lower() == value, value.upper() == value, value.isdigit()]):