From e4e9b11b79fdc78a44e386fc85d18661a6f4e8a6 Mon Sep 17 00:00:00 2001 From: Bernardo Damele Date: Fri, 14 Jan 2011 12:47:07 +0000 Subject: [PATCH] Minor code refactoring and adjustments - kb.dbms is needed in fingerprint.py, not getIdentifiedDBMS because when checkDbms() method is called, it's within the fingerprint phase and at that stage, getIdentifiedDBMS() would always return kb.misc.fpDbms. --- lib/controller/handler.py | 7 +++---- plugins/dbms/access/fingerprint.py | 6 ++---- plugins/dbms/firebird/fingerprint.py | 4 +++- plugins/dbms/maxdb/fingerprint.py | 6 ++---- plugins/dbms/mssqlserver/fingerprint.py | 8 +++----- plugins/dbms/mysql/fingerprint.py | 6 ++---- plugins/dbms/oracle/fingerprint.py | 6 ++---- plugins/dbms/postgresql/fingerprint.py | 6 ++---- plugins/dbms/sqlite/fingerprint.py | 6 ++---- plugins/dbms/sybase/fingerprint.py | 8 +++----- plugins/generic/enumeration.py | 3 --- 11 files changed, 24 insertions(+), 42 deletions(-) diff --git a/lib/controller/handler.py b/lib/controller/handler.py index 51e8efc6c..a4dae69d1 100644 --- a/lib/controller/handler.py +++ b/lib/controller/handler.py @@ -94,11 +94,10 @@ def setHandler(): conf.dbmsConnector.connect() if handler.checkDbms(): - if not conf.dbms or conf.dbms in dbmsAliases: - kb.dbmsDetected = True - conf.dbmsHandler = handler + kb.dbmsDetected = True + conf.dbmsHandler = handler - break + break else: conf.dbmsConnector = None diff --git a/plugins/dbms/access/fingerprint.py b/plugins/dbms/access/fingerprint.py index 15d6389c7..0b50bad6f 100644 --- a/plugins/dbms/access/fingerprint.py +++ b/plugins/dbms/access/fingerprint.py @@ -14,7 +14,6 @@ from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getCurrentThreadData from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.common import randomInt from lib.core.common import randomStr from lib.core.common import wasLastRequestDBMSError @@ -149,11 +148,10 @@ class Fingerprint(GenericFingerprint): return value def checkDbms(self): - if (getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in ACCESS_ALIASES) or conf.dbms in ACCESS_ALIASES: + if not conf.extensiveFp and (kb.dbms is not None and kb.dbms.lower() in ACCESS_ALIASES) or conf.dbms in ACCESS_ALIASES: setDbms(DBMS.ACCESS) - if not conf.extensiveFp: - return True + return True logMsg = "testing Microsoft Access" logger.info(logMsg) diff --git a/plugins/dbms/firebird/fingerprint.py b/plugins/dbms/firebird/fingerprint.py index 1882c2273..99965adc4 100644 --- a/plugins/dbms/firebird/fingerprint.py +++ b/plugins/dbms/firebird/fingerprint.py @@ -98,13 +98,15 @@ class Fingerprint(GenericFingerprint): def __dialectCheck(self): retVal = None + if getIdentifiedDBMS(): result = inject.checkBooleanExpression("EXISTS(SELECT CURRENT_DATE FROM RDB$DATABASE)") retVal = "dialect 3" if result else "dialect 1" + return retVal def checkDbms(self): - if (getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in FIREBIRD_ALIASES) or conf.dbms in FIREBIRD_ALIASES: + if not conf.extensiveFp and (kb.dbms is not None and kb.dbms.lower() in FIREBIRD_ALIASES) or conf.dbms in FIREBIRD_ALIASES: setDbms(DBMS.FIREBIRD) self.getBanner() diff --git a/plugins/dbms/maxdb/fingerprint.py b/plugins/dbms/maxdb/fingerprint.py index 6d05b250c..1b57dc485 100644 --- a/plugins/dbms/maxdb/fingerprint.py +++ b/plugins/dbms/maxdb/fingerprint.py @@ -13,7 +13,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.common import randomInt from lib.core.common import randomRange from lib.core.data import conf @@ -101,13 +100,12 @@ class Fingerprint(GenericFingerprint): return value def checkDbms(self): - if (getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in MAXDB_ALIASES) or conf.dbms in MAXDB_ALIASES: + if not conf.extensiveFp and (kb.dbms is not None and kb.dbms.lower() in MAXDB_ALIASES) or conf.dbms in MAXDB_ALIASES: setDbms(DBMS.MAXDB) self.getBanner() - if not conf.extensiveFp: - return True + return True logMsg = "testing SAP MaxDB" logger.info(logMsg) diff --git a/plugins/dbms/mssqlserver/fingerprint.py b/plugins/dbms/mssqlserver/fingerprint.py index 2449831c5..160f8b401 100644 --- a/plugins/dbms/mssqlserver/fingerprint.py +++ b/plugins/dbms/mssqlserver/fingerprint.py @@ -11,7 +11,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.common import getUnicode from lib.core.common import randomInt from lib.core.data import conf @@ -73,17 +72,16 @@ class Fingerprint(GenericFingerprint): return value def checkDbms(self): - if ((getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in MSSQL_ALIASES) \ + if not conf.extensiveFp and ((kb.dbms is not None and kb.dbms.lower() in MSSQL_ALIASES) \ or conf.dbms in MSSQL_ALIASES) and kb.dbmsVersion and \ kb.dbmsVersion[0].isdigit(): setDbms("%s %s" % (DBMS.MSSQL, kb.dbmsVersion[0])) self.getBanner() - if not conf.extensiveFp: - kb.os = "Windows" + kb.os = "Windows" - return True + return True infoMsg = "testing Microsoft SQL Server" logger.info(infoMsg) diff --git a/plugins/dbms/mysql/fingerprint.py b/plugins/dbms/mysql/fingerprint.py index ff7707c7e..a9e5e6adc 100644 --- a/plugins/dbms/mysql/fingerprint.py +++ b/plugins/dbms/mysql/fingerprint.py @@ -13,7 +13,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.common import getUnicode from lib.core.common import randomInt from lib.core.data import conf @@ -152,7 +151,7 @@ class Fingerprint(GenericFingerprint): * http://dev.mysql.com/doc/refman/6.0/en/news-6-0-x.html (manual has been withdrawn) """ - if ((getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in MYSQL_ALIASES) \ + if not conf.extensiveFp and ((kb.dbms is not None and kb.dbms.lower() in MYSQL_ALIASES) \ or conf.dbms in MYSQL_ALIASES) and kb.dbmsVersion and \ kb.dbmsVersion[0] != UNKNOWN_DBMS_VERSION: kb.dbmsVersion[0] = kb.dbmsVersion[0].replace(">", "") @@ -166,8 +165,7 @@ class Fingerprint(GenericFingerprint): self.getBanner() - if not conf.extensiveFp: - return True + return True infoMsg = "testing MySQL" logger.info(infoMsg) diff --git a/plugins/dbms/oracle/fingerprint.py b/plugins/dbms/oracle/fingerprint.py index 49f150f2b..0e5466a0e 100644 --- a/plugins/dbms/oracle/fingerprint.py +++ b/plugins/dbms/oracle/fingerprint.py @@ -13,7 +13,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger @@ -65,13 +64,12 @@ class Fingerprint(GenericFingerprint): return value def checkDbms(self): - if (getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in ORACLE_ALIASES) or conf.dbms in ORACLE_ALIASES: + if not conf.extensiveFp and (kb.dbms is not None and kb.dbms.lower() in ORACLE_ALIASES) or conf.dbms in ORACLE_ALIASES: setDbms(DBMS.ORACLE) self.getBanner() - if not conf.extensiveFp: - return True + return True logMsg = "testing Oracle" logger.info(logMsg) diff --git a/plugins/dbms/postgresql/fingerprint.py b/plugins/dbms/postgresql/fingerprint.py index 8d764aca7..ae8ad8257 100644 --- a/plugins/dbms/postgresql/fingerprint.py +++ b/plugins/dbms/postgresql/fingerprint.py @@ -13,7 +13,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.common import getUnicode from lib.core.common import randomInt from lib.core.data import conf @@ -74,13 +73,12 @@ class Fingerprint(GenericFingerprint): * http://www.postgresql.org/docs/8.4/interactive/release.html (up to 8.4.2) """ - if (getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in PGSQL_ALIASES) or conf.dbms in PGSQL_ALIASES: + if not conf.extensiveFp and (kb.dbms is not None and kb.dbms.lower() in PGSQL_ALIASES) or conf.dbms in PGSQL_ALIASES: setDbms(DBMS.PGSQL) self.getBanner() - if not conf.extensiveFp: - return True + return True infoMsg = "testing PostgreSQL" logger.info(infoMsg) diff --git a/plugins/dbms/sqlite/fingerprint.py b/plugins/dbms/sqlite/fingerprint.py index a65e86cbb..45fffc158 100644 --- a/plugins/dbms/sqlite/fingerprint.py +++ b/plugins/dbms/sqlite/fingerprint.py @@ -11,7 +11,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.data import conf from lib.core.data import kb from lib.core.data import logger @@ -71,13 +70,12 @@ class Fingerprint(GenericFingerprint): * http://www.sqlite.org/cvstrac/wiki?p=LoadableExtensions """ - if (getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in SQLITE_ALIASES) or conf.dbms in SQLITE_ALIASES: + if not conf.extensiveFp and (kb.dbms is not None and kb.dbms.lower() in SQLITE_ALIASES) or conf.dbms in SQLITE_ALIASES: setDbms(DBMS.SQLITE) self.getBanner() - if not conf.extensiveFp: - return True + return True logMsg = "testing SQLite" logger.info(logMsg) diff --git a/plugins/dbms/sybase/fingerprint.py b/plugins/dbms/sybase/fingerprint.py index 3ec8ef69a..28051357b 100644 --- a/plugins/dbms/sybase/fingerprint.py +++ b/plugins/dbms/sybase/fingerprint.py @@ -11,7 +11,6 @@ from lib.core.agent import agent from lib.core.common import formatDBMSfp from lib.core.common import formatFingerprint from lib.core.common import getErrorParsedDBMSesFormatted -from lib.core.common import getIdentifiedDBMS from lib.core.common import randomInt from lib.core.data import conf from lib.core.data import kb @@ -64,17 +63,16 @@ class Fingerprint(GenericFingerprint): return value def checkDbms(self): - if ((getIdentifiedDBMS() is not None and getIdentifiedDBMS().lower() in SYBASE_ALIASES) \ + if not conf.extensiveFp and ((kb.dbms is not None and kb.dbms.lower() in SYBASE_ALIASES) \ or conf.dbms in SYBASE_ALIASES) and kb.dbmsVersion and \ kb.dbmsVersion[0].isdigit(): setDbms("%s %s" % (DBMS.SYBASE, kb.dbmsVersion[0])) self.getBanner() - if not conf.extensiveFp: - kb.os = "Windows" + kb.os = "Windows" - return True + return True infoMsg = "testing Sybase" logger.info(infoMsg) diff --git a/plugins/generic/enumeration.py b/plugins/generic/enumeration.py index 3bebea5ee..2c9aa3511 100644 --- a/plugins/generic/enumeration.py +++ b/plugins/generic/enumeration.py @@ -81,9 +81,6 @@ class Enumeration: return if kb.data.banner is None: - # TODO: is this assignement an ugly hack? - kb.dbmsDetected = True - infoMsg = "fetching banner" logger.info(infoMsg)