Bug Fix: backup_operator module fails to download large registry hives (HKLM\SYSTEM)#1253
Bug Fix: backup_operator module fails to download large registry hives (HKLM\SYSTEM)#1253RajChowdhury240 wants to merge 1 commit into
backup_operator module fails to download large registry hives (HKLM\SYSTEM)#1253Conversation
…lure impacket's smb3.read() is recursive — its own docstring warns "This function should NOT be used for reading files directly". When get_file_single() calls getFile() → retr_file() → read(MaxReadSize), the HKLM\SYSTEM hive on a DC (often 50–100 MB) causes the recursive reassembly to corrupt SMB framing, producing: "Unpacked data doesn't match constant value b'...' should be 'þSMB'" Fix: replace get_file_single() with _download_hive(), which opens the file directly via openFile() and reads in ≤64 KB fixed chunks. Each individual read() call stays well below MaxReadSize, avoiding the recursive code path entirely. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
It looks like the PR template may not have been filled out. The following sections appear to be missing:
Please edit your PR description to include them. The template helps reviewers understand and test your changes. Thanks! |
Lab Tested : https://www.hacksmarter.org/courses/1e19584b-4577-402d-a264-d6476d2d1b9bBefore :
After the fix :
|
|
Hi and thanks for the PR. However, why does downloading large(r) files with Please also disclose AI usage as stated in the PR template. |
|
--get-file and the old backup_operator both call getFile() → retr_file(). The difference is what retr_file does Why it breaks for hives specifically:smb3.read() is recursive (line 1367–1406 in impacket's smb3.py says literally: "IMPORTANT NOTE: As you can see, When DataRemaining > 0 in the server's response, read() calls itself: For SYSVOL-backed files (created via RegSaveKey), Windows' SMB server returns partial responses with Why --get-file works:
The fix's guarantee:Our _download_hive() calls smb.readFile() directly with 64 KB chunks and explicit offsets, never passing |
|
Hi, so first, your answer looks highly AI generated. As per AI policy, please do not respond with AI generated text. Please write them with your own words (or use a translator). Besides that, I definitely have downloaded larger files (1GB+) off of SMB shares so I am not sure if the problem is the size per se. I have tried to replace the recursively reading However, applying some custom download function patch inside NetExec does not solve the root problem, but just bypasses it. This needs to be fixed in impacket not NetExec. For anyone trying to replicate the problem:
Here my ps script for creating the hive (created by gemini): # Define the path to the temporarily mounted hive
$targetKey = "HKLM:\TempSystem\HiveBloatTest"
# Create a temporary key to hold the junk data
New-Item -Path $targetKey -Force | Out-Null
# Create a 512 KB payload
$payload = New-Object byte[] (512KB)
# Loop to write the payload 2,000 times (adds ~1 GB of bloat)
Write-Host "Inflating hive... this may take a moment."
for ($i = 1; $i -le 2000; $i++) {
Set-ItemProperty -Path $targetKey -Name "JunkData$i" -Value $payload -Type Binary
}
Write-Host "Inflation complete!" |


#1252 Fixed
Description
backup_operator failed downloading large registry hives (HKLM\SYSTEM, 50–100 MB on DCs). Root cause: getFile() → retr_file() → smb3.read(MaxReadSize) is recursive —
impacket's own docs warn against using it directly for large reads. Multi-response reassembly corrupted SMB framing, producing STATUS_INVALID_PARAMETER / þSMB
magic-byte mismatch.
Fix replaces get_file_single() with _download_hive(): opens the remote file via openFile() and reads in 64 KB chunks via readFile(offset, 65536), terminating on
STATUS_END_OF_FILE or partial chunk. Bypasses recursive path entirely.
Type of change
Setup guide for review
Requires: domain account in Backup Operators group on a DC with HKLM\SYSTEM > 10 MB.
netexec smb <dc_ip> -u <backup_op_user> -p -M backup_operator
Verify all three hives download (SAM, SECURITY, SYSTEM) and secretsdump parses the SYSTEM hive cleanly.
Checklist
AI Usage
I have used Claude Code Opus 4.8 model