From bc08ebeebd994efe23e699a3785294941294c142 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 15 Nov 2021 16:26:45 +0530 Subject: [PATCH 1/4] Island: Remove config option for custom singleton mutex name --- monkey/monkey_island/cc/services/config_schema/internal.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/monkey/monkey_island/cc/services/config_schema/internal.py b/monkey/monkey_island/cc/services/config_schema/internal.py index 981ccdaab..f90a545ef 100644 --- a/monkey/monkey_island/cc/services/config_schema/internal.py +++ b/monkey/monkey_island/cc/services/config_schema/internal.py @@ -8,13 +8,6 @@ INTERNAL = { "title": "General", "type": "object", "properties": { - "singleton_mutex_name": { - "title": "Singleton mutex name", - "type": "string", - "default": "{2384ec59-0df8-4ab9-918c-843740924a28}", - "description": "The name of the mutex used to determine whether the monkey is " - "already running", - }, "keep_tunnel_open_time": { "title": "Keep tunnel open time", "type": "integer", From 4c08bf1a62c10c392952edddaad41d1f6e474904 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 15 Nov 2021 16:30:39 +0530 Subject: [PATCH 2/4] Agent: Remove option for custom singleton mutex name and add it as a constant --- monkey/infection_monkey/config.py | 3 --- monkey/infection_monkey/example.conf | 1 - monkey/infection_monkey/system_singleton.py | 9 +++++---- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/monkey/infection_monkey/config.py b/monkey/infection_monkey/config.py index 2c6e4b678..d25ff7ebe 100644 --- a/monkey/infection_monkey/config.py +++ b/monkey/infection_monkey/config.py @@ -99,9 +99,6 @@ class Configuration(object): # sets whether or not the monkey is alive. if false will stop scanning and exploiting alive = True - # string of the mutex name for single instance - singleton_mutex_name = "{2384ec59-0df8-4ab9-918c-843740924a28}" - # how long to wait between scan iterations timeout_between_iterations = 100 diff --git a/monkey/infection_monkey/example.conf b/monkey/infection_monkey/example.conf index de6965a6e..b2a5c24dd 100644 --- a/monkey/infection_monkey/example.conf +++ b/monkey/infection_monkey/example.conf @@ -56,7 +56,6 @@ "smb_service_name": "InfectionMonkey", "retry_failed_explotation": true, "self_delete_in_cleanup": true, - "singleton_mutex_name": "{2384ec59-0df8-4ab9-918c-843740924a28}", "skip_exploit_if_file_exist": false, "exploit_user_list": [], "exploit_password_list": [], diff --git a/monkey/infection_monkey/system_singleton.py b/monkey/infection_monkey/system_singleton.py index 745ecea67..c08ded467 100644 --- a/monkey/infection_monkey/system_singleton.py +++ b/monkey/infection_monkey/system_singleton.py @@ -3,11 +3,12 @@ import logging import sys from abc import ABCMeta, abstractmethod -from infection_monkey.config import WormConfiguration - logger = logging.getLogger(__name__) +SINGLETON_MUTEX_NAME = "{2384ec59-0df8-4ab9-918c-843740924a28}" + + class _SystemSingleton(object, metaclass=ABCMeta): @abstractmethod def try_lock(self): @@ -20,7 +21,7 @@ class _SystemSingleton(object, metaclass=ABCMeta): class WindowsSystemSingleton(_SystemSingleton): def __init__(self): - self._mutex_name = r"Global\%s" % (WormConfiguration.singleton_mutex_name,) + self._mutex_name = r"Global\%s" % (SINGLETON_MUTEX_NAME,) self._mutex_handle = None def try_lock(self): @@ -55,7 +56,7 @@ class WindowsSystemSingleton(_SystemSingleton): class LinuxSystemSingleton(_SystemSingleton): def __init__(self): - self._unix_sock_name = str(WormConfiguration.singleton_mutex_name) + self._unix_sock_name = str(SINGLETON_MUTEX_NAME) self._sock_handle = None def try_lock(self): From 57cc2ef64a0a7975f1b049ce0c57ae29b906f426 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 15 Nov 2021 16:31:45 +0530 Subject: [PATCH 3/4] UT: Remove custom singleton mutex name config option from UT sample config --- .../data_for_tests/monkey_configs/monkey_config_standard.json | 1 - 1 file changed, 1 deletion(-) diff --git a/monkey/tests/data_for_tests/monkey_configs/monkey_config_standard.json b/monkey/tests/data_for_tests/monkey_configs/monkey_config_standard.json index a90773aa7..561300d1f 100644 --- a/monkey/tests/data_for_tests/monkey_configs/monkey_config_standard.json +++ b/monkey/tests/data_for_tests/monkey_configs/monkey_config_standard.json @@ -44,7 +44,6 @@ }, "internal": { "general": { - "singleton_mutex_name": "{2384ec59-0df8-4ab9-918c-843740924a28}", "keep_tunnel_open_time": 60, "monkey_dir_name": "monkey_dir", "started_on_island": false From f90434d38da734e43e39153e6ffbbc898699f8e2 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Mon, 15 Nov 2021 16:35:07 +0530 Subject: [PATCH 4/4] Chaneglog: Add entry for removing custom singleton mutex name config option --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac9093b9e..7b78ad996 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/). - Checkbox for file logging. #1537 - Remove serialization of config. #1537 - Checkbox that gave the option to not try to first move the dropper file. #1537 +- Custom singleton mutex name config option. #1589 ### Fixed - A bug in network map page that caused delay of telemetry log loading. #1545