Path: blob/master/plugins/dbms/hsqldb/connector.py
2992 views
#!/usr/bin/env python12"""3Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)4See the file 'LICENSE' for copying permission5"""67try:8import jaydebeapi9import jpype10except:11pass1213import logging1415from lib.core.common import checkFile16from lib.core.common import getSafeExString17from lib.core.common import readInput18from lib.core.data import conf19from lib.core.data import logger20from lib.core.exception import SqlmapConnectionException21from plugins.generic.connector import Connector as GenericConnector2223class Connector(GenericConnector):24"""25Homepage: https://pypi.python.org/pypi/JayDeBeApi/ & http://jpype.sourceforge.net/26User guide: https://pypi.python.org/pypi/JayDeBeApi/#usage & http://jpype.sourceforge.net/doc/user-guide/userguide.html27API: -28Debian package: -29License: LGPL & Apache License 2.030"""3132def connect(self):33self.initConnection()34try:35msg = "please enter the location of 'hsqldb.jar'? "36jar = readInput(msg)37checkFile(jar)38args = "-Djava.class.path=%s" % jar39jvm_path = jpype.getDefaultJVMPath()40jpype.startJVM(jvm_path, args)41except Exception as ex:42raise SqlmapConnectionException(getSafeExString(ex))4344try:45driver = 'org.hsqldb.jdbc.JDBCDriver'46connection_string = 'jdbc:hsqldb:mem:.' # 'jdbc:hsqldb:hsql://%s/%s' % (self.hostname, self.db)47self.connector = jaydebeapi.connect(driver, connection_string, str(self.user), str(self.password))48except Exception as ex:49raise SqlmapConnectionException(getSafeExString(ex))5051self.initCursor()52self.printConnected()5354def fetchall(self):55try:56return self.cursor.fetchall()57except Exception as ex:58logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))59return None6061def execute(self, query):62retVal = False6364try:65self.cursor.execute(query)66retVal = True67except Exception as ex:68logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))6970self.connector.commit()7172return retVal7374def select(self, query):75retVal = None7677upper_query = query.upper()7879if query and not (upper_query.startswith("SELECT ") or upper_query.startswith("VALUES ")):80query = "VALUES %s" % query8182if query and upper_query.startswith("SELECT ") and " FROM " not in upper_query:83query = "%s FROM (VALUES(0))" % query8485self.cursor.execute(query)86retVal = self.cursor.fetchall()8788return retVal899091