feat(ghidra): enable Windows x64 read-only analysis (#699)

* feat(ghidra): enable Windows x64 read-only analysis

* test(ghidra): exercise native Windows runtime boundaries

* test(ghidra): verify current Windows inventory and isolate ACL observer

* fix(ghidra): align Windows admission and address P0 review
This commit is contained in:
N0zoM1z0
2026-10-06 16:53:33 +08:00
committed by GitHub
parent cf061159ab
commit 26881da76a
65 changed files with 4091 additions and 356 deletions
+18 -3
View File
@@ -2,6 +2,8 @@ import { chmod, mkdtemp, rm } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { WindowsPrivateRuntime } from "../windows/WindowsPrivateRuntime.js";
import {
windowsNativeCapabilities,
type WindowsNativeCapability,
@@ -43,7 +45,7 @@ export class PrivateRuntimeRootUnavailableError extends Error {
}
/**
* Owns one POSIX mode-0700 temporary runtime root and removes it idempotently.
* Owns a private temporary runtime root and removes it idempotently.
*
* Protocol adapters decide what belongs inside the directory; this primitive
* establishes a private filesystem boundary on POSIX and deterministic cleanup.
@@ -52,7 +54,10 @@ export class PrivateRuntimeRootUnavailableError extends Error {
export class PrivateRuntimeRoot {
#closePromise: Promise<void> | undefined;
private constructor(readonly path: string) {}
private constructor(
readonly path: string,
private readonly windowsRuntime?: WindowsPrivateRuntime,
) {}
/** Allocate a new private runtime root without performing protocol work. */
static async create(
@@ -62,6 +67,13 @@ export class PrivateRuntimeRoot {
const capability = privateRuntimeRootCapability(platform);
if (!capability.available)
throw new PrivateRuntimeRootUnavailableError(capability.reason);
if (platform === "win32") {
const runtime = WindowsPrivateRuntime.create(
options.parent ?? tmpdir(),
options.prefix ?? "rea-provider-",
);
return new PrivateRuntimeRoot(runtime.observation.path, runtime);
}
const path = await mkdtemp(
join(options.parent ?? tmpdir(), options.prefix ?? "rea-provider-"),
);
@@ -76,7 +88,10 @@ export class PrivateRuntimeRoot {
/** Remove the runtime root; concurrent and repeated callers share cleanup. */
close(): Promise<void> {
this.#closePromise ??= rm(this.path, { recursive: true, force: true });
this.#closePromise ??=
this.windowsRuntime === undefined
? rm(this.path, { recursive: true, force: true })
: Promise.resolve().then(() => this.windowsRuntime?.close());
return this.#closePromise;
}
}
+46 -9
View File
@@ -1,6 +1,9 @@
import { spawn, type ChildProcess } from "node:child_process";
import type { EventEmitter } from "node:events";
import type { Readable } from "node:stream";
import { WindowsOwnedProcess } from "../windows/WindowsOwnedProcess.js";
import type {
OwnedProcessGroup,
ProcessCleanupResult,
@@ -28,20 +31,34 @@ export interface OwnedProviderProcessSpawnOptions {
/** Spawned process paired with the identity proof required for group cleanup. */
export interface SpawnedOwnedProviderProcess {
readonly process: ChildProcess;
readonly process: ProviderProcessHandle;
readonly ownership: OwnedProcessGroup;
readonly cleanup?: () => Promise<ProcessCleanupResult>;
}
/** Process events and streams required by provider lifecycle supervision. */
export interface ProviderProcessHandle extends Pick<
EventEmitter,
"on" | "once" | "off"
> {
readonly pid?: number | undefined;
readonly stdout: Readable | null;
readonly stderr: Readable | null;
readonly exitCode: number | null;
readonly signalCode: NodeJS.Signals | null;
kill(signal?: NodeJS.Signals | number): boolean;
}
/** Process handle returned by a provider-specific launcher. */
export type ProviderProcessLaunch =
| {
readonly process: ChildProcess;
readonly process: ProviderProcessHandle;
readonly ownsProcessLifetime: false;
readonly ownership?: never;
readonly cleanup?: never;
}
| {
readonly process: ChildProcess;
readonly process: ProviderProcessHandle;
readonly ownsProcessLifetime: true;
readonly ownership?: OwnedProcessGroup;
readonly cleanup?: () => Promise<ProcessCleanupResult>;
@@ -102,7 +119,7 @@ export type ProviderProcessStopResult =
| { readonly status: "incomplete"; readonly reason: string };
/**
* Spawn a provider in a dedicated POSIX process group with an ownership token.
* Spawn a provider in an owned Windows job or dedicated POSIX process group.
*
* The caller remains responsible for persisting any ownership manifest and for
* selecting provider-specific command arguments or environment values.
@@ -112,17 +129,37 @@ export const spawnOwnedProviderProcess = async (
): Promise<SpawnedOwnedProviderProcess> => {
const platform = options.platform ?? process.platform;
const hostEnvironment = options.hostEnvironment ?? process.env;
const environment = {
...hostEnvironment,
...options.env,
REA_PROCESS_RUN_ID: options.runId,
};
if (platform === "win32" && process.platform === "win32") {
const child = new WindowsOwnedProcess(
options.command,
options.arguments,
options.cwd,
environment,
options.windowsVerbatimArguments ?? false,
);
return {
process: child,
ownership: {
runId: options.runId,
leaderPid: child.pid,
processGroupId: child.pid,
expectedParentPid: process.pid,
},
cleanup: () => child.cleanup(),
};
}
const child = spawn(options.command, [...options.arguments], {
shell: false,
windowsHide: true,
stdio: ["ignore", "pipe", "pipe"],
detached: platform !== "win32",
windowsVerbatimArguments: options.windowsVerbatimArguments ?? false,
env: {
...hostEnvironment,
...options.env,
REA_PROCESS_RUN_ID: options.runId,
},
env: environment,
...(options.cwd === undefined ? {} : { cwd: options.cwd }),
});
await waitForSpawn(child);
+27 -6
View File
@@ -1,8 +1,6 @@
/**
* Provider-neutral security controls that require a verified Windows native
* authority. Runtime probes and POSIX permissions do not satisfy these
* controls.
*/
import { systemWindowsNativeAuthority } from "../windows/WindowsNativeLoader.js";
/** Windows controls are proven by the packaged native boundary, not POSIX flags. */
export type WindowsNativeCapability =
| {
readonly available: true;
@@ -24,7 +22,7 @@ export interface WindowsNativeCapabilitySet {
/** Stable explanation used whenever the native Windows authority is absent. */
export const WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON =
"Verified Windows native authority is unavailable: Job Object process ownership, private runtime DACL enforcement, and reparse-safe path admission are not implemented; chmod(0700) is insufficient for Windows private DACL proof, and taskkill is not a Job Object security proof";
"Windows native controls are unavailable in this runtime; use the Windows x64 REA package with its matching bundled native artifact.";
/**
* Describe native Windows controls without inferring them from taskkill,
@@ -46,6 +44,22 @@ export const windowsNativeCapabilities = (
};
}
if (process.platform === "win32") {
const loaded = systemWindowsNativeAuthority();
const capability = loaded.available
? ({ available: true, reason: null, proof: "native-authority" } as const)
: ({
available: false,
reason: loaded.reason,
proof: "not-proven",
} as const);
return {
job_object_process_ownership: capability,
private_runtime_dacl: capability,
reparse_safe_path_admission: capability,
};
}
const notProven = {
available: false,
reason: WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON,
@@ -63,3 +77,10 @@ export const hasWindowsNativeAuthority = (platform: NodeJS.Platform): boolean =>
Object.values(windowsNativeCapabilities(platform)).every(
({ available }) => available,
);
/** Preserve the actual loader or operating-system constraint in provider errors. */
export const windowsNativeAuthorityUnavailableReason = (
platform: NodeJS.Platform,
): string =>
windowsNativeCapabilities(platform).job_object_process_ownership.reason ??
WINDOWS_NATIVE_AUTHORITY_UNAVAILABLE_REASON;