created a timeout class that will timeout a function if it takes to long, added the timeout to the nmap scan, if it takes over 2 minutes it will timeout, you can increase the timeout with the --time-sec flag

This commit is contained in:
ekultek 2017-11-29 11:48:12 -06:00
parent 92653aa038
commit c0382bdb17
7 changed files with 105 additions and 57 deletions

View file

@ -1,4 +1,4 @@
e4ea2d20dd1e0ec58e68159689e2cb74 ./zeus.py
cfa0a16384b1b143f9c2cbd474f1a55c ./zeus.py
4b32db388e8acda35570c734d27c950c ./etc/scripts/launch_sqlmap.sh
6ad5f22ec4a6f8324bfb1b01ab6d51ec ./etc/scripts/cleanup.sh
74d7bee13890a9dd279bb857591647ce ./etc/scripts/reinstall.sh
@ -70,14 +70,14 @@ d41d8cd98f00b204e9800998ecf8427e ./lib/attacks/__init__.py
d2846e039fefee741db24dd64f7bd50e ./lib/attacks/whois_lookup/whois.py
d2846e039fefee741db24dd64f7bd50e ./lib/attacks/admin_panel_finder/__init__.py
b5cd5e913cc62112776153bdf0f60fa4 ./lib/attacks/xss_scan/__init__.py
353dc2653372e78962bd0398df9a2f5f ./lib/attacks/nmap_scan/__init__.py
e9915cc0bc3de60aaf2accfaea77d059 ./lib/attacks/nmap_scan/__init__.py
216999fa0e84866d5c1d96d5676034e4 ./lib/attacks/nmap_scan/nmap_opts.py
6f5d4adc7777b6696d4b290367364a38 ./lib/header_check/__init__.py
3252422e2934d26987ab9b0eb00c5f9d ./lib/header_check/__init__.py
39221756c132732dbdc2b14772dcab11 ./lib/core/common.py
1faa2b5dfad6eb538bbfe42942d2a9da ./lib/core/errors.py
4433353fb5c55578391d8b4006191ee8 ./lib/core/errors.py
d41d8cd98f00b204e9800998ecf8427e ./lib/core/__init__.py
48e4cd38111bad891e2f221b50cd4fb0 ./lib/core/settings.py
4b507b34677b414b8338475fea2c012a ./lib/core/cache.py
0320e44e0095889a92d2595f0a3428ca ./lib/core/settings.py
d3c1663ff908e10dfb2425bf84d80759 ./lib/core/decorators.py
9a02e5b913d210350545ac26510a63c9 ./var/search/__init__.py
0545ee54ade186681b25d157fb32f350 ./var/search/selenium_search.py
8f8a7e791f91f0ef3544f2ed8364ab56 ./var/search/pgp_search.py

View file

@ -4,7 +4,9 @@ import socket
import nmap
import lib.core.common
import lib.core.errors
import lib.core.settings
import lib.core.decorators
from var.auto_issue.github import request_issue_creation
@ -53,10 +55,11 @@ class NmapHook(object):
spacer_data = {4: " " * 8, 6: " " * 6, 8: " " * 4}
lib.core.settings.logger.info(lib.core.settings.set_color("finding data for IP '{}'...".format(self.ip)))
json_data = json.loads(json_data)["scan"]
host = json_data[self.ip]["hostnames"][0]["name"]
print(
"{}\nScanned: {} ({})\tStatus: {}\nProtocol: {}\n".format(
sep, self.ip,
json_data[self.ip]["hostnames"][0]["name"],
host if host is not "" or None else "unknown",
json_data[self.ip]["status"]["state"],
"TCP"
)
@ -89,57 +92,73 @@ def perform_port_scan(url, scanner=NmapHook, **kwargs):
"""
verbose = kwargs.get("verbose", False)
opts = kwargs.get("opts", None)
timeout_time = kwargs.get("timeout", None)
url = url.strip()
lib.core.settings.logger.info(lib.core.settings.set_color(
"attempting to find IP address for hostname '{}'...".format(url)
))
found_ip_address = socket.gethostbyname(url)
lib.core.settings.logger.info(lib.core.settings.set_color(
"found IP address for given URL -> '{}'...".format(found_ip_address), level=25
))
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"checking for nmap on your system...", level=10
if timeout_time is None:
timeout_time = 120
with lib.core.decorators.TimeOut(seconds=timeout_time):
lib.core.settings.logger.warning(lib.core.settings.set_color(
"if the port scan is not completed in {}(m) it will timeout...".format(
lib.core.settings.convert_to_minutes(timeout_time)
), level=30
))
url = url.strip()
lib.core.settings.logger.info(lib.core.settings.set_color(
"attempting to find IP address for hostname '{}'...".format(url)
))
found_ip_address = socket.gethostbyname(url)
lib.core.settings.logger.info(lib.core.settings.set_color(
"found IP address for given URL -> '{}'...".format(found_ip_address), level=25
))
nmap_exists = "".join(find_nmap())
if nmap_exists:
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"nmap has been found under '{}'...".format(nmap_exists), level=10
"checking for nmap on your system...", level=10
))
lib.core.settings.logger.info(lib.core.settings.set_color(
"starting port scan on IP address '{}'...".format(found_ip_address)
))
try:
data = scanner(found_ip_address, opts=opts)
json_data = data.get_all_info()
data.show_open_ports(json_data)
file_path = data.send_to_file(json_data)
nmap_exists = "".join(find_nmap())
if nmap_exists:
if verbose:
lib.core.settings.logger.debug(lib.core.settings.set_color(
"nmap has been found under '{}'...".format(nmap_exists), level=10
))
lib.core.settings.logger.info(lib.core.settings.set_color(
"port scan completed, all data saved to JSON file under '{}'...".format(file_path)
"starting port scan on IP address '{}'...".format(found_ip_address)
))
except KeyError:
try:
data = scanner(found_ip_address, opts=opts)
json_data = data.get_all_info()
data.show_open_ports(json_data)
file_path = data.send_to_file(json_data)
lib.core.settings.logger.info(lib.core.settings.set_color(
"port scan completed, all data saved to JSON file under '{}'...".format(file_path)
))
except KeyError:
lib.core.settings.logger.fatal(lib.core.settings.set_color(
"no port information found for '{}({})'...".format(
url, found_ip_address
), level=50
))
except KeyboardInterrupt:
if not lib.core.common.pause():
lib.core.common.shutdown()
except lib.core.errors.PortScanTimeOutException:
lib.core.settings.logger.error(lib.core.settings.set_color(
"port scan is taking to long and has hit the timeout, you "
"can increase this time by passing the --time-sec flag (IE "
"--time-sec 300)...", level=40
))
except Exception as e:
lib.core.settings.logger.exception(lib.core.settings.set_color(
"ran into exception '{}', cannot continue quitting...".format(e), level=50
))
request_issue_creation()
pass
else:
lib.core.settings.logger.fatal(lib.core.settings.set_color(
"no port information found for '{}({})'...".format(
url, found_ip_address
), level=50
"nmap was not found on your system...", level=50
))
except KeyboardInterrupt:
if not lib.core.common.pause():
lib.core.common.shutdown()
except Exception as e:
lib.core.settings.logger.exception(lib.core.settings.set_color(
"ran into exception '{}', cannot continue quitting...".format(e), level=50
))
request_issue_creation()
pass
else:
lib.core.settings.logger.fatal(lib.core.settings.set_color(
"nmap was not found on your system...", level=50
))
lib.core.common.run_fix(
"would you like to automatically install it",
"sudo sh {}".format(lib.core.settings.NMAP_INSTALLER_TOOL),
"nmap is not installed, please install it in order to continue..."
)
lib.core.common.run_fix(
"would you like to automatically install it",
"sudo sh {}".format(lib.core.settings.NMAP_INSTALLER_TOOL),
"nmap is not installed, please install it in order to continue..."
)

View file

@ -1,8 +1,26 @@
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

View file

@ -16,4 +16,7 @@ class SpiderTestFailure(Exception): pass
class InvalidInputProvided(Exception): pass
class InvalidTamperProvided(Exception): pass
class InvalidTamperProvided(Exception): pass
class PortScanTimeOutException(Exception): pass

View file

@ -46,7 +46,7 @@ CLONE = "https://github.com/ekultek/zeus-scanner.git"
ISSUE_LINK = "https://github.com/ekultek/zeus-scanner/issues"
# current version <major.minor.commit.patch ID>
VERSION = "1.3.5.{}".format(PATCH_ID)
VERSION = "1.3.6".format(PATCH_ID)
# colors to output depending on the version
VERSION_TYPE_COLORS = {"dev": 33, "stable": 92, "other": 30}
@ -985,7 +985,7 @@ def run_attacks(url, **kwargs):
from lib.attacks import nmap_scan
url_ip_address = replace_http(url.strip())
return nmap_scan.perform_port_scan(
url_ip_address, verbose=verbose,
url_ip_address, verbose=verbose, timeout=timeout,
opts=create_arguments(nmap=True, nmap_args=nmap_arguments)
)
elif admin:
@ -1123,3 +1123,11 @@ def tails(file_object, last_lines=50):
lines = list(file_object)
pos *= 2
return "".join(lines[-last_lines:])
def convert_to_minutes(seconds):
"""
convert an amount of seconds to minutes and seconds
"""
import time
return time.strftime("%M:%S", time.gmtime(seconds))

View file

@ -8,7 +8,7 @@ from xml.dom import minidom
from requests.exceptions import ConnectionError
from var.auto_issue.github import request_issue_creation
from lib.core.cache import cache
from lib.core.decorators import cache
from lib.core.common import (
write_to_log_file,
shutdown,

View file

@ -132,7 +132,7 @@ if __name__ == "__main__":
search_items.add_option("--x-forward", dest="forwardedForRandomIP", action="store_true",
help="Add a header called 'X-Forwarded-For' with three random IP addresses")
search_items.add_option("--time-sec", dest="controlTimeout", metavar="SECONDS", type=int,
help="Control the sleep time to the WhoIS lookup to prevent errors")
help="Control the sleep and timeout times in relevant situations")
# obfuscation options
anon = optparse.OptionGroup(parser, "Anonymity arguments",