From 885a871be82b14021b490fc3fb30ec0900aa1b49 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 1 Apr 2022 17:09:50 +0530 Subject: [PATCH] Agent: Add timeouts to utils/linux/users.py --- monkey/infection_monkey/utils/linux/users.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/monkey/infection_monkey/utils/linux/users.py b/monkey/infection_monkey/utils/linux/users.py index 002c63f96..df01f9f18 100644 --- a/monkey/infection_monkey/utils/linux/users.py +++ b/monkey/infection_monkey/utils/linux/users.py @@ -3,6 +3,7 @@ import logging import shlex import subprocess +from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT from infection_monkey.utils.auto_new_user import AutoNewUser logger = logging.getLogger(__name__) @@ -43,7 +44,9 @@ class AutoNewLinuxUser(AutoNewUser): logger.debug( "Trying to add {} with commands {}".format(self.username, str(commands_to_add_user)) ) - _ = subprocess.check_output(commands_to_add_user, stderr=subprocess.STDOUT) + _ = subprocess.check_output( + commands_to_add_user, stderr=subprocess.STDOUT, timeout=SHORT_REQUEST_TIMEOUT + ) def __enter__(self): return self # No initialization/logging on needed in Linux @@ -52,7 +55,7 @@ class AutoNewLinuxUser(AutoNewUser): command_as_new_user = shlex.split( "sudo -u {username} {command}".format(username=self.username, command=command) ) - return subprocess.call(command_as_new_user) + return subprocess.call(command_as_new_user, timeout=SHORT_REQUEST_TIMEOUT) def __exit__(self, _exc_type, value, traceback): # delete the user. @@ -62,4 +65,6 @@ class AutoNewLinuxUser(AutoNewUser): self.username, str(commands_to_delete_user) ) ) - _ = subprocess.check_output(commands_to_delete_user, stderr=subprocess.STDOUT) + _ = subprocess.check_output( + commands_to_delete_user, stderr=subprocess.STDOUT, timeout=SHORT_REQUEST_TIMEOUT + )