How to use the pypsexec.scmr.DesiredAccess function in pypsexec

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_scmr.py View on Github external
def test_enumerate_services(self, session):
        scmr = SCMRApi(session)
        scmr.open()
        try:
            scmr_handle = scmr.open_sc_manager_w(
                session.connection.server_name,
                None,
                DesiredAccess.SC_MANAGER_CONNECT |
                DesiredAccess.SC_MANAGER_CREATE_SERVICE |
                DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE)

            types = ServiceType.SERVICE_INTERACTIVE_PROCESS | \
                ServiceType.SERVICE_KERNEL_DRIVER | \
                ServiceType.SERVICE_WIN32_SHARE_PROCESS | \
                ServiceType.SERVICE_WIN32_OWN_PROCESS | \
                ServiceType.SERVICE_FILE_SYSTEM_DRIVER
            actual = scmr.enum_services_status_w(scmr_handle,
                                                 types,
                                                 EnumServiceState.
                                                 SERVICE_STATE_ALL)

            assert len(actual) > 0
            assert isinstance(actual[0]['display_name'], string_types)
            assert isinstance(actual[0]['service_name'], string_types)
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def open(self):
        if self._scmr:
            log.debug("Handle for SCMR on %s is already open"
                      % self.smb_session.connection.server_name)
            return

        # connect to the SCMR Endpoint
        log.info("Opening handle for SCMR on %s"
                 % self.smb_session.connection.server_name)
        self._scmr = SCMRApi(self.smb_session)
        self._scmr.open()
        self._scmr_handle = self._scmr.open_sc_manager_w(
            self.smb_session.connection.server_name,
            None,
            DesiredAccess.SC_MANAGER_CONNECT |
            DesiredAccess.SC_MANAGER_CREATE_SERVICE |
            DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE
        )
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def open(self):
        if self._scmr:
            log.debug("Handle for SCMR on %s is already open"
                      % self.smb_session.connection.server_name)
            return

        # connect to the SCMR Endpoint
        log.info("Opening handle for SCMR on %s"
                 % self.smb_session.connection.server_name)
        self._scmr = SCMRApi(self.smb_session)
        self._scmr.open()
        self._scmr_handle = self._scmr.open_sc_manager_w(
            self.smb_session.connection.server_name,
            None,
            DesiredAccess.SC_MANAGER_CONNECT |
            DesiredAccess.SC_MANAGER_CREATE_SERVICE |
            DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE
        )
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
if self._scmr:
            log.debug("Handle for SCMR on %s is already open"
                      % self.smb_session.connection.server_name)
            return

        # connect to the SCMR Endpoint
        log.info("Opening handle for SCMR on %s"
                 % self.smb_session.connection.server_name)
        self._scmr = SCMRApi(self.smb_session)
        self._scmr.open()
        self._scmr_handle = self._scmr.open_sc_manager_w(
            self.smb_session.connection.server_name,
            None,
            DesiredAccess.SC_MANAGER_CONNECT |
            DesiredAccess.SC_MANAGER_CREATE_SERVICE |
            DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE
        )
github jborean93 / pypsexec / pypsexec / exec.py View on Github external
guid = uuid.uuid4()

