/** * Bash Kill Guard — Intercepts bash kill commands and prevents them from * terminating WrongStack processes (either the agent itself or child processes * it has spawned). * * This module hooks into the bash tool's command parsing to detect and block * dangerous kill commands targeting protected PIDs. * * Handles: * - Direct kill commands: kill -9 12345, kill -- 12345, kill 111 12345 (every target) * - Sequenced commands: `true; kill 12345`, `a && kill 12345`, `a || kill 12345`, * `a & kill 12345`, newline-separated — each segment is checked on its own * - Shell -c wrapped: bash -c "kill -9 12345" (any shell path — see P2 #10) * - Full path kills: /bin/kill -9 12345 * - Name-based kills: pkill, killall, pgrep * - Windows equivalents: taskkill, tskill * - PowerShell Stop-Process / kill alias: Stop-Process -Name node, kill -Id 12345 * - WMIC process termination: wmic process where "name='node.exe'" delete * or wmic process where "ProcessId=1234" delete * - Script-based kill (script is named kill*.sh, kill*.ps1, kill*.bat) * * Security contract: every "Handles" bullet must map to both a detector * AND a block path in isKillRelatedCommand + parseKillCommand + isKillProtected. * Script-based kills are blocked conservatively (can't inspect script content). * * Known bypasses (NOT handled — this is a static regex parser, not a shell): * Static analysis of shell strings is inherently defeatable by obfuscation. * This guard is one defense-in-depth layer behind the permission policy and * the project-escape checks, not the sole gate. Treat a miss here as expected, * not as a hole to plug with ever-more-clever regexes. The patterns below are * known to evade detection: * - Base64 / decode pipes: `echo bCAtOSAxMjM0NQ== | base64 -d | sh` * - Variable indirection: `sig=-9; target=12345; kill $sig $target` * - Command substitution: `$(printf kill) -9 12345` * - String concatenation / quote-splitting: `ki''ll -9 12345`, `k"i"ll 12345` * - Aliases and functions: `alias x=kill; x -9 12345` * - eval / source: `eval "ki""ll -9 12345"` * - node -e eval: `node -e "process.kill(12345)"` (handled by exec-kill-guard.ts) * - Scripts not named kill/terminate/stop*: `runkill.sh`, `/tmp/cleanup.bat` * * Mitigation: rely on the permission policy (confirm/deny gate) and YOLO * destructive detection as the primary controls; this guard is a best-effort * fast path for the common non-obfuscated forms. */ export interface KillCommand { /** First PID target (kept for single-target callers). */ pid?: number; /** Every PID target when the command names more than one (`kill 1 2 3`). */ pids?: number[]; name?: string; signal?: string; isGroupKill: boolean; isAllKill: boolean; originalCommand: string; } export interface KillCheckResult { blocked: boolean; reason?: string; } export declare function parseKillCommand(command: string): KillCommand | null; /** * Main entry point: Check if a bash command contains a kill operation targeting protected PIDs. * Returns a result indicating whether to block and why. */ export declare function checkAndBlockKillCommand(command: string): Promise; /** * Get a safe error message for blocked kill commands. */ export declare function getBlockedKillMessage(pid: number, signal?: string): string; //# sourceMappingURL=bash-kill-guard.d.ts.map