|
8 | 8 | from datetime import datetime |
9 | 9 | from pypsrp.wsman import NAMESPACES |
10 | 10 | from pypsrp.client import Client |
| 11 | +from pypsrp.powershell import PSDataStreams |
11 | 12 | from termcolor import colored |
12 | 13 |
|
13 | 14 | from impacket.examples.secretsdump import LocalOperations, LSASecrets, SAMHashes |
@@ -260,12 +261,30 @@ def execute(self, payload=None, get_output=False, shell_type="cmd"): |
260 | 261 | return result[0] |
261 | 262 | self.logger.success(f"Executed command (shell type: {shell_type})") |
262 | 263 | if not self.args.no_output: |
263 | | - if result[2] == 0: |
264 | | - for line in result[0].replace("\r", "").splitlines(): |
265 | | - self.logger.highlight(line.strip()) |
| 264 | + if shell_type == "powershell": |
| 265 | + result: tuple[str, PSDataStreams, bool] |
| 266 | + if result[2]: |
| 267 | + self.logger.fail("Error executing powershell command, non-zero return code") |
| 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()) |
| 276 | + # Display stdout |
| 277 | + for line in result[0].splitlines(): |
| 278 | + self.logger.highlight(line.rstrip()) |
266 | 279 | else: |
267 | | - for line in result[1].replace("\r", "").splitlines(): |
268 | | - self.logger.fail(line.strip()) |
| 280 | + # Tuple of (stdout, stderr, returncode) |
| 281 | + result: tuple[str, str, int] |
| 282 | + if result[2] == 0: |
| 283 | + for line in result[0].replace("\r", "").splitlines(): |
| 284 | + self.logger.highlight(line.rstrip()) |
| 285 | + else: |
| 286 | + for line in result[1].replace("\r", "").splitlines(): |
| 287 | + self.logger.fail(line.rstrip()) |
269 | 288 |
|
270 | 289 | def ps_execute(self, payload=None, get_output=False): |
271 | 290 | command = payload if payload else self.args.ps_execute |
|
0 commit comments