connection = Connection(guid, server, port)
try:
    connection.connect()

    session = Session(connection, username, password)
    session.connect()

    # open the service manager
    scmr_api = SCMRApi(session)
    scmr_api.open()

    try:
        sc_desired_access = DesiredAccess.SC_MANAGER_CONNECT | \
                            DesiredAccess.SC_MANAGER_CREATE_SERVICE | \
                            DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE
        scm_handle = scmr_api.open_sc_manager_w(server, None, sc_desired_access)

        try:
            svc_desired_access = DesiredAccess.SERVICE_QUERY_STATUS | \
                                 DesiredAccess.SERVICE_START | \
                                 DesiredAccess.SERVICE_STOP | \
                                 DesiredAccess.DELETE

            # delete and create a brand new service
            try:
                service_handle = scmr_api.open_service_w(scm_handle, svc_name,
                                                         svc_desired_access)
            except SCMRException as exc:
                # check the return code wasn't service does not exist
                if exc.return_code != 1060:
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def _open_service(self):
        if self._handle:
            return self._handle

        # connect to the desired service in question
        desired_access = DesiredAccess.SERVICE_QUERY_STATUS | \
            DesiredAccess.SERVICE_START | \
            DesiredAccess.SERVICE_STOP | \
            DesiredAccess.DELETE
        try:
            log.info("Opening handle for Service %s" % self.name)
            self._handle = self._scmr.open_service_w(self._scmr_handle,
                                                     self.name,
                                                     desired_access)
        except SCMRException as exc:
            if exc.return_code != \
                    ScmrReturnValues.ERROR_SERVICE_DOES_NOT_EXIST:
                raise exc
            else:
                log.debug("Could not open handle for service %s as it did "
                          "not exist" % self.name)
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def _open_service(self):
        if self._handle:
            return self._handle

        # connect to the desired service in question
        desired_access = DesiredAccess.SERVICE_QUERY_STATUS | \
            DesiredAccess.SERVICE_START | \
            DesiredAccess.SERVICE_STOP | \
            DesiredAccess.DELETE
        try:
            log.info("Opening handle for Service %s" % self.name)
            self._handle = self._scmr.open_service_w(self._scmr_handle,
                                                     self.name,
                                                     desired_access)
        except SCMRException as exc:
            if exc.return_code != \
                    ScmrReturnValues.ERROR_SERVICE_DOES_NOT_EXIST:
                raise exc
            else:
                log.debug("Could not open handle for service %s as it did "
                          "not exist" % self.name)
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def _open_service(self):
        if self._handle:
            return self._handle

        # connect to the desired service in question
        desired_access = DesiredAccess.SERVICE_QUERY_STATUS | \
            DesiredAccess.SERVICE_START | \
            DesiredAccess.SERVICE_STOP | \
            DesiredAccess.DELETE
        try:
            log.info("Opening handle for Service %s" % self.name)
            self._handle = self._scmr.open_service_w(self._scmr_handle,
                                                     self.name,
                                                     desired_access)
        except SCMRException as exc:
            if exc.return_code != \
                    ScmrReturnValues.ERROR_SERVICE_DOES_NOT_EXIST:
                raise exc
            else:
                log.debug("Could not open handle for service %s as it did "
                          "not exist" % self.name)
github jborean93 / pypsexec / pypsexec / scmr.py View on Github external
def _open_service(self):
        if self._handle:
            return self._handle

        # connect to the desired service in question
        desired_access = DesiredAccess.SERVICE_QUERY_STATUS | \
            DesiredAccess.SERVICE_START | \
            DesiredAccess.SERVICE_STOP | \
            DesiredAccess.DELETE
        try:
            log.info("Opening handle for Service %s" % self.name)
            self._handle = self._scmr.open_service_w(self._scmr_handle,
                                                     self.name,
                                                     desired_access)
        except SCMRException as exc:
            if exc.return_code != \
                    ScmrReturnValues.ERROR_SERVICE_DOES_NOT_EXIST:
                raise exc
            else:
                log.debug("Could not open handle for service %s as it did "
                          "not exist" % self.name)
github jborean93 / pypsexec / pypsexec / exec.py View on Github external
# Setup SMB connection and session
guid = uuid.uuid4()

connection = Connection(guid, server, port)
try:
    connection.connect()

    session = Session(connection, username, password)
    session.connect()

    # open the service manager
    scmr_api = SCMRApi(session)
    scmr_api.open()

    try:
        sc_desired_access = DesiredAccess.SC_MANAGER_CONNECT | \
                            DesiredAccess.SC_MANAGER_CREATE_SERVICE | \
                            DesiredAccess.SC_MANAGER_ENUMERATE_SERVICE
        scm_handle = scmr_api.open_sc_manager_w(server, None, sc_desired_access)

        try:
            svc_desired_access = DesiredAccess.SERVICE_QUERY_STATUS | \
                                 DesiredAccess.SERVICE_START | \
                                 DesiredAccess.SERVICE_STOP | \
                                 DesiredAccess.DELETE

            # delete and create a brand new service
            try:
                service_handle = scmr_api.open_service_w(scm_handle, svc_name,
                                                         svc_desired_access)
            except SCMRException as exc:
                # check the return code wasn't service does not exist