How to use pypsexec - 10 common examples

To help you get started, we’ve selected a few pypsexec examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jborean93 / pypsexec / tests / test_client.py View on Github external
def test_empty_filled_queue(self):
        client = Client("server", "username", "password")
        queue = Queue()
        queue.put(b"Hello")
        queue.put(b"\n")
        queue.put(b"World")
        expected = b"Hello\nWorld"
        actual = client._empty_queue(queue)
        assert actual == expected
github jborean93 / pypsexec / tests / test_client.py View on Github external
def _get_paexec_files_and_services(self, client):
        server = os.environ['PYPSEXEC_SERVER']
        username = os.environ['PYPSEXEC_USERNAME']
        password = os.environ['PYPSEXEC_PASSWORD']
        paexec_services = []

        # need to close and reopen the connection to ensure deletes are
        # processed
        client.disconnect()
        client = Client(server, username=username, password=password)
        client.connect()
        scmr = client._service._scmr
        scmr_handle = client._service._scmr_handle

        services = scmr.enum_services_status_w(scmr_handle,
                                               ServiceType.
                                               SERVICE_WIN32_OWN_PROCESS,
                                               EnumServiceState.
                                               SERVICE_STATE_ALL)
        for service in services:
            if service['service_name'].lower().startswith("paexec"):
                paexec_services.append(service['service_name'])

        smb_tree = TreeConnect(client.session,
                               r"\\%s\ADMIN$" % client.connection.server_name)
        smb_tree.connect()
github jborean93 / pypsexec / tests / test_client.py View on Github external
def _get_new_generic_client(self, client):
        username = os.environ['PYPSEXEC_USERNAME']
        password = os.environ['PYPSEXEC_PASSWORD']
        new_client = Client(client.server, username, password)
        new_client.pid = 1234
        new_client.current_host = "other-host"
        new_client.service_name = "PAExec-%d-%s"\
                                  % (new_client.pid, new_client.current_host)
        new_client._exe_file = "%s.exe" % new_client.service_name
        new_client._service = Service(new_client.service_name,
                                      new_client.session)
        return new_client
github jborean93 / pypsexec / tests / test_client.py View on Github external
def test_proc_both_elevated_and_limited_error(self):
        client = Client("username", "password", "server")
        with pytest.raises(PypsexecException) as exc:
            client.run_executable("whoami",
                                  run_elevated=True,
                                  run_limited=True)
        assert str(exc.value) == "Both run_elevated and run_limited are " \
                                 "set, only 1 of these can be true"
github jborean93 / pypsexec / tests / test_client.py View on Github external
def client(self):
        server = os.environ.get('PYPSEXEC_SERVER', None)
        username = os.environ.get('PYPSEXEC_USERNAME', None)
        password = os.environ.get('PYPSEXEC_PASSWORD', None)

        if server and username and password:
            client = Client(server, username=username, password=password)
            client.connect()
            try:
                client.create_service()
                yield client
            finally:
                client.disconnect()
        else:
            pytest.skip("PYPSEXEC_SERVER, PYPSEXEC_USERNAME, PYPSEXEC_PASSWORD"
                        " environment variables were not set. Integration "
github jborean93 / pypsexec / tests / test_client.py View on Github external
def test_proc_stdin_and_async(self):
        client = Client("username", "password", "server")
        with pytest.raises(PypsexecException) as exc:
            client.run_executable("whoami",
                                  asynchronous=True,
                                  stdin=b"")
        assert str(exc.value) == "Cannot send stdin data on an interactive " \
                                 "or asynchronous process"
github jborean93 / pypsexec / tests / test_exceptions.py View on Github external
def test_throw_pypsexec_exception(self):
        with pytest.raises(PypsexecException) as exc:
            raise PypsexecException("hi")
        assert str(exc.value) == "hi"
github jborean93 / pypsexec / tests / test_client.py View on Github external
def test_proc_stdin_and_interactive(self):
        client = Client("username", "password", "server")
        with pytest.raises(PypsexecException) as exc:
            client.run_executable("whoami",
                                  interactive=True,
                                  stdin=b"")
        assert str(exc.value) == "Cannot send stdin data on an interactive " \
                                 "or asynchronous process"
github jborean93 / pypsexec / tests / test_scmr.py View on Github external
def test_open_service_missing(self, session):
        service = Service("missing-service", session)
        service.open()
        assert service._handle is None

        with pytest.raises(PypsexecException) as exc:
            service.start()
        assert str(exc.value) == "Cannot start service missing-service as " \
                                 "it does not exist"

        with pytest.raises(PypsexecException) as exc:
            service.stop()
        assert str(exc.value) == "Cannot stop service missing-service as " \
                                 "it does not exist"
        service.close()
github jborean93 / pypsexec / tests / test_exceptions.py View on Github external
def test_throw_pypsexec_exception(self):
        with pytest.raises(PypsexecException) as exc:
            raise PypsexecException("hi")
        assert str(exc.value) == "hi"