2012-02-22 14:40:11 +04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
"""
|
2012-07-12 21:38:03 +04:00
|
|
|
Copyright (c) 2006-2012 sqlmap developers (http://sqlmap.org/)
|
2012-02-22 14:40:11 +04:00
|
|
|
See the file 'doc/COPYING' for copying permission
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
import ibm_db_dbi
|
2012-12-06 13:21:53 +04:00
|
|
|
except ImportError:
|
2012-02-22 14:40:11 +04:00
|
|
|
pass
|
|
|
|
|
2012-10-23 17:34:59 +04:00
|
|
|
import logging
|
|
|
|
|
|
|
|
from lib.core.data import conf
|
2012-02-22 14:40:11 +04:00
|
|
|
from lib.core.data import logger
|
2012-12-06 17:14:19 +04:00
|
|
|
from lib.core.exception import SqlmapConnectionException
|
2012-02-22 14:40:11 +04:00
|
|
|
from plugins.generic.connector import Connector as GenericConnector
|
|
|
|
|
|
|
|
class Connector(GenericConnector):
|
|
|
|
"""
|
|
|
|
Homepage: http://code.google.com/p/ibm-db/
|
|
|
|
User guide: http://code.google.com/p/ibm-db/wiki/README
|
|
|
|
API: http://www.python.org/dev/peps/pep-0249/
|
|
|
|
License: Apache License 2.0
|
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
GenericConnector.__init__(self)
|
|
|
|
|
|
|
|
def connect(self):
|
|
|
|
self.initConnection()
|
|
|
|
|
|
|
|
try:
|
|
|
|
database = "DRIVER={IBM DB2 ODBC DRIVER};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)
|
|
|
|
except ibm_db_dbi.OperationalError, msg:
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapConnectionException(msg)
|
2012-02-22 14:40:11 +04:00
|
|
|
|
|
|
|
|
2013-01-18 14:21:23 +04:00
|
|
|
self.initCursor()
|
2012-02-22 14:40:11 +04:00
|
|
|
self.connected()
|
|
|
|
|
|
|
|
def fetchall(self):
|
|
|
|
try:
|
|
|
|
return self.cursor.fetchall()
|
|
|
|
except ibm_db_dbi.ProgrammingError, msg:
|
2012-10-23 17:34:59 +04:00
|
|
|
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
2012-02-22 14:40:11 +04:00
|
|
|
return None
|
|
|
|
|
|
|
|
def execute(self, query):
|
|
|
|
try:
|
|
|
|
self.cursor.execute(query)
|
|
|
|
except (ibm_db_dbi.OperationalError, ibm_db_dbi.ProgrammingError), msg:
|
2012-10-23 17:34:59 +04:00
|
|
|
logger.log(logging.WARN if conf.dbmsHandler else logging.DEBUG, "(remote) %s" % msg[1])
|
2012-02-22 14:40:11 +04:00
|
|
|
except ibm_db_dbi.InternalError, msg:
|
2013-01-04 02:20:55 +04:00
|
|
|
raise SqlmapConnectionException(msg[1])
|
2012-02-22 14:40:11 +04:00
|
|
|
|
|
|
|
self.connector.commit()
|
|
|
|
|
|
|
|
def select(self, query):
|
|
|
|
self.execute(query)
|
|
|
|
return self.fetchall()
|