mirror of
https://github.com/Ekultek/Zeus-Scanner.git
synced 2026-03-11 08:55:51 +00:00
45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
import signal
|
|
from functools import wraps
|
|
|
|
import lib.core.errors
|
|
import lib.core.settings
|
|
|
|
|
|
class TimeOut:
|
|
def __init__(self, seconds=1, error_message='Timeout'):
|
|
self.seconds = seconds
|
|
self.error_message = error_message
|
|
|
|
def handle_timeout(self, signum, frame):
|
|
raise lib.core.errors.PortScanTimeOutException(self.error_message)
|
|
|
|
def __enter__(self):
|
|
signal.signal(signal.SIGALRM, self.handle_timeout)
|
|
signal.alarm(self.seconds)
|
|
|
|
def __exit__(self, type_, value, traceback):
|
|
signal.alarm(0)
|
|
|
|
|
|
def cache(func):
|
|
"""
|
|
if we come across the same URL more then once, it will be cached into memory
|
|
so that we don't have to test it again
|
|
"""
|
|
__cache = {}
|
|
|
|
@wraps(func)
|
|
def func_wrapper(*args, **kwargs):
|
|
if args in __cache:
|
|
lib.core.settings.logger.warning(lib.core.settings.set_color(
|
|
"cached detection has shown that the target URL WAF/IPS/IDS is '{}'...".format(
|
|
__cache[args]
|
|
), level=35
|
|
))
|
|
return __cache[args]
|
|
else:
|
|
__to_cache = func(*args, **kwargs)
|
|
__cache[args] = __to_cache
|
|
return __to_cache
|
|
|
|
return func_wrapper
|