Moved imports to top of try
This commit is contained in:
parent
ae414bcd13
commit
86cf09419c
|
@ -31,14 +31,15 @@ class CommunicateAsNewUser(PBA):
|
||||||
def run(self):
|
def run(self):
|
||||||
username = USERNAME + ''.join(random.choice(string.ascii_lowercase) for _ in range(5))
|
username = USERNAME + ''.join(random.choice(string.ascii_lowercase) for _ in range(5))
|
||||||
if is_windows_os():
|
if is_windows_os():
|
||||||
|
# Importing these only on windows, as they won't exist on linux.
|
||||||
|
import win32con
|
||||||
|
import win32process
|
||||||
|
import win32security
|
||||||
|
|
||||||
if not self.try_to_create_user_windows(username, PASSWORD):
|
if not self.try_to_create_user_windows(username, PASSWORD):
|
||||||
return # no point to continue if failed creating the user.
|
return # no point to continue if failed creating the user.
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Importing these only on windows, as they won't exist on linux.
|
|
||||||
import win32con
|
|
||||||
import win32process
|
|
||||||
import win32security
|
|
||||||
# Logon as new user: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonusera
|
# Logon as new user: https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-logonusera
|
||||||
new_user_logon_token_handle = win32security.LogonUser(
|
new_user_logon_token_handle = win32security.LogonUser(
|
||||||
username,
|
username,
|
||||||
|
@ -99,7 +100,7 @@ class CommunicateAsNewUser(PBA):
|
||||||
logger.debug("Trying to execute these commands: {}".format(final_command))
|
logger.debug("Trying to execute these commands: {}".format(final_command))
|
||||||
output = subprocess.check_output(final_command, stderr=subprocess.STDOUT, shell=True)
|
output = subprocess.check_output(final_command, stderr=subprocess.STDOUT, shell=True)
|
||||||
PostBreachTelem(self, (
|
PostBreachTelem(self, (
|
||||||
CREATED_PROCESS_AS_USER_LINUX_FORMAT.format(commandline, username, output[:50]), True)).send()
|
CREATED_PROCESS_AS_USER_LINUX_FORMAT.format(commandline, username, output[:150]), True)).send()
|
||||||
return
|
return
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
PostBreachTelem(self, (e.output, False)).send()
|
PostBreachTelem(self, (e.output, False)).send()
|
||||||
|
|
Loading…
Reference in New Issue