Joining commands using ,,.join() for linux

This commit is contained in:
Shay Nehmad 2019-09-04 12:40:53 +03:00
parent 4f912d9d1e
commit 097d8831c8
2 changed files with 6 additions and 15 deletions

View File

@ -4,16 +4,6 @@ from common.data.post_breach_consts import POST_BREACH_BACKDOOR_USER
from infection_monkey.post_breach.pba import PBA
from infection_monkey.config import WormConfiguration
__author__ = 'danielg'
LINUX_COMMANDS = ['useradd', '-M', '--expiredate',
datetime.datetime.today().strftime('%Y-%m-%d'), '--inactive', '0', '-c', 'MONKEY_USER',
WormConfiguration.user_to_add]
WINDOWS_COMMANDS = ['net', 'user', WormConfiguration.user_to_add,
WormConfiguration.remote_user_pass,
'/add', '/ACTIVE:NO']
class BackdoorUser(PBA):
def __init__(self):
@ -34,13 +24,13 @@ class BackdoorUser(PBA):
def get_linux_commands_to_add_user(username):
linux_cmds = [
'useradd',
'-M',
'-M', # Do not create homedir
'--expiredate',
datetime.datetime.today().strftime('%Y-%m-%d'),
'--inactive',
'0',
'-c',
'MONKEY_USER',
'-c', # Comment
'MONKEY_USER', # Comment
username]
return linux_cmds

View File

@ -95,8 +95,9 @@ class CommunicateAsNewUser(PBA):
linux_cmds = BackdoorUser.get_linux_commands_to_add_user(username)
commandline = "'ping -c 2 google.com'"
linux_cmds.extend([";", "sudo", "-u", username, commandline])
logger.debug("Trying these commands: {}".format(str(linux_cmds)))
output = subprocess.check_output(linux_cmds, stderr=subprocess.STDOUT, shell=True)
final_command = ' '.join(linux_cmds)
logger.debug("Trying to execute these commands: {}".format(final_command))
output = subprocess.check_output(final_command, stderr=subprocess.STDOUT, shell=True)
PostBreachTelem(self, (
CREATED_PROCESS_AS_USER_LINUX_FORMAT.format(commandline, username, output[:50]), True)).send()
return