Skip to content

Commit 33f3f7c

Browse files
committed
Remove global variable
1 parent 64f0f78 commit 33f3f7c

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

nxc/modules/schtask_as.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ def deleteartifact(self):
154154
dce.connect()
155155
dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
156156
dce.bind(tsch.MSRPC_UUID_TSCHS)
157-
self.logger.display(f"Deleting task \\{tmpName}")
158-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
157+
self.logger.display(f"Deleting task \\{self.task}")
158+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
159159
dce.disconnect()
160160

161161
def execute(self, command, output=False):
@@ -234,57 +234,57 @@ def gen_xml(self, command, fileless=False):
234234
return xml
235235

236236
def execute_handler(self, command, fileless=False):
237-
global tmpName
238237
dce = self.__rpctransport.get_dce_rpc()
239238

240239
if self.__doKerberos:
241240
dce.set_auth_type(RPC_C_AUTHN_GSS_NEGOTIATE)
242241

243242
dce.set_credentials(*self.__rpctransport.get_credentials())
244243
dce.connect()
245-
tmpName = gen_random_string(8) if self.task is None else self.task
244+
# Give self.task a random string as name if not already specified
245+
self.task = gen_random_string(8) if self.task is None else self.task
246246
xml = self.gen_xml(command, fileless)
247247

248248
self.logger.info(f"Task XML: {xml}")
249-
self.logger.info(f"Creating task \\{tmpName}")
249+
self.logger.info(f"Creating task \\{self.task}")
250250
try:
251251
# windows server 2003 has no MSRPC_UUID_TSCHS, if it bind, it will return abstract_syntax_not_supported
252252
dce.set_auth_level(RPC_C_AUTHN_LEVEL_PKT_PRIVACY)
253253
dce.bind(tsch.MSRPC_UUID_TSCHS)
254-
tsch.hSchRpcRegisterTask(dce, f"\\{tmpName}", xml, tsch.TASK_CREATE, NULL, tsch.TASK_LOGON_NONE)
254+
tsch.hSchRpcRegisterTask(dce, f"\\{self.task}", xml, tsch.TASK_CREATE, NULL, tsch.TASK_LOGON_NONE)
255255
except Exception as e:
256256
if "ERROR_NONE_MAPPED" in str(e):
257257
self.logger.fail(f"User {self.user} is not connected on the target, cannot run the task")
258-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
258+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
259259
if e.error_code and hex(e.error_code) == "0x80070005":
260260
self.logger.fail("Schtask_as: Create schedule task got blocked.")
261-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
261+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
262262
if "ERROR_TRUSTED_DOMAIN_FAILURE" in str(e):
263263
self.logger.fail(f"User {self.user} does not exist in the domain.")
264-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
264+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
265265
if "SCHED_S_TASK_HAS_NOT_RUN" in str(e):
266-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
266+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
267267
if "ERROR_ALREADY_EXISTS" in str(e):
268268
self.logger.fail(f"Schtask_as: Create schedule task failed: {e}")
269269
else:
270270
self.logger.fail(f"Schtask_as: Create schedule task failed: {e}")
271-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
271+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
272272
return
273273

274-
self.logger.info(f"Running task \\{tmpName}")
275-
tsch.hSchRpcRun(dce, f"\\{tmpName}")
274+
self.logger.info(f"Running task \\{self.task}")
275+
tsch.hSchRpcRun(dce, f"\\{self.task}")
276276

277277
done = False
278278
while not done:
279-
self.logger.debug(f"Calling SchRpcGetLastRunInfo for \\{tmpName}")
280-
resp = tsch.hSchRpcGetLastRunInfo(dce, f"\\{tmpName}")
279+
self.logger.debug(f"Calling SchRpcGetLastRunInfo for \\{self.task}")
280+
resp = tsch.hSchRpcGetLastRunInfo(dce, f"\\{self.task}")
281281
if resp["pLastRuntime"]["wYear"] != 0:
282282
done = True
283283
else:
284284
sleep(2)
285285

286-
self.logger.info(f"Deleting task \\{tmpName}")
287-
tsch.hSchRpcDelete(dce, f"\\{tmpName}")
286+
self.logger.info(f"Deleting task \\{self.task}")
287+
tsch.hSchRpcDelete(dce, f"\\{self.task}")
288288

289289
if self.__retOutput:
290290
if fileless:

0 commit comments

Comments
 (0)