Files
CommandForge/helper/CommandForge.Elevator/Program.cs
T
poli0981andClaude Opus 4.8 6e9e5dc3c5 Phase 3a: elevation broker + Safe admin commands
- Elevator pipe server: accepts only a commandId, validates it against its OWN
  embedded catalog (id exists + requiresAdmin), runs via ProcessCommandExecutor,
  streams output, supports mid-run cancel. Never builds a command from pipe input.
- Pipe: per-session GUID name + current-user DACL; UI is the pipe server
  (medium IL), Elevator connects as client (high IL) to avoid the integrity barrier.
- BrokerElevationService: spawns the Elevator once per session via runas (one UAC),
  relays Run/Cancel and streamed output; graceful UAC-declined handling.
- RunCommandUseCase routes admin commands to the broker, others in-process.
- 6 Safe admin commands (DISM CheckHealth/ScanHealth/Analyze, chkdsk read,
  BitLocker status, Windows features) + EN/VI strings; system-maintenance populated.
- Wpf copies CommandForge.Elevator.exe next to the app (build + publish).
- Security hardening (from review): pin process WorkingDirectory to System32 so a
  bare executable name can't resolve from an attacker-controlled CWD when elevated.
- Tests: pipe protocol round-trip, ElevationServer over an in-process named pipe
  (fakes), admin/non-admin routing (35 total).

Build -c Release: 0 warnings. dotnet test: 35/35. UAC flow verified manually.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 20:54:10 +07:00

44 lines
1.4 KiB
C#

// CommandForge.Elevator — privileged broker helper (runs elevated, requireAdministrator).
//
// Connects to the UI's named pipe and serves ONLY admin commands from its OWN embedded catalog
// (golden rules #1/#2). It never builds a command line from pipe input — it accepts a commandId,
// looks it up, validates requiresAdmin, and runs it.
using System.IO.Pipes;
using CommandForge.Infrastructure;
using CommandForge.Infrastructure.Catalog;
using CommandForge.Infrastructure.Elevation;
using CommandForge.Infrastructure.Execution;
if (args.Length < 1 || string.IsNullOrWhiteSpace(args[0]))
{
return 2;
}
var pipeName = args[0];
AppPaths.EnsureCreated();
var logPath = Path.Combine(AppPaths.LogsDirectory, "elevator.log");
void Log(string message) =>
File.AppendAllText(logPath, $"{DateTimeOffset.Now:O} {message}{Environment.NewLine}");
try
{
Log($"Starting; connecting to pipe {pipeName}");
using var client = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut, PipeOptions.Asynchronous);
await client.ConnectAsync(30_000);
Log("Connected to UI");
var server = new ElevationServer(new JsonCatalogProvider(), new ProcessCommandExecutor(new SystemProcessRunner()));
await server.RunAsync(client, CancellationToken.None);
Log("Pipe closed; exiting");
return 0;
}
catch (Exception ex)
{
Log($"Failed: {ex}");
return 1;
}