|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +""" |
| 4 | +Copyright (c) 2006-2013 sqlmap developers (http://sqlmap.org/) |
| 5 | +See the file 'doc/COPYING' for copying permission |
| 6 | +""" |
| 7 | + |
| 8 | +try: |
| 9 | + from thirdparty import jaydebeapi |
| 10 | + import jpype |
| 11 | +except ImportError, msg: |
| 12 | + pass |
| 13 | + |
| 14 | +import logging |
| 15 | + |
| 16 | +from lib.core.data import conf |
| 17 | +from lib.core.data import logger |
| 18 | +from lib.core.exception import SqlmapConnectionException |
| 19 | +from plugins.generic.connector import Connector as GenericConnector |
| 20 | + |
| 21 | +class Connector(GenericConnector): |
| 22 | + """ |
| 23 | + Homepage: http://jpype.sourceforge.net/ |
| 24 | + User guide: http://jpype.sourceforge.net/doc/user-guide/userguide.html |
| 25 | + API: http://code.google.com/p/pymysql/ |
| 26 | + Debian package: <none> |
| 27 | + License: Apache License V2.0 |
| 28 | + """ |
| 29 | + |
| 30 | + def __init__(self): |
| 31 | + GenericConnector.__init__(self) |
| 32 | + |
| 33 | + def connect(self): |
| 34 | + self.initConnection() |
| 35 | + try: |
| 36 | + jar = './thirdparty/hsql/hsqldb.jar' |
| 37 | + args='-Djava.class.path=%s' % jar |
| 38 | + jvm_path = jpype.getDefaultJVMPath() |
| 39 | + jpype.startJVM(jvm_path, args) |
| 40 | + except (Exception), msg: #todo fix with specific error |
| 41 | + raise SqlmapConnectionException(msg[0]) |
| 42 | + try: |
| 43 | + driver = 'org.hsqldb.jdbc.JDBCDriver' |
| 44 | + connection_string = 'jdbc:hsqldb:mem:.' #'jdbc:hsqldb:hsql://%s/%s' % (self.hostname, self.db) |
| 45 | + self.connector = jaydebeapi.connect(driver, |
| 46 | + connection_string, |
| 47 | + str(self.user), |
| 48 | + str(self.password)) |
| 49 | + except (Exception), msg: #todo what kind of error is this?! |
| 50 | + raise SqlmapConnectionException(msg[0]) |
| 51 | + |
| 52 | + self.initCursor() |
| 53 | + self.printConnected() |
| 54 | + |
| 55 | + def fetchall(self): |
| 56 | + try: |
| 57 | + return self.cursor.fetchall() |
| 58 | + except (Exception), msg: |
| 59 | + logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1]) |
| 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), msg: #todo fix with specific error |
| 69 | + logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1]) |
| 70 | + except Exception, msg: #todo fix with specific error |
| 71 | + raise SqlmapConnectionException(msg[1]) |
| 72 | + |
| 73 | + self.connector.commit() |
| 74 | + |
| 75 | + return retVal |
| 76 | + |
| 77 | + def select(self, query): |
| 78 | + retVal = None |
| 79 | + |
| 80 | + upper_query = query.upper() |
| 81 | + |
| 82 | + if query and not (upper_query.startswith("SELECT ") or upper_query.startswith("VALUES ")): |
| 83 | + query = "VALUES %s" % query |
| 84 | + |
| 85 | + if query and upper_query.startswith("SELECT ") and " FROM " not in upper_query: |
| 86 | + query = "%s FROM (VALUES(0))" % query |
| 87 | + |
| 88 | + self.cursor.execute(query) |
| 89 | + retVal = self.cursor.fetchall() |
| 90 | + |
| 91 | + return retVal |
0 commit comments