Changed to similar levels of abstracion in user creation and deletion + not async

This commit is contained in:
Shay Nehmad 2019-10-03 12:25:26 +03:00
parent 04e1817931
commit 16f8c7841e
2 changed files with 7 additions and 6 deletions

View File

@ -54,10 +54,11 @@ class CommunicateAsNewUser(PBA):
final_command = ' '.join(linux_cmds) final_command = ' '.join(linux_cmds)
exit_status = os.system(final_command) exit_status = os.system(final_command)
self.send_ping_result_telemetry(exit_status, commandline, username) self.send_ping_result_telemetry(exit_status, commandline, username)
# delete the user, async in case it gets stuck. # delete the user.
commands_to_delete_user = get_linux_commands_to_delete_user(username) commands_to_delete_user = get_linux_commands_to_delete_user(username)
logger.debug("Trying to delete the user {} with commands {}".format(username, str(commands_to_delete_user))) logger.debug("Trying to delete the user {} with commands {}".format(username, str(commands_to_delete_user)))
_ = subprocess.Popen(commands_to_delete_user, stderr=subprocess.STDOUT, shell=True) delete_user_output = subprocess.check_output(" ".join(commands_to_delete_user), stderr=subprocess.STDOUT, shell=True)
logger.debug("Deletion output: {}".format(delete_user_output))
# Leaking the process on purpose - nothing we can do if it's stuck. # Leaking the process on purpose - nothing we can do if it's stuck.
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError as e:
PostBreachTelem(self, (e.output, False)).send() PostBreachTelem(self, (e.output, False)).send()

View File

@ -3,12 +3,12 @@ import datetime
def get_linux_commands_to_add_user(username): def get_linux_commands_to_add_user(username):
return [ return [
'useradd', 'adduser', # https://linux.die.net/man/8/adduser
'-M', # Do not create homedir '-M', # Do not create homedir
'--expiredate', '--expiredate', # The date on which the user account will be disabled.
datetime.datetime.today().strftime('%Y-%m-%d'), datetime.datetime.today().strftime('%Y-%m-%d'),
'--inactive', '--inactive', # The number of days after a password expires until the account is permanently disabled.
'0', '0', # A value of 0 disables the account as soon as the password has expired
'-c', # Comment '-c', # Comment
'MONKEY_USER', # Comment 'MONKEY_USER', # Comment
username] username]