SIGN IN SIGN UP
sqlmapproject / sqlmap UNCLAIMED

Automatic SQL injection and database takeover tool

36950 0 0 Python
2019-05-08 12:47:52 +02:00
#!/usr/bin/env python
2010-04-06 14:33:57 +00:00
2010-04-06 20:40:14 +00:00
"""
2023-01-02 23:24:59 +01:00
Copyright (c) 2006-2023 sqlmap developers (https://sqlmap.org/)
2017-10-11 14:50:46 +02:00
See the file 'LICENSE' for copying permission
2010-04-06 20:40:14 +00:00
"""
2010-04-06 14:33:57 +00:00
import threading
2010-04-06 15:24:56 +00:00
from lib.core.data import logger
2012-12-07 11:54:34 +01:00
from lib.core.enums import CUSTOM_LOGGING
from lib.core.enums import TIMEOUT_STATE
2010-04-06 15:24:56 +00:00
2019-05-30 22:40:51 +02:00
def timeout(func, args=None, kwargs=None, duration=1, default=None):
2010-04-06 14:33:57 +00:00
class InterruptableThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
self.result = None
self.timeout_state = None
2010-04-06 14:33:57 +00:00
def run(self):
try:
2019-05-30 22:40:51 +02:00
self.result = func(*(args or ()), **(kwargs or {}))
self.timeout_state = TIMEOUT_STATE.NORMAL
2019-01-22 01:20:27 +01:00
except Exception as ex:
logger.log(CUSTOM_LOGGING.TRAFFIC_IN, ex)
2010-04-06 14:33:57 +00:00
self.result = default
self.timeout_state = TIMEOUT_STATE.EXCEPTION
2010-04-06 14:33:57 +00:00
thread = InterruptableThread()
thread.start()
2010-04-06 14:59:31 +00:00
thread.join(duration)
2010-04-06 20:40:14 +00:00
if thread.is_alive():
return default, TIMEOUT_STATE.TIMEOUT
2010-04-06 14:33:57 +00:00
else:
return thread.result, thread.timeout_state