feat(ghidra): launch bounded Windows headless sessions
Invoke analyzeHeadless.bat through an absolute cmd.exe with fixed interpreter switches, quoted arguments, delayed expansion disabled, and fail-closed metacharacter and length checks. Isolate Windows home and temporary coordinates, hide provider windows, and terminate the P0 launcher tree through bounded taskkill cleanup. Advertise explicit limitations that this preview does not provide Job Object ownership, DACL enforcement, reparse-point authority, or hostile-target safety.
This commit is contained in:
@@ -39,6 +39,11 @@ export interface ProcessOwnershipHost {
|
||||
signalGroup(processGroupId: number, signal: NodeJS.Signals): void;
|
||||
}
|
||||
|
||||
/** Narrow Windows P0 seam for bounded process-tree termination. */
|
||||
export interface WindowsProcessTreeHost {
|
||||
terminateTree(rootPid: number): Promise<"terminated" | "missing">;
|
||||
}
|
||||
|
||||
/** Per-member reason that token-verified cleanup failed closed. */
|
||||
interface ProcessOwnershipValidationFailure {
|
||||
readonly pid: number;
|
||||
@@ -63,6 +68,30 @@ export type ProcessGroupObservation =
|
||||
| { readonly state: "alive" }
|
||||
| { readonly state: "unverifiable"; readonly reason: string };
|
||||
|
||||
/**
|
||||
* Terminate one Windows process tree through the platform utility.
|
||||
*
|
||||
* This is a bounded P0 cleanup mechanism, not Job Object ownership proof. The
|
||||
* caller-visible Windows limitations must preserve that distinction.
|
||||
*/
|
||||
export const cleanupWindowsProcessTree = async (
|
||||
rootPid: number,
|
||||
host: WindowsProcessTreeHost = systemWindowsProcessTreeHost,
|
||||
): Promise<ProcessCleanupResult> => {
|
||||
if (!Number.isSafeInteger(rootPid) || rootPid <= 0)
|
||||
return { cleaned: false, reason: "Windows process-tree PID is invalid" };
|
||||
try {
|
||||
const result = await host.terminateTree(rootPid);
|
||||
return { cleaned: true, signaled: result === "terminated" };
|
||||
} catch {
|
||||
return {
|
||||
cleaned: false,
|
||||
reason:
|
||||
"Windows P0 process-tree termination failed; Job Object ownership is unavailable",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
/** Select the PTY root group and groups led by an observed captured process. */
|
||||
export const selectCapturedProcessGroupIds = (
|
||||
rootPid: number,
|
||||
@@ -135,6 +164,27 @@ const systemHost: ProcessOwnershipHost = {
|
||||
},
|
||||
};
|
||||
|
||||
const systemWindowsProcessTreeHost: WindowsProcessTreeHost = {
|
||||
async terminateTree(rootPid) {
|
||||
try {
|
||||
await execFileAsync(
|
||||
"taskkill.exe",
|
||||
["/pid", String(rootPid), "/t", "/f"],
|
||||
{ windowsHide: true, timeout: 5_000 },
|
||||
);
|
||||
return "terminated";
|
||||
} catch (cause: unknown) {
|
||||
if (
|
||||
cause instanceof Error &&
|
||||
"code" in cause &&
|
||||
(cause.code === 128 || cause.code === "ESRCH")
|
||||
)
|
||||
return "missing";
|
||||
throw cause;
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
/** Read the capture run token currently exposed by one live process. */
|
||||
export const readProcessRunId = async (
|
||||
pid: number,
|
||||
|
||||
@@ -105,6 +105,7 @@ export const spawnOwnedProviderProcess = async (
|
||||
): Promise<SpawnedOwnedProviderProcess> => {
|
||||
const child = spawn(options.command, [...options.arguments], {
|
||||
shell: false,
|
||||
windowsHide: true,
|
||||
stdio: ["ignore", "pipe", "pipe"],
|
||||
detached: process.platform !== "win32",
|
||||
env: {
|
||||
|
||||
Reference in New Issue
Block a user