sqlmap/plugins/dbms/hsqldb/connector.py

90 lines
2.7 KiB
Python
Raw Normal View History

2019-05-08 13:47:52 +03:00
#!/usr/bin/env python
2013-06-24 17:34:25 +04:00
"""
2020-01-01 15:25:15 +03:00
Copyright (c) 2006-2020 sqlmap developers (http://sqlmap.org/)
2017-10-11 15:50:46 +03:00
See the file 'LICENSE' for copying permission
2013-06-24 17:34:25 +04:00
"""
try:
2013-07-01 14:50:03 +04:00
import jaydebeapi
2013-06-24 17:34:25 +04:00
import jpype
2017-09-04 18:05:48 +03:00
except:
2013-06-24 17:34:25 +04:00
pass
import logging
2013-07-01 14:50:03 +04:00
from lib.core.common import checkFile
2019-01-22 03:20:27 +03:00
from lib.core.common import getSafeExString
2013-07-01 14:50:03 +04:00
from lib.core.common import readInput
2013-06-24 17:34:25 +04:00
from lib.core.data import conf
from lib.core.data import logger
from lib.core.exception import SqlmapConnectionException
from plugins.generic.connector import Connector as GenericConnector
class Connector(GenericConnector):
"""
2013-07-01 14:50:03 +04:00
Homepage: https://pypi.python.org/pypi/JayDeBeApi/ & http://jpype.sourceforge.net/
User guide: https://pypi.python.org/pypi/JayDeBeApi/#usage & http://jpype.sourceforge.net/doc/user-guide/userguide.html
API: -
Debian package: -
License: LGPL & Apache License 2.0
2013-06-24 17:34:25 +04:00
"""
def connect(self):
self.initConnection()
try:
2013-07-01 14:50:03 +04:00
msg = "what's the location of 'hsqldb.jar'? "
jar = readInput(msg)
checkFile(jar)
args = "-Djava.class.path=%s" % jar
2013-06-24 17:34:25 +04:00
jvm_path = jpype.getDefaultJVMPath()
jpype.startJVM(jvm_path, args)
2019-01-22 03:20:27 +03:00
except Exception as ex:
raise SqlmapConnectionException(getSafeExString(ex))
2013-07-01 14:50:03 +04:00
2013-06-24 17:34:25 +04:00
try:
driver = 'org.hsqldb.jdbc.JDBCDriver'
connection_string = 'jdbc:hsqldb:mem:.' # 'jdbc:hsqldb:hsql://%s/%s' % (self.hostname, self.db)
self.connector = jaydebeapi.connect(driver, connection_string, str(self.user), str(self.password))
2019-01-22 03:20:27 +03:00
except Exception as ex:
raise SqlmapConnectionException(getSafeExString(ex))
2013-06-24 17:34:25 +04:00
self.initCursor()
self.printConnected()
def fetchall(self):
try:
return self.cursor.fetchall()
2019-01-22 03:20:27 +03:00
except Exception as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
2013-06-24 17:34:25 +04:00
return None
def execute(self, query):
retVal = False
try:
self.cursor.execute(query)
retVal = True
2019-01-22 03:20:27 +03:00
except Exception as ex:
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
2013-06-24 17:34:25 +04:00
self.connector.commit()
return retVal
def select(self, query):
retVal = None
upper_query = query.upper()
if query and not (upper_query.startswith("SELECT ") or upper_query.startswith("VALUES ")):
query = "VALUES %s" % query
if query and upper_query.startswith("SELECT ") and " FROM " not in upper_query:
query = "%s FROM (VALUES(0))" % query
self.cursor.execute(query)
retVal = self.cursor.fetchall()
return retVal