3 Commits
Author SHA1 Message Date
tomas.kracmar ffccedb439 refactor: move provider-side tools to tools/
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).
2026-11-04 13:04:10 +01:00
tomas.kracmar 4fe884e658 refactor(Extract-NTHashes): move the export into the module as Send-ElysiumHashExport
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.
2026-11-04 13:01:26 +01:00
tomas.kracmar 89c5e21002 fix(decrypt): read ELY2 and use PBKDF2-SHA256 to match the PowerShell side
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.
2026-11-04 09:24:37 +01:00