Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions impacket/examples/regsecrets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from impacket.dcerpc.v5 import transport, rrp, scmr, wkst
from impacket.dcerpc.v5.rpcrt import DCERPCException
from impacket.crypto import transformKey
from impacket.system_errors import ERROR_NO_MORE_ITEMS, ERROR_SERVICE_NOT_ACTIVE
from impacket.system_errors import ERROR_DEPENDENT_SERVICES_RUNNING, ERROR_NO_MORE_ITEMS, ERROR_SERVICE_NOT_ACTIVE
from impacket.structure import hexdump
from impacket.krb5 import constants
from impacket.krb5.crypto import string_to_key
Expand Down Expand Up @@ -191,7 +191,10 @@ def __restore(self):
scmr.hRControlService(self.__scmr, self.__serviceHandle, scmr.SERVICE_CONTROL_STOP)
except DCERPCException as e:
# Not running (e.g. starting it failed in enableRegistry()): nothing to stop, go on with the restore
if e.get_error_code() != ERROR_SERVICE_NOT_ACTIVE:
# Running dependents (e.g. Dfs on a DC, after an idle stop): it cannot be stopped, go on with the restore
if e.get_error_code() == ERROR_DEPENDENT_SERVICES_RUNNING:
LOG.info('Service %s cannot be stopped, other running services depend on it' % self.__serviceName)
elif e.get_error_code() != ERROR_SERVICE_NOT_ACTIVE:
raise
self.__shouldStop = False
if self.__disabled is True:
Expand Down
5 changes: 4 additions & 1 deletion impacket/examples/secretsdump.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,10 @@ def __restore(self):
scmr.hRControlService(self.__scmr, self.__serviceHandle, scmr.SERVICE_CONTROL_STOP)
except DCERPCException as e:
# Not running (e.g. starting it failed in enableRegistry()): nothing to stop, go on with the restore
if e.get_error_code() != system_errors.ERROR_SERVICE_NOT_ACTIVE:
# Running dependents (e.g. Dfs on a DC, after an idle stop): it cannot be stopped, go on with the restore
if e.get_error_code() == system_errors.ERROR_DEPENDENT_SERVICES_RUNNING:
LOG.info('Service %s cannot be stopped, other running services depend on it' % self.__serviceName)
elif e.get_error_code() != system_errors.ERROR_SERVICE_NOT_ACTIVE:
raise
self.__shouldStop = False
if self.__disabled is True:
Expand Down
15 changes: 15 additions & 0 deletions tests/misc/test_remoteoperations.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ def test_start_type_is_restored_when_service_is_not_running(self):
scmr.hRControlService.assert_called_once()
scmr.hRChangeServiceConfigW.assert_called_once()

def test_restore_goes_on_when_dependent_services_are_running(self):
# DC where RemoteRegistry had stopped itself when idle while Dfs, which depends on it, kept running
remoteOps = self.newRemoteOps()
self.setPrivate(remoteOps, 'shouldStop', True)
self.setPrivate(remoteOps, 'serviceHandle', 'service-handle')
scmrDce = mock.Mock()
self.setPrivate(remoteOps, 'scmr', scmrDce)
with self.patchModule('scmr') as scmr:
scmr.hRControlService.side_effect = DCERPCException(error_code=system_errors.ERROR_DEPENDENT_SERVICES_RUNNING)
with self.assertLogs('impacket', level='INFO'):
remoteOps.finish()
remoteOps.finish()
scmr.hRControlService.assert_called_once()
scmrDce.disconnect.assert_called_once_with()

def test_other_stop_errors_are_raised(self):
remoteOps = self.newRemoteOps()
self.setPrivate(remoteOps, 'shouldStop', True)
Expand Down
Loading