diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5415a..6964a32 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ Starting with **v2.2.0**, Elysium uses a **unified project version**. All script ## [Unreleased] ### Fixed +- **Security:** the KHDB updater joined shard names from the downloaded manifest straight onto local paths, so a tampered manifest (for example from a compromised KHDB bucket) could name a shard `../../something` and have a file of its choosing written outside the shard directory - including over Elysium's own scripts on the admin host the tool runs on. Manifest validation now rejects shard names that are rooted, contain `..` segments, or contain `:` (Windows drive-relative paths, NTFS alternate data streams), before anything is downloaded. - `README.md` swapped the menu numbers for Lithnet (documented as 5) and Uninstall (documented as 4), and `Uninstall.ps1` had no confirmation, so an operator following the README to update the Lithnet store recursively deleted the whole install directory, reports included. The README and the `Elysium.ps1` help block now match the menu, and `Uninstall.ps1` requires typing `YES` (or `-Force` for unattended use). - `decrypt.py` could not decrypt any current export: it did not recognize `ELY2` (so v2.4.6 files fell through to the legacy branch), and its `ELY1` branch used pycryptodome's default PBKDF2 PRF (HMAC-SHA1) while `Extract-NTHashes.ps1` has always used HMAC-SHA256. It now reads `ELY2` (verifying the HMAC before decrypting), `ELY1`, and the legacy format; encodes the passphrase as UTF-8 to match .NET; prompts for the passphrase without echo; refuses input that does not end in `.enc` instead of overwriting it; and exits non-zero on failure. New `tests/test_decrypt.py` round-trips through the real PowerShell encryptor. - `Test-WeakADPasswords.ps1` did not relaunch under Windows PowerShell like `Extract-NTHashes.ps1` does, so a direct run under `pwsh` loaded DSInternals through `-UseWindowsPowerShell` implicit remoting, which returns deserialized objects. It also set the PSGallery repository to `Trusted` on the host as a side effect of installing DSInternals; that is removed (`-Force` on the install already covers the prompt). diff --git a/src/Elysium/Private/Khdb.ps1 b/src/Elysium/Private/Khdb.ps1 index f6134b4..41c4189 100644 --- a/src/Elysium/Private/Khdb.ps1 +++ b/src/Elysium/Private/Khdb.ps1 @@ -57,6 +57,11 @@ function Validate-Manifest { if (-not $entry) { throw 'Manifest contains null shard entries.' } $name = [string]$entry.name if ([string]::IsNullOrWhiteSpace($name)) { throw 'Manifest shard entry is missing name.' } + # Shard names are joined onto local paths. A tampered manifest must not be able to place files + # outside the shard directory (e.g. over Elysium's own scripts on an admin host). + if ([System.IO.Path]::IsPathRooted($name) -or $name.Contains(':') -or @($name -split '[\\/]') -contains '..') { + throw "Manifest shard name '$name' is not a plain relative path inside the shard directory." + } $hash = [string]$entry.sha256 if ([string]::IsNullOrWhiteSpace($hash) -or $hash.Length -ne 64) { throw "Manifest shard '$name' is missing a valid sha256." } $sizeValue = [string]$entry.size diff --git a/tests/Elysium.Tests.ps1 b/tests/Elysium.Tests.ps1 index b6cfe3d..8789f72 100644 --- a/tests/Elysium.Tests.ps1 +++ b/tests/Elysium.Tests.ps1 @@ -92,6 +92,10 @@ Describe 'KHDB manifest and merge' { { Validate-Manifest ([pscustomobject]@{ shards = @((& $ok '00.txt'), (& $ok '00.txt')) }) } | Should -Throw '*duplicate*' { Validate-Manifest ([pscustomobject]@{ shards = @([pscustomobject]@{ name = '00.txt'; sha256 = 'abc'; size = 1 }) }) } | Should -Throw '*sha256*' { Validate-Manifest ([pscustomobject]@{ shardSize = 9; shards = @((& $ok '00.txt')) }) } | Should -Throw '*shardSize*' + foreach ($name in '../x.txt', '..\x.txt', 'a/../../x.txt', '/etc/x.txt', 'C:x.txt', '00.txt:stream') { + { Validate-Manifest ([pscustomobject]@{ shards = @((& $ok $name)) }) } | Should -Throw '*not a plain relative path*' + } + { Validate-Manifest ([pscustomobject]@{ shards = @((& $ok 'sub/00.txt')) }) } | Should -Not -Throw } It 'throws when shards would merge out of order' { @@ -172,6 +176,13 @@ Describe 'Update-ElysiumKhdb (incremental sync against a fake S3 store)' { { Update-ElysiumKhdb -MaxParallelTransfers 2 6>$null } | Should -Throw '*00.txt*mismatch*' Get-Content -LiteralPath $khdb | Should -Be $before } + + It 'refuses a manifest whose shard names point outside the shard directory' { + # What a tampered bucket could serve: a valid checksum for a file meant to land two levels up. + Publish-Shards @{ '../../escaped.txt' = @('00112233445566778899AABBCCDDEEFF') } + { Update-ElysiumKhdb -MaxParallelTransfers 1 6>$null } | Should -Throw "*'../../escaped.txt'*" + Test-Path -LiteralPath (Join-Path $TestDrive 'escaped.txt') | Should -BeFalse + } } Describe 'Update-ElysiumLithnetStore' {