Compare commits

...
Author SHA1 Message Date
kevin_janssen 715287a559 Record optimized Windows agent and helper build from the verified directory sharing fix
Rust development slice / linux (push) Failing after 6s
2026-11-15 17:17:42 +01:00
kevin_janssen e952698f5e Allow protected Windows profile publication while the public directory stays pinned
Rust development slice / linux (push) Failing after 6s
2026-11-15 17:10:54 +01:00
kevin_janssen aa36b178aa Record verified cloud receiver and automatic close time for the console window
Rust development slice / linux (push) Failing after 6s
2026-11-15 17:05:23 +01:00
kevin_janssen d37160ba41 Return fixed Windows maintenance results over a foreground loopback SSH forward
Rust development slice / linux (push) Failing after 7s
2026-11-15 17:03:38 +01:00
kevin_janssen 577132fb42 Expose the existing passive Windows console reader as a directly runnable script
Rust development slice / linux (push) Failing after 6s
2026-11-15 17:01:33 +01:00
kevin_janssen ca588abce4 Prepare guarded console completion for the verified Windows time profile
Rust development slice / linux (push) Failing after 7s
2026-11-15 16:56:27 +01:00
kevin_janssen 53d17757ab Record operator verification of the retained Windows time profile candidate
Rust development slice / linux (push) Failing after 7s
2026-11-15 16:53:58 +01:00
8 changed files with 402 additions and 68 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ impl Client {
ipc::service_sid(crate::SERVICE_NAME)?,
ipc::service_sid(ipc::HELPER_SERVICE)?,
];
let _root = ipc::PinnedFile::open(Path::new(PUBLIC_ROOT), true, &readers, &[], false)?;
let _root = ipc::PinnedFile::open_read_shared(Path::new(PUBLIC_ROOT), true, &readers, &[])?;
let mut file = ipc::PinnedFile::open(Path::new(PIN_PATH), false, &readers, &[], false)?;
ensure!(file.file.metadata()?.len() <= 16384, "HELPER_PIN_SIZE");
let mut bytes = Vec::new();
+3 -1
View File
@@ -216,7 +216,9 @@ pub fn read_settings() -> Result<(Settings, Vec<PinnedFile>)> {
let agent = ipc::service_sid(crate::SERVICE_NAME)?;
let helper = ipc::service_sid(ipc::HELPER_SERVICE)?;
let readers = vec![agent, helper];
let root = PinnedFile::open(Path::new(PUBLIC_ROOT), true, &readers, &[], false)?;
// A rename into PUBLIC_ROOT opens the directory with FILE_ADD_FILE.
// The handle stays read-only and denies deletion of the pinned directory.
let root = PinnedFile::open_read_shared(Path::new(PUBLIC_ROOT), true, &readers, &[])?;
let mut file = PinnedFile::open(Path::new(CONFIG_PATH), false, &readers, &[], false)?;
ensure!(file.file.metadata()?.len() <= 32768, "SYSTEM_CONFIG_SIZE");
use std::io::Read;
+1 -2
View File
@@ -751,12 +751,11 @@ mod installed {
settings.agent.service_sid.clone(),
settings.helper.service_sid.clone(),
];
files.push(PinnedFile::open(
files.push(PinnedFile::open_read_shared(
Path::new(PUBLIC_ROOT),
true,
&readers,
&[],
false,
)?);
let mut config_file =
PinnedFile::open(Path::new(CONFIG_PATH), false, &readers, &[], false)?;
@@ -0,0 +1,112 @@
#requires -Version 5.1
#requires -RunAsAdministrator
# Finish the single, console-verified public-file publication on the test VM.
# Run in a fresh Windows PowerShell process. No SSH or RMM job is involved.
$ErrorActionPreference = 'Stop'
$caseId = 'ad9fd154-b2be-4f5d-9e17-65abb721ceaf'
$controllerHash = 'd8b4fd4fd9ca5310cc1591ce3c2ccae5bd72a2ade43b21a8187cfdfb960b3427'
$configHash = '2b4a8a7080770304b80e2a665fa5f5ee1ebbd9182e7c80b184e75b114575b42b'
$bootstrap = 'C:\ProgramData\RustDiscoveryBootstrap'
$casePath = Join-Path $bootstrap "time-profile-$caseId"
$original = Join-Path (Join-Path $bootstrap $controllerHash) 'InstallPublicTimeProfile.ps1'
$originalBytes = [IO.File]::ReadAllBytes($original)
$sha = [Security.Cryptography.SHA256]::Create()
try {
$digest = [BitConverter]::ToString($sha.ComputeHash($originalBytes)).Replace('-', '')
} finally { $sha.Dispose() }
if ($digest -ne $controllerHash) { throw 'Unexpected original controller' }
# Import the verified definitions (including native FileID/SCM checks) from the
# installed original. Its first top-level preflight and install body are excluded.
$source = [Text.Encoding]::UTF8.GetString($originalBytes)
$boundary = "`nCheckControl `$boot `$true`n"
$index = $source.IndexOf($boundary, [StringComparison]::Ordinal)
if ($index -lt 1 -or $index -ne $source.LastIndexOf($boundary, [StringComparison]::Ordinal)) {
throw 'Original controller definition boundary missing'
}
$intent = Get-Content -LiteralPath (Join-Path $casePath 'intent.json') -Raw | ConvertFrom-Json
if ($intent.id -cne $caseId -or $intent.request.id -cne $caseId -or
$intent.request.script_sha256 -cne $controllerHash -or $intent.request.config_sha256 -cne $configHash) {
throw 'Unexpected original intent'
}
$global:RmmTimeProfilePayload = $intent.request
. ([scriptblock]::Create($source.Substring(0, $index)))
CheckControl $boot $true
CheckControl $folder $true
foreach ($leaf in 'intent.json','publish-intent.json','directory-acl-intent.json','directory-acl-done.json') {
CheckControl (Join-Path $folder $leaf) $false
}
CheckControl $active $false
$activeRecord = Get-Content -LiteralPath $active -Raw | ConvertFrom-Json
if ($activeRecord.id -cne $caseId -or $activeRecord.script_sha256 -cne $controllerHash -or
$activeRecord.config_sha256 -cne $configHash -or $activeRecord.no_retry -ne $true) {
throw 'Unexpected active publication record'
}
$bytes = ConfigBytes
$publish = Get-Content -LiteralPath (Join-Path $folder 'publish-intent.json') -Raw | ConvertFrom-Json
$aclDone = Get-Content -LiteralPath (Join-Path $folder 'directory-acl-done.json') -Raw | ConvertFrom-Json
$staged = Join-Path $folder 'time-attestation.candidate.json'
$resultPath = Join-Path $folder 'result.json'
$reservation = Join-Path $folder 'console-finalization-intent.json'
foreach ($path in @($target,$resultPath,$reservation)) {
if (Test-Path -LiteralPath $path) { throw 'Existing target or finalization record: read original case' }
}
$null = ReadAcl $staged $false
$rootAcl = ReadAcl $helperRoot $true
$expected = @{
volume_serial = '9815088561147542064'
file_id = '6d990300000003000000000000000000'
bytes = 1177
acl_sha256 = '3a426f649cd6ff4e82bf70205c8ecc7d5b2c0775fa1e10fc30ce35de9bb12493'
sha256 = $configHash
}
if ($publish.create_once -ne $true -or $publish.config_sha256 -cne $configHash -or
!(JsonEqual $expected $publish.staged) -or !(JsonEqual $expected (FileIdentity $staged)) -or
(FileVolume $helperRoot) -cne $expected.volume_serial -or $rootAcl.Sddl -cne $aclDone.sddl -or
(AclHash $helperRoot) -cne '186d85132cf0e16cbb9623ad9636b7777741939a8cae3d689a2af1eb267a7f49') {
throw 'Original file identity or permissions changed'
}
if ($p.probe_sha256 -cne '727732fb4b38ac5431a330527bd52a3ab80af8f189ae75a7b48eceb1d4b69cac' -or
$p.system_probe_sha256 -cne '77a344912c61b7ac4a92152ae1b534ca7c36fe6f7dc4675783f20558c3a7f434') {
throw 'Unexpected native status probes'
}
$before = ActualState $true
SameLive $request.expected_native $before
SameLive $intent.before $before
if ($before.agent_kernel.creation_filetime -cne '134392294174782153' -or
$before.helper_kernel.creation_filetime -cne '134392294130218261') { throw 'Service generation changed' }
$heldAgent = [RmmPipeNative]::Open([int]$before.service.pid)
try {
$heldHelper = [RmmPipeNative]::Open([int]$before.helper_service.pid)
try {
$null = Kernel 'agent' $before.service $heldAgent
$null = Kernel 'helper' $before.helper_service $heldHelper
# WriteNew uses CreateNew. Concurrent or later invocations cannot republish.
WriteNew $reservation @{id=$caseId; config_sha256=$configHash; utc=[DateTime]::UtcNow.ToString('o')}
try {
[IO.File]::Move($staged, $target)
} catch {
$cause = $_.Exception.GetBaseException()
$failure = @{id=$caseId; phase='File.Move'; hresult=('0x{0:X8}' -f $cause.HResult); exception=$cause.GetType().FullName}
WriteNew (Join-Path $folder 'console-finalization-error.json') $failure
throw ("File.Move: {0} ({1})." -f $failure.exception, $failure.hresult)
}
$null = ReadAcl $target $false
$published = FileIdentity $target
if (!(JsonEqual $expected $published) -or (Test-Path -LiteralPath $staged)) { throw 'Publication postcheck failed' }
$after = ActualState $true
SameLive $before $after
$null = Kernel 'agent' $before.service $heldAgent
$null = Kernel 'helper' $before.helper_service $heldHelper
WriteNew $resultPath @{
id=$caseId; installed=$true; install_not_before=$intent.install_not_before
configuration=$published; native=$after; original_root_sddl=$intent.original_root_sddl
root_sddl=(Get-Acl -LiteralPath $helperRoot).Sddl; no_jobs=$true
clock_runtime_qualified=$false; services_changed=$false; private_key_read=$false
console_finalized=$true; original_move_failed=$true
}
'Zeitprofil veroeffentlicht; Dateiidentitaet und Dienstgenerationen geprueft.'
} finally { $heldHelper.Dispose() }
} finally { $heldAgent.Dispose() }
@@ -0,0 +1,105 @@
#requires -Version 5.1
#requires -RunAsAdministrator
# The relay receives a fixed public receipt. There is no command reader.
$ErrorActionPreference = 'Stop'
$until = [DateTimeOffset]::Parse('2026-11-15T17:00:00+00:00')
$deadline = [DateTimeOffset]::UtcNow.AddMinutes(12)
if ($deadline -gt $until) { $deadline = $until }
if ($deadline -le [DateTimeOffset]::UtcNow) { throw 'Das Wartungsfenster ist abgelaufen.' }
$base = 'https://gitea.incoso.eu/kevin_janssen/rust-discovery/raw/commit/577132fb422bf854276b3afb5bafdb12d2c08427/deploy/windows'
$bootstrap = 'C:\ProgramData\RustDiscoveryBootstrap'
$caseId = 'ad9fd154-b2be-4f5d-9e17-65abb721ceaf'
$case = Join-Path $bootstrap "time-profile-$caseId"
$access = 'C:\ProgramData\RmmDevAccess'
$sshBin = Join-Path $env:WINDIR 'System32\OpenSSH'
$known = Join-Path $access 'known_hosts'
$key = Join-Path $access 'tunnel_ed25519'
$fp = & "$sshBin\ssh-keygen.exe" -lf $known
if ($LASTEXITCODE -ne 0 -or @($fp).Count -ne 1 -or
$fp.Split(' ')[1] -cne 'SHA256:+NEin4XJc3CbhjQi7/ZpMIgxOrXn8AT2tlpTaXW5quw') { throw 'Server-Hostpin stimmt nicht.' }
$session = [guid]::NewGuid().ToString()
$work = Join-Path $bootstrap "time-receipt-$session"
$null = New-Item -ItemType Directory -Path $work
$listener = $null
$ssh = $null
$scripts = [ordered]@{
'Complete-OriginalTimeProfile.ps1' = '5ad85ae7a3a513d3cc2f5f5dca3e48eb42fd863522c3384f9c64cdcf0273ef1a'
'Read-PassiveTimeSamples.ps1' = 'd9e2b9344c19af1296b86ec70ba754ef820f369ac5ec897979bd4233e0722d04'
}
try {
foreach ($name in $scripts.Keys) {
$path = Join-Path $work $name
Invoke-WebRequest -UseBasicParsing -Uri "$base/$name" -OutFile $path -TimeoutSec 30
if ((Get-FileHash -LiteralPath $path).Hash -ne $scripts[$name]) { throw "Downloadhash: $name" }
Unblock-File -LiteralPath $path
}
$listener = [Net.Sockets.TcpListener]::new([Net.IPAddress]::Loopback, 0)
$listener.Start(4)
$port = $listener.LocalEndpoint.Port
$options = @('-F','NUL','-N','-T','-o','BatchMode=yes','-o','IdentitiesOnly=yes',
'-o','ForwardAgent=no','-o','StrictHostKeyChecking=yes','-o','GlobalKnownHostsFile=NUL',
'-o',"UserKnownHostsFile=$known",'-o','ExitOnForwardFailure=yes','-o','ConnectTimeout=10',
'-o','ServerAliveInterval=15','-o','ServerAliveCountMax=2','-i',$key,
'-R',"127.0.0.1:22240:127.0.0.1:$port",'rmm-win-tunnel@discovery.ease-technologies.de')
$ssh = Start-Process -FilePath "$sshBin\ssh.exe" -ArgumentList $options -PassThru -NoNewWindow
if ($ssh.WaitForExit(1800)) { throw "SSH Exit $($ssh.ExitCode)" }
Write-Host 'Wartungsfenster aktiv. Dieses Fenster offen lassen. Strg+C beendet es.'
$receipt = [ordered]@{session=$session; case_id=$caseId; phase='preflight'; read_only_channel=$true}
$result = Join-Path $case 'result.json'
try {
if (!(Test-Path -LiteralPath $result)) {
$null = & (Join-Path $work 'Complete-OriginalTimeProfile.ps1')
}
$record = Get-Content -LiteralPath $result -Raw | ConvertFrom-Json
$actual = Get-FileHash -LiteralPath 'C:\ProgramData\RustDiscoverySystem\time-attestation.json'
if ($record.id -cne $caseId -or $record.installed -ne $true -or
$record.console_finalized -ne $true -or $record.clock_runtime_qualified -ne $false -or
$actual.Hash -ne '2b4a8a7080770304b80e2a665fa5f5ee1ebbd9182e7c80b184e75b114575b42b') { throw 'Unexpected publication result' }
$marker = Get-Content -LiteralPath (Join-Path $case 'console-finalization-intent.json') -Raw | ConvertFrom-Json
if ($marker.id -cne $caseId -or $marker.config_sha256 -ne $actual.Hash) { throw 'Unexpected finalization intent' }
$receipt.phase = 'published'
$receipt.publication_since = $marker.utc
$receipt.result_sha256 = (Get-FileHash -LiteralPath $result).Hash
} catch {
$receipt.phase = 'finalization_failed'
$receipt.exception_type = $_.Exception.GetBaseException().GetType().FullName
$receipt.line = $_.InvocationInfo.ScriptLineNumber
$receipt.file = [IO.Path]::GetFileName($_.InvocationInfo.ScriptName)
Write-Warning $_.Exception.Message
$failurePath = Join-Path $case 'console-finalization-error.json'
if (Test-Path -LiteralPath $failurePath) {
$failure = Get-Content -LiteralPath $failurePath -Raw | ConvertFrom-Json
if ($failure.id -ceq $caseId -and $failure.hresult -cmatch '^0x[0-9A-Fa-f]{8}$') { $receipt.move_hresult = $failure.hresult }
}
}
$readScript = Join-Path $work 'Read-PassiveTimeSamples.ps1'
$readInput = @{id=$session; agent_sha256='0549d9ebea73cff996938f859b92192cc333de194128d7c6859a3f1d2e85893c'; helper_sha256='59675a3cbb3a5d213fc764f38379d6b81baaf9d47a7124470cc2767d4985763e'} | ConvertTo-Json -Compress
while ([DateTimeOffset]::UtcNow -lt $deadline -and !$ssh.HasExited) {
if (!$listener.Pending()) { Start-Sleep -Milliseconds 250; continue }
$client = $listener.AcceptTcpClient()
try {
if ($receipt.phase -eq 'published') {
$receipt.native = $null
try {
$json = $readInput | & "$env:WINDIR\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -ExecutionPolicy RemoteSigned -File $readScript
if ($LASTEXITCODE -eq 0) { $receipt.native = ($json -join "`n") | ConvertFrom-Json }
} catch { Write-Warning 'Passive Zeitbelege aktuell nicht lesbar.' }
}
$client.SendTimeout = 3000
$body = [Text.Encoding]::UTF8.GetBytes(($receipt | ConvertTo-Json -Depth 16 -Compress))
if ($body.Length -gt 65536) { throw 'Ergebnis zu gross.' }
$client.GetStream().Write($body,0,$body.Length)
} catch { Write-Warning $_.Exception.Message } finally { $client.Dispose() }
}
} finally {
if ($null -ne $ssh) {
try { if (!$ssh.HasExited) { $ssh.Kill(); $ssh.WaitForExit() } } finally { $ssh.Dispose() }
}
if ($null -ne $listener) { $listener.Stop() }
foreach ($name in $scripts.Keys) {
$path = Join-Path $work $name
if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path }
}
if ((Get-ChildItem -LiteralPath $work -Force | Measure-Object).Count -eq 0) { [IO.Directory]::Delete($work) }
}
@@ -0,0 +1,63 @@
$ErrorActionPreference='Stop';$p=([Console]::In.ReadLine()|ConvertFrom-Json)
if((($p.PSObject.Properties.Name|Sort-Object)-join',')-cne'agent_sha256,helper_sha256,id'-or[guid]::ParseExact($p.id,'D').ToString()-cne$p.id-or$p.agent_sha256-cnotmatch'^[0-9a-f]{64}$'-or$p.helper_sha256-cnotmatch'^[0-9a-f]{64}$'){throw 'Fixed public sample read'}
$state='C:\ProgramData\RustDiscovery\state';$agent='RmmDiscoveryWindows';$helper='RmmDiscoverySystemHelper'
$agentSid=(New-Object Security.Principal.NTAccount('NT SERVICE',$agent)).Translate([Security.Principal.SecurityIdentifier]).Value
$allowed=@('S-1-5-18','S-1-5-32-544',$agentSid)
function Check($path,[bool]$directory){
$i=Get-Item -LiteralPath $path -Force
if($i.PSIsContainer-ne$directory-or($i.Attributes-band[IO.FileAttributes]::ReparsePoint)){throw 'Regular public report path'}
$ancestor=$i.Directory;if($directory){$ancestor=$i.Parent};while($null-ne$ancestor){if($ancestor.Attributes-band[IO.FileAttributes]::ReparsePoint){throw 'Public report reparse ancestry'};$ancestor=$ancestor.Parent}
$acl=Get-Acl -LiteralPath $path;$owner=$acl.GetOwner([Security.Principal.SecurityIdentifier]).Value
if($owner-cnotin$allowed-and!(!$directory-and$owner-ceq'S-1-5-19')){throw 'Public report owner'}
$rules=@($acl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier]));if(!$rules.Count){throw 'Public report empty DACL'}
foreach($r in $rules){if($r.AccessControlType-ne'Allow'-or$r.IdentityReference.Value-cnotin$allowed){throw 'Public report broad DACL'}}
if($directory-and!$acl.AreAccessRulesProtected){throw 'Protected public report directory'}
return @{owner_sid=$owner;sddl=$acl.Sddl;dacl_checked=$true}
}
Add-Type -TypeDefinition @'
using System; using System.Text; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles;
public static class RmmPassiveTimeRead {
[StructLayout(LayoutKind.Sequential)] public struct Info {public uint Attr,CL,CH,AL,AH,WL,WH,Volume,SizeH,SizeL,Links,IndexH,IndexL;}
[DllImport("kernel32.dll",SetLastError=true)] public static extern bool GetFileInformationByHandle(SafeFileHandle h,out Info i);
[DllImport("kernel32.dll",SetLastError=true)] static extern IntPtr OpenProcess(uint access,bool inherit,int pid);
[DllImport("kernel32.dll",SetLastError=true,CharSet=CharSet.Unicode)] static extern bool QueryFullProcessImageName(IntPtr h,uint flags,StringBuilder text,ref uint size);
[DllImport("kernel32.dll",SetLastError=true)] static extern bool GetProcessTimes(IntPtr h,out long creation,out long exit,out long kernel,out long user);
[DllImport("kernel32.dll",SetLastError=true)] static extern bool GetExitCodeProcess(IntPtr h,out uint code);
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr h);
public static string[] Process(int pid){IntPtr h=OpenProcess(0x1000,false,pid);if(h==IntPtr.Zero)throw new InvalidOperationException("QUERY_PROCESS");try{long c,e,k,u;uint code,size=32768;StringBuilder image=new StringBuilder((int)size);if(!GetProcessTimes(h,out c,out e,out k,out u)||!QueryFullProcessImageName(h,0,image,ref size)||!GetExitCodeProcess(h,out code)||code!=259)throw new InvalidOperationException("LIVE_PROCESS");return new string[]{c.ToString(System.Globalization.CultureInfo.InvariantCulture),image.ToString()};}finally{CloseHandle(h);}}
}
'@
function Hash([byte[]]$bytes){$h=[Security.Cryptography.SHA256]::Create();try{return([BitConverter]::ToString($h.ComputeHash($bytes))).Replace('-','').ToLowerInvariant()}finally{$h.Dispose()}}
function Runtime($role){
$name=$agent;$image='C:\Program Files\RustDiscovery\rmm-agent-windows.exe';$owner='NT AUTHORITY\LocalService';$mode='Auto';$sha=$p.agent_sha256
if($role-ceq'helper'){$name=$helper;$image='C:\Program Files\RustDiscovery\rmm-helper-windows.exe';$owner='LocalSystem';$mode='Manual';$sha=$p.helper_sha256}
$s=Get-CimInstance Win32_Service -Filter ("Name='"+$name+"'") -OperationTimeoutSec 5
if(!$s-or$s.State-cne'Running'-or$s.StartName-cne$owner-or$s.StartMode-cne$mode-or$s.ProcessId-le0-or$s.ServiceType-cne'Own Process'){throw 'Current fixed service role'}
$expected='"'+$image+'" --service';if($role-ceq'agent'){$expected+=' --config "C:\ProgramData\RustDiscovery\config.json"'}
if($s.PathName-cne$expected){throw 'Current fixed service command'}
$native=[RmmPassiveTimeRead]::Process([int]$s.ProcessId)
if($native[1]-cne$image-or(Get-FileHash -LiteralPath $image -Algorithm SHA256).Hash.ToLowerInvariant()-cne$sha){throw 'Current fixed service image'}
return [ordered]@{pid=[uint32]$s.ProcessId;birth_filetime=$native[0];image=$native[1];sha256=$sha;start_name=$s.StartName;start_mode=$s.StartMode;command=$s.PathName}
}
function Boot{return (Get-CimInstance Win32_OperatingSystem -Property LastBootUpTime -OperationTimeoutSec 5).LastBootUpTime.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture)}
$null=Check 'C:\ProgramData\RustDiscovery' $true;$directory=Check $state $true
$boot=Boot;$before=[ordered]@{agent=(Runtime 'agent');helper=(Runtime 'helper')};$reports=[ordered]@{}
foreach($name in @('agent-time-sample.json','helper-time-sample.json')){
$path=Join-Path $state $name
if(!(Test-Path -LiteralPath $path)){$reports[$name]=$null;continue}
$stream=[IO.File]::Open($path,[IO.FileMode]::Open,[IO.FileAccess]::Read,[IO.FileShare]::Read)
try{
$meta=Check $path $false;$info=New-Object RmmPassiveTimeRead+Info
if(![RmmPassiveTimeRead]::GetFileInformationByHandle($stream.SafeFileHandle,[ref]$info)-or$info.Links-ne1-or($info.Attr-band0x410)-ne0-or$info.SizeH-ne0-or$info.SizeL-lt1-or$info.SizeL-gt8192-or$stream.Length-ne$info.SizeL){throw 'Single-link bounded public report'}
$raw=New-Object byte[] $info.SizeL;$offset=0;while($offset-lt$raw.Length){$count=$stream.Read($raw,$offset,$raw.Length-$offset);if($count-le0){throw 'Complete held public report'};$offset+=$count}
$after=New-Object RmmPassiveTimeRead+Info
if(![RmmPassiveTimeRead]::GetFileInformationByHandle($stream.SafeFileHandle,[ref]$after)-or$after.IndexH-ne$info.IndexH-or$after.IndexL-ne$info.IndexL-or$after.WH-ne$info.WH-or$after.WL-ne$info.WL-or$after.SizeL-ne$info.SizeL-or$after.Links-ne1){throw 'Stable held public report'}
$again=Check $path $false;if($again.sddl-cne$meta.sddl-or$again.owner_sid-cne$meta.owner_sid){throw 'Stable public report security'}
$meta['volume']=$info.Volume;$meta['index_high']=$info.IndexH;$meta['index_low']=$info.IndexL;$meta['last_write_filetime']=(([uint64]$info.WH-shl32)-bor$info.WL).ToString([Globalization.CultureInfo]::InvariantCulture)
$reports[$name]=@{raw_base64=[Convert]::ToBase64String($raw);sha256=(Hash $raw);metadata=$meta}
}finally{$stream.Dispose()}
}
$after=[ordered]@{agent=(Runtime 'agent');helper=(Runtime 'helper')}
$directoryAfter=Check $state $true
if(($before|ConvertTo-Json -Depth 8 -Compress)-cne($after|ConvertTo-Json -Depth 8 -Compress)-or(Boot)-cne$boot-or$directory.sddl-cne$directoryAfter.sddl){throw 'Stable process, directory and boot during public read'}
@{id=$p.id;read_only=$true;boot_ticks=$boot;runtime=$after;state_metadata=$directory;reports=$reports;observed_at=[DateTime]::UtcNow.ToString('o')}|ConvertTo-Json -Depth 12 -Compress
+1 -64
View File
@@ -27,70 +27,7 @@ SECOND_NS = 1_000_000_000
# No report is requested from a service. The only content reads on the guest
# are these two public JSONs and public executable hashes. CIM/process queries
# obtain current boot/SCM/image/birth metadata without starting another binary.
SCRIPT = r'''$ErrorActionPreference='Stop';$p=([Console]::In.ReadLine()|ConvertFrom-Json)
if((($p.PSObject.Properties.Name|Sort-Object)-join',')-cne'agent_sha256,helper_sha256,id'-or[guid]::ParseExact($p.id,'D').ToString()-cne$p.id-or$p.agent_sha256-cnotmatch'^[0-9a-f]{64}$'-or$p.helper_sha256-cnotmatch'^[0-9a-f]{64}$'){throw 'Fixed public sample read'}
$state='C:\ProgramData\RustDiscovery\state';$agent='RmmDiscoveryWindows';$helper='RmmDiscoverySystemHelper'
$agentSid=(New-Object Security.Principal.NTAccount('NT SERVICE',$agent)).Translate([Security.Principal.SecurityIdentifier]).Value
$allowed=@('S-1-5-18','S-1-5-32-544',$agentSid)
function Check($path,[bool]$directory){
$i=Get-Item -LiteralPath $path -Force
if($i.PSIsContainer-ne$directory-or($i.Attributes-band[IO.FileAttributes]::ReparsePoint)){throw 'Regular public report path'}
$ancestor=$i.Directory;if($directory){$ancestor=$i.Parent};while($null-ne$ancestor){if($ancestor.Attributes-band[IO.FileAttributes]::ReparsePoint){throw 'Public report reparse ancestry'};$ancestor=$ancestor.Parent}
$acl=Get-Acl -LiteralPath $path;$owner=$acl.GetOwner([Security.Principal.SecurityIdentifier]).Value
if($owner-cnotin$allowed-and!(!$directory-and$owner-ceq'S-1-5-19')){throw 'Public report owner'}
$rules=@($acl.GetAccessRules($true,$true,[Security.Principal.SecurityIdentifier]));if(!$rules.Count){throw 'Public report empty DACL'}
foreach($r in $rules){if($r.AccessControlType-ne'Allow'-or$r.IdentityReference.Value-cnotin$allowed){throw 'Public report broad DACL'}}
if($directory-and!$acl.AreAccessRulesProtected){throw 'Protected public report directory'}
return @{owner_sid=$owner;sddl=$acl.Sddl;dacl_checked=$true}
}
Add-Type -TypeDefinition @'
using System; using System.Text; using System.Runtime.InteropServices; using Microsoft.Win32.SafeHandles;
public static class RmmPassiveTimeRead {
[StructLayout(LayoutKind.Sequential)] public struct Info {public uint Attr,CL,CH,AL,AH,WL,WH,Volume,SizeH,SizeL,Links,IndexH,IndexL;}
[DllImport("kernel32.dll",SetLastError=true)] public static extern bool GetFileInformationByHandle(SafeFileHandle h,out Info i);
[DllImport("kernel32.dll",SetLastError=true)] static extern IntPtr OpenProcess(uint access,bool inherit,int pid);
[DllImport("kernel32.dll",SetLastError=true,CharSet=CharSet.Unicode)] static extern bool QueryFullProcessImageName(IntPtr h,uint flags,StringBuilder text,ref uint size);
[DllImport("kernel32.dll",SetLastError=true)] static extern bool GetProcessTimes(IntPtr h,out long creation,out long exit,out long kernel,out long user);
[DllImport("kernel32.dll",SetLastError=true)] static extern bool GetExitCodeProcess(IntPtr h,out uint code);
[DllImport("kernel32.dll")] static extern bool CloseHandle(IntPtr h);
public static string[] Process(int pid){IntPtr h=OpenProcess(0x1000,false,pid);if(h==IntPtr.Zero)throw new InvalidOperationException("QUERY_PROCESS");try{long c,e,k,u;uint code,size=32768;StringBuilder image=new StringBuilder((int)size);if(!GetProcessTimes(h,out c,out e,out k,out u)||!QueryFullProcessImageName(h,0,image,ref size)||!GetExitCodeProcess(h,out code)||code!=259)throw new InvalidOperationException("LIVE_PROCESS");return new string[]{c.ToString(System.Globalization.CultureInfo.InvariantCulture),image.ToString()};}finally{CloseHandle(h);}}
}
'@
function Hash([byte[]]$bytes){$h=[Security.Cryptography.SHA256]::Create();try{return([BitConverter]::ToString($h.ComputeHash($bytes))).Replace('-','').ToLowerInvariant()}finally{$h.Dispose()}}
function Runtime($role){
$name=$agent;$image='C:\Program Files\RustDiscovery\rmm-agent-windows.exe';$owner='NT AUTHORITY\LocalService';$mode='Auto';$sha=$p.agent_sha256
if($role-ceq'helper'){$name=$helper;$image='C:\Program Files\RustDiscovery\rmm-helper-windows.exe';$owner='LocalSystem';$mode='Manual';$sha=$p.helper_sha256}
$s=Get-CimInstance Win32_Service -Filter ("Name='"+$name+"'") -OperationTimeoutSec 5
if(!$s-or$s.State-cne'Running'-or$s.StartName-cne$owner-or$s.StartMode-cne$mode-or$s.ProcessId-le0-or$s.ServiceType-cne'Own Process'){throw 'Current fixed service role'}
$expected='"'+$image+'" --service';if($role-ceq'agent'){$expected+=' --config "C:\ProgramData\RustDiscovery\config.json"'}
if($s.PathName-cne$expected){throw 'Current fixed service command'}
$native=[RmmPassiveTimeRead]::Process([int]$s.ProcessId)
if($native[1]-cne$image-or(Get-FileHash -LiteralPath $image -Algorithm SHA256).Hash.ToLowerInvariant()-cne$sha){throw 'Current fixed service image'}
return [ordered]@{pid=[uint32]$s.ProcessId;birth_filetime=$native[0];image=$native[1];sha256=$sha;start_name=$s.StartName;start_mode=$s.StartMode;command=$s.PathName}
}
function Boot{return (Get-CimInstance Win32_OperatingSystem -Property LastBootUpTime -OperationTimeoutSec 5).LastBootUpTime.ToUniversalTime().Ticks.ToString([Globalization.CultureInfo]::InvariantCulture)}
$null=Check 'C:\ProgramData\RustDiscovery' $true;$directory=Check $state $true
$boot=Boot;$before=[ordered]@{agent=(Runtime 'agent');helper=(Runtime 'helper')};$reports=[ordered]@{}
foreach($name in @('agent-time-sample.json','helper-time-sample.json')){
$path=Join-Path $state $name
if(!(Test-Path -LiteralPath $path)){$reports[$name]=$null;continue}
$stream=[IO.File]::Open($path,[IO.FileMode]::Open,[IO.FileAccess]::Read,[IO.FileShare]::Read)
try{
$meta=Check $path $false;$info=New-Object RmmPassiveTimeRead+Info
if(![RmmPassiveTimeRead]::GetFileInformationByHandle($stream.SafeFileHandle,[ref]$info)-or$info.Links-ne1-or($info.Attr-band0x410)-ne0-or$info.SizeH-ne0-or$info.SizeL-lt1-or$info.SizeL-gt8192-or$stream.Length-ne$info.SizeL){throw 'Single-link bounded public report'}
$raw=New-Object byte[] $info.SizeL;$offset=0;while($offset-lt$raw.Length){$count=$stream.Read($raw,$offset,$raw.Length-$offset);if($count-le0){throw 'Complete held public report'};$offset+=$count}
$after=New-Object RmmPassiveTimeRead+Info
if(![RmmPassiveTimeRead]::GetFileInformationByHandle($stream.SafeFileHandle,[ref]$after)-or$after.IndexH-ne$info.IndexH-or$after.IndexL-ne$info.IndexL-or$after.WH-ne$info.WH-or$after.WL-ne$info.WL-or$after.SizeL-ne$info.SizeL-or$after.Links-ne1){throw 'Stable held public report'}
$again=Check $path $false;if($again.sddl-cne$meta.sddl-or$again.owner_sid-cne$meta.owner_sid){throw 'Stable public report security'}
$meta['volume']=$info.Volume;$meta['index_high']=$info.IndexH;$meta['index_low']=$info.IndexL;$meta['last_write_filetime']=(([uint64]$info.WH-shl32)-bor$info.WL).ToString([Globalization.CultureInfo]::InvariantCulture)
$reports[$name]=@{raw_base64=[Convert]::ToBase64String($raw);sha256=(Hash $raw);metadata=$meta}
}finally{$stream.Dispose()}
}
$after=[ordered]@{agent=(Runtime 'agent');helper=(Runtime 'helper')}
$directoryAfter=Check $state $true
if(($before|ConvertTo-Json -Depth 8 -Compress)-cne($after|ConvertTo-Json -Depth 8 -Compress)-or(Boot)-cne$boot-or$directory.sddl-cne$directoryAfter.sddl){throw 'Stable process, directory and boot during public read'}
@{id=$p.id;read_only=$true;boot_ticks=$boot;runtime=$after;state_metadata=$directory;reports=$reports;observed_at=[DateTime]::UtcNow.ToString('o')}|ConvertTo-Json -Depth 12 -Compress
'''
SCRIPT = Path(__file__).with_name('Read-PassiveTimeSamples.ps1').read_text(encoding='utf-8')
def need(value, tag):
+116
View File
@@ -180,6 +180,64 @@ getrennt zu prüfen. Eine spätere Fortsetzung benötigt zuerst eine lesende
Ursachenklärung und einen konkret geprüften Vertrag für den ursprünglichen
Teilfall; ein neuer Fall darf diesen Marker nicht umgehen.
## Sharing-Verletzung bei der Konsolenfinalisierung
Die VM meldete beim gesonderten Konsolenabschluss für `File.Move` den HRESULT
`0x80070020` (Win32 32, Sharing-Verletzung). Der Helper hielt seit seinem
Start einen Lesehandle auf `C:\ProgramData\RustDiscoverySystem`. Der Code
erlaubte ausschließlich `FILE_SHARE_READ`. Beim Verschieben des Kandidaten
aus dem Bootstrap-Verzeichnis öffnet Windows den **Zielordner** für
`FILE_ADD_FILE`. Dieser Zugriff kollidiert mit dem gehaltenen Handle. Die
native Fehlermeldung nennt keine Prozess-ID. Die Zuordnung folgt aus den
Öffnungsmodi des Helpers und der dokumentierten Windows-Rename-Operation.
[Windows-Rename](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/87f86c9b-6c2a-4803-84b7-131a74a434fa)
· [Windows-Sharingprüfung](https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-fsa/8c0e3f4f-0729-49f4-a14d-7f7add593819)
Im korrigierten Quellstand öffnen der Helper, der Agent beim Laden des
Peer-Pins und die Zeitprüfung genau diesen öffentlichen Stamm über
`PinnedFile::open_read_shared`. Der Lesehandle lässt auch einen berechtigten
Schreibzugriff auf den Ordner zu. Weiterhin sperrt er das Löschen und
Umbenennen des Ordners. Über Kinddateien entscheiden deren eigene DACL und
gehaltene Datei-Pins. Einstellungen, Peer-Pin und Zeitprofildatei werden
weiterhin mit geteiltem Lesezugriff geöffnet. Die vorhandenen Prüfungen von
Owner, DACL, Reparse-Attributen und Dateiidentität laufen bei jedem Pin.
Workspace-Formatprüfung, Cargo-Check aller Windows-Ziele mit `system-helper`
und Clippy mit `-D warnings` bestanden im Windows-Clock-Builder offline.
Beide x86-64-PE-Debugprogramme wurden dort gelinkt. Agent-SHA-256
`b5fe5ea55c857415c979f06851e54a2d1fbe4cbfe2fe7ad1660e209aae3fa583`,
Helper-SHA-256 `c6b41b0867df23f2c04c2550a39678672ef66d35a4b41215769265924deaf8a1`.
Der erste Buildversuch endete in einem anderen Builder wegen fehlendem
`widl`. Die Windows-VM hat diese Änderungen bisher weder ausgeführt noch
durch erneute Profilveröffentlichung und zwei passive Rollenbelege bestätigt.
### Optimiertes Release-Paar für die nächste Windows-Abnahme
Am 15. November 2026 wurden Agent und Helper aus Commit
`e952698f5e2bab808e816858a727ef40347f6142` auf dem Entwicklungsrechner
gebaut. Der Quellstand kam aus einem schreibgeschützt eingebundenen Git-Archiv.
Der unabhängige Vergleich nach dem Build bestätigte alle 708 Quelldateien
gegen Git-Tree `708c88b4d6a92d9f9cbebc70146250062532f45f`.
Rust 1.99.1 und Cargo 1.99.1 liefen im vorhandenen Clock-Builder ohne Netzwerk.
Der ausgeführte Befehl war
```sh
cargo build --release --target x86_64-pc-windows-gnu --features system-helper --locked --offline -p rmm-agent-windows --bin rmm-agent-windows --bin rmm-helper-windows
```
| Datei | Bytes | SHA-256 |
| --- | ---: | --- |
| `rmm-agent-windows.exe` | 23 543 434 | `2dd64e743431ad4c8244e43bef30c4c1c2123ad26a094853811a418626bb87e7` |
| `rmm-helper-windows.exe` | 17 191 183 | `9c313c07a20c82797cbd8c8ca7c289c1d227b0bd6a4a686f38c4db3bbdded199` |
Beide Dateien haben einen ausführbaren PE32+-Header mit AMD64-Maschinenkennung
`0x8664`. Der private Originalbeleg `profile-share-release-e952698/receipt.json`
hat SHA-256 `1ec1ec472043e8673e5b92f9029fd809434451d9452e3b24bbd85b21f017017d`.
Das erste Prüfskript traf auf dem Notebook auf eine ältere Python-Hashlib ohne
`file_digest`. Die Nachprüfung lief mit SHA-256 über dieselben fertigen Bytes.
Die Installation dieses Paars und die native Profilveröffentlichung mit den
zu diesen Binaries passenden Zeitprofilbindungen stehen aus.
## Unabhängiger lokaler Review des Move-Fehlers und fester Diagnosepfad
Der nachfolgende Review liest ausschließlich Quellen und vorhandene öffentliche
@@ -260,3 +318,61 @@ Source-/Intent-/Receiptbindung ohne Legacy-Hashadoption. Der Transport ist dabei
vollständig gemockt; dies ist kein nativer Befund. Die Kontrollbelege des alten
fehlgeschlagenen Installationsfalls bleiben bytegleich erhalten. Ein konkreter
Publikationsfix wurde mangels belegter nativer Fehlerursache nicht erfunden.
## Nachlese durch die Bedienperson auf der Windows-VM
In der administrativen VM-Konsole konnte die Bedienperson den Kandidaten
`time-attestation.candidate.json` lesen. SHA-256 stimmte mit dem im
Publish-Intent hinterlegten Wert `2b4a8a7080770304b80e2a665fa5f5ee1ebbd9182e7c80b184e75b114575b42b`
überein. Für den festen Zielpfad unter `RustDiscoverySystem` meldete
PowerShell `ObjectNotFound`. Dieser Konsolenbefund ergänzt den früheren
Readback um den Inhalt des verbliebenen Kandidaten. FileID, DACL und
Dienstgeneration wurden bei dieser Konsolenabfrage nicht erfasst.
Für die Fortsetzung an derselben VM-Konsole liegt
[`Complete-OriginalTimeProfile.ps1`](../deploy/windows/Complete-OriginalTimeProfile.ps1)
bereit. Der Befehl übernimmt die Prüffunktionen aus den SHA-256-geprüften
Bytes des bereits installierten Controllers. Vor der Veröffentlichung prüft er
die ursprüngliche Datei-ID und das Volume, den Inhalt, die DACL, die
ursprünglichen Marker und beide laufenden Dienstgenerationen. Er hält die
beiden Prozesshandles während der Veröffentlichung offen. Ein exklusiv
erstellter zusätzlicher Marker verhindert eine doppelte Ausführung.
Nach der Verschiebung an den festen Zielpfad vergleicht das Skript die
Dateiidentität und die Dienstzustände erneut. Bei einem neuen Move-Fehler erfasst
es Fehlerklasse und HRESULT für diesen Aufruf. Ein erneuter Start trifft auf
den Abschlussmarker oder den vorhandenen Zielpfad und beendet sich. Das
Ergebnis einer erfolgreichen Veröffentlichung hält die separate
Laufzeitprüfung der beiden Dienstrollen ausdrücklich offen.
Lokal geprüft wurden die PowerShell-Syntax, die Bindung an die gespeicherten
Originalbelege und der Vergleich mit der tatsächlichen Kandidatenidentität.
Eine veränderte FileID wurde im lokalen Vergleich abgewiesen. Die Ausführung
des Abschlussbefehls auf der VM und die anschließende Zeitprüfung stehen aus.
## Ergebnis vom Konsolenschritt automatisch abholen
Für den vorbereiteten Profilabschluss steht `Open-TimeProfileReceiptWindow.ps1`
zur Verfügung. Die Bedienperson startet es auf der Windows-VM. Das Skript prüft
die beiden Downloads gegen feste SHA-256-Werte, öffnet den vorhandenen
Reverse-SSH-Transport und führt den festen Abschluss lokal aus. Die
Weiterleitung auf dem Server ist an `127.0.0.1:22240` gebunden. Auf der VM
endet sie an einem temporären Loopback-Port. Der Prozess sendet dort den
Abschlussstatus und die öffentlichen Belege der beiden Zeitdienstrollen.
Er liest keine Befehle vom Socket. Die Gast-Kontofrist und die Aufgabenplanung
werden nicht geändert. Strg+C oder zwölf Minuten beenden das Vordergrundfenster.
Die serverseitige Frist für den vorhandenen Transportschlüssel und der aktive
Abschalttimer wurden für den 15. November 2026, 18:00 Uhr MEZ, geprüft.
Beim Bereitstellen wurden der PowerShell-Parser, die Downloadhashes, die
bestehenden Quellprüfungen und die sechs lokalen Prüffälle für die Zeitbelege
ausgeführt. Ein Ergebnis von der VM liegt bei Bereitstellung noch nicht vor.
Der Ergebnisempfänger auf dem permanenten Server wurde anschließend gestartet.
Seine Anfangsprüfung des laufenden Gateways und der gespeicherten
Windows-Gerätebindung war erfolgreich. Der Server fragt den Loopback-Port
nur bei vorhandenem SSH-Listener ab und legt eingehende Belege im privaten
Fall `time-profile-receipt-f7f56e9f` ab. Für Zeitbelege verwendet er die
bestehende Rollen-, Boot-, Generations- und Altersprüfung mit je einer
Datenbanklesung vor und nach dem Empfang. Die Bereitstellung des Empfängers
belegt noch keine Profilveröffentlichung auf dem Gast.