diff --git a/pwncat/modules/windows/enumerate/system/clipboard.py b/pwncat/modules/windows/enumerate/system/clipboard.py index 7d8cce3..6cadab3 100644 --- a/pwncat/modules/windows/enumerate/system/clipboard.py +++ b/pwncat/modules/windows/enumerate/system/clipboard.py @@ -2,25 +2,26 @@ from typing import Any, Dict, List -import pwncat import rich.markup + +import pwncat from pwncat import util from pwncat.db import Fact from pwncat.modules import ModuleFailed -from pwncat.modules.enumerate import EnumerateModule, Schedule from pwncat.platform import PlatformError -from pwncat.platform.windows import PowershellError, Windows +from pwncat.platform.windows import Windows, PowershellError +from pwncat.modules.enumerate import Schedule, EnumerateModule class ClipboardData(Fact): - def __init__(self, source, contents:str): + def __init__(self, source, contents: str): super().__init__(source=source, types=["system.clipboard"]) self.contents: bool = contents - def title(self, session): return f"Current clipboard contents:" + def description(self, session): return f"[yellow]{rich.markup.escape(self.contents)}[/yellow]" @@ -33,25 +34,18 @@ class Module(EnumerateModule): def enumerate(self, session): - try: - result = session.platform.powershell( - f"Get-Clipboard" - ) + result = session.platform.powershell(f"Get-Clipboard") if not result: - raise ModuleFailed( - f"failed to retrieve clipboard contents" - ) + return - if isinstance(result[0],list): + if isinstance(result[0], list) and result: contents = "\n".join(result[0]) else: contents = result[0] except PowershellError as exc: - raise ModuleFailed( - f"failed to retrieve clipboard contents" - ) from exc + raise ModuleFailed(f"failed to retrieve clipboard contents") from exc yield ClipboardData(self.name, contents) diff --git a/pwncat/platform/windows.py b/pwncat/platform/windows.py index 58b88f4..802b256 100644 --- a/pwncat/platform/windows.py +++ b/pwncat/platform/windows.py @@ -25,6 +25,7 @@ import signal import pathlib import tarfile import termios +import binascii import readline import textwrap import subprocess @@ -475,7 +476,12 @@ class Windows(Platform): if wait: # Receive the response - result = self.parse_response(self.channel.recvline()) + while True: + try: + result = self.parse_response(self.channel.recvline()) + break + except (gzip.BadGzipFile, binascii.Error) as exc: + continue # Raise an appropriate error if needed if result["error"] != 0: