Repository navigation
Conversation
RemoteOperations.finish() now always runs, so registry modules and --sam/--lsa/--ntds no longer leave RemoteRegistry started on the target (fortra/impacket#2329).
|
The bot findings are all pre-existing on main: these lines are only re-indented by the |
NeffIsBack
left a comment
There was a problem hiding this comment.
The changes in remove-mic.py seem independent of the context manager changes. Please pull them out of this PR and create a separate one.
68b42fc to
a9c88c9
Compare
| pillaged_from=host_id, | ||
| ) | ||
| add_sam_hash.sam_hashes += 1 | ||
| with self.remote_ops: |
There was a problem hiding this comment.
On a DC, Dfs (DFS Namespace) depends on RemoteRegistry, so when the service was idle-stopped and we started it, the stop in finish() fails with ERROR_DEPENDENT_SERVICES_RUNNING. On main this was logged with debug, now it reaches self.logger.exception() and --sam ends with a full traceback after a successful dump (DC 2022, RemoteRegistry STOPPED before the run):
SMB 192.168.56.3 445 DC01 [+] Added 3 SAM hashes to the database
│ ❱ 1275 │ return dce.request(request) │
...
DCERPCSessionError: SCMR SessionError: code: 0x41b - ERROR_DEPENDENT_SERVICES_RUNNING - A
stop control has been sent to a service that other running services are dependent on.
Same for lsa() at line 2384. Since you wrote fortra/impacket#2329, I think the cleanest place is __restore(), next to the ERROR_SERVICE_NOT_ACTIVE case: the service cannot be stopped, there is nothing left to restore. Otherwise please catch it here and keep the debug line.
There was a problem hiding this comment.
Good catch, thanks! Fixed in __restore() as you suggested: fortra/impacket#2402. I'll bump the lock here once it's merged.
| if secret.find("$") == -1 and secret_type == NTDSHashes.SECRET_TYPE.NTDS and "_history" not in secret: | ||
| if secret.find("\\") != -1: | ||
| domain, clean_hash = secret.split("\\") | ||
| with self.remote_ops: |
There was a problem hiding this comment.
Same issue, but there is no try around this with, so the error leaves ntds() and aborts proto_flow() for the host: every option or module that comes after --ntds is skipped. On main it was a debug line.
SMB 192.168.56.3 445 DC01 [+] Dumping the NTDS, this could take a while so go grab a redbull...
[14:29:14] ERROR Exception while calling proto_flow() on target 192.168.56.3: SCMR SessionError:
code: 0x41b - ERROR_DEPENDENT_SERVICES_RUNNING - A stop control has been sent to a
service that other running services are dependent on.
There was a problem hiding this comment.
Same fix (fortra/impacket#2402), finish() no longer raises in this case.
| def on_admin_login(self, context, connection): | ||
| try: | ||
| remote_ops = RemoteOperations(connection.conn, False) | ||
| with RemoteOperations(connection.conn, False) as remote_ops: |
There was a problem hiding this comment.
The removed finally logged a finish() failure with debug, and there is no other handler in this module, so on a DC the result is now followed by Exception while calling proto_flow() (same output as the ntds() comment) and the next modules are skipped. Same for the contextlib.suppress(Exception) removed in rdp.py (115, 150) and wdigest.py (35, 63, 98): these had no "existing error handler" to fall back on.
There was a problem hiding this comment.
Same fix (fortra/impacket#2402). Right, the PR description was wrong about the existing handlers, I'll fix it with the bump.
|
As draft waiting for fortra/impacket#2402 to be merged |
Description
Several registry modules leave the
RemoteRegistryservice started on the target (and its start type changed when it was disabled):onelogonandwccnever callRemoteOperations.finish(), anduac,reg-winlogon,wdigest,rdp,enum_interfacesand--sam/--lsa/--ntdsonly call it when everything succeeds.fortra/impacket#2329 added context manager support to
RemoteOperations, so every call site now useswith RemoteOperations(...) as remote_ops:andfinish()always runs, even after an error. This replaces the manualfinish()calls andtry/finallyblocks, and #1465.The impacket lock is bumped to fortra/impacket@7aa3770d (
uv.lockandpoetry.lock). An error raised byfinish()itself is no longer silenced: it now reaches the module's existing error handler.The bump breaks
-M remove-mic(fortra/impacket#2339), fixed separately in #1555 which should be merged first. Only other visible change:--lsacached hash dates now print with microseconds and+00:00(fortra/impacket#2215).AI Assistance
Claude Code (Claude Opus 5.5) migrated the call sites and ran the before/after tests. I reviewed it and tested it on my lab.
Type of change
Insert an "x" inside the brackets for relevant items
Setup guide for the review
Tested on GOAD (CASTELBLACK, where
RemoteRegistryis stopped by default, and WINTERFELL). Hide whitespace in the diff: most lines are only re-indented.On main
RemoteRegistryis still RUNNING afterwcc, with this PR it is STOPPED again. Same output as main for the other migrated modules,onelogon(DC),raisechild,--sam/--lsa(regdump and secdump) and--ntds, and the service is STOPPED after each of them.Screenshots (if appropriate):
Checklist:
Insert an "x" inside the brackets for completed and relevant items (do not delete options)
poetry run ruff check ., use--fixto automatically fix what it can)tests/e2e_commands.txtfile if necessary (new modules or features are required to be added to the e2e tests)