-
-
Save lhecker/393252fb1e95b3bc118d40ace802a505 to your computer and use it in GitHub Desktop.
Find environment strings with embedded nulls
This file contains 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
function Check($key) { | |
foreach ($name in $key.GetValueNames()) { | |
if ($key.GetValue($name).ToString().Contains("`0")) { | |
Write-Output "$($key.Name): $($name)" | |
} | |
} | |
} | |
$hklm = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, 0) | |
$hkcu = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::CurrentUser, 0) | |
Check($hklm.OpenSubKey('Software\Microsoft\Windows\CurrentVersion')) | |
Check($hklm.OpenSubKey('SYSTEM\CurrentControlSet\Control\Session Manager\Environment')) | |
Check($hkcu.OpenSubKey('Environment')) | |
$volenv = $hkcu.OpenSubKey('Volatile Environment') | |
Check($volenv) | |
foreach ($name in $volenv.GetSubKeyNames()) { | |
Check($volenv.OpenSubKey($name)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment