Forum Discussion

zlate81's avatar
zlate81
Copper Contributor
Jul 09, 2025

MDE not detecting regsecrets.py from impacket-toolkit

In a recent red-team engagement we got exposed to the regsecrets.py toolkit which made it possible to extract SAM hive without any detection from the MDE.

I have tried to use advanced hunting to see if there are any event that would make up for a good custom detection rule but no success yet, please share if you have any queries that works for you.

 

Some information regarding this script:

 

This script is a modification of secretsdump.py that uses a different technique to extract registry secrets (the logic regarding DCSync operations has been removed). It does not write files on the disk and does not perform reg save like operations. This allow recovering the SAM database and the LSA secrets while being less prone to detection by security product.
All required keys are accessed using registry queries. To access keys within the SAM and SECURITY hives, the dwOption of https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-rrp/8cb48f55-19e1-4ea2-8d76-dd0f6934f0d9 allows passing the REG_OPTION_BACKUP_RESTORE value to disable any ACL checks performed, thus, allowing to access these registry keys normally restricted to the SYSTEM user.

 

Thanks in advance for sharing some experience of detecting this.

 

2 Replies

  • zlate81's avatar
    zlate81
    Copper Contributor

    Why is Microsoft not making this kind of data available in the advanced hunting ?

    I have marked a few things i can see in the device timeline but I'm not able to find it in the advanced hunting logs:

     

    In the table DeviceRegistryEvents there are only  the ActionTypes:

    • RegistryKeyDeleted
    • RegistryKeyCreated
    • RegistryValueSet
    • RegistryValueDeleted

    Hope someone can shed some light on this.

    • defensiveorigins's avatar
      defensiveorigins
      Copper Contributor

      This is a tough one to catch, to be sure (red teamer here). However, depending on your log stack, ingestion configuration, etc, my first advice is make sure you are collecting process invocation (4688) events. This tool also uses the RemoteRegistry service to perform its operations over SMB/445 - so there might be some additional opportunities there. While this is not a perfect detection mechanism, it should get you moving in the right direction. 

      Sentinel KQL I use for this detect:
      SecurityEvent
      | where EventID == 4688
      | where CommandLine contains "RemoteRegistry"
      | project TimeGenerated , Computer , ParentProcessName , CommandLine

Resources