Python impacket.dcerpc.v5.scmr.hREnumServicesStatusW() Examples

The following are 6 code examples of impacket.dcerpc.v5.scmr.hREnumServicesStatusW(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module impacket.dcerpc.v5.scmr , or try the search function .
Example #1
Source File: test_scmr.py    From CVE-2017-7494 with GNU General Public License v3.0 5 votes vote down vote up
def test_enumservices(self):
        dce, rpctransport, scHandle  = self.connect()

        #####################
        # EnumServicesStatusW
        dwServiceType = scmr.SERVICE_KERNEL_DRIVER | scmr.SERVICE_FILE_SYSTEM_DRIVER | scmr.SERVICE_WIN32_OWN_PROCESS | scmr.SERVICE_WIN32_SHARE_PROCESS
        dwServiceState = scmr.SERVICE_STATE_ALL
        cbBufSize = 0
        resp = scmr.hREnumServicesStatusW(dce, scHandle, dwServiceType, dwServiceState)

        resp = scmr.hRCloseServiceHandle(dce, scHandle) 
Example #2
Source File: test_scmr.py    From cracke-dit with MIT License 5 votes vote down vote up
def test_enumservices(self):
        dce, rpctransport, scHandle  = self.connect()

        #####################
        # EnumServicesStatusW
        dwServiceType = scmr.SERVICE_KERNEL_DRIVER | scmr.SERVICE_FILE_SYSTEM_DRIVER | scmr.SERVICE_WIN32_OWN_PROCESS | scmr.SERVICE_WIN32_SHARE_PROCESS
        dwServiceState = scmr.SERVICE_STATE_ALL
        cbBufSize = 0
        resp = scmr.hREnumServicesStatusW(dce, scHandle, dwServiceType, dwServiceState)

        resp = scmr.hRCloseServiceHandle(dce, scHandle) 
Example #3
Source File: test_scmr.py    From Slackor with GNU General Public License v3.0 5 votes vote down vote up
def test_enumservices(self):
        dce, rpctransport, scHandle  = self.connect()

        #####################
        # EnumServicesStatusW
        dwServiceType = scmr.SERVICE_KERNEL_DRIVER | scmr.SERVICE_FILE_SYSTEM_DRIVER | scmr.SERVICE_WIN32_OWN_PROCESS | scmr.SERVICE_WIN32_SHARE_PROCESS
        dwServiceState = scmr.SERVICE_STATE_ALL
        scmr.hREnumServicesStatusW(dce, scHandle, dwServiceType, dwServiceState)

        scmr.hRCloseServiceHandle(dce, scHandle) 
Example #4
Source File: rpc.py    From ActiveReign with GNU General Public License v3.0 5 votes vote down vote up
def list_services(self):
        services = {}
        # https://github.com/SecureAuthCorp/impacket/blob/master/examples/services.py
        self.create_rpc_con(r'\svcctl')
        ans = scmr.hROpenSCManagerW(self.rpc_connection)
        scManagerHandle = ans['lpScHandle']
        resp = scmr.hREnumServicesStatusW(self.rpc_connection, scManagerHandle)
        for i in range(len(resp)):
            name = resp[i]['lpServiceName'][:-1]
            services[name]              = {}
            services[name]['Name']      = name
            services[name]['Display']   = resp[i]['lpDisplayName'][:-1]

            state = resp[i]['ServiceStatus']['dwCurrentState']
            if state == scmr.SERVICE_CONTINUE_PENDING:
                services[name]['Status'] = "CONTINUE PENDING"
            elif state == scmr.SERVICE_PAUSE_PENDING:
                services[name]['Status'] = "PAUSE PENDING"
            elif state == scmr.SERVICE_PAUSED:
                services[name]['Status'] = "PAUSED"
            elif state == scmr.SERVICE_RUNNING:
                services[name]['Status'] = "RUNNING"
            elif state == scmr.SERVICE_START_PENDING:
                services[name]['Status'] = "START PENDING"
            elif state == scmr.SERVICE_STOP_PENDING:
                services[name]['Status'] = "STOP PENDING"
            elif state == scmr.SERVICE_STOPPED:
                services[name]['Status'] = "STOPPED"
            else:
                services[name]['Status'] = "UNKNOWN"

        self.rpc_connection.disconnect()
        return services 
Example #5
Source File: test_scmr.py    From PiBunny with MIT License 5 votes vote down vote up
def test_enumservices(self):
        dce, rpctransport, scHandle  = self.connect()

        #####################
        # EnumServicesStatusW
        dwServiceType = scmr.SERVICE_KERNEL_DRIVER | scmr.SERVICE_FILE_SYSTEM_DRIVER | scmr.SERVICE_WIN32_OWN_PROCESS | scmr.SERVICE_WIN32_SHARE_PROCESS
        dwServiceState = scmr.SERVICE_STATE_ALL
        cbBufSize = 0
        resp = scmr.hREnumServicesStatusW(dce, scHandle, dwServiceType, dwServiceState)

        resp = scmr.hRCloseServiceHandle(dce, scHandle) 
Example #6
Source File: computer.py    From BloodHound.py with MIT License 4 votes vote down vote up
def rpc_get_services(self):
        """
        Query services with stored credentials via RPC.
        These credentials can be dumped with mimikatz via lsadump::secrets or via secretsdump.py
        """
        binding = r'ncacn_np:%s[\PIPE\svcctl]' % self.addr
        serviceusers = []
        dce = self.dce_rpc_connect(binding, scmr.MSRPC_UUID_SCMR)
        if dce is None:
            return
        try:
            resp = scmr.hROpenSCManagerW(dce)
            scManagerHandle = resp['lpScHandle']
            # TODO: Figure out if filtering out service types makes sense
            resp = scmr.hREnumServicesStatusW(dce,
                                              scManagerHandle,
                                              dwServiceType=scmr.SERVICE_WIN32_OWN_PROCESS,
                                              dwServiceState=scmr.SERVICE_STATE_ALL)
            # TODO: Skip well-known services to save on traffic
            for i in range(len(resp)):
                try:
                    ans = scmr.hROpenServiceW(dce, scManagerHandle, resp[i]['lpServiceName'][:-1])
                    serviceHandle = ans['lpServiceHandle']
                    svcresp = scmr.hRQueryServiceConfigW(dce, serviceHandle)
                    svc_user = svcresp['lpServiceConfig']['lpServiceStartName'][:-1]
                    if '@' in svc_user:
                        logging.info("Found user service: %s running as %s on %s",
                                     resp[i]['lpServiceName'][:-1],
                                     svc_user,
                                     self.hostname)
                        serviceusers.append(svc_user)
                except DCERPCException as e:
                    if 'rpc_s_access_denied' not in str(e):
                        logging.debug('Exception querying service %s via RPC: %s', resp[i]['lpServiceName'][:-1], e)
        except DCERPCException as e:
            logging.debug('Exception connecting to RPC: %s', e)
        except Exception as e:
            if 'connection reset' in str(e):
                logging.debug('Connection was reset: %s', e)
            else:
                raise e

        dce.disconnect()
        return serviceusers