diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d5cf0e0..4e9b3cd7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and simply didn't have the time to go back and retroactively create one. ### Fixed - Possible exception due to _pre-registering_ of `session` with `manager` +- Fixed base64 stream in `LinuxWriter` ### Added - Added alternatives to `bash` to be used during _shell upgrade_ for a _better shell_ - Added a warning message when a `KeyboardInterrupt` is caught diff --git a/pwncat/facts/ability.py b/pwncat/facts/ability.py index 79d3e46c..68a94810 100644 --- a/pwncat/facts/ability.py +++ b/pwncat/facts/ability.py @@ -346,6 +346,7 @@ def open( exit_cmd.encode("utf-8") ), name=path, + stream=self.method.stream ) # Automatically decode to the specified encoding if requested diff --git a/pwncat/platform/linux.py b/pwncat/platform/linux.py index c9c45e73..5b5e8b01 100644 --- a/pwncat/platform/linux.py +++ b/pwncat/platform/linux.py @@ -19,6 +19,7 @@ import pathlib import tempfile import subprocess +import base64 from io import TextIOWrapper, BufferedIOBase, UnsupportedOperation from typing import List, Union, BinaryIO, Optional, Generator from subprocess import TimeoutExpired, CalledProcessError @@ -382,7 +383,7 @@ class LinuxWriter(BufferedIOBase): 0x7F, ] - def __init__(self, popen, on_close=None, name: str = None): + def __init__(self, popen, on_close=None, name: str = None, stream = Stream.RAW): super().__init__() self.popen = popen @@ -390,6 +391,7 @@ def __init__(self, popen, on_close=None, name: str = None): self.since_newline = 0 self.on_close = on_close self.name = name + self.stream = stream def readable(self): return False @@ -418,7 +420,9 @@ def write(self, b): if self.popen.poll() is not None: raise PermissionError("file write failed") - if self.popen.platform.has_pty: + if self.stream is Stream.BASE64: + self.popen.stdin.write(base64.b64encode(b)) + elif self.popen.platform.has_pty: # Control sequences need escaping translated = [] for idx, c in enumerate(b):