Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sqlmapproject
GitHub Repository: sqlmapproject/sqlmap
Path: blob/master/plugins/dbms/hsqldb/connector.py
2992 views
1
#!/usr/bin/env python
2
3
"""
4
Copyright (c) 2006-2025 sqlmap developers (https://sqlmap.org)
5
See the file 'LICENSE' for copying permission
6
"""
7
8
try:
9
import jaydebeapi
10
import jpype
11
except:
12
pass
13
14
import logging
15
16
from lib.core.common import checkFile
17
from lib.core.common import getSafeExString
18
from lib.core.common import readInput
19
from lib.core.data import conf
20
from lib.core.data import logger
21
from lib.core.exception import SqlmapConnectionException
22
from plugins.generic.connector import Connector as GenericConnector
23
24
class Connector(GenericConnector):
25
"""
26
Homepage: https://pypi.python.org/pypi/JayDeBeApi/ & http://jpype.sourceforge.net/
27
User guide: https://pypi.python.org/pypi/JayDeBeApi/#usage & http://jpype.sourceforge.net/doc/user-guide/userguide.html
28
API: -
29
Debian package: -
30
License: LGPL & Apache License 2.0
31
"""
32
33
def connect(self):
34
self.initConnection()
35
try:
36
msg = "please enter the location of 'hsqldb.jar'? "
37
jar = readInput(msg)
38
checkFile(jar)
39
args = "-Djava.class.path=%s" % jar
40
jvm_path = jpype.getDefaultJVMPath()
41
jpype.startJVM(jvm_path, args)
42
except Exception as ex:
43
raise SqlmapConnectionException(getSafeExString(ex))
44
45
try:
46
driver = 'org.hsqldb.jdbc.JDBCDriver'
47
connection_string = 'jdbc:hsqldb:mem:.' # 'jdbc:hsqldb:hsql://%s/%s' % (self.hostname, self.db)
48
self.connector = jaydebeapi.connect(driver, connection_string, str(self.user), str(self.password))
49
except Exception as ex:
50
raise SqlmapConnectionException(getSafeExString(ex))
51
52
self.initCursor()
53
self.printConnected()
54
55
def fetchall(self):
56
try:
57
return self.cursor.fetchall()
58
except Exception as ex:
59
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
60
return None
61
62
def execute(self, query):
63
retVal = False
64
65
try:
66
self.cursor.execute(query)
67
retVal = True
68
except Exception as ex:
69
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) '%s'" % getSafeExString(ex))
70
71
self.connector.commit()
72
73
return retVal
74
75
def select(self, query):
76
retVal = None
77
78
upper_query = query.upper()
79
80
if query and not (upper_query.startswith("SELECT ") or upper_query.startswith("VALUES ")):
81
query = "VALUES %s" % query
82
83
if query and upper_query.startswith("SELECT ") and " FROM " not in upper_query:
84
query = "%s FROM (VALUES(0))" % query
85
86
self.cursor.execute(query)
87
retVal = self.cursor.fetchall()
88
89
return retVal
90
91