Path: blob/master/plugins/dbms/hsqldb/fingerprint.py
2992 views
#!/usr/bin/env python12"""3Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)4See the file 'LICENSE' for copying permission5"""67import re89from lib.core.common import Backend10from lib.core.common import Format11from lib.core.common import unArrayizeValue12from lib.core.data import conf13from lib.core.data import kb14from lib.core.data import logger15from lib.core.enums import DBMS16from lib.core.session import setDbms17from lib.core.settings import HSQLDB_ALIASES18from lib.request import inject19from plugins.generic.fingerprint import Fingerprint as GenericFingerprint2021class Fingerprint(GenericFingerprint):22def __init__(self):23GenericFingerprint.__init__(self, DBMS.HSQLDB)2425def getFingerprint(self):26value = ""27wsOsFp = Format.getOs("web server", kb.headersFp)2829if wsOsFp and not conf.api:30value += "%s\n" % wsOsFp3132if kb.data.banner:33dbmsOsFp = Format.getOs("back-end DBMS", kb.bannerFp)3435if dbmsOsFp and not conf.api:36value += "%s\n" % dbmsOsFp3738value += "back-end DBMS: "39actVer = Format.getDbms()4041if not conf.extensiveFp:42value += actVer43return value4445blank = " " * 1546value += "active fingerprint: %s" % actVer4748if kb.bannerFp:49banVer = kb.bannerFp.get("dbmsVersion")5051if banVer:52if re.search(r"-log$", kb.data.banner or ""):53banVer += ", logging enabled"5455banVer = Format.getDbms([banVer])56value += "\n%sbanner parsing fingerprint: %s" % (blank, banVer)5758htmlErrorFp = Format.getErrorParsedDBMSes()5960if htmlErrorFp:61value += "\n%shtml error message fingerprint: %s" % (blank, htmlErrorFp)6263return value6465def checkDbms(self):66"""67References for fingerprint:68DATABASE_VERSION()69version 2.2.6 added two-arg REPLACE functio REPLACE('a','a') compared to REPLACE('a','a','d')70version 2.2.5 added SYSTIMESTAMP function71version 2.2.3 added REGEXPR_SUBSTRING and REGEXPR_SUBSTRING_ARRAY functions72version 2.2.0 added support for ROWNUM() function73version 2.1.0 added MEDIAN aggregate function74version < 2.0.1 added support for datetime ROUND and TRUNC functions75version 2.0.0 added VALUES support76version 1.8.0.4 Added org.hsqldbdb.Library function, getDatabaseFullProductVersion to return the77full version string, including the 4th digit (e.g 1.8.0.4).78version 1.7.2 CASE statements added and INFORMATION_SCHEMA7980"""8182if not conf.extensiveFp and Backend.isDbmsWithin(HSQLDB_ALIASES):83setDbms("%s %s" % (DBMS.HSQLDB, Backend.getVersion()))8485if Backend.isVersionGreaterOrEqualThan("1.7.2"):86kb.data.has_information_schema = True8788self.getBanner()8990return True9192infoMsg = "testing %s" % DBMS.HSQLDB93logger.info(infoMsg)9495result = inject.checkBooleanExpression("CASEWHEN(1=1,1,0)=1")9697if result:98infoMsg = "confirming %s" % DBMS.HSQLDB99logger.info(infoMsg)100101result = inject.checkBooleanExpression("LEAST(ROUNDMAGIC(PI()),3)=3")102103if not result:104warnMsg = "the back-end DBMS is not %s" % DBMS.HSQLDB105logger.warning(warnMsg)106107return False108else:109result = inject.checkBooleanExpression("ZERO() IS 0") # Note: check for H2 DBMS (sharing majority of same functions)110if result:111warnMsg = "the back-end DBMS is not %s" % DBMS.HSQLDB112logger.warning(warnMsg)113114return False115116kb.data.has_information_schema = True117Backend.setVersion(">= 1.7.2")118setDbms("%s 1.7.2" % DBMS.HSQLDB)119120banner = self.getBanner()121if banner:122Backend.setVersion("= %s" % banner)123else:124if inject.checkBooleanExpression("(SELECT [RANDNUM] FROM (VALUES(0)))=[RANDNUM]"):125Backend.setVersionList([">= 2.0.0", "< 2.3.0"])126else:127banner = unArrayizeValue(inject.getValue("\"org.hsqldbdb.Library.getDatabaseFullProductVersion\"()", safeCharEncode=True))128if banner:129Backend.setVersion("= %s" % banner)130else:131Backend.setVersionList([">= 1.7.2", "< 1.8.0"])132133return True134else:135warnMsg = "the back-end DBMS is not %s" % DBMS.HSQLDB136logger.warning(warnMsg)137138dbgMsg = "...or version is < 1.7.2"139logger.debug(dbgMsg)140141return False142143def getHostname(self):144warnMsg = "on HSQLDB it is not possible to enumerate the hostname"145logger.warning(warnMsg)146147def checkDbmsOs(self, detailed=False):148if Backend.getOs():149infoMsg = "the back-end DBMS operating system is %s" % Backend.getOs()150logger.info(infoMsg)151else:152self.userChooseDbmsOs()153154155