Skip to content

Commit 5514bfe

Browse files
authored
fresh schtask_as.py
Signed-off-by: Kahvi-0xFF <46513413+Kahvi-0@users.noreply.github.com>
1 parent a754149 commit 5514bfe

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

nxc/modules/schtask_as.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from traceback import format_exc
33
from nxc.protocols.smb.atexec import TSCH_EXEC
44

5+
56
class NXCModule:
67
"""
78
Execute a scheduled task remotely as a already connected user by @Defte_
@@ -50,7 +51,6 @@ def options(self, context, module_options):
5051
name = "schtask_as"
5152
description = "Remotely execute a scheduled task as a logged on user"
5253
supported_protocols = ["smb"]
53-
multiple_hosts = False
5454

5555
def on_admin_login(self, context, connection):
5656
self.logger = context.log
@@ -69,18 +69,17 @@ def on_admin_login(self, context, connection):
6969
return 1
7070
else:
7171
self.logger.display(f"Uploading {self.binary_to_upload}")
72-
binary_file_location = self.tmp_share if self.output_file_location is None else self.output_file_location
7372
with open(self.binary_to_upload, "rb") as binary_to_upload:
7473
try:
7574
self.binary_to_upload_name = os.path.basename(self.binary_to_upload)
76-
connection.conn.putFile(self.share, f"{binary_file_location}{self.binary_to_upload_name}", binary_to_upload.read)
77-
self.logger.success(f"Binary {self.binary_to_upload_name} successfully uploaded in {binary_file_location}{self.binary_to_upload_name}")
75+
connection.conn.putFile(self.share, f"{self.tmp_share}{self.binary_to_upload_name}", binary_to_upload.read)
76+
self.logger.success(f"Binary {self.binary_to_upload_name} successfully uploaded in {self.tmp_share}{self.binary_to_upload_name}")
7877
except Exception as e:
79-
self.logger.fail(f"Error writing file to share {binary_file_location}: {e}")
78+
self.logger.fail(f"Error writing file to share {self.tmp_share}: {e}")
8079
return 1
8180

8281
# Returnes self.command_to_run or \Windows\temp\BinToExecute.exe depending if BINARY=BinToExecute.exe
83-
#self.command_to_run = self.command_to_run if not self.binary_to_upload else f"{self.tmp_share}{self.command_to_run}"
82+
self.command_to_run = self.command_to_run if not self.binary_to_upload else f"{self.tmp_share}{self.command_to_run}"
8483
self.logger.display("Connecting to the remote Service control endpoint")
8584
try:
8685
exec_method = TSCH_EXEC(
@@ -97,14 +96,13 @@ def on_admin_login(self, context, connection):
9796
self.logger,
9897
connection.args.get_output_tries,
9998
connection.args.share,
100-
self.run_task_as,
99+
self.run_task_as,
101100
self.command_to_run,
102101
self.output_filename,
103102
self.task_name,
104103
self.output_file_location,
105104
)
106105

107-
108106
self.logger.display(f"Executing {self.command_to_run} as {self.run_task_as}")
109107
output = exec_method.execute(self.command_to_run, True)
110108

@@ -124,9 +122,7 @@ def on_admin_login(self, context, connection):
124122
finally:
125123
if self.binary_to_upload:
126124
try:
127-
context.log.success("Sleeping for 10 seconds to let binary run")
128-
sleep(10)
129-
connection.conn.deleteFile(self.share, f"{binary_file_location}{self.binary_to_upload_name}")
130-
context.log.success(f"Binary {binary_file_location}{self.binary_to_upload_name} successfully deleted")
125+
connection.conn.deleteFile(self.share, f"{self.tmp_share}{self.binary_to_upload_name}")
126+
context.log.success(f"Binary {self.binary_to_upload_name} successfully deleted")
131127
except Exception as e:
132128
context.log.fail(f"Error deleting {self.binary_to_upload_name} on {self.share}: {e}")

0 commit comments

Comments
 (0)