2019-05-08 13:47:52 +03:00
|
|
|
#!/usr/bin/env python
|
2016-09-23 13:33:27 +03:00
|
|
|
|
|
|
|
"""
|
2024-01-04 01:11:52 +03:00
|
|
|
Copyright (c) 2006-2024 sqlmap developers (https://sqlmap.org/)
|
2017-10-11 15:50:46 +03:00
|
|
|
See the file 'LICENSE' for copying permission
|
2016-09-23 13:33:27 +03:00
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
import ibm_db_dbi
|
2017-09-04 18:05:48 +03:00
|
|
|
except:
|
2016-09-23 13:33:27 +03:00
|
|
|
pass
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2018-10-04 14:42:13 +03:00
|
|
|
from lib.core.common import getSafeExString
|
2016-09-23 13:33:27 +03: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):
|
|
|
|
"""
|
2018-05-08 15:06:34 +03:00
|
|
|
Homepage: https://github.com/ibmdb/python-ibmdb
|
|
|
|
User guide: https://github.com/ibmdb/python-ibmdb/wiki/README
|
|
|
|
API: https://www.python.org/dev/peps/pep-0249/
|
2016-09-23 13:33:27 +03:00
|
|
|
License: Apache License 2.0
|
|
|
|
"""
|
|
|
|
|
|
|
|
def connect(self):
|
|
|
|
self.initConnection()
|
|
|
|
|
|
|
|
try:
|
|
|
|
database = "DATABASE=%s;HOSTNAME=%s;PORT=%s;PROTOCOL=TCPIP;" % (self.db, self.hostname, self.port)
|
|
|
|
self.connector = ibm_db_dbi.connect(database, self.user, self.password)
|
2019-01-22 04:08:02 +03:00
|
|
|
except ibm_db_dbi.OperationalError as ex:
|
|
|
|
raise SqlmapConnectionException(getSafeExString(ex))
|
2016-09-23 13:33:27 +03:00
|
|
|
|
|
|
|
self.initCursor()
|
|
|
|
self.printConnected()
|
|
|
|
|
|
|
|
def fetchall(self):
|
|
|
|
try:
|
|
|
|
return self.cursor.fetchall()
|
2019-01-22 04:08:02 +03:00
|
|
|
except ibm_db_dbi.ProgrammingError as ex:
|
|
|
|
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
|
2016-09-23 13:33:27 +03:00
|
|
|
return None
|
|
|
|
|
|
|
|
def execute(self, query):
|
|
|
|
try:
|
|
|
|
self.cursor.execute(query)
|
2019-01-22 04:08:02 +03:00
|
|
|
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError) as ex:
|
|
|
|
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % getSafeExString(ex))
|
|
|
|
except ibm_db_dbi.InternalError as ex:
|
|
|
|
raise SqlmapConnectionException(getSafeExString(ex))
|
2016-09-23 13:33:27 +03:00
|
|
|
|
|
|
|
self.connector.commit()
|
|
|
|
|
|
|
|
def select(self, query):
|
|
|
|
self.execute(query)
|
|
|
|
return self.fetchall()
|