From 0632beb9924d2a1381acc3816d730088422ef2c5 Mon Sep 17 00:00:00 2001 From: Mitul16 Date: Wed, 16 Feb 2022 16:19:35 +0530 Subject: [PATCH] chore: Pre-merge tasks completed Oops, I missed the import for PlatformError :p --- docs/source/conf.py | 3 ++- pwncat/commands/upload.py | 8 +++++++- pwncat/modules/linux/implant/authorized_key.py | 4 +++- tests/conftest.py | 13 +++++++------ tests/test_session.py | 15 ++++++++------- 5 files changed, 27 insertions(+), 16 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 80faa23..390c04d 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -12,7 +12,8 @@ # import os import sys -sys.path.insert(0, os.path.abspath('../..')) + +sys.path.insert(0, os.path.abspath("../..")) # -- Project information ----------------------------------------------------- diff --git a/pwncat/commands/upload.py b/pwncat/commands/upload.py index 98cc8b4..ffa86c7 100644 --- a/pwncat/commands/upload.py +++ b/pwncat/commands/upload.py @@ -14,6 +14,7 @@ from rich.progress import ( import pwncat from pwncat.util import console, copyfileobj, human_readable_size, human_readable_delta from pwncat.commands import Complete, Parameter, CommandDefinition +from pwncat.platform import PlatformError class Command(CommandDefinition): @@ -77,5 +78,10 @@ class Command(CommandDefinition): f"uploaded [cyan]{human_readable_size(length)}[/cyan] " f"in [green]{human_readable_delta(elapsed)}[/green]" ) - except (FileNotFoundError, PermissionError, IsADirectoryError, PlatformError) as exc: + except ( + FileNotFoundError, + PermissionError, + IsADirectoryError, + PlatformError, + ) as exc: self.parser.error(str(exc)) diff --git a/pwncat/modules/linux/implant/authorized_key.py b/pwncat/modules/linux/implant/authorized_key.py index c813f07..f7ac677 100644 --- a/pwncat/modules/linux/implant/authorized_key.py +++ b/pwncat/modules/linux/implant/authorized_key.py @@ -93,7 +93,9 @@ class Module(ImplantModule): yield Status("verifying user permissions") current_user = session.current_user() if user != "__pwncat_current__" and current_user.id != 0: - raise ModuleFailed("only [blue]root[/blue] can install implants for other users") + raise ModuleFailed( + "only [blue]root[/blue] can install implants for other users" + ) if not os.path.isfile(key): raise ModuleFailed(f"private key [bleu]{key}[/blue] does not exist") diff --git a/tests/conftest.py b/tests/conftest.py index bb1f4b2..a65517f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,9 +8,10 @@ import dataclasses from io import StringIO import pytest -from pwncat.channel import ChannelError from Crypto.PublicKey import RSA +from pwncat.channel import ChannelError + PLATFORM_MAP = {"ubuntu": "linux", "centos": "linux", "windows": "windows"} @@ -37,13 +38,13 @@ def connection_details_for(name): @pytest.fixture(params=["ubuntu", "centos"]) def linux_details(request): - """ Get available connection details for linux hosts """ + """Get available connection details for linux hosts""" return connection_details_for(request.param) @pytest.fixture(params=["windows"]) def windows_details(request): - """ Get available connection details for windows hosts """ + """Get available connection details for windows hosts""" return connection_details_for(request.param) @@ -84,18 +85,18 @@ set -g db "memory://" @pytest.fixture(params=["windows", "ubuntu", "centos"]) def session(request): - """ Start a session with any platform """ + """Start a session with any platform""" yield from session_for(request) @pytest.fixture(params=["windows"]) def windows(request): - """ Start a windows session """ + """Start a windows session""" yield from session_for(request) @pytest.fixture(params=["ubuntu", "centos"]) def linux(request): - """ Start a linux session """ + """Start a linux session""" yield from session_for(request) diff --git a/tests/test_session.py b/tests/test_session.py index 79949d3..2f8339a 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -1,6 +1,7 @@ #!/usr/bin/env python3 import pytest + from pwncat.modules import IncorrectPlatformError @@ -13,13 +14,13 @@ def test_session_iter_users(session): def test_session_find_user_name(session): - """ Test that locating a user by name works """ + """Test that locating a user by name works""" assert session.find_user(name="john") is not None def test_session_find_user_uid(linux): - """ Test locating a user by their UID (for linux only) """ + """Test locating a user by their UID (for linux only)""" user = linux.find_user(uid=0) @@ -28,7 +29,7 @@ def test_session_find_user_uid(linux): def test_session_find_user_sid(windows): - """ Test locating a user by their SID (for windows only) """ + """Test locating a user by their SID (for windows only)""" # This is the SID of the Administrator in the windows servercore image... # This will only work from the testing container, but I've decided that's fine. @@ -39,7 +40,7 @@ def test_session_find_user_sid(windows): def test_session_find_module(session): - """ Test that locating modules works """ + """Test that locating modules works""" assert len(list(session.find_module("enumerate.*"))) > 0 assert len(list(session.find_module("enumerate.user"))) == 1 @@ -47,7 +48,7 @@ def test_session_find_module(session): def test_session_run_module(session): - """ Test running a module within a session """ + """Test running a module within a session""" # We should be able to enumerate a hostname facts = session.run("enumerate", types=["system.hostname"]) @@ -55,14 +56,14 @@ def test_session_run_module(session): def test_session_wrong_platform_linux(linux): - """ Test that windows modules don't run in linux """ + """Test that windows modules don't run in linux""" with pytest.raises(IncorrectPlatformError): linux.run("windows.enumerate.user") def test_session_wrong_platform_windows(windows): - """ Test that linux modules don't run on windows """ + """Test that linux modules don't run on windows""" with pytest.raises(IncorrectPlatformError): windows.run("linux.enumerate.user")