diff --git a/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py b/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py index 2ab4476d8..034383140 100644 --- a/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py +++ b/monkey/infection_monkey/post_breach/actions/communicate_as_new_user.py @@ -47,7 +47,7 @@ class CommunicateAsNewUser(PBA): def communicate_as_new_user_linux(self, username): try: - with create_auto_new_user(username, PASSWORD) as new_user: + with create_auto_new_user(username, PASSWORD, False) as new_user: commandline = "sudo -u {username} ping -c 1 {domain}".format( username=new_user.username, domain=PING_TEST_DOMAIN) @@ -64,7 +64,7 @@ class CommunicateAsNewUser(PBA): import win32event try: - with create_auto_new_user(username, PASSWORD) as new_user: + with create_auto_new_user(username, PASSWORD, True) as new_user: # Using os.path is OK, as this is on windows for sure ping_app_path = os.path.join(os.environ["WINDIR"], "system32", "PING.exe") if not os.path.exists(ping_app_path): diff --git a/monkey/infection_monkey/utils/windows/auto_new_user.py b/monkey/infection_monkey/utils/windows/auto_new_user.py index c22b40c54..89fc464fc 100644 --- a/monkey/infection_monkey/utils/windows/auto_new_user.py +++ b/monkey/infection_monkey/utils/windows/auto_new_user.py @@ -32,7 +32,8 @@ class AutoNewUser: __metaclass__ = abc.ABCMeta def __init__(self, username, password): - raise NotImplementedError() + self.username = username + self.password = password @abc.abstractmethod def __enter__(self): @@ -60,8 +61,6 @@ class AutoNewLinuxUser(AutoNewUser): :raises: subprocess.CalledProcessError if failed to add the user. """ super(AutoNewLinuxUser, self).__init__(username, password) - self.username = username - self.password = password commands_to_add_user = get_linux_commands_to_add_user(username) logger.debug("Trying to add {} with commands {}".format(self.username, str(commands_to_add_user))) @@ -87,8 +86,6 @@ class AutoNewWindowsUser(AutoNewUser): :raises: subprocess.CalledProcessError if failed to add the user. """ super(AutoNewWindowsUser, self).__init__(username, password) - self.username = username - self.password = password windows_cmds = get_windows_commands_to_add_user(self.username, self.password, True) _ = subprocess.check_output(windows_cmds, stderr=subprocess.STDOUT, shell=True)