Skip to content

fix(backup_operator): add random suffix to dump filenames#1124

Merged
NeffIsBack merged 3 commits intoPennyw0rth:mainfrom
PatchRequest:fix/backup_operator_random_suffix
Mar 11, 2026
Merged

fix(backup_operator): add random suffix to dump filenames#1124
NeffIsBack merged 3 commits intoPennyw0rth:mainfrom
PatchRequest:fix/backup_operator_random_suffix

Conversation

@PatchRequest
Copy link
Copy Markdown
Contributor

Summary

The backup_operator module uses static filenames (SAM, SYSTEM, SECURITY) when saving registry hives to SYSVOL. If the cleanup step fails to delete these files, running the module again is impossible because hBaseRegSaveKey refuses to overwrite existing files:

nxc smb 10.27.10.7 -u obiwan -p 'wz(}ab4=/&_f' -M backup_operator
SMB         10.27.10.7      445    JEDHA            [*] Windows Server 2022 Build 20348 x64 (name:JEDHA) (domain:rebels.local) (signing:True) (SMBv1:None) (Null Auth:True)
SMB         10.27.10.7      445    JEDHA            [+] rebels.local\obiwan:wz(}ab4=/&_f 
BACKUP_O... 10.27.10.7      445    JEDHA            [*] Triggering RemoteRegistry to start through named pipe...
BACKUP_O... 10.27.10.7      445    JEDHA            [-] Couldn't save HKLM\SAM: RRP SessionError: code: 0xb7 - ERROR_ALREADY_EXISTS - Cannot create a file when that file already exists. on path \\10.27.10.7\SYSVOL\SAM

Fix

Each run now generates an 8-character random suffix appended to the dump filenames (e.g. SAM_a1b2c3d4, SYSTEM_a1b2c3d4, SECURITY_a1b2c3d4). This avoids collisions with leftover files from previous runs. The suffix is consistently used across saving, downloading, and cleanup.

Test plan

  • Run backup_operator module against a target
  • Verify hive files are saved and downloaded with randomized names
  • Verify cleanup deletes the randomized files
  • If cleanup fails, verify the module can be run again without ERROR_ALREADY_EXISTS

@NeffIsBack
Copy link
Copy Markdown
Member

Thanks for the bug fix PR!

Maybe we should opt for just completely randomising the name, similar to other places that need files as output. I'll look into it soon.

@NeffIsBack NeffIsBack added the bug-fix This Pull Request fixes a bug label Feb 27, 2026
@NeffIsBack
Copy link
Copy Markdown
Member

@Marshall-Hallenbeck the PR template script crashed with an unhandled error btw. Looks like it can't access something...?

@Marshall-Hallenbeck
Copy link
Copy Markdown
Collaborator

@Marshall-Hallenbeck the PR template script crashed with an unhandled error btw. Looks like it can't access something...?

Hmm wtf. I'll take a deeper look...

@Marshall-Hallenbeck
Copy link
Copy Markdown
Collaborator

@NeffIsBack ah, to post a comment it needs the write privilege for PRs, which makes sense. I had Copilot do something useful for once and it told me this and I had it create the PR: #1126

Copy link
Copy Markdown
Member

@NeffIsBack NeffIsBack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Before:
Image

After:
Image

@NeffIsBack NeffIsBack merged commit 1d24435 into Pennyw0rth:main Mar 11, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug-fix This Pull Request fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants