From 9db70d10ed8bc34b4fc310187f1b09f69097426d Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Sun, 28 Nov 2021 15:52:07 -0500 Subject: [PATCH] Added lpwd and lcd commands for local cwd changes Also updated the documentation to reflect the new commands. Ran tests and formatting requirements. Fixes #218. --- CHANGELOG.md | 1 + docs/requirements.txt | 2 ++ docs/source/commands/index.rst | 2 ++ docs/source/commands/lcd.rst | 14 ++++++++++++++ docs/source/commands/lpwd.rst | 10 ++++++++++ pwncat/commands/lcd.py | 27 +++++++++++++++++++++++++++ pwncat/commands/lpwd.py | 17 +++++++++++++++++ 7 files changed, 73 insertions(+) create mode 100644 docs/source/commands/lcd.rst create mode 100644 docs/source/commands/lpwd.rst create mode 100644 pwncat/commands/lcd.py create mode 100644 pwncat/commands/lpwd.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 84eb506..04d690c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,7 @@ and simply didn't have the time to go back and retroactively create one. - Added `OSError` for `bind` protocol to show appropriate error messages - Contributing guidelines for GitHub maintainers - Installation instructions for BlackArch +- Added `lpwd` and `lcd` commands to interact with the local working directory ([#218](https://github.com/calebstewart/pwncat/issues/218)) ### Changed - Removed handling of `shell` argument to `Popen` to prevent `euid` problems ([#179](https://github.com/calebstewart/pwncat/issues/179)) - Changed some 'red' warning message color to 'yellow' diff --git a/docs/requirements.txt b/docs/requirements.txt index a04ff9f..042c3ec 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -10,4 +10,6 @@ zodburi==2.4.0 jinja2 paramiko==2.7.2 sphinx-toolbox==2.11.2 +apeye<1.0.0 enum-tools==0.6.4 +sphinx_rtd_theme==1.0.0 diff --git a/docs/source/commands/index.rst b/docs/source/commands/index.rst index c6e658e..fd8930b 100644 --- a/docs/source/commands/index.rst +++ b/docs/source/commands/index.rst @@ -12,7 +12,9 @@ Command index connect.rst download.rst escalate.rst + lcd.rst load.rst + lpwd.rst run.rst info.rst search.rst diff --git a/docs/source/commands/lcd.rst b/docs/source/commands/lcd.rst new file mode 100644 index 0000000..75fe425 --- /dev/null +++ b/docs/source/commands/lcd.rst @@ -0,0 +1,14 @@ +lcd +=== + +The ``lcwd`` command allows you to change the *local* working directory of the running +pwncat instance. This effects any command which interacts with the local filesystem ( +e.g. ``upload`` and ``download``). + +.. code-block:: bash + + # Example from @DanaEpp :P + lcd ~/engagements/client_some_gawd_aweful_guid/host_abc/loot + # Now, the following downloads will end up in the above directory + download /path/to/some/loot + download /paht/to/some/other/loot diff --git a/docs/source/commands/lpwd.rst b/docs/source/commands/lpwd.rst new file mode 100644 index 0000000..32b9d5e --- /dev/null +++ b/docs/source/commands/lpwd.rst @@ -0,0 +1,10 @@ +lpwd +==== + +The ``lpwd`` directory will print the current *local* working directory. This is the directory +which commands like ``upload`` and ``download`` will interpret as ``.``. + +.. code-block:: bash + + # Print the local working directory + lpwd diff --git a/pwncat/commands/lcd.py b/pwncat/commands/lcd.py new file mode 100644 index 0000000..78ab1a6 --- /dev/null +++ b/pwncat/commands/lcd.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 +import os +import pathlib + +import pwncat +from pwncat.commands import Complete, Parameter, CommandDefinition + + +class Command(CommandDefinition): + """Change the local current working directory""" + + PROG = "lcd" + ARGS = { + "path": Parameter(Complete.LOCAL_FILE), + } + + def run(self, manager: "pwncat.manager.Manager", args): + + # Expand `~` + path = pathlib.Path(args.path).expanduser() + + # Ensure the directory exists + if not path.is_dir(): + self.parser.error(f"{path}: not a directory") + + # Change to that directory + os.chdir(str(path)) diff --git a/pwncat/commands/lpwd.py b/pwncat/commands/lpwd.py new file mode 100644 index 0000000..9e929dd --- /dev/null +++ b/pwncat/commands/lpwd.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +from pathlib import Path + +import pwncat +from pwncat.util import console +from pwncat.commands import CommandDefinition + + +class Command(CommandDefinition): + """Print the local current working directory""" + + PROG = "lpwd" + ARGS = {} + + def run(self, manager: "pwncat.manager.Manager", args): + + console.print(Path.cwd())