Prepare-KHDBStorage.ps1 (publishes the KHDB) and decrypt.py
(decrypts client hash exports on the provider's cracking machine)
are only ever run by the tool provider, but sat next to the client
scripts that every customer clones. Moved both to tools/ so the
client surface (root wrappers + src/Elysium) is separate from
provider tooling; packaging the module later ships only src/Elysium.
Prepare-KHDBStorage.ps1 now resolves Elysium.Common.ps1 and the
default ElysiumSettings.txt from the repo root (one level up) instead
of its own folder. tests/test_decrypt.py imports decrypt from tools/.
README and AGENTS paths updated; AGENTS' structure listing also gets
the module lines back after the settings sample, where they belong.
Verified: decrypt round trip passes from the new location, and
tools/Prepare-KHDBStorage.ps1 -SkipUpload runs from the repo root and
produces a package (manifest, 256 shards, khdb-clean.txt).
Fourth root script converted, same mechanical approach as
Test-ElysiumPasswordQuality (AST line ranges, then a line-by-line
comparison ignoring indentation that shows only these differences):
- Script body -> src/Elysium/Public/Send-ElysiumHashExport.ps1
(exported, [CmdletBinding()], comment-based help).
- Protect-FileWithAES -> Private/Crypto.ps1 (the ELY2 format in one
place). tests/test_decrypt.py now dot-sources that file instead of
pulling the function out of the script's AST.
- S3 put/get/delete, Get-FileSha256Hex and Get-FileChecksum ->
Private/Storage.ps1; Normalize-ReportPath -> Private/Settings.ps1.
- The script's own Domain<N> loop -> the shared
Get-DomainDetailsFromSettings; the only difference was a
Domain<N>DA value that nothing read.
- The hash export's Out-File gets an explicit -Encoding utf8 (the
value the script-level $PSDefaultParameterValues default supplied),
so that session-global default and $OutputEncoding are dropped.
- Transcript via the shared helper (same extract-hashes-*.log name),
$scriptRoot -> $InstallRoot; the completion message moves to the
wrapper.
Extract-NTHashes.ps1 is now a thin wrapper (relaunch under
powershell.exe, import module, call the cmdlet).
Verified on macOS: decrypt round trip passes against Crypto.ps1, 22/22
Pester tests pass, and the cmdlet runs through settings to its
passphrase check and writes its transcript. The AD extraction and
upload need a Windows run.
Third root script converted. This one cannot be exercised end-to-end
without a Windows host and a domain, so the move is mechanical: the
split used the script's own AST (function and statement line ranges),
and a line-by-line comparison ignoring indentation shows only the
intended differences below.
- Script body -> src/Elysium/Public/Test-ElysiumPasswordQuality.ps1
(exported, [CmdletBinding()], comment-based help).
- Its helpers -> Private/PasswordQuality.ps1; the inner
Test-WeakADPasswords function is renamed Invoke-WeakPasswordTest.
Several of them read variables the cmdlet sets ($runningInPSCore,
$onWindows, $reportPathBase, $timestamp, $header, $footer) through
dynamic scoping, exactly as they read script-level variables before;
the file header says so, and they become parameters in a later step.
- Get-DomainDetailsFromSettings -> Private/Settings.ps1.
- The inline KHDB path resolution becomes Get-KhdbPath (same
semantics); transcript via the shared helper; $scriptRoot ->
$InstallRoot.
- `exit` / `exit 0` -> `return`: inside a module function, exit would
end the operator's whole PowerShell session.
- Dropped the script-level $PSDefaultParameterValues /
$OutputEncoding block: both Out-File calls already pass
-Encoding utf8, nothing else writes files or calls native commands,
and in a cmdlet it would mutate the caller's session-global table.
Dropped the forced $VerbosePreference = 'SilentlyContinue', so
-Verbose now works.
ActiveDirectory/DSInternals are now imported from inside the module,
so they load into the module's session state instead of the global
one. Checked with stand-in modules: Get-Module (used by
Import-CompatModule and the DSInternals version check) still sees
them from module code, their commands are callable from module code,
and nothing leaks into the caller's session.
Test-WeakADPasswords.ps1 is now a thin wrapper (relaunch under
powershell.exe, import module, call the cmdlet).
Tests: domain list parsing; Resolve-DSInternalsWeakHashFile on a
clean file (passed through), a legacy file (case, HASH:count and
duplicates normalized into a temp file), and unsorted/malformed files.
22/22 Pester tests pass. On macOS the cmdlet runs through settings
and domain parsing (with -Verbose) up to its Windows-only guard and
writes its transcript. Needs a Windows run against a domain.
Second root script converted to a module cmdlet, same pattern as
Update-ElysiumKhdb:
- The script body -> src/Elysium/Public/Update-ElysiumLithnetStore.ps1,
exported, same parameters.
- Get-ListFromSetting and Resolve-ExistingPath -> Private/Settings.ps1.
The script's own Get-BooleanSetting copy is dropped for the shared
one (TryParse instead of Convert.ToBoolean; both accept exactly
true/false and fall back to the default for anything else).
- The inline default-KHDB resolution becomes Get-KhdbPath in
Private/Khdb.ps1 (InstallationPath + WeakPasswordsDatabase via
Get-InstallationPath), for the other scripts to reuse.
- Transcript via the shared Start/Stop-ElysiumTranscript; $PSScriptRoot
becomes $InstallRoot.
Update-LithnetStore.ps1 is now a thin wrapper (relaunch under pwsh,
import module, call the cmdlet with the bound parameters).
Tests, with global stub functions standing in for the Lithnet cmdlets
so they can be mocked on any OS: default KHDB under
InstallationPath/WeakPasswordsDatabase plus settings and parameter
sources each go to the right import cmdlet; HIBP sync on/off;
Close-Store runs when an import fails; a missing KHDB names the path.
18/18 Pester tests pass. The wrapper also ran end-to-end against a stub
LithnetPasswordProtection module on PSModulePath: all three lists
imported, store closed, transcript written under Reports/logs.
First root script converted to a module cmdlet. Behavior is unchanged;
the code moves mostly verbatim:
- Update-KHDB (the function) -> src/Elysium/Public/Update-ElysiumKhdb.ps1,
exported, with comment-based help and [CmdletBinding()]. It now sets
TLS 1.2 itself, since the module may be imported without the script.
- Manifest/shard/merge/validation helpers -> Private/Khdb.ps1.
- HTTP download helpers (Azure SAS, native SigV4 S3, retry) ->
Private/Storage.ps1; Get-BooleanSetting -> Private/Settings.ps1.
- The per-script Start/Stop-*Transcript pair -> one shared
Start/Stop-ElysiumTranscript in Private/Transcript.ps1 (the other
scripts switch to it as they are converted).
- $scriptRoot becomes $InstallRoot: the repo root in both the module
(two levels above src/Elysium) and the Elysium.Common.ps1 loader.
Settings, KHDB and Reports stay where they are for now.
Update-KHDB.ps1 is now a thin wrapper: relaunch under pwsh as before,
import the module from src/Elysium, call Update-ElysiumKhdb with the
bound parameters. The menu and direct invocations are unchanged.
Tests: manifest validation, out-of-order merge, empty KHDB, and an
end-to-end Update-ElysiumKhdb run against a fake Azure container with
only Invoke-DownloadWithRetry mocked - first sync (case and HASH:count
normalization, ordered merge), no-op second run (manifest only), one
changed shard plus removal of a shard the manifest no longer lists.
14/14 Pester tests pass. Separately, the wrapper ran the real HTTP
code against a local stand-in for an S3-compatible endpoint, on both
the serial and the PowerShell 7 parallel path (helpers injected into
runspaces from module scope), and produced the same merged KHDB.
Locks down current behavior of the helpers in src/Elysium/Private
before the storage layer is rewritten (one HttpClient path, Windows
PowerShell 5.1 only):
- Read-KeyValueSettingsFile: comments, blank and malformed lines,
quote stripping, '=' inside values (SAS tokens), missing file;
Read-ElysiumSettings throws on a missing file.
- Combine-StoragePath, Build-BlobUri (SAS with/without leading '?',
percent-escaping preserved, empty SAS rejected), BuildS3Uri
(path-style and virtual-host with a non-default port).
- BuildAuthHeaders: full Authorization header for a path-style GET
and a virtual-host PUT on port 9000, with Get-Date mocked. The
expected signatures were generated by botocore 1.43 (S3SigV4Auth)
from the same inputs, so they come from an independent
implementation rather than from this code.
8/8 pass on pwsh 7 with Pester 5.9.1. Mutation check: dropping the
port from the signed Host header fails exactly the port-9000 test.
decrypt.py could not decrypt any current export:
- It did not know the ELY2 format introduced in v2.4.6, so ELY2 files
fell through to the legacy branch and failed.
- Its ELY1 branch called pycryptodome's PBKDF2 with the default PRF
(HMAC-SHA1), while Extract-NTHashes.ps1 has used HMAC-SHA256 since
ELY1 was introduced, so ELY1 files never decrypted either.
Now reads ELY2 (HMAC-SHA256 verified before decrypting, keys taken
from one 64-byte PBKDF2 output exactly like the two sequential
Rfc2898DeriveBytes.GetBytes(32) calls), ELY1, and the legacy format.
Key derivation uses stdlib hashlib.pbkdf2_hmac with the passphrase
encoded as UTF-8, matching .NET's string overload (pycryptodome
defaulted to latin-1). Padding is checked with Crypto.Util.Padding
instead of a length-byte range check.
Also: the passphrase prompt no longer echoes (getpass), an input path
not ending in .enc is refused instead of being overwritten by the
output, and failures exit non-zero.
tests/test_decrypt.py encrypts with the real Protect-FileWithAES
(extracted from Extract-NTHashes.ps1's AST, so the script body never
runs) via pwsh and decrypts with decrypt.py: ASCII and non-ASCII
passphrases round-trip; a wrong passphrase and a flipped ciphertext
bit are rejected by the HMAC check. With the old SHA1 derivation
patched back in, the test fails.