forked from p15670423/monkey
Merge pull request #861 from VakarisZ/schedule_jobs_bugfix
Schedule jobs bugfix
This commit is contained in:
commit
ac71a3ecb5
|
@ -20,3 +20,7 @@ class CredentialsNotRequiredError(RegistrationNotNeededError):
|
||||||
|
|
||||||
class AlreadyRegisteredError(RegistrationNotNeededError):
|
class AlreadyRegisteredError(RegistrationNotNeededError):
|
||||||
""" Raise to indicate the reason why registration is not required """
|
""" Raise to indicate the reason why registration is not required """
|
||||||
|
|
||||||
|
|
||||||
|
class VersionServerConnectionError(Exception):
|
||||||
|
""" Raise to indicate that connection to version update server failed """
|
||||||
|
|
|
@ -84,7 +84,7 @@ class ControlClient(object):
|
||||||
if ControlClient.proxies:
|
if ControlClient.proxies:
|
||||||
debug_message += " through proxies: %s" % ControlClient.proxies
|
debug_message += " through proxies: %s" % ControlClient.proxies
|
||||||
LOG.debug(debug_message)
|
LOG.debug(debug_message)
|
||||||
requests.get("https://%s/api?action=is-up" % (server,), # noqa: DUO123
|
requests.get(f"https://{server}/api?action=is-up", # noqa: DUO123
|
||||||
verify=False,
|
verify=False,
|
||||||
proxies=ControlClient.proxies,
|
proxies=ControlClient.proxies,
|
||||||
timeout=TIMEOUT_IN_SECONDS)
|
timeout=TIMEOUT_IN_SECONDS)
|
||||||
|
|
|
@ -16,4 +16,6 @@ class ScheduleJobs(PBA):
|
||||||
linux_cmd=' '.join(linux_cmds),
|
linux_cmd=' '.join(linux_cmds),
|
||||||
windows_cmd=windows_cmds)
|
windows_cmd=windows_cmds)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
super(ScheduleJobs, self).run()
|
||||||
remove_scheduled_jobs()
|
remove_scheduled_jobs()
|
||||||
|
|
|
@ -5,7 +5,7 @@ SCHEDULED_TASK_COMMAND = r'C:\windows\system32\cmd.exe'
|
||||||
|
|
||||||
|
|
||||||
def get_windows_commands_to_schedule_jobs():
|
def get_windows_commands_to_schedule_jobs():
|
||||||
return f'schtasks /Create /SC monthly /TN {SCHEDULED_TASK_NAME} /TR {SCHEDULED_TASK_COMMAND}'
|
return f'schtasks /Create /SC monthly /F /TN {SCHEDULED_TASK_NAME} /TR {SCHEDULED_TASK_COMMAND}'
|
||||||
|
|
||||||
|
|
||||||
def get_windows_commands_to_remove_scheduled_jobs():
|
def get_windows_commands_to_remove_scheduled_jobs():
|
||||||
|
|
|
@ -25,9 +25,9 @@ class PostBreach(object):
|
||||||
"""
|
"""
|
||||||
Executes all post breach actions.
|
Executes all post breach actions.
|
||||||
"""
|
"""
|
||||||
pool = Pool(5)
|
with Pool(5) as pool:
|
||||||
pool.map(self.run_pba, self.pba_list)
|
pool.map(self.run_pba, self.pba_list)
|
||||||
LOG.info("All PBAs executed. Total {} executed.".format(len(self.pba_list)))
|
LOG.info("All PBAs executed. Total {} executed.".format(len(self.pba_list)))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def config_to_pba_list() -> Sequence[PBA]:
|
def config_to_pba_list() -> Sequence[PBA]:
|
||||||
|
@ -40,5 +40,6 @@ class PostBreach(object):
|
||||||
try:
|
try:
|
||||||
LOG.debug("Executing PBA: '{}'".format(pba.name))
|
LOG.debug("Executing PBA: '{}'".format(pba.name))
|
||||||
pba.run()
|
pba.run()
|
||||||
|
LOG.debug(f"Execution of {pba.name} finished")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
LOG.error("PBA {} failed. Error info: {}".format(pba.name, e))
|
LOG.error("PBA {} failed. Error info: {}".format(pba.name, e))
|
||||||
|
|
|
@ -3,6 +3,7 @@ import logging
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||||
|
from common.utils.exceptions import VersionServerConnectionError
|
||||||
from common.version import get_version
|
from common.version import get_version
|
||||||
|
|
||||||
__author__ = "itay.mizeretz"
|
__author__ = "itay.mizeretz"
|
||||||
|
@ -29,8 +30,8 @@ class VersionUpdateService:
|
||||||
if VersionUpdateService.newer_version is None:
|
if VersionUpdateService.newer_version is None:
|
||||||
try:
|
try:
|
||||||
VersionUpdateService.newer_version = VersionUpdateService._check_new_version()
|
VersionUpdateService.newer_version = VersionUpdateService._check_new_version()
|
||||||
except Exception:
|
except VersionServerConnectionError:
|
||||||
logger.exception('Failed updating version number')
|
logger.info('Failed updating version number')
|
||||||
|
|
||||||
return VersionUpdateService.newer_version
|
return VersionUpdateService.newer_version
|
||||||
|
|
||||||
|
@ -42,7 +43,11 @@ class VersionUpdateService:
|
||||||
"""
|
"""
|
||||||
url = VersionUpdateService.VERSION_SERVER_CHECK_NEW_URL % (env_singleton.env.get_deployment(), get_version())
|
url = VersionUpdateService.VERSION_SERVER_CHECK_NEW_URL % (env_singleton.env.get_deployment(), get_version())
|
||||||
|
|
||||||
reply = requests.get(url, timeout=15)
|
try:
|
||||||
|
reply = requests.get(url, timeout=7)
|
||||||
|
except requests.exceptions.RequestException:
|
||||||
|
logger.info("Can't get latest monkey version, probably no connection to the internet.")
|
||||||
|
raise VersionServerConnectionError
|
||||||
|
|
||||||
res = reply.json().get('newer_version', None)
|
res = reply.json().get('newer_version', None)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue