Skip to content
Merged
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
10 changes: 10 additions & 0 deletions pkg/relay/remoteregistry.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,21 @@ func ensureRemoteRegistryStarted(client *SMBRelayClient) *remoteRegistryState {
// it) and re-applies the SERVICE_DISABLED start type (if it was disabled
// before we enabled it). Errors are logged but not returned; we're on the
// cleanup path after the real work has completed.
//
// The caller's tree state may have moved off IPC$ (e.g., the attack switched
// to ADMIN$ to download a saved hive), so we re-TreeConnect to IPC$ before
// opening svcctl. That makes this function safe to invoke from any defer
// position without coupling it to the attack's tree management.
func restoreRemoteRegistryState(client *SMBRelayClient, state *remoteRegistryState) {
if state == nil || (!state.startedByUs && !state.wasDisabled) {
return
}

if err := client.TreeConnect("IPC$"); err != nil {
log.Printf("[-] Warning: could not re-tree-connect to IPC$ for RemoteRegistry restore: %v", err)
return
}

sc, closeFn, err := openSvcctl(client)
if err != nil {
log.Printf("[-] Warning: could not reopen svcctl to restore RemoteRegistry: %v", err)
Expand Down