Skip to content

Commit 0da48a3

Browse files
committed
Improve code for printing the PS streams
1 parent b232520 commit 0da48a3

1 file changed

Lines changed: 8 additions & 13 deletions

File tree

nxc/protocols/winrm.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -265,19 +265,14 @@ def execute(self, payload=None, get_output=False, shell_type="cmd"):
265265
result: tuple[str, PSDataStreams, bool]
266266
if result[2]:
267267
self.logger.fail("Error executing powershell command, non-zero return code")
268-
# Display all channels of the PSDataStreams
269-
for msg in result[1].debug:
270-
self.logger.debug(str(msg).rstrip())
271-
for msg in result[1].verbose:
272-
self.logger.display(str(msg).rstrip())
273-
for msg in result[1].information:
274-
self.logger.display(str(msg).rstrip())
275-
for msg in result[1].progress:
276-
self.logger.display(str(msg).rstrip())
277-
for msg in result[1].warning:
278-
self.logger.display(str(msg).rstrip())
279-
for msg in result[1].error:
280-
self.logger.fail(str(msg).rstrip())
268+
for out_type in ["debug", "verbose", "information", "progress", "warning", "error"]:
269+
stream: list[str] = getattr(result[1], out_type)
270+
for msg in stream:
271+
if str(msg) != "None":
272+
if out_type == "error":
273+
self.logger.fail(str(msg).rstrip())
274+
else:
275+
self.logger.display(str(msg).rstrip())
281276
# Display stdout
282277
for line in result[0].splitlines():
283278
self.logger.highlight(line.rstrip())

0 commit comments

Comments
 (0)