1
0
mirror of https://github.com/calebstewart/pwncat.git synced 2024-11-27 02:44:14 +01:00

chore: Pre-merge tasks completed

Oops, I missed the import for PlatformError :p
This commit is contained in:
Mitul16 2022-02-16 16:19:35 +05:30
parent 1f6c82026e
commit 0632beb992
No known key found for this signature in database
GPG Key ID: 5C5BBBE501A9BA25
5 changed files with 27 additions and 16 deletions

View File

@ -12,7 +12,8 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('../..'))
sys.path.insert(0, os.path.abspath("../.."))
# -- Project information -----------------------------------------------------

View File

@ -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))

View File

@ -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")

View File

@ -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)

View File

@ -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")