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.
10 KiB
Elysium — Agent Context
This file is written for AI coding agents. The project language is English; all code comments, documentation, and settings are in English.
Project Overview
Elysium is a Windows-focused Active Directory weak-password assessment toolkit. It is implemented entirely in PowerShell (with one Python decryption helper) and is designed to be run from a dedicated, trusted Windows host by an operator with replication-equivalent rights on the target AD domain.
The tool performs three core workflows:
- Update Known-Hashes Database (KHDB) — Download an incremental, sharded hash database from remote storage (Azure Blob or S3-compatible).
- Test Weak AD Passwords — Use DSInternals to replicate account data and test passwords against the local KHDB, producing timestamped text reports.
- Extract and Send Current Hashes — Pull NTLM hashes (without usernames) from live AD, compress, encrypt, and upload them back to the tool provider to improve the KHDB. This step is optional.
- Update Lithnet Password Protection Store — Populate a local Lithnet Password Protection store with compromised hashes, plaintext passwords, and banned words.
Technology Stack
- Runtime: Windows PowerShell 5.1 or PowerShell 7 (
pwsh). - Required PowerShell modules:
DSInternals,ActiveDirectory(RSAT). - Optional PowerShell modules:
Az.Storage,AWS.Tools.S3/AWSPowerShell.NetCore,LithnetPasswordProtection. - Python 3:
decrypt.pyrequirespycryptodomefor decrypting uploaded payload files. - Network: TLS 1.2+ enforced; native S3 SigV4 signing implemented in pure PowerShell/.NET (no AWS Tools required).
Project Structure
Elysium.ps1 # Main menu / orchestrator script
Elysium.Common.ps1 # Transitional loader: dot-sources src/Elysium/Private/*.ps1 into the calling script
ElysiumSettings.txt # Live configuration (key=value format, # comments)
src/Elysium/Elysium.psd1 # Module manifest; ModuleVersion is the single source of the project version
src/Elysium/Elysium.psm1 # Root module: dot-sources Private/ and Public/
src/Elysium/Private/ # Shared helpers: Relaunch, Settings, Storage (Azure/S3/SigV4), AdPreflight
src/Elysium/Public/ # Exported cmdlets (root scripts are being converted into these)
ElysiumSettings.txt.sample # Documented template for operators
Update-KHDB.ps1 # Wrapper: relaunch under pwsh, then call Update-ElysiumKhdb (src/Elysium/Public)
Prepare-KHDBStorage.ps1 # KHDB publisher: split source into shards, build manifest, upload
Test-WeakADPasswords.ps1 # Wrapper: relaunch under powershell.exe, then call Test-ElysiumPasswordQuality
Extract-NTHashes.ps1 # Hash extraction, compression, encryption, upload
Update-LithnetStore.ps1 # Wrapper: relaunch under pwsh, then call Update-ElysiumLithnetStore
Uninstall.ps1 # Self-removal script
decrypt.py # Python 3 decryptor for .enc payloads (ELY2, ELY1, legacy)
tests/test_decrypt.py # ELY2 round trip: PowerShell encryptor -> decrypt.py
khdb.txt # Local merged KHDB file (generated by Update-KHDB.ps1)
Reports/ # Generated reports and transcript logs
Configuration Format
ElysiumSettings.txt uses a simple Key=value format. Lines starting with # are comments. Values are not quoted by default; if quotes are used they are stripped by some parsers.
Key sections:
StorageProvider—AzureorS3- Azure:
storageAccountName,containerName,sasToken - S3:
s3EndpointUrl,s3Region,s3BucketName,s3AccessKeyId,s3SecretAccessKey,s3ForcePathStyle,s3UseAwsTools - KHDB layout:
KhdbManifestPath,KhdbShardPrefix,KhdbLocalShardDir - App:
InstallationPath,ReportPathBase,WeakPasswordsDatabase,CheckOnlyEnabledUsers - Lithnet:
LithnetStorePath,LithnetSyncHibp,LithnetHashSources,LithnetPlaintextSources,LithnetBannedWordSources - Telemetry (optional):
UsageBeaconUrl,UsageBeaconMethod,UsageBeaconInstanceId,UsageBeaconTimeoutSeconds - Domains:
Domain1Name,Domain1DC,Domain2Name,Domain2DC, ...
PowerShell Edition Handling
This project has nuanced PowerShell edition rules that must be preserved:
- Scripts that benefit from parallelism (
Update-KHDB.ps1,Prepare-KHDBStorage.ps1,Update-LithnetStore.ps1,Uninstall.ps1) auto-relaunch underpwsh(PowerShell 7+) viaRestart-WithPwshIfAvailableinElysium.Common.ps1. - Scripts that require legacy modules (
Test-WeakADPasswords.ps1,Extract-NTHashes.ps1) auto-relaunch underWindows PowerShell(powershell.exe) viaRestart-WithWindowsPowerShellIfAvailable, becauseDSInternalsandActiveDirectoryoften need the Desktop edition. Elysium.ps1(the menu) checks$PSVersionTable.PSEditionand invokes the appropriate child process for options 2 and 3.
When modifying any script, keep the . $commonHelper import and the corresponding Restart-With*IfAvailable call at the top.
Code Style Guidelines
- Strict mode and error handling are mandatory at the top of every script:
$ErrorActionPreference = 'Stop' Set-StrictMode -Version Latest - Every operational script starts a transcript into
Reports/logs/(or%TEMP%for uninstall) and stops it in afinallyblock. - Functions use
Verb-Nounnaming. Private helpers are alsoVerb-Noun. - Settings parsing is done manually via
Get-Contentand string splitting on=, notConvertFrom-StringData. - Paths are resolved relative to
$PSScriptRootwhenever possible. - Large file operations use
StreamReader/StreamWriterwith explicitUTF8Encoding($false)(no BOM) and large buffers (1 MiB preferred). - S3-native functions (SigV4) are duplicated in scripts that need them because they run in parallel
ForEach-Object -Parallelscopes where module imports are not preserved.
Build / Run Commands
There is no package manager or build system. The tool is run directly:
# Main menu
.\Elysium.ps1
# Direct invocation (respects auto-relaunch behavior)
.\Update-KHDB.ps1
.\Update-KHDB.ps1 -MaxParallelTransfers 8
.\Test-WeakADPasswords.ps1
.\Extract-NTHashes.ps1
.\Update-LithnetStore.ps1
.\Prepare-KHDBStorage.ps1 -SourcePath .\khdb.txt -OutputRoot .\publish -StorageProvider S3 -SkipUpload
.\Uninstall.ps1
No CI pipeline exists. Two automated checks, both runnable on any OS with pwsh:
Invoke-Pester ./tests(Pester 5): module helpers - settings parsing, storage URIs, SigV4 signatures checked against values generated by botocore, KHDB manifest/merge validation - an end-to-endUpdate-ElysiumKhdbincremental sync with onlyInvoke-DownloadWithRetrymocked,Update-ElysiumLithnetStoreagainst stubbed Lithnet cmdlets, and the pure password-quality helpers (domain list, KHDB normalization for DSInternals). The AD/DSInternals code paths themselves need a Windows host and a domain. Run after touching anything insrc/Elysium/.python3 tests/test_decrypt.py(needspwshon PATH andpycryptodome): encrypts with the realProtect-FileWithAESfromExtract-NTHashes.ps1and decrypts withdecrypt.py. Run it after touching either side of the export format.
Testing & Validation
- KHDB validation:
Validate-KHDBFileinsrc/Elysium/Private/Khdb.ps1checks 32-hex format, sorting, and duplicates. - DSInternals compatibility:
Resolve-DSInternalsWeakHashFileinsrc/Elysium/Private/PasswordQuality.ps1normalizes legacyHASH:countlines into a temporary hash-only file. - Upload integrity: After every upload, the script downloads the blob back and compares SHA256 checksums before deleting local artifacts.
- Credential pre-check:
Test-WeakADPasswords.ps1validates credentials against the chosen DC withGet-ADDomainand checks the three replication extended rights before attempting DCSync.
Security Considerations
- The operator passphrase is stored DPAPI-protected (
ConvertFrom-SecureString) in the user-level environment variableELYSIUM_PASSPHRASE, and decrypted only in memory right before use. Do not log or serialize the plaintext. Test-WeakADPasswords.ps1refuses to run when Windows FIPS policy is enabled (HKLM:\SYSTEM\CurrentControlSet\Control\Lsa\FipsAlgorithmPolicy\Enabled = 1) because DSInternals operations may fail or be limited.- The extract-and-send workflow uploads hashes only (no usernames). Encryption format
ELY2: PBKDF2 (SHA-256, 100k iterations, random 16-byte salt, UTF-8 passphrase) yields 64 bytes - the first 32 are the AES-256-CBC key, the next 32 the HMAC-SHA256 key. Layout:ELY2 | salt | iv | ciphertext | HMAC(magic..ciphertext). Any change must keepdecrypt.pyin sync (seetests/test_decrypt.py). - S3 requests are signed with native SigV4 via
System.Net.Http.HttpClientso no AWS credentials file or third-party module is required. If AWS Tools are used (s3UseAwsTools = true), the native path is still available as a fallback. - Reports contain sensitive AD data. They are written to
Reports/under the script root by default. - All network operations enforce TLS 1.2+ (
[System.Net.ServicePointManager]::SecurityProtocol).
Notes for Agents
- Do not introduce new package-manager files (e.g.,
package.json,pyproject.toml,Cargo.toml). This project is intentionally dependency-light and script-driven. - When adding new settings, keep the
key=valueflat format and update bothElysiumSettings.txt.sampleand any parser that reads the file. - If you add a new operational script, include the standard banner, strict mode, transcript logging, and the
Elysium.Common.ps1relauncher pattern. - The version lives only in
src/Elysium/Elysium.psd1(ModuleVersion); code reads it as$ElysiumVersion. Do not add version numbers to file banners. - The
.gitignoreexcludeskhdb.txt,ElysiumSettings.txt,Reports/,khdb-shards/, andkhdb-manifest.json. Exception:khdb.txthas been tracked since the first commit, so the ignore rule does not apply to it. Do notgit rmit casually - client clones have a locally modifiedkhdb.txt, and an upstream deletion makes theirgit pullfail.