From 91ca828c721bcc974a843259f6ac1e83a801a88b Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Mon, 26 Jul 2021 11:20:48 +0300 Subject: [PATCH] Monkey: add launch time to the monkey collection Launch time is needed if we want to tell the user when exactly the exploit occurred/monkey got run --- monkey/common/common_consts/time_formats.py | 3 +++ monkey/infection_monkey/control.py | 3 +++ monkey/monkey_island/cc/models/monkey.py | 1 + vulture_allowlist.py | 1 + 4 files changed, 8 insertions(+) create mode 100644 monkey/common/common_consts/time_formats.py diff --git a/monkey/common/common_consts/time_formats.py b/monkey/common/common_consts/time_formats.py new file mode 100644 index 000000000..d150ce46e --- /dev/null +++ b/monkey/common/common_consts/time_formats.py @@ -0,0 +1,3 @@ +# Default time format used in the application, follows European standard. +# Example: 1992-03-04 10:32:05 +DEFAULT_TIME_FORMAT = "%Y-%m-%d %H:%M:%S" diff --git a/monkey/infection_monkey/control.py b/monkey/infection_monkey/control.py index feff589c1..beac0f716 100644 --- a/monkey/infection_monkey/control.py +++ b/monkey/infection_monkey/control.py @@ -1,6 +1,7 @@ import json import logging import platform +from datetime import datetime from pprint import pformat from socket import gethostname from urllib.parse import urljoin @@ -11,6 +12,7 @@ from requests.exceptions import ConnectionError import infection_monkey.monkeyfs as monkeyfs import infection_monkey.tunnel as tunnel from common.common_consts.api_url_consts import T1216_PBA_FILE_DOWNLOAD_PATH +from common.common_consts.time_formats import DEFAULT_TIME_FORMAT from common.common_consts.timeouts import ( LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT, @@ -60,6 +62,7 @@ class ControlClient(object): "internet_access": has_internet_access, "config": WormConfiguration.as_dict(), "parent": parent, + "launch_time": str(datetime.now().strftime(DEFAULT_TIME_FORMAT)), } if ControlClient.proxies: diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index fc87c4605..70ca9fbf9 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -40,6 +40,7 @@ class Monkey(Document): hostname = StringField() internet_access = BooleanField() ip_addresses = ListField(StringField()) + launch_time = StringField() keepalive = DateTimeField() modifytime = DateTimeField() # TODO make "parent" an embedded document, so this can be removed and the schema explained ( diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 5a430dc6c..b39d61dd8 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -70,6 +70,7 @@ PbaResults # unused class (monkey/monkey_island/cc/models/pba_results.py:4) internet_access # unused variable (monkey/monkey_island/cc/models/monkey.py:43) config_error # unused variable (monkey/monkey_island/cc/models/monkey.py:53) pba_results # unused variable (monkey/monkey_island/cc/models/monkey.py:55) +launch_time # unused variable (monkey/monkey_island/cc/models/monkey.py) command_control_channel # unused variable (monkey/monkey_island/cc/models/monkey.py:58) meta # unused variable (monkey/monkey_island/cc/models/zero_trust/finding.py:37) meta # unused variable (monkey/monkey_island/cc/models/monkey_ttl.py:34)