backup_operator: winrm support and query-based smb extraction - #1401
Open
XiaoliChan wants to merge 8 commits into
Open
backup_operator: winrm support and query-based smb extraction#1401XiaoliChan wants to merge 8 commits into
XiaoliChan wants to merge 8 commits into
Conversation
…MConnection When running over the wmi protocol the module now reuses the protocol's authenticated IWbemLevel1Login instead of creating its own DCOMConnection to the same target - whose disconnect would clash with the protocol's own on impacket versions that do not guard the INTERFACE.CONNECTIONS thread entry (KeyError: ThreadPoolExecutor-x_x). Over smb nothing changes: the module still creates its own DCOMConnection since the protocol has none.
…nd DCOMConnection Same pattern as the rdp module fix: BitLockerWMI creates its own DCOMConnection to the same target the wmi protocol already holds one for, and disconnecting it removes the shared INTERFACE.CONNECTIONS thread entry, so the protocol-level disconnect afterwards raises KeyError on impacket versions that do not guard it. Reuse the protocol's IWbemLevel1Login instead - over smb nothing changes.
Enumerating the shell resource succeeds for any WinRM-authorized user, so every valid login was reported as (Pwn3d!). admin_privs now comes from a WinRM configuration read - admin only, milliseconds on both paths. Command execution is probed separately by opening each shell endpoint (cmd and PowerShell runspace have separate SDDLs) without running a command, shown SSH-style: [+] dom\admin:pass (Pwn3d!) Shell access! (all) [+] dom\user:pass Shell access! (cmd only)
…lter The query is sent as a wsman:Filter with the Microsoft WQL dialect and executed server-side (projection and WHERE included) - no PowerShell process on the target and no DCOM access. Results are pulled until EndOfSequence. Gated by requires_admin: the WinRM service WMI plugin only serves Administrators, Interactive and Remote Management Users (network logons lack the Interactive group), and the namespace itself needs Remote Enable on top.
…nections, bitlocker wmi_invoke on the winrm protocol executes a WMI method natively over WS-Management (method INPUT body in the class resource URI namespace, instance addressed by a selector on the class key property) - no PowerShell process, the WinRM equivalent of the smb/wmi protocols calling WMI methods over DCOM. Four modules gain winrm support on top of the wmi_query and wmi_invoke primitives: rdp (enable/disable, RAM, port), enum_dns, get_netconnections and bitlocker, with the fault code mapping in faults.py.
FileTransfer_WMI reads through one PS_ModuleFile GET, zero process on the target not even a runspace; files above the stock 500KB envelope get MaxEnvelopeSizeKb raised for the read and restored right after. FileTransfer_Compatible serves every system with the PowerShell machinery: one ReadAllBytes invoke for small files, parallel chunks over four connections for big ones, and a native cmd copy bridge for the PowerShell 2.0 kernel paths the managed layer rejects. The protocol get_file goes through it.
RemoteOperations creates a VSS snapshot with Win32_ShadowCopy.Create via native WSMan Invoke, resolves the DeviceObject through WQL, and fetches the SAM, SECURITY and SYSTEM hives plus the NTDS database from the shadow copy GLOBALROOT path through the file transfer - all without spawning a process for the critical steps. sam(), lsa() and ntds() parse locally with impacket, matching the smb protocol output and database storage. NTDS options aligned with smb: --history, --kerberos-keys, --enabled, --user. --list-snapshots and --use-snapshot-id manage the snapshots. WinRM 2.0 compatibility: kernel path bridge, chunked reads, vssadmin delete fallback.
The winrm side saves the hives with reg save wrapped in a runspace, fetches them back through the file transfer, parses locally and deletes in the same session. reg save is refused on HKLM\SECURITY for a plain backup operator, so that hive is optional. The smb side walks the hives with impacket's regsecrets: backup-intent opens and registry queries through the SeBackupPrivilege, no RegSaveKey and no hive file dropped on the target.
XiaoliChan
requested review from
Marshall-Hallenbeck,
NeffIsBack,
mpgn and
zblurx
as code owners
September 6, 2026 13:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
winrm side: saves the hives with reg save wrapped in a runspace, fetches them back through the file transfer, parses locally and deletes in the same session. reg save is refused on
HKLM\SECURITYfor a plain backup operator, so that hive is optional. No NTDS dump over winrm.smb side: rewritten with impacket's regsecrets — backup-intent opens and registry queries through the SeBackupPrivilege, no RegSaveKey and no hive file dropped on the target.
Type of change
Setup guide for the review
Just install pypsrp
Screenshots (if appropriate)
(placeholder - screenshots to be added)
Checklist
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)