fix(passphrase): store DPAPI-protected, never plaintext or echoed
Elysium.ps1 used Read-Host without -AsSecureString (echoed the AES passphrase to the console) and persisted it as plaintext in HKCU\Environment via SetEnvironmentVariable, readable by anyone with console visibility or local registry access. Switched to Read-Host -AsSecureString and store ConvertFrom-SecureString's DPAPI output (decryptable only by the same user on the same machine) instead of the raw value. Extract-NTHashes.ps1, the only other consumer, now decrypts that DPAPI-protected string back to a plain string via ConvertTo-SecureString + NetworkCredential right before handing it to Protect-FileWithAES. A stale plaintext value from a prior version is detected and the operator is prompted to re-enter it. DPAPI protection is Windows-only, consistent with the rest of this Windows/AD-only tool; not runnable end-to-end on this (non-Windows) dev machine, verified by AST parse only. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -190,9 +190,15 @@ try {
|
||||
try { $s3ForcePathStyle = [System.Convert]::ToBoolean($s3ForcePathStyle) } catch { $s3ForcePathStyle = $true }
|
||||
try { $s3UseAwsTools = [System.Convert]::ToBoolean($s3UseAwsTools) } catch { $s3UseAwsTools = $false }
|
||||
|
||||
# Retrieve the passphrase from a user environment variable
|
||||
$passphrase = [System.Environment]::GetEnvironmentVariable("ELYSIUM_PASSPHRASE", [System.EnvironmentVariableTarget]::User)
|
||||
if ([string]::IsNullOrWhiteSpace($passphrase)) { throw 'Passphrase not found in ELYSIUM_PASSPHRASE environment variable.' }
|
||||
# Retrieve the DPAPI-protected passphrase from a user environment variable (see Elysium.ps1)
|
||||
$protectedPassphrase = [System.Environment]::GetEnvironmentVariable("ELYSIUM_PASSPHRASE", [System.EnvironmentVariableTarget]::User)
|
||||
if ([string]::IsNullOrWhiteSpace($protectedPassphrase)) { throw 'Passphrase not found in ELYSIUM_PASSPHRASE environment variable. Run Elysium.ps1 once to set it.' }
|
||||
try {
|
||||
$securePassphrase = ConvertTo-SecureString -String $protectedPassphrase -ErrorAction Stop
|
||||
} catch {
|
||||
throw "ELYSIUM_PASSPHRASE is not in the expected DPAPI-protected format (leftover from an older Elysium version?). Re-run Elysium.ps1 to re-enter it."
|
||||
}
|
||||
$passphrase = [System.Net.NetworkCredential]::new('', $securePassphrase).Password
|
||||
|
||||
$timestamp = Get-Date -Format "yyyyMMdd-HHmmss"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user