some update

This commit is contained in:
Miroslav Stampar 2010-04-06 14:59:31 +00:00
parent 60f04f0a41
commit c24f1cc07c
8 changed files with 45 additions and 39 deletions

View File

@ -2,22 +2,26 @@
import threading import threading
def timeout(func, args=(), kwargs={}, timeout_duration=1, default=None): def timeout(func, args=(), kwargs={}, duration=1, default=None):
class InterruptableThread(threading.Thread): class InterruptableThread(threading.Thread):
def __init__(self): def __init__(self):
threading.Thread.__init__(self) threading.Thread.__init__(self)
self.exceeded = False
self.exceptionMsg = None
self.result = None self.result = None
def run(self): def run(self):
try: try:
self.result = func(*args, **kwargs) self.result = func(*args, **kwargs)
except: except Exception, msg:
self.exceptionMsg = msg
self.result = default self.result = default
thread = InterruptableThread() thread = InterruptableThread()
thread.start() thread.start()
thread.join(timeout_duration) thread.join(duration)
if thread.isAlive(): self.exceeded = thread.isAlive()
if self.exceeded:
return default return default
else: else:
return thread.result return thread.result

View File

@ -30,6 +30,7 @@ except ImportError, _:
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -60,11 +61,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except pyodbc.ProgrammingError, msg: logger.log(8, self.exceptionMsg[1])
logger.log(8, msg[1]) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)

View File

@ -30,6 +30,7 @@ except ImportError, _:
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -59,11 +60,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except kinterbasdb.OperationalError, msg: logger.log(8, self.exceptionMsg[1])
logger.log(8, msg[1]) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)

View File

@ -31,6 +31,7 @@ except ImportError, _:
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -63,11 +64,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except (pymssql.ProgrammingError, pymssql.OperationalError, _mssql.MssqlDatabaseException), msg: logger.log(8, self.exceptionMsg)
logger.log(8, msg) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)

View File

@ -30,6 +30,7 @@ except ImportError, _:
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -59,11 +60,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except MySQLdb.ProgrammingError, msg: logger.log(8, self.exceptionMsg[1])
logger.log(8, msg[1]) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)

View File

@ -27,8 +27,10 @@ try:
except ImportError, _: except ImportError, _:
pass pass
from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -60,11 +62,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except cx_Oracle.InterfaceError, msg: logger.log(8, self.exceptionMsg)
logger.log(8, msg) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)

View File

@ -27,8 +27,10 @@ try:
except ImportError, _: except ImportError, _:
pass pass
from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -58,11 +60,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except psycopg2.ProgrammingError, msg: logger.log(8, self.exceptionMsg)
logger.log(8, msg) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)

View File

@ -30,6 +30,7 @@ except ImportError, _:
from lib.core.data import conf from lib.core.data import conf
from lib.core.data import logger from lib.core.data import logger
from lib.core.exception import sqlmapConnectionException from lib.core.exception import sqlmapConnectionException
from lib.utils.timeout import timeout
from plugins.generic.connector import Connector as GenericConnector from plugins.generic.connector import Connector as GenericConnector
@ -60,11 +61,10 @@ class Connector(GenericConnector):
self.connected() self.connected()
def fetchall(self): def fetchall(self):
try: retVal = timeout(func=self.cursor.fetchall, duration=conf.timeout, default=None)
return self.cursor.fetchall() if self.exceptionMsg:
except sqlite3.OperationalError, msg: logger.log(8, self.exceptionMsg[0])
logger.log(8, msg[0]) return retVal
return None
def execute(self, query): def execute(self, query):
logger.debug(query) logger.debug(query)