@pensar/apex 1.7.0 → 1.8.0-canary.147b4685
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/agent-1m7c81my.js +19 -0
- package/build/{agent-beywhvf3.js → agent-py1mc4t9.js} +7 -7
- package/build/{auth-wvh553ea.js → auth-8tq7wxj1.js} +4 -4
- package/build/{authentication-ec7trwb4.js → authentication-58pffc05.js} +7 -7
- package/build/{blackboxAgent-ng2t2p2x.js → blackboxAgent-srftgqrc.js} +8 -8
- package/build/{blackboxPentest-rwyjy4kq.js → blackboxPentest-8q75j9eg.js} +12 -12
- package/build/{cli-q2dty8g4.js → cli-06z2ke44.js} +1 -1
- package/build/{cli-836bfgxg.js → cli-2atft0nk.js} +1 -1
- package/build/{cli-40ef01tb.js → cli-a7thepd4.js} +1 -1
- package/build/{cli-r879p2yz.js → cli-cymw8d24.js} +1 -1
- package/build/{cli-xtqm11qt.js → cli-e0g5cmyk.js} +1 -1
- package/build/{cli-gr3zncst.js → cli-hcs4hne1.js} +1 -1
- package/build/{cli-x3k26g1t.js → cli-j2rk8d21.js} +262 -159
- package/build/{cli-09prdch1.js → cli-ks7e63fy.js} +6 -6
- package/build/{cli-vvyq7ace.js → cli-kskaanbe.js} +1 -1
- package/build/{cli-zr7sg2m2.js → cli-m85a0s8v.js} +2 -2
- package/build/{cli-06zt0g1a.js → cli-mhx0ab9e.js} +2 -2
- package/build/{cli-5m0347h3.js → cli-t9zcagc4.js} +1 -1
- package/build/{cli-nqx9y9ds.js → cli-tsc0twgs.js} +1 -1
- package/build/{cli-rc7hyq7e.js → cli-wncegd0f.js} +55 -6
- package/build/cli.js +31 -27
- package/build/{fixes-1z283wdz.js → fixes-m7j440q1.js} +4 -4
- package/build/{index-j3hw6d4w.js → index-0vjhy05w.js} +58 -48
- package/build/{index-1p5bg26t.js → index-4a35h62w.js} +4 -4
- package/build/{index-py7gtxez.js → index-hfwhm80n.js} +2 -2
- package/build/{index-a4ydz3dd.js → index-q1ffe1hm.js} +7 -7
- package/build/{index-5a173a2k.js → index-r2n4jwsm.js} +6 -6
- package/build/{issues-trbzy8n0.js → issues-zn06qnhy.js} +4 -4
- package/build/{logs-c88md0h3.js → logs-k811t9g8.js} +4 -4
- package/build/{offesecAgent-ahcz5hcx.js → offesecAgent-pa5dw1pw.js} +7 -7
- package/build/{pentest-4932ke3a.js → pentest-v8as6b2g.js} +12 -12
- package/build/{pentests-re8dzxt9.js → pentests-cqmnx226.js} +4 -4
- package/build/{projects-dqp4m0ws.js → projects-c4j1q060.js} +4 -4
- package/build/{targetedPentest-de8a67va.js → targetedPentest-0wxxx05x.js} +8 -8
- package/build/{threatModel-waz866yk.js → threatModel-mhmh7xef.js} +8 -8
- package/build/{uninstall-0bwz7jdn.js → uninstall-7amh2f55.js} +1 -1
- package/package.json +1 -1
- package/build/agent-63cc9rpx.js +0 -19
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
update,
|
|
17
17
|
write,
|
|
18
18
|
writeRaw
|
|
19
|
-
} from "./cli-
|
|
19
|
+
} from "./cli-tsc0twgs.js";
|
|
20
20
|
import {
|
|
21
21
|
parseTargetUrl
|
|
22
22
|
} from "./cli-3y0dgy56.js";
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
require_tslib,
|
|
30
30
|
streamResponse,
|
|
31
31
|
toggleTool
|
|
32
|
-
} from "./cli-
|
|
32
|
+
} from "./cli-wncegd0f.js";
|
|
33
33
|
import {
|
|
34
34
|
_enum,
|
|
35
35
|
_null,
|
|
@@ -57,15 +57,15 @@ import {
|
|
|
57
57
|
} from "./cli-0ghkg3w6.js";
|
|
58
58
|
import {
|
|
59
59
|
signGatewayRequest
|
|
60
|
-
} from "./cli-
|
|
60
|
+
} from "./cli-e0g5cmyk.js";
|
|
61
61
|
import {
|
|
62
62
|
config,
|
|
63
63
|
ensureValidToken,
|
|
64
64
|
getPensarApiUrl
|
|
65
|
-
} from "./cli-
|
|
65
|
+
} from "./cli-06z2ke44.js";
|
|
66
66
|
import {
|
|
67
67
|
getCurrentVersion
|
|
68
|
-
} from "./cli-
|
|
68
|
+
} from "./cli-cymw8d24.js";
|
|
69
69
|
import {
|
|
70
70
|
__commonJS,
|
|
71
71
|
__require,
|
|
@@ -115782,6 +115782,32 @@ OUTPUT HANDLING:
|
|
|
115782
115782
|
- The tool's timeout parameter is in SECONDS, not milliseconds
|
|
115783
115783
|
- Good timeout examples: 30, 60, 120
|
|
115784
115784
|
- Do NOT pass millisecond values like 30000 or 120000
|
|
115785
|
+
- If the tool's timeout is hit, the partial stdout the command had already
|
|
115786
|
+
produced is still returned (with exit code 124). It is safe to set a
|
|
115787
|
+
conservative timeout: you will not lose the bytes a fuzzer printed
|
|
115788
|
+
before the kill.
|
|
115789
|
+
|
|
115790
|
+
LONG-RUNNING FUZZERS AND SCANNERS:
|
|
115791
|
+
|
|
115792
|
+
Wordlist fuzzers (ffuf, gobuster, dirb, wfuzz, dirsearch) and large nmap
|
|
115793
|
+
scans against slow targets routinely take longer than a single tool call
|
|
115794
|
+
should. ALWAYS bound them with their OWN internal time budget, set BELOW
|
|
115795
|
+
the tool's timeout, so the tool exits cleanly with full output and you
|
|
115796
|
+
don't have to rely on signal-based truncation.
|
|
115797
|
+
|
|
115798
|
+
General rule: set the inner tool's runtime cap at least 5s below the
|
|
115799
|
+
execute_command timeout, so the tool exits gracefully and flushes its
|
|
115800
|
+
results to disk before any signal arrives.
|
|
115801
|
+
|
|
115802
|
+
- ffuf: pair with -maxtime <seconds> and a sane -rate.
|
|
115803
|
+
Example: ffuf -u <url>/FUZZ -w <wordlist> -maxtime 55 -rate 50
|
|
115804
|
+
with the tool's timeout=60.
|
|
115805
|
+
- gobuster: has no -maxtime flag. Wrap with the \`timeout\` coreutils
|
|
115806
|
+
command and tune --timeout / --threads.
|
|
115807
|
+
Example: timeout 55 gobuster dir -u <url> -w <wordlist> --timeout 5s --threads 20
|
|
115808
|
+
with the tool's timeout=60.
|
|
115809
|
+
- nmap: prefer --host-timeout, --max-rtt-timeout, and -T4 / --min-rate
|
|
115810
|
+
to bound total runtime against slow networks.
|
|
115785
115811
|
|
|
115786
115812
|
IMPORTANT: Always analyze results and adjust your approach based on findings.`,
|
|
115787
115813
|
inputSchema: executeCommandInputSchema,
|
|
@@ -119360,7 +119386,7 @@ async function generateThreatModelForEndpoint(ctx, input) {
|
|
|
119360
119386
|
return threatModelLimiter(async () => {
|
|
119361
119387
|
if (ctx.abortSignal?.aborted)
|
|
119362
119388
|
return null;
|
|
119363
|
-
const { CodeAgent } = await import("./agent-
|
|
119389
|
+
const { CodeAgent } = await import("./agent-1m7c81my.js");
|
|
119364
119390
|
const subagentId = `threat-model-${sanitize(input.appName)}-${sanitize(input.routePath)}`;
|
|
119365
119391
|
ctx.eventBus?.emit("subagent-spawn", {
|
|
119366
119392
|
subagentId,
|
|
@@ -120049,7 +120075,7 @@ When to use delegate_to_auth_subagent vs authenticate_session:
|
|
|
120049
120075
|
if (credentials) {
|
|
120050
120076
|
ctx.session.credentialManager.addFromAuthCredentials(credentials);
|
|
120051
120077
|
}
|
|
120052
|
-
const { runAuthenticationAgent } = await import("./authentication-
|
|
120078
|
+
const { runAuthenticationAgent } = await import("./authentication-58pffc05.js");
|
|
120053
120079
|
const localBus = new AgentEventBus;
|
|
120054
120080
|
AgentEventBus.attachChild(localBus, ctx.eventBus, subagentId);
|
|
120055
120081
|
const result = await runAuthenticationAgent({
|
|
@@ -120962,7 +120988,7 @@ should be passed directly to spawn_pentest_swarm for deep testing.`,
|
|
|
120962
120988
|
});
|
|
120963
120989
|
if (cwd) {
|
|
120964
120990
|
try {
|
|
120965
|
-
const { WhiteboxAttackSurfaceAgent } = await import("./agent-
|
|
120991
|
+
const { WhiteboxAttackSurfaceAgent } = await import("./agent-py1mc4t9.js");
|
|
120966
120992
|
const localBus = new AgentEventBus;
|
|
120967
120993
|
AgentEventBus.attachChild(localBus, ctx.eventBus, subagentId);
|
|
120968
120994
|
const agent = new WhiteboxAttackSurfaceAgent({
|
|
@@ -121011,7 +121037,7 @@ should be passed directly to spawn_pentest_swarm for deep testing.`,
|
|
|
121011
121037
|
}
|
|
121012
121038
|
}
|
|
121013
121039
|
try {
|
|
121014
|
-
const { BlackboxAttackSurfaceAgent } = await import("./blackboxAgent-
|
|
121040
|
+
const { BlackboxAttackSurfaceAgent } = await import("./blackboxAgent-srftgqrc.js");
|
|
121015
121041
|
const localBus = new AgentEventBus;
|
|
121016
121042
|
AgentEventBus.attachChild(localBus, ctx.eventBus, subagentId);
|
|
121017
121043
|
const agent = new BlackboxAttackSurfaceAgent({
|
|
@@ -121087,7 +121113,7 @@ Pass every target you want tested — the swarm handles concurrency automaticall
|
|
|
121087
121113
|
toolCallDescription: exports_external.string().describe("A concise, human-readable description of what this tool call is doing")
|
|
121088
121114
|
}),
|
|
121089
121115
|
execute: async ({ targets }) => {
|
|
121090
|
-
const { runPentestSwarm, DEFAULT_CONCURRENCY } = await import("./pentest-
|
|
121116
|
+
const { runPentestSwarm, DEFAULT_CONCURRENCY } = await import("./pentest-v8as6b2g.js");
|
|
121091
121117
|
if (!ctx.model) {
|
|
121092
121118
|
return {
|
|
121093
121119
|
success: false,
|
|
@@ -121215,7 +121241,7 @@ Returns an array of results with the text output from each agent.`,
|
|
|
121215
121241
|
});
|
|
121216
121242
|
}
|
|
121217
121243
|
async function runSingleCodingAgent(ctx, codebasePath, objective, agentIndex, name) {
|
|
121218
|
-
const { CodeAgent } = await import("./agent-
|
|
121244
|
+
const { CodeAgent } = await import("./agent-1m7c81my.js");
|
|
121219
121245
|
const subagentId = `coding-agent-${agentIndex}`;
|
|
121220
121246
|
ctx.eventBus?.emit("subagent-spawn", {
|
|
121221
121247
|
subagentId,
|
|
@@ -121276,7 +121302,7 @@ Omit \`cwd\` for blackbox mode (live target probing only).`,
|
|
|
121276
121302
|
toolCallDescription: exports_external.string().describe("A concise, human-readable description of what this tool call is doing")
|
|
121277
121303
|
}),
|
|
121278
121304
|
execute: async ({ target, cwd }) => {
|
|
121279
|
-
const { runPentestWorkflow: workflow } = await import("./pentest-
|
|
121305
|
+
const { runPentestWorkflow: workflow } = await import("./pentest-v8as6b2g.js");
|
|
121280
121306
|
if (!ctx.model) {
|
|
121281
121307
|
return {
|
|
121282
121308
|
success: false,
|
|
@@ -125938,7 +125964,48 @@ function createResponseTool(responseSchema, onResult) {
|
|
|
125938
125964
|
// src/core/agents/offSecAgent/tools/persistentShell.ts
|
|
125939
125965
|
import { spawn as spawn4, spawnSync } from "child_process";
|
|
125940
125966
|
import { randomBytes } from "crypto";
|
|
125967
|
+
import {
|
|
125968
|
+
closeSync,
|
|
125969
|
+
mkdirSync as mkdirSync12,
|
|
125970
|
+
openSync,
|
|
125971
|
+
readFileSync as readFileSync4,
|
|
125972
|
+
readSync,
|
|
125973
|
+
statSync,
|
|
125974
|
+
unlinkSync as unlinkSync2
|
|
125975
|
+
} from "fs";
|
|
125976
|
+
import { tmpdir } from "os";
|
|
125977
|
+
import { join as join18 } from "path";
|
|
125941
125978
|
var MAX_BUFFER = 5000000;
|
|
125979
|
+
var APEX_TMP_ROOT = join18(tmpdir(), `apex-shell-${process.pid}`);
|
|
125980
|
+
try {
|
|
125981
|
+
mkdirSync12(APEX_TMP_ROOT, { recursive: true });
|
|
125982
|
+
} catch {}
|
|
125983
|
+
function readTempfileCapped(path) {
|
|
125984
|
+
try {
|
|
125985
|
+
const stat2 = statSync(path);
|
|
125986
|
+
if (stat2.size === 0)
|
|
125987
|
+
return "";
|
|
125988
|
+
if (stat2.size <= MAX_BUFFER) {
|
|
125989
|
+
return readFileSync4(path, "utf-8");
|
|
125990
|
+
}
|
|
125991
|
+
const fd = openSync(path, "r");
|
|
125992
|
+
try {
|
|
125993
|
+
const buf = Buffer.alloc(MAX_BUFFER);
|
|
125994
|
+
readSync(fd, buf, 0, MAX_BUFFER, stat2.size - MAX_BUFFER);
|
|
125995
|
+
return `(stdout truncated)...
|
|
125996
|
+
` + buf.toString("utf-8");
|
|
125997
|
+
} finally {
|
|
125998
|
+
closeSync(fd);
|
|
125999
|
+
}
|
|
126000
|
+
} catch {
|
|
126001
|
+
return "";
|
|
126002
|
+
}
|
|
126003
|
+
}
|
|
126004
|
+
function unlinkSafe(path) {
|
|
126005
|
+
try {
|
|
126006
|
+
unlinkSync2(path);
|
|
126007
|
+
} catch {}
|
|
126008
|
+
}
|
|
125942
126009
|
var stdbufAvailable = null;
|
|
125943
126010
|
function hasStdbuf() {
|
|
125944
126011
|
if (stdbufAvailable !== null)
|
|
@@ -125983,6 +126050,7 @@ class PersistentShell {
|
|
|
125983
126050
|
extraEnv;
|
|
125984
126051
|
current = null;
|
|
125985
126052
|
pendingCancel = null;
|
|
126053
|
+
writeChain = Promise.resolve();
|
|
125986
126054
|
constructor(opts) {
|
|
125987
126055
|
this.cwd = opts?.cwd;
|
|
125988
126056
|
this.extraEnv = opts?.env;
|
|
@@ -126019,9 +126087,13 @@ class PersistentShell {
|
|
|
126019
126087
|
if (cmd) {
|
|
126020
126088
|
this.current = null;
|
|
126021
126089
|
this.pendingCancel = null;
|
|
126090
|
+
const diskStdout = readTempfileCapped(cmd.outPath);
|
|
126091
|
+
const diskStderr = readTempfileCapped(cmd.errPath);
|
|
126092
|
+
unlinkSafe(cmd.outPath);
|
|
126093
|
+
unlinkSafe(cmd.errPath);
|
|
126022
126094
|
cmd.resolve({
|
|
126023
|
-
stdout: extractFallbackStdout(cmd),
|
|
126024
|
-
stderr: cmd.stderr || "",
|
|
126095
|
+
stdout: diskStdout || extractFallbackStdout(cmd) || "(no output)",
|
|
126096
|
+
stderr: diskStderr || cmd.stderr || "",
|
|
126025
126097
|
exitCode: 1
|
|
126026
126098
|
});
|
|
126027
126099
|
}
|
|
@@ -126080,6 +126152,8 @@ class PersistentShell {
|
|
|
126080
126152
|
}
|
|
126081
126153
|
const effectiveExit = cmd.forcedExitCode != null ? cmd.forcedExitCode : isNaN(naturalExitCode) ? 1 : naturalExitCode;
|
|
126082
126154
|
const effectiveStderr = cmd.forcedStderrSuffix ? (cmd.stderr || "") + cmd.forcedStderrSuffix : cmd.stderr || "";
|
|
126155
|
+
unlinkSafe(cmd.outPath);
|
|
126156
|
+
unlinkSafe(cmd.errPath);
|
|
126083
126157
|
const resolve5 = cmd.resolve;
|
|
126084
126158
|
this.current = null;
|
|
126085
126159
|
this.pendingCancel = null;
|
|
@@ -126110,129 +126184,131 @@ class PersistentShell {
|
|
|
126110
126184
|
return { stdout: "", stderr: "Shell has been disposed", exitCode: 1 };
|
|
126111
126185
|
}
|
|
126112
126186
|
if (abortSignal?.aborted) {
|
|
126113
|
-
return {
|
|
126114
|
-
stdout: "",
|
|
126115
|
-
stderr: "Command aborted",
|
|
126116
|
-
exitCode: 130
|
|
126117
|
-
};
|
|
126187
|
+
return { stdout: "", stderr: "Command aborted", exitCode: 130 };
|
|
126118
126188
|
}
|
|
126119
|
-
this.
|
|
126120
|
-
|
|
126121
|
-
|
|
126122
|
-
|
|
126123
|
-
|
|
126124
|
-
|
|
126125
|
-
|
|
126126
|
-
|
|
126127
|
-
|
|
126128
|
-
|
|
126129
|
-
|
|
126130
|
-
|
|
126131
|
-
|
|
126132
|
-
|
|
126133
|
-
|
|
126134
|
-
|
|
126135
|
-
|
|
126136
|
-
|
|
126137
|
-
|
|
126138
|
-
exitMarkerPrefix
|
|
126139
|
-
|
|
126140
|
-
|
|
126141
|
-
|
|
126142
|
-
|
|
126143
|
-
|
|
126144
|
-
|
|
126145
|
-
|
|
126146
|
-
|
|
126147
|
-
|
|
126148
|
-
|
|
126149
|
-
|
|
126150
|
-
|
|
126151
|
-
|
|
126152
|
-
|
|
126153
|
-
|
|
126154
|
-
|
|
126155
|
-
|
|
126156
|
-
this.pendingCancel = pending.resolve;
|
|
126157
|
-
let abortCleanup;
|
|
126158
|
-
if (abortSignal) {
|
|
126159
|
-
const onAbort = () => {
|
|
126160
|
-
if (resolved)
|
|
126161
|
-
return;
|
|
126162
|
-
pending.forcedExitCode = 130;
|
|
126163
|
-
pending.forcedStderrSuffix = pending.stderr ? `
|
|
126164
|
-
(aborted)` : "(aborted)";
|
|
126165
|
-
killDescendants(proc.pid, "SIGTERM");
|
|
126166
|
-
killEscalationTimer = setTimeout(() => {
|
|
126189
|
+
const release = await this.acquireTurn();
|
|
126190
|
+
try {
|
|
126191
|
+
if (this.disposed) {
|
|
126192
|
+
return { stdout: "", stderr: "Shell has been disposed", exitCode: 1 };
|
|
126193
|
+
}
|
|
126194
|
+
if (abortSignal?.aborted) {
|
|
126195
|
+
return { stdout: "", stderr: "Command aborted", exitCode: 130 };
|
|
126196
|
+
}
|
|
126197
|
+
this.ensureAlive();
|
|
126198
|
+
const proc = this.proc;
|
|
126199
|
+
if (!proc || !proc.stdin || !proc.stdout || !proc.stderr) {
|
|
126200
|
+
return { stdout: "", stderr: "Failed to spawn shell", exitCode: 1 };
|
|
126201
|
+
}
|
|
126202
|
+
return await new Promise((resolve5) => {
|
|
126203
|
+
let resolved = false;
|
|
126204
|
+
let timeoutTimer;
|
|
126205
|
+
let abortCleanup;
|
|
126206
|
+
const nonceHex = randomBytes(8).toString("hex");
|
|
126207
|
+
const marker = `__APEX_${nonceHex}__`;
|
|
126208
|
+
const exitMarkerPrefix = `${marker}_EXIT_`;
|
|
126209
|
+
const cutoverMarker = `${marker}_CUTOVER`;
|
|
126210
|
+
const outPath = join18(APEX_TMP_ROOT, `${nonceHex}.out`);
|
|
126211
|
+
const errPath = join18(APEX_TMP_ROOT, `${nonceHex}.err`);
|
|
126212
|
+
const pending = {
|
|
126213
|
+
streamedStdout: "",
|
|
126214
|
+
authoritativeStdout: "",
|
|
126215
|
+
cutoverSeen: false,
|
|
126216
|
+
cutoverMarker,
|
|
126217
|
+
stderr: "",
|
|
126218
|
+
stdoutTruncated: false,
|
|
126219
|
+
exitMarkerPrefix,
|
|
126220
|
+
onData,
|
|
126221
|
+
forcedExitCode: null,
|
|
126222
|
+
forcedStderrSuffix: null,
|
|
126223
|
+
outPath,
|
|
126224
|
+
errPath,
|
|
126225
|
+
resolve: (result) => {
|
|
126167
126226
|
if (resolved)
|
|
126168
126227
|
return;
|
|
126169
|
-
|
|
126170
|
-
|
|
126171
|
-
|
|
126172
|
-
|
|
126173
|
-
pending.
|
|
126174
|
-
|
|
126175
|
-
|
|
126176
|
-
|
|
126177
|
-
|
|
126178
|
-
|
|
126179
|
-
}, 500);
|
|
126228
|
+
resolved = true;
|
|
126229
|
+
if (timeoutTimer)
|
|
126230
|
+
clearTimeout(timeoutTimer);
|
|
126231
|
+
if (pending.killEscalationTimer)
|
|
126232
|
+
clearTimeout(pending.killEscalationTimer);
|
|
126233
|
+
pending._activeSalvageId = undefined;
|
|
126234
|
+
if (abortCleanup)
|
|
126235
|
+
abortCleanup();
|
|
126236
|
+
resolve5(result);
|
|
126237
|
+
}
|
|
126180
126238
|
};
|
|
126181
|
-
|
|
126182
|
-
|
|
126183
|
-
|
|
126184
|
-
|
|
126185
|
-
timeoutTimer = setTimeout(() => {
|
|
126186
|
-
if (resolved)
|
|
126187
|
-
return;
|
|
126188
|
-
pending.forcedExitCode = 124;
|
|
126189
|
-
killDescendants(proc.pid, "SIGTERM");
|
|
126190
|
-
killEscalationTimer = setTimeout(() => {
|
|
126239
|
+
this.current = pending;
|
|
126240
|
+
this.pendingCancel = pending.resolve;
|
|
126241
|
+
if (abortSignal) {
|
|
126242
|
+
const onAbort = () => {
|
|
126191
126243
|
if (resolved)
|
|
126192
126244
|
return;
|
|
126193
|
-
|
|
126194
|
-
|
|
126195
|
-
|
|
126196
|
-
|
|
126197
|
-
|
|
126198
|
-
|
|
126199
|
-
|
|
126200
|
-
|
|
126201
|
-
|
|
126202
|
-
|
|
126203
|
-
|
|
126204
|
-
|
|
126205
|
-
|
|
126206
|
-
|
|
126207
|
-
|
|
126208
|
-
|
|
126209
|
-
|
|
126210
|
-
|
|
126211
|
-
`
|
|
126212
|
-
|
|
126245
|
+
pending.forcedExitCode = 130;
|
|
126246
|
+
pending.forcedStderrSuffix = pending.stderr ? `
|
|
126247
|
+
(aborted)` : "(aborted)";
|
|
126248
|
+
pending.killEscalationTimer = scheduleSalvageKill(proc.pid, pending, 130);
|
|
126249
|
+
};
|
|
126250
|
+
abortSignal.addEventListener("abort", onAbort, { once: true });
|
|
126251
|
+
abortCleanup = () => abortSignal.removeEventListener("abort", onAbort);
|
|
126252
|
+
}
|
|
126253
|
+
if (timeoutSeconds != null && timeoutSeconds > 0) {
|
|
126254
|
+
timeoutTimer = setTimeout(() => {
|
|
126255
|
+
if (resolved)
|
|
126256
|
+
return;
|
|
126257
|
+
pending.forcedExitCode = 124;
|
|
126258
|
+
pending.killEscalationTimer = scheduleSalvageKill(proc.pid, pending, 124);
|
|
126259
|
+
}, timeoutSeconds * 1000);
|
|
126260
|
+
}
|
|
126261
|
+
const tailCmd = hasStdbuf() ? `stdbuf -oL tail -n +1 -f -s 0.05 "$__APEX_OUT"` : `tail -n +1 -f -s 0.05 "$__APEX_OUT"`;
|
|
126262
|
+
const shOutPath = `'${outPath.replace(/'/g, `'\\''`)}'`;
|
|
126263
|
+
const shErrPath = `'${errPath.replace(/'/g, `'\\''`)}'`;
|
|
126264
|
+
const wrapped = [
|
|
126265
|
+
`__APEX_OUT=${shOutPath}`,
|
|
126266
|
+
`__APEX_ERR=${shErrPath}`,
|
|
126267
|
+
`: > "$__APEX_OUT"`,
|
|
126268
|
+
`: > "$__APEX_ERR"`,
|
|
126269
|
+
`${tailCmd} 2>/dev/null &`,
|
|
126270
|
+
`__APEX_TAIL=$!`,
|
|
126271
|
+
`{ ${command}
|
|
126213
126272
|
} </dev/null >"$__APEX_OUT" 2>"$__APEX_ERR"`,
|
|
126214
|
-
|
|
126215
|
-
|
|
126216
|
-
|
|
126217
|
-
|
|
126218
|
-
|
|
126219
|
-
|
|
126220
|
-
|
|
126221
|
-
|
|
126222
|
-
|
|
126223
|
-
|
|
126224
|
-
].join(`
|
|
126273
|
+
`__APEX_EC=$?`,
|
|
126274
|
+
`sleep 0.1`,
|
|
126275
|
+
`kill "$__APEX_TAIL" 2>/dev/null`,
|
|
126276
|
+
`wait "$__APEX_TAIL" 2>/dev/null`,
|
|
126277
|
+
`printf '%s\\n' "${cutoverMarker}"`,
|
|
126278
|
+
`cat "$__APEX_OUT"`,
|
|
126279
|
+
`cat "$__APEX_ERR" >&2`,
|
|
126280
|
+
`echo "${exitMarkerPrefix}$__APEX_EC"`,
|
|
126281
|
+
``
|
|
126282
|
+
].join(`
|
|
126225
126283
|
`);
|
|
126226
|
-
|
|
126227
|
-
|
|
126228
|
-
|
|
126229
|
-
|
|
126230
|
-
|
|
126231
|
-
|
|
126232
|
-
|
|
126233
|
-
|
|
126234
|
-
|
|
126284
|
+
try {
|
|
126285
|
+
proc.stdin.write(wrapped);
|
|
126286
|
+
} catch {
|
|
126287
|
+
pending.resolve({
|
|
126288
|
+
stdout: "",
|
|
126289
|
+
stderr: "Failed to write to shell stdin",
|
|
126290
|
+
exitCode: 1
|
|
126291
|
+
});
|
|
126292
|
+
}
|
|
126293
|
+
});
|
|
126294
|
+
} catch (e) {
|
|
126295
|
+
return {
|
|
126296
|
+
stdout: "",
|
|
126297
|
+
stderr: e instanceof Error ? e.message : String(e),
|
|
126298
|
+
exitCode: 1
|
|
126299
|
+
};
|
|
126300
|
+
} finally {
|
|
126301
|
+
release();
|
|
126302
|
+
}
|
|
126303
|
+
}
|
|
126304
|
+
async acquireTurn() {
|
|
126305
|
+
const myTurn = this.writeChain;
|
|
126306
|
+
let release;
|
|
126307
|
+
this.writeChain = new Promise((res) => {
|
|
126308
|
+
release = res;
|
|
126235
126309
|
});
|
|
126310
|
+
await myTurn;
|
|
126311
|
+
return release;
|
|
126236
126312
|
}
|
|
126237
126313
|
cancelCurrentCommand() {
|
|
126238
126314
|
const cmd = this.current;
|
|
@@ -126242,19 +126318,10 @@ class PersistentShell {
|
|
|
126242
126318
|
cmd.forcedStderrSuffix = cmd.stderr ? `
|
|
126243
126319
|
(cancelled by user)` : "(cancelled by user)";
|
|
126244
126320
|
if (this.proc.pid && process.platform !== "win32") {
|
|
126245
|
-
|
|
126246
|
-
setTimeout(() => {
|
|
126247
|
-
if (this.proc?.pid)
|
|
126248
|
-
killDescendants(this.proc.pid, "SIGKILL");
|
|
126249
|
-
setTimeout(() => {
|
|
126250
|
-
cmd.resolve({
|
|
126251
|
-
stdout: extractFallbackStdout(cmd),
|
|
126252
|
-
stderr: (cmd.stderr || "") + (cmd.forcedStderrSuffix ?? ""),
|
|
126253
|
-
exitCode: 130
|
|
126254
|
-
});
|
|
126255
|
-
}, 2000);
|
|
126256
|
-
}, 500);
|
|
126321
|
+
cmd.killEscalationTimer = scheduleSalvageKill(this.proc.pid, cmd, 130);
|
|
126257
126322
|
} else {
|
|
126323
|
+
unlinkSafe(cmd.outPath);
|
|
126324
|
+
unlinkSafe(cmd.errPath);
|
|
126258
126325
|
cmd.resolve({
|
|
126259
126326
|
stdout: extractFallbackStdout(cmd),
|
|
126260
126327
|
stderr: (cmd.stderr || "") + (cmd.forcedStderrSuffix ?? ""),
|
|
@@ -126267,6 +126334,13 @@ class PersistentShell {
|
|
|
126267
126334
|
if (this.disposed)
|
|
126268
126335
|
return;
|
|
126269
126336
|
this.disposed = true;
|
|
126337
|
+
if (this.current?.killEscalationTimer) {
|
|
126338
|
+
clearTimeout(this.current.killEscalationTimer);
|
|
126339
|
+
}
|
|
126340
|
+
if (this.current) {
|
|
126341
|
+
unlinkSafe(this.current.outPath);
|
|
126342
|
+
unlinkSafe(this.current.errPath);
|
|
126343
|
+
}
|
|
126270
126344
|
if (this.proc) {
|
|
126271
126345
|
try {
|
|
126272
126346
|
this.proc.stdin?.write(`exit
|
|
@@ -126299,10 +126373,10 @@ class PersistentShell {
|
|
|
126299
126373
|
this.proc = null;
|
|
126300
126374
|
}
|
|
126301
126375
|
}
|
|
126302
|
-
function
|
|
126376
|
+
function enumerateDescendants(rootPid) {
|
|
126303
126377
|
if (!rootPid || process.platform === "win32")
|
|
126304
|
-
return;
|
|
126305
|
-
const
|
|
126378
|
+
return [];
|
|
126379
|
+
const descendants = [];
|
|
126306
126380
|
const queue = [rootPid];
|
|
126307
126381
|
while (queue.length > 0) {
|
|
126308
126382
|
const pid = queue.shift();
|
|
@@ -126313,25 +126387,54 @@ function killDescendants(rootPid, signal) {
|
|
|
126313
126387
|
`)) {
|
|
126314
126388
|
const child = parseInt(line, 10);
|
|
126315
126389
|
if (Number.isFinite(child) && child > 0) {
|
|
126316
|
-
|
|
126390
|
+
descendants.push(child);
|
|
126317
126391
|
queue.push(child);
|
|
126318
126392
|
}
|
|
126319
126393
|
}
|
|
126320
126394
|
}
|
|
126321
126395
|
} catch {}
|
|
126322
126396
|
}
|
|
126323
|
-
|
|
126397
|
+
return descendants;
|
|
126398
|
+
}
|
|
126399
|
+
function signalPids(pids, signal) {
|
|
126400
|
+
if (process.platform === "win32")
|
|
126401
|
+
return;
|
|
126402
|
+
for (let i = pids.length - 1;i >= 0; i--) {
|
|
126324
126403
|
try {
|
|
126325
|
-
process.kill(
|
|
126404
|
+
process.kill(pids[i], signal);
|
|
126326
126405
|
} catch {}
|
|
126327
126406
|
}
|
|
126328
126407
|
}
|
|
126408
|
+
var SALVAGE_GRACE_MS = 200;
|
|
126409
|
+
function scheduleSalvageKill(rootPid, pending, exitCode) {
|
|
126410
|
+
if (pending.killEscalationTimer) {
|
|
126411
|
+
clearTimeout(pending.killEscalationTimer);
|
|
126412
|
+
}
|
|
126413
|
+
const pids = enumerateDescendants(rootPid);
|
|
126414
|
+
signalPids(pids, "SIGTERM");
|
|
126415
|
+
const salvageId = {};
|
|
126416
|
+
pending._activeSalvageId = salvageId;
|
|
126417
|
+
return setTimeout(() => {
|
|
126418
|
+
if (pending._activeSalvageId !== salvageId)
|
|
126419
|
+
return;
|
|
126420
|
+
const diskStdout = readTempfileCapped(pending.outPath);
|
|
126421
|
+
const diskStderr = readTempfileCapped(pending.errPath);
|
|
126422
|
+
unlinkSafe(pending.outPath);
|
|
126423
|
+
unlinkSafe(pending.errPath);
|
|
126424
|
+
signalPids(pids, "SIGKILL");
|
|
126425
|
+
pending.resolve({
|
|
126426
|
+
stdout: diskStdout || extractFallbackStdout(pending) || "(no output)",
|
|
126427
|
+
stderr: (diskStderr || pending.stderr || "") + (pending.forcedStderrSuffix ?? ""),
|
|
126428
|
+
exitCode
|
|
126429
|
+
});
|
|
126430
|
+
}, SALVAGE_GRACE_MS);
|
|
126431
|
+
}
|
|
126329
126432
|
|
|
126330
126433
|
// src/core/agents/offSecAgent/prompt.ts
|
|
126331
|
-
import { existsSync as existsSync12, readdirSync as readdirSync3, statSync } from "fs";
|
|
126332
|
-
import { join as
|
|
126434
|
+
import { existsSync as existsSync12, readdirSync as readdirSync3, statSync as statSync2 } from "fs";
|
|
126435
|
+
import { join as join19 } from "path";
|
|
126333
126436
|
function buildProvidedFilesSection(sessionRootPath) {
|
|
126334
|
-
const providedDir =
|
|
126437
|
+
const providedDir = join19(sessionRootPath, "provided_files");
|
|
126335
126438
|
if (!existsSync12(providedDir))
|
|
126336
126439
|
return "";
|
|
126337
126440
|
let entries;
|
|
@@ -126342,7 +126445,7 @@ function buildProvidedFilesSection(sessionRootPath) {
|
|
|
126342
126445
|
}
|
|
126343
126446
|
const fileEntries = entries.filter((name) => name !== "README.md").map((name) => {
|
|
126344
126447
|
try {
|
|
126345
|
-
const stat2 =
|
|
126448
|
+
const stat2 = statSync2(join19(providedDir, name));
|
|
126346
126449
|
if (!stat2.isFile())
|
|
126347
126450
|
return null;
|
|
126348
126451
|
return { name, size: stat2.size };
|
|
@@ -126763,7 +126866,7 @@ class ApprovalTimeoutError extends ApprovalDeniedError {
|
|
|
126763
126866
|
init_zod();
|
|
126764
126867
|
import path from "path";
|
|
126765
126868
|
import os from "os";
|
|
126766
|
-
import { existsSync as existsSync13, readFileSync as
|
|
126869
|
+
import { existsSync as existsSync13, readFileSync as readFileSync5 } from "fs";
|
|
126767
126870
|
init_toolset();
|
|
126768
126871
|
var DEFAULT_OUTCOME_GUIDANCE = "Prove the exploit can be run but do not exfiltrate data or cause any harm to the system. " + "Create proof-of-concept exploits that demonstrate the vulnerability exists without causing damage.";
|
|
126769
126872
|
var EXFIL_OUTCOME_GUIDANCE = "Exfiltrate data to extract the flag value. " + "Create proof-of-concept exploits that successfully extract the flag from the target system.";
|
|
@@ -127115,7 +127218,7 @@ async function loadOperatorState(sessionId) {
|
|
|
127115
127218
|
const statePath = path.join(session.rootPath, "messages.json");
|
|
127116
127219
|
if (!existsSync13(statePath))
|
|
127117
127220
|
return null;
|
|
127118
|
-
const data =
|
|
127221
|
+
const data = readFileSync5(statePath, "utf-8");
|
|
127119
127222
|
const parsed = JSON.parse(data);
|
|
127120
127223
|
if (Array.isArray(parsed)) {
|
|
127121
127224
|
return {
|
|
@@ -127265,8 +127368,8 @@ var sessions = {
|
|
|
127265
127368
|
};
|
|
127266
127369
|
|
|
127267
127370
|
// src/core/agents/offSecAgent/offensiveSecurityAgent.ts
|
|
127268
|
-
import { join as
|
|
127269
|
-
import { mkdirSync as
|
|
127371
|
+
import { join as join20 } from "path";
|
|
127372
|
+
import { mkdirSync as mkdirSync13, existsSync as existsSync14 } from "fs";
|
|
127270
127373
|
import { writeFile as writeFile4 } from "fs/promises";
|
|
127271
127374
|
class OffensiveSecurityAgent {
|
|
127272
127375
|
streamResult;
|
|
@@ -127311,15 +127414,15 @@ class OffensiveSecurityAgent {
|
|
|
127311
127414
|
input.commandCancelHandle.cancel = () => shell.cancelCurrentCommand();
|
|
127312
127415
|
}
|
|
127313
127416
|
}
|
|
127314
|
-
const messagesDir = input.messagesDir ?? (input.subagentId ?
|
|
127315
|
-
const tracePath = input.subagentId ?
|
|
127417
|
+
const messagesDir = input.messagesDir ?? (input.subagentId ? join20(input.session.rootPath, "subagents", input.subagentId) : input.session.rootPath);
|
|
127418
|
+
const tracePath = input.subagentId ? join20(input.session.rootPath, "subagents", `${input.subagentId}.trace.jsonl`) : join20(messagesDir, "trace.jsonl");
|
|
127316
127419
|
const traceWriter = new StepTraceWriter({
|
|
127317
127420
|
tracePath,
|
|
127318
127421
|
agentId: input.subagentId ?? null,
|
|
127319
127422
|
eventBus: this.eventBus
|
|
127320
127423
|
});
|
|
127321
127424
|
const taskDriven = input.session.config?.taskDriven ?? false;
|
|
127322
|
-
const tasksDir = input.tasksDir ?? (taskDriven ? input.subagentId ?
|
|
127425
|
+
const tasksDir = input.tasksDir ?? (taskDriven ? input.subagentId ? join20(input.session.rootPath, "subagents", `${input.subagentId}-tasks`) : join20(input.session.rootPath, "tasks") : undefined);
|
|
127323
127426
|
const credentialManager = input.credentialManager ?? input.session.credentialManager;
|
|
127324
127427
|
const builtinTools = createAllTools({
|
|
127325
127428
|
session: input.session,
|
|
@@ -127390,9 +127493,9 @@ class OffensiveSecurityAgent {
|
|
|
127390
127493
|
activeTools = activeTools.filter((t) => planSet.has(t));
|
|
127391
127494
|
}
|
|
127392
127495
|
if (!existsSync14(messagesDir)) {
|
|
127393
|
-
|
|
127496
|
+
mkdirSync13(messagesDir, { recursive: true });
|
|
127394
127497
|
}
|
|
127395
|
-
const messagesPath =
|
|
127498
|
+
const messagesPath = join20(messagesDir, "messages.json");
|
|
127396
127499
|
const initialMessagesRef = {
|
|
127397
127500
|
current: input.messages ? [...input.messages] : [
|
|
127398
127501
|
{
|
|
@@ -14,31 +14,31 @@ import {
|
|
|
14
14
|
updateManifestEntryStatus,
|
|
15
15
|
writeAgentManifest,
|
|
16
16
|
writeExecutionMetrics
|
|
17
|
-
} from "./cli-
|
|
17
|
+
} from "./cli-hcs4hne1.js";
|
|
18
18
|
import {
|
|
19
19
|
TargetedPentestAgent,
|
|
20
20
|
buildPentestSystemPrompt
|
|
21
|
-
} from "./cli-
|
|
21
|
+
} from "./cli-t9zcagc4.js";
|
|
22
22
|
import {
|
|
23
23
|
EndpointSchema
|
|
24
24
|
} from "./cli-0fy9j5dw.js";
|
|
25
25
|
import {
|
|
26
26
|
BlackboxAttackSurfaceAgent
|
|
27
|
-
} from "./cli-
|
|
27
|
+
} from "./cli-mhx0ab9e.js";
|
|
28
28
|
import {
|
|
29
29
|
createThreatModelPrompt
|
|
30
30
|
} from "./cli-fw5r7pfj.js";
|
|
31
31
|
import {
|
|
32
32
|
CodeAgent
|
|
33
|
-
} from "./cli-
|
|
33
|
+
} from "./cli-m85a0s8v.js";
|
|
34
34
|
import {
|
|
35
35
|
FindingsRegistry,
|
|
36
36
|
OffensiveSecurityAgent,
|
|
37
37
|
PLAN_MODE_TOOL_NAMES
|
|
38
|
-
} from "./cli-
|
|
38
|
+
} from "./cli-j2rk8d21.js";
|
|
39
39
|
import {
|
|
40
40
|
hasToolCall
|
|
41
|
-
} from "./cli-
|
|
41
|
+
} from "./cli-wncegd0f.js";
|
|
42
42
|
import {
|
|
43
43
|
exports_external1 as exports_external,
|
|
44
44
|
init_zod
|