Skip to content

Commit 8074d76

Browse files
committed
properly handle shell metacharacters in command output for wmi
1 parent 434ed73 commit 8074d76

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

nxc/protocols/wmi/wmiexec.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def execute_WithOutput(self, command):
6767
self.__registry_Path = f"Software\\Classes\\{gen_random_string(8)}"
6868

6969
# 1. Run the command and write output to file
70-
self.execute_remote(f'{self.__shell} {command} 1> "{result_output}" 2>&1')
70+
self.execute_remote(f'{self.__shell} ({command}) 1> "{result_output}" 2>&1')
7171
self.logger.info(f"Waiting {self.__exec_timeout}s for command to complete.")
7272
time.sleep(self.__exec_timeout)
7373

@@ -109,7 +109,7 @@ def execute_WithOutput_psh(self, command):
109109

110110
# 1. Run the command and write output to file
111111
if not command.lower().startswith("powershell"):
112-
command = f"powershell -Command {command}"
112+
command = f'powershell -Command "& {{{command}}}"'
113113
self.execute_remote(f'{command} > "{result_output}" 2>&1')
114114
self.logger.info(f"Waiting {self.__exec_timeout}s for command to complete.")
115115
time.sleep(self.__exec_timeout)

0 commit comments

Comments
 (0)