fix(Update-KHDB): reject manifest shard names that escape the shard directory
Security. Shard names come from the downloaded manifest and were joined onto local paths unchecked, both for the staging download and the final Move-Item into the shard directory. A manifest served from a compromised (or spoofed) KHDB bucket could name a shard '../../something' with a matching SHA-256 and have that file written outside the shard directory - outside the install directory with enough '../' - on an admin host that also holds replication credentials. Overwriting one of Elysium's own scripts would turn that into code execution on the next run. TLS limits this to an attacker who controls the storage. Reproduced before the fix against the fake S3 store: the updater logged "Shard '../../escaped.txt' updated." and the file appeared two levels above the shard directory. Validate-Manifest, which runs before any download, now rejects shard names that are rooted, contain a '..' segment (either separator), or contain ':' (Windows drive-relative paths, NTFS alternate data streams). Plain relative subpaths like 'sub/00.txt' stay allowed. Tests: unit cases for each rejected form plus an allowed subpath, and an end-to-end case where the store serves such a manifest - the run now fails naming the shard and nothing is written outside. 31/31 Pester tests pass.
This commit is contained in:
@@ -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).
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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' {
|
||||
|
||||
Reference in New Issue
Block a user