1
0
mirror of https://github.com/calebstewart/pwncat.git synced 2024-11-24 01:25:37 +01:00
pwncat/tests/test_session.py

70 lines
2.0 KiB
Python
Raw Normal View History

2021-05-31 03:01:57 +02:00
#!/usr/bin/env python3
import pytest
2021-05-31 03:01:57 +02:00
from pwncat.modules import IncorrectPlatformError
def test_session_iter_users(session):
"""Test the ability to iterate users. This happens
implicitly with session.current_user(), but it's worth
testing separately."""
assert "john" in [user.name for user in session.iter_users()]
def test_session_find_user_name(session):
"""Test that locating a user by name works"""
2021-05-31 03:01:57 +02:00
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)"""
2021-05-31 03:01:57 +02:00
user = linux.find_user(uid=0)
assert user is not None
assert user.name == "root"
def test_session_find_user_sid(windows):
"""Test locating a user by their SID (for windows only)"""
2021-05-31 03:01:57 +02:00
# 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.
user = windows.find_user(uid="S-1-5-21-1417486881-3347836355-822217238-500")
assert user is not None
assert user.name == "Administrator"
def test_session_find_module(session):
"""Test that locating modules works"""
2021-05-31 03:01:57 +02:00
assert len(list(session.find_module("enumerate.*"))) > 0
assert len(list(session.find_module("enumerate.user"))) == 1
assert len(list(session.find_module("module_does_not_exist"))) == 0
def test_session_run_module(session):
"""Test running a module within a session"""
2021-05-31 03:01:57 +02:00
# We should be able to enumerate a hostname
facts = session.run("enumerate", types=["system.hostname"])
assert len(facts) > 0
def test_session_wrong_platform_linux(linux):
"""Test that windows modules don't run in linux"""
2021-05-31 03:01:57 +02:00
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"""
2021-05-31 03:01:57 +02:00
with pytest.raises(IncorrectPlatformError):
windows.run("linux.enumerate.user")