bugxhunter 0.9.4 → 0.9.6
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/.env.example +26 -1
- package/README.md +1 -0
- package/docker-compose.yml +30 -11
- package/package.json +1 -1
- package/server/dist/opencode.js +11 -1
- package/server/dist/providers.js +2 -2
- package/server/dist/recon-driver.js +190 -0
- package/server/dist/recon.js +538 -0
- package/web/dist/assets/{index-D_KMKSAo.js → index-BSYyJO9q.js} +1 -1
- package/web/dist/index.html +1 -1
|
@@ -0,0 +1,538 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Supervised recon / autopwn — the thin slice.
|
|
3
|
+
* -----------------------------------------------------------------------------
|
|
4
|
+
* Adds ARTEX's one genuine edge — an autonomous recon -> hypothesise -> test ->
|
|
5
|
+
* confirm loop — to BugXHunter, without importing ARTEX's failure modes
|
|
6
|
+
* (runaway frontier cost, rate-limit thrash, config-artifact-as-finding).
|
|
7
|
+
*
|
|
8
|
+
* Routing follows a roles x profiles x harness design (the general pattern from
|
|
9
|
+
* the public aider / Claude Code / Roo multi-model research, reimplemented here
|
|
10
|
+
* from scratch for pentest roles). `routeModel` escalates on evidence and sheds
|
|
11
|
+
* a rate-limited model to a healthy neighbour. `EnvFidelity` tags every finding
|
|
12
|
+
* with the environment it was seen in.
|
|
13
|
+
*
|
|
14
|
+
* SECURITY — the approval gate. `classifyCommand` is the security boundary. Two
|
|
15
|
+
* Mythos reviews showed that trying to CLASSIFY arbitrary shell is fail-open:
|
|
16
|
+
* the shell re-parses the string (chaining, substitution, redirection, globbing,
|
|
17
|
+
* $VAR expansion), so predicting what it will run is a losing game. So the gate
|
|
18
|
+
* is now DEFAULT-ASK with a tiny, positively-validated allowlist: a command is
|
|
19
|
+
* auto-allowed only if it contains NO shell metacharacters at all (making it
|
|
20
|
+
* shell-neutral — argv-execution and shell-execution are identical), and every
|
|
21
|
+
* stage is a known binary whose args pass a POSITIVE allowlist. Fetchers are
|
|
22
|
+
* curl GET/HEAD to EXACTLY the in-scope origin (WHATWG host+port, no userinfo,
|
|
23
|
+
* no redirects). Everything else asks and the human reads the real command.
|
|
24
|
+
*/
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
const ROLES = ["executor", "triage", "verify", "escalate"];
|
|
27
|
+
/** Built-in profiles, cheap -> capable (authored cheapest-role-first so shedding
|
|
28
|
+
* and budget fallback pick the cheapest). `scx/*` is open-weight, `anthropic/*`
|
|
29
|
+
* is Claude. `recon-open` works with no Anthropic key. */
|
|
30
|
+
export const BUILTIN_PROFILES = {
|
|
31
|
+
"recon-open": {
|
|
32
|
+
models: { executor: "scx/GLM-5.3", triage: "scx/GLM-5.3-Flash", verify: "scx/GLM-5.3", escalate: "scx/GLM-5.3" },
|
|
33
|
+
harness: {
|
|
34
|
+
executor: { tools: "core", maxRounds: 80, budgetTokens: 3_000_000 },
|
|
35
|
+
triage: { tools: "core" }, verify: { tools: "core" }, escalate: { tools: "core" },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
"recon-balanced": {
|
|
39
|
+
models: { executor: "scx/GLM-5.3", triage: "anthropic/claude-haiku-5-5", verify: "anthropic/claude-sonnet-5-5", escalate: "anthropic/claude-mythos-5-2" },
|
|
40
|
+
harness: {
|
|
41
|
+
executor: { tools: "core", maxRounds: 60, budgetTokens: 2_000_000, effort: "medium" },
|
|
42
|
+
triage: { tools: "core" }, verify: { tools: "core", effort: "high" }, escalate: { tools: "core", effort: "high" },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
"recon-quality": {
|
|
46
|
+
models: { executor: "anthropic/claude-haiku-5-5", triage: "anthropic/claude-haiku-5-5", verify: "anthropic/claude-sonnet-5-5", escalate: "anthropic/claude-mythos-5-2" },
|
|
47
|
+
harness: {
|
|
48
|
+
executor: { tools: "core", maxRounds: 50, budgetTokens: 2_000_000, effort: "high" },
|
|
49
|
+
triage: { tools: "core" }, verify: { tools: "core", effort: "high" }, escalate: { tools: "core", effort: "high" },
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
export const DEFAULT_PROFILE = "recon-balanced";
|
|
54
|
+
export function parseReconHarness(raw) {
|
|
55
|
+
if (!raw || typeof raw !== "object")
|
|
56
|
+
return undefined;
|
|
57
|
+
const r = raw;
|
|
58
|
+
const h = {};
|
|
59
|
+
if (typeof r.budgetTokens === "number" && Number.isInteger(r.budgetTokens) && r.budgetTokens >= 1)
|
|
60
|
+
h.budgetTokens = r.budgetTokens;
|
|
61
|
+
if (typeof r.maxRounds === "number" && Number.isInteger(r.maxRounds) && r.maxRounds >= 1)
|
|
62
|
+
h.maxRounds = r.maxRounds;
|
|
63
|
+
if (r.tools === "full" || r.tools === "core")
|
|
64
|
+
h.tools = r.tools;
|
|
65
|
+
if (r.effort === "low" || r.effort === "medium" || r.effort === "high")
|
|
66
|
+
h.effort = r.effort;
|
|
67
|
+
return Object.keys(h).length ? h : undefined;
|
|
68
|
+
}
|
|
69
|
+
export function parseProfile(def) {
|
|
70
|
+
if (!def || typeof def !== "object")
|
|
71
|
+
return null;
|
|
72
|
+
const d = def;
|
|
73
|
+
if (!d.models || typeof d.models !== "object")
|
|
74
|
+
return null;
|
|
75
|
+
const m = d.models;
|
|
76
|
+
const models = {};
|
|
77
|
+
for (const role of ROLES) {
|
|
78
|
+
if (typeof m[role] !== "string" || !m[role])
|
|
79
|
+
return null;
|
|
80
|
+
models[role] = m[role];
|
|
81
|
+
}
|
|
82
|
+
const harness = {};
|
|
83
|
+
if (d.harness && typeof d.harness === "object") {
|
|
84
|
+
for (const role of ROLES) {
|
|
85
|
+
const h = parseReconHarness(d.harness[role]);
|
|
86
|
+
if (h)
|
|
87
|
+
harness[role] = h;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return Object.keys(harness).length ? { models, harness } : { models };
|
|
91
|
+
}
|
|
92
|
+
export function loadProfiles() {
|
|
93
|
+
const merged = { ...BUILTIN_PROFILES };
|
|
94
|
+
const file = (process.env.RECON_PROFILES_FILE || "").trim();
|
|
95
|
+
if (!file)
|
|
96
|
+
return merged;
|
|
97
|
+
try {
|
|
98
|
+
const parsed = JSON.parse(readFileSync(file, "utf8"));
|
|
99
|
+
for (const name of Object.keys(parsed)) {
|
|
100
|
+
const p = parseProfile(parsed[name]);
|
|
101
|
+
if (p)
|
|
102
|
+
merged[name] = p;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
catch { /* no file / bad json -> built-ins only */ }
|
|
106
|
+
return merged;
|
|
107
|
+
}
|
|
108
|
+
export function activeProfileName() {
|
|
109
|
+
return (process.env.RECON_PROFILE || "").trim() || DEFAULT_PROFILE;
|
|
110
|
+
}
|
|
111
|
+
export function activeProfile() {
|
|
112
|
+
const profiles = loadProfiles();
|
|
113
|
+
const name = activeProfileName();
|
|
114
|
+
return Object.hasOwn(profiles, name) ? profiles[name] : BUILTIN_PROFILES[DEFAULT_PROFILE];
|
|
115
|
+
}
|
|
116
|
+
export function profileNames() {
|
|
117
|
+
return Object.keys(loadProfiles());
|
|
118
|
+
}
|
|
119
|
+
const ROLE_ENV = {
|
|
120
|
+
executor: "RECON_EXECUTOR_MODEL", triage: "RECON_TRIAGE_MODEL",
|
|
121
|
+
verify: "RECON_VERIFY_MODEL", escalate: "RECON_ESCALATE_MODEL",
|
|
122
|
+
};
|
|
123
|
+
export function modelFor(role) {
|
|
124
|
+
return (process.env[ROLE_ENV[role]] || "").trim() || activeProfile().models[role];
|
|
125
|
+
}
|
|
126
|
+
export function harnessFor(role) {
|
|
127
|
+
return activeProfile().harness?.[role] ?? {};
|
|
128
|
+
}
|
|
129
|
+
const ESCALATE_AFTER_VALUE = (() => {
|
|
130
|
+
const n = Number(process.env.RECON_ESCALATE_AFTER);
|
|
131
|
+
return Number.isInteger(n) && n >= 1 ? n : 2;
|
|
132
|
+
})();
|
|
133
|
+
/** Stuck attempts before the executor earns a stronger model (validated env). */
|
|
134
|
+
export function escalateAfter() { return ESCALATE_AFTER_VALUE; }
|
|
135
|
+
function capped(model, s) {
|
|
136
|
+
const provider = model.split("/")[0];
|
|
137
|
+
return Boolean(s.rateLimited?.[model] || s.rateLimited?.[provider]);
|
|
138
|
+
}
|
|
139
|
+
function tierOrder() {
|
|
140
|
+
return [modelFor("executor"), modelFor("triage"), modelFor("verify"), modelFor("escalate")];
|
|
141
|
+
}
|
|
142
|
+
function cheapestHealthy(s) {
|
|
143
|
+
for (const m of tierOrder())
|
|
144
|
+
if (!capped(m, s))
|
|
145
|
+
return m;
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
function shed(model, s) {
|
|
149
|
+
const order = tierOrder();
|
|
150
|
+
const from = order.indexOf(model);
|
|
151
|
+
const start = from >= 0 ? from : 0;
|
|
152
|
+
for (let t = start - 1; t >= 0; t--)
|
|
153
|
+
if (!capped(order[t], s))
|
|
154
|
+
return order[t];
|
|
155
|
+
for (let t = start + 1; t < order.length; t++)
|
|
156
|
+
if (!capped(order[t], s))
|
|
157
|
+
return order[t];
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
export function allCapped(s) {
|
|
161
|
+
return tierOrder().every((m) => capped(m, s));
|
|
162
|
+
}
|
|
163
|
+
/** Deterministic router: role baseline; escalate on evidence; budget-spent ->
|
|
164
|
+
* cheapest healthy; rate-limited -> healthy neighbour (cheaper first). */
|
|
165
|
+
export function routeModel(role, s = {}) {
|
|
166
|
+
let model = modelFor(role);
|
|
167
|
+
const stuck = (s.attempts ?? 0) >= ESCALATE_AFTER_VALUE;
|
|
168
|
+
const grave = s.severityHint === "high" || s.severityHint === "critical";
|
|
169
|
+
if (role === "executor" && (stuck || grave))
|
|
170
|
+
model = modelFor("escalate");
|
|
171
|
+
if (s.budgetRemaining !== undefined && s.budgetRemaining <= 0)
|
|
172
|
+
return cheapestHealthy(s) ?? modelFor("executor");
|
|
173
|
+
if (capped(model, s))
|
|
174
|
+
return shed(model, s) ?? model;
|
|
175
|
+
return model;
|
|
176
|
+
}
|
|
177
|
+
/** Pure read filters: safe to run on piped stdin with pattern/field operands. */
|
|
178
|
+
const FILTERS = new Set(["grep", "egrep", "fgrep", "rg", "head", "tail", "cut", "sort", "uniq", "jq", "wc", "column", "tr"]);
|
|
179
|
+
/** nmap flags we are confident do not exploit or write. */
|
|
180
|
+
const NMAP_SAFE = new Set(["-sv", "-st", "-pn", "-n", "-v", "-vv", "--open", "-6"]);
|
|
181
|
+
/** curl flags that take no value and neither write, reroute, nor change method. */
|
|
182
|
+
const CURL_SAFE_NOVAL = new Set([
|
|
183
|
+
"-s", "-S", "-i", "-I", "-k", "-f", "-g", "-q", "-#", "-v", "-6", "-4",
|
|
184
|
+
"--silent", "--show-error", "--include", "--head", "--insecure", "--fail", "--globoff",
|
|
185
|
+
"--compressed", "--http1.1", "--http1.0", "--http2", "--no-progress-meter", "--verbose", "--ipv4", "--ipv6",
|
|
186
|
+
]);
|
|
187
|
+
/** curl flags that take one value, where the value can't reroute or read a file. */
|
|
188
|
+
const CURL_SAFE_VAL = new Set([
|
|
189
|
+
"-H", "--header", "-A", "--user-agent", "-e", "--referer", "-m", "--max-time", "--connect-timeout",
|
|
190
|
+
"-b", "--cookie", "--retry", "--retry-delay",
|
|
191
|
+
]);
|
|
192
|
+
/** single-letter curl flags inside those value-taking long/short names, for clusters. */
|
|
193
|
+
const CURL_SAFE_NOVAL_LETTERS = new Set([..."sSiIkfgq#v64"]);
|
|
194
|
+
/**
|
|
195
|
+
* Risk tier for one shell command. DEFAULT-ASK: a command is auto-allowed only
|
|
196
|
+
* if it is shell-neutral (no metacharacters) AND every stage positively validates.
|
|
197
|
+
*/
|
|
198
|
+
export function classifyCommand(command, ctx = {}) {
|
|
199
|
+
if (!command)
|
|
200
|
+
return "ask";
|
|
201
|
+
// Shell metacharacters make a string's effect shell-dependent and unpredictable.
|
|
202
|
+
// Reject them all: the allowed subset then runs identically via argv or a shell.
|
|
203
|
+
// (`|` is handled by splitting into stages; `||` leaves an empty stage -> ask.)
|
|
204
|
+
if (/[\r\n\\$`;&<>(){}*?!~]/.test(command))
|
|
205
|
+
return "ask";
|
|
206
|
+
if (command.includes("||"))
|
|
207
|
+
return "ask";
|
|
208
|
+
const stages = command.split("|").map((s) => s.trim()).filter(Boolean);
|
|
209
|
+
if (!stages.length)
|
|
210
|
+
return "ask";
|
|
211
|
+
for (let i = 0; i < stages.length; i++) {
|
|
212
|
+
const argv = tokenize(stages[i]);
|
|
213
|
+
if (!argv || !argv.length)
|
|
214
|
+
return "ask";
|
|
215
|
+
if (stageAllow(argv, i === 0, ctx) === "ask")
|
|
216
|
+
return "ask";
|
|
217
|
+
}
|
|
218
|
+
return "allow";
|
|
219
|
+
}
|
|
220
|
+
/** Split a stage into argv, honouring single/double quotes. null = unbalanced (ask). */
|
|
221
|
+
function tokenize(s) {
|
|
222
|
+
const out = [];
|
|
223
|
+
let cur = "", q = null, has = false;
|
|
224
|
+
for (const c of s) {
|
|
225
|
+
if (q) {
|
|
226
|
+
if (c === q)
|
|
227
|
+
q = null;
|
|
228
|
+
else
|
|
229
|
+
cur += c;
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
if (c === '"' || c === "'") {
|
|
233
|
+
q = c;
|
|
234
|
+
has = true;
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (/\s/.test(c)) {
|
|
238
|
+
if (cur || has) {
|
|
239
|
+
out.push(cur);
|
|
240
|
+
cur = "";
|
|
241
|
+
has = false;
|
|
242
|
+
}
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
cur += c;
|
|
246
|
+
has = true;
|
|
247
|
+
}
|
|
248
|
+
if (q)
|
|
249
|
+
return null;
|
|
250
|
+
if (cur || has)
|
|
251
|
+
out.push(cur);
|
|
252
|
+
return out;
|
|
253
|
+
}
|
|
254
|
+
function stageAllow(argv, isFirst, ctx) {
|
|
255
|
+
const bin = argv[0].toLowerCase();
|
|
256
|
+
if (bin.includes("/") || bin.includes("="))
|
|
257
|
+
return "ask"; // path or env-prefix
|
|
258
|
+
const args = argv.slice(1);
|
|
259
|
+
if (bin === "curl")
|
|
260
|
+
return isFirst ? curlAllow(args, ctx) : "ask"; // a fetch is a source, never downstream
|
|
261
|
+
if (bin === "nmap")
|
|
262
|
+
return isFirst ? nmapAllow(args, ctx) : "ask";
|
|
263
|
+
// Filters auto-allow ONLY downstream of a source (reading piped stdin), never as
|
|
264
|
+
// a first stage (which would read a file) — so file reads are never auto-allowed.
|
|
265
|
+
if (FILTERS.has(bin))
|
|
266
|
+
return isFirst ? "ask" : filterAllow(bin, args);
|
|
267
|
+
return "ask";
|
|
268
|
+
}
|
|
269
|
+
/** A non-flag operand that looks like a file path. */
|
|
270
|
+
const FILE_OPERAND = /\/|^~|\.(?:html?|json|txt|log|xml|js|ts|csv|conf|env|pem|key|ya?ml|sh|py|ini|cfg|db|sqlite|md)$/i;
|
|
271
|
+
/** curl is safe only as a GET/HEAD to exactly the in-scope origin, via a positive
|
|
272
|
+
* flag allowlist (unknown flag -> ask), no redirects, no file read/write. */
|
|
273
|
+
function curlAllow(args, ctx) {
|
|
274
|
+
if (!ctx.scopeHost)
|
|
275
|
+
return "ask";
|
|
276
|
+
let url = false;
|
|
277
|
+
for (let i = 0; i < args.length; i++) {
|
|
278
|
+
const a = args[i];
|
|
279
|
+
if (a === "-X" || a === "--request") {
|
|
280
|
+
const v = (args[++i] ?? "").toUpperCase();
|
|
281
|
+
if (v !== "GET" && v !== "HEAD")
|
|
282
|
+
return "ask";
|
|
283
|
+
continue;
|
|
284
|
+
}
|
|
285
|
+
if (a.startsWith("--")) {
|
|
286
|
+
const eq = a.indexOf("=");
|
|
287
|
+
const flag = eq >= 0 ? a.slice(0, eq) : a;
|
|
288
|
+
if (CURL_SAFE_NOVAL.has(flag))
|
|
289
|
+
continue;
|
|
290
|
+
if (CURL_SAFE_VAL.has(flag)) {
|
|
291
|
+
const v = eq >= 0 ? a.slice(eq + 1) : args[++i];
|
|
292
|
+
if (v === undefined)
|
|
293
|
+
return "ask";
|
|
294
|
+
if ((flag === "--header" || flag === "--cookie") && v.startsWith("@"))
|
|
295
|
+
return "ask"; // @file read
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
return "ask";
|
|
299
|
+
}
|
|
300
|
+
if (a.startsWith("-") && a.length > 1) {
|
|
301
|
+
if (CURL_SAFE_NOVAL.has(a))
|
|
302
|
+
continue;
|
|
303
|
+
if (CURL_SAFE_VAL.has(a)) {
|
|
304
|
+
const v = args[++i];
|
|
305
|
+
if (v === undefined)
|
|
306
|
+
return "ask";
|
|
307
|
+
if ((a === "-H" || a === "-b") && v.startsWith("@"))
|
|
308
|
+
return "ask";
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
// a cluster of safe no-value single flags, e.g. -sS, -sI
|
|
312
|
+
if ([...a.slice(1)].every((c) => CURL_SAFE_NOVAL_LETTERS.has(c)))
|
|
313
|
+
continue;
|
|
314
|
+
return "ask";
|
|
315
|
+
}
|
|
316
|
+
if (!okUrl(a, ctx))
|
|
317
|
+
return "ask";
|
|
318
|
+
url = true;
|
|
319
|
+
}
|
|
320
|
+
return url ? "allow" : "ask";
|
|
321
|
+
}
|
|
322
|
+
/** True if `arg` is an http(s) URL for exactly the in-scope origin, no userinfo. */
|
|
323
|
+
function okUrl(arg, ctx) {
|
|
324
|
+
let u;
|
|
325
|
+
try {
|
|
326
|
+
u = new URL(arg);
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return false;
|
|
330
|
+
}
|
|
331
|
+
if (u.protocol !== "http:" && u.protocol !== "https:")
|
|
332
|
+
return false;
|
|
333
|
+
if (u.username || u.password)
|
|
334
|
+
return false; // userinfo would reroute the real connection
|
|
335
|
+
if (u.hostname.toLowerCase() !== ctx.scopeHost)
|
|
336
|
+
return false;
|
|
337
|
+
const port = u.port || (u.protocol === "https:" ? "443" : "80");
|
|
338
|
+
if (ctx.scopePort && port !== ctx.scopePort)
|
|
339
|
+
return false;
|
|
340
|
+
return true;
|
|
341
|
+
}
|
|
342
|
+
/** A read filter, on piped stdin, with no file-path operands (no file reads). */
|
|
343
|
+
function filterAllow(bin, args) {
|
|
344
|
+
if (bin === "sort" && args.some((a) => a === "-o" || a === "--output" || a.startsWith("--output=")))
|
|
345
|
+
return "ask";
|
|
346
|
+
for (const a of args) {
|
|
347
|
+
if (a.startsWith("-"))
|
|
348
|
+
continue;
|
|
349
|
+
if (FILE_OPERAND.test(a))
|
|
350
|
+
return "ask"; // a file operand would read a file instead of stdin
|
|
351
|
+
}
|
|
352
|
+
return "allow";
|
|
353
|
+
}
|
|
354
|
+
/** nmap is safe without NSE / file output / aggressive scripts, against the in-scope host. */
|
|
355
|
+
function nmapAllow(args, ctx) {
|
|
356
|
+
if (!ctx.scopeHost)
|
|
357
|
+
return "ask";
|
|
358
|
+
let target = false;
|
|
359
|
+
for (const a of args) {
|
|
360
|
+
if (a.startsWith("-")) {
|
|
361
|
+
const low = a.toLowerCase();
|
|
362
|
+
if (NMAP_SAFE.has(low))
|
|
363
|
+
continue;
|
|
364
|
+
if (/^-p[\d,\-]+$/i.test(a))
|
|
365
|
+
continue; // -p80,443
|
|
366
|
+
if (/^-t[0-5]$/i.test(a))
|
|
367
|
+
continue; // -T4
|
|
368
|
+
return "ask"; // -sC/-A/--script/-sS/-o*/single-dash-long/etc.
|
|
369
|
+
}
|
|
370
|
+
if (a.toLowerCase() !== ctx.scopeHost)
|
|
371
|
+
return "ask";
|
|
372
|
+
target = true;
|
|
373
|
+
}
|
|
374
|
+
return target ? "allow" : "ask";
|
|
375
|
+
}
|
|
376
|
+
/** The in-scope host (lowercase, portless) from a scope string or URL. */
|
|
377
|
+
export function hostOf(scope) {
|
|
378
|
+
return originOf(scope).host;
|
|
379
|
+
}
|
|
380
|
+
/** The in-scope origin (host + normalized port) from a scope string or URL. */
|
|
381
|
+
export function originOf(scope) {
|
|
382
|
+
try {
|
|
383
|
+
const u = new URL(/^[a-z][a-z0-9+.-]*:\/\//i.test(scope) ? scope : `http://${scope}`);
|
|
384
|
+
return { host: u.hostname.toLowerCase(), port: u.port || (u.protocol === "https:" ? "443" : "80") };
|
|
385
|
+
}
|
|
386
|
+
catch {
|
|
387
|
+
return {};
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
/* ─────────────── the denylist floor (hard-deny shapes) ─────────────── */
|
|
391
|
+
/** Leading tokens that wrap another command; peeled so the real command shows. */
|
|
392
|
+
const WRAPPERS = new Set(["sudo", "doas", "nice", "ionice", "nohup", "setsid", "stdbuf", "command", "builtin", "exec", "eval", "time", "caffeinate", "xargs"]);
|
|
393
|
+
/**
|
|
394
|
+
* Peel wrapper / `env VAR=…` / `sh -c "…"` layers and return every effective
|
|
395
|
+
* command string to scan — so intent hidden inside `sudo env X=1 bash -c "rm -rf /"`
|
|
396
|
+
* is unwrapped before matching. (Structural normalisation, the technique from the
|
|
397
|
+
* public codex / tc-cli safety scanners; reimplemented here.)
|
|
398
|
+
*/
|
|
399
|
+
export function effectiveCommands(cmd, depth = 0) {
|
|
400
|
+
if (depth > 6 || !cmd)
|
|
401
|
+
return [cmd];
|
|
402
|
+
const out = [];
|
|
403
|
+
let words = tokenize(cmd) ?? cmd.trim().split(/\s+/);
|
|
404
|
+
let i = 0;
|
|
405
|
+
while (i < words.length && /^[A-Za-z_]\w*=/.test(words[i]))
|
|
406
|
+
i++; // leading VAR=val
|
|
407
|
+
if (words[i] === "env") {
|
|
408
|
+
i++;
|
|
409
|
+
while (i < words.length && /^[A-Za-z_]\w*=/.test(words[i]))
|
|
410
|
+
i++;
|
|
411
|
+
}
|
|
412
|
+
words = words.slice(i);
|
|
413
|
+
while (words.length > 1 && WRAPPERS.has(words[0])) {
|
|
414
|
+
const w = words[0];
|
|
415
|
+
words = words.slice(1);
|
|
416
|
+
if (w === "timeout" || w === "nice" || w === "ionice" || w === "xargs") {
|
|
417
|
+
while (words.length > 1 && /^[-\d]/.test(words[0]))
|
|
418
|
+
words = words.slice(1);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
out.push(words.join(" "));
|
|
422
|
+
if (/^(?:ba|z|k|da)?sh$/.test(words[0] ?? "")) {
|
|
423
|
+
const m = /\s-[a-z]*c\b\s+(['"])([\s\S]*?)\1/.exec(cmd); // sh -c "<inner>"
|
|
424
|
+
if (m)
|
|
425
|
+
for (const inner of effectiveCommands(m[2], depth + 1))
|
|
426
|
+
out.push(inner);
|
|
427
|
+
}
|
|
428
|
+
return out;
|
|
429
|
+
}
|
|
430
|
+
function isRmRf(c) {
|
|
431
|
+
if (!/(^|[\s;&|])rm(\s|$)/.test(c))
|
|
432
|
+
return false;
|
|
433
|
+
return (/\s-\w*[rR]/.test(c) && /\s-\w*f/.test(c)) || (/--recursive/.test(c) && /--force/.test(c)) || /--no-preserve-root/.test(c);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Hard-deny shapes for a SUPERVISED pentest — returns a reason or null. Re-scoped
|
|
437
|
+
* from a coding agent's denylist: these are things the agent would run on ITS OWN
|
|
438
|
+
* host (wreck the box) or that turn the agent into a victim/zombie (download->shell,
|
|
439
|
+
* reverse shell, secret exfil). They are NOT in-scope attacks on the target (a
|
|
440
|
+
* `curl -X DELETE http://target/x` is the job and is handled by the allow/ask tier),
|
|
441
|
+
* so denying them never blocks legitimate testing.
|
|
442
|
+
*/
|
|
443
|
+
export function commandHazard(command) {
|
|
444
|
+
for (const c of effectiveCommands(command)) {
|
|
445
|
+
// Agent-host catastrophic
|
|
446
|
+
if (isRmRf(c) && /(^|\s)(\/|~|\$HOME|\/\*|\*|~\/\*?)(\s|$)/.test(c))
|
|
447
|
+
return "recursive force-delete of a root/home/unqualified target";
|
|
448
|
+
if (/(^|[\s;&|])mkfs(\.\w+)?\b/.test(c))
|
|
449
|
+
return "filesystem format (mkfs)";
|
|
450
|
+
if (/\bdd\b[^\n]*\bof=\/dev\/(?:sd|nvme|hd|vd|mmcblk|disk|xvd)/.test(c))
|
|
451
|
+
return "dd over a raw block device";
|
|
452
|
+
if (/>\s*\/dev\/(?:sd|nvme|hd|vd|mmcblk|disk|xvd)/.test(c))
|
|
453
|
+
return "redirect over a raw block device";
|
|
454
|
+
if (/:\s*\(\s*\)\s*\{\s*:\s*\|\s*:\s*&\s*\}\s*;\s*:/.test(c))
|
|
455
|
+
return "fork bomb";
|
|
456
|
+
if (/\bchmod\b\s+(?:-\w*R\w*\s+)?0*777\s+\/(?:\s|$)/.test(c))
|
|
457
|
+
return "world-writable chmod of the filesystem root";
|
|
458
|
+
// Agent-compromise: the agent itself turned into a victim/zombie (never a legit test of the target)
|
|
459
|
+
if (/\b(?:curl|wget|fetch)\b[^\n|]*\|\s*(?:sudo\s+)?(?:ba|z|k)?sh\b/.test(c))
|
|
460
|
+
return "piping a download straight into a shell (agent RCE)";
|
|
461
|
+
if (/\bbase64\b\s+(?:-d|--decode)\b[^\n|]*\|\s*(?:ba|z|k)?sh\b/.test(c))
|
|
462
|
+
return "decoding base64 straight into a shell";
|
|
463
|
+
if (/\/dev\/(?:tcp|udp)\//.test(c))
|
|
464
|
+
return "raw socket via /dev/tcp (reverse shell from the agent)";
|
|
465
|
+
if (/\bnc\b[^\n]*\s-\w*e\b/.test(c))
|
|
466
|
+
return "netcat -e (reverse shell from the agent)";
|
|
467
|
+
if (/\b(?:ba|z|k)?sh\b\s+-\w*i\w*\b[^\n]*(?:>&|>|2>&1)/.test(c) && /\/dev\/tcp|\d{1,3}(?:\.\d{1,3}){3}/.test(c))
|
|
468
|
+
return "interactive shell redirected to a socket (reverse shell)";
|
|
469
|
+
}
|
|
470
|
+
return null;
|
|
471
|
+
}
|
|
472
|
+
/* ─────────────── env hygiene ─────────────── */
|
|
473
|
+
/** Operator / provider secrets that must never reach the executor's subprocess env,
|
|
474
|
+
* so a prompt-injected agent (fed adversarial target output) has nothing to exfil. */
|
|
475
|
+
export const SENSITIVE_ENV = [
|
|
476
|
+
"AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY", "AWS_SESSION_TOKEN", "GITHUB_TOKEN", "GH_TOKEN", "NPM_TOKEN",
|
|
477
|
+
"ANTHROPIC_API_KEY", "OPENAI_API_KEY", "SCX_API", "SCX_API_KEY", "OPENROUTER_API_KEY", "NVIDIA_API_KEY",
|
|
478
|
+
"AZURE_CLIENT_SECRET", "GCP_SERVICE_ACCOUNT", "OPEN_RUNNER_SECRET", "GITHUB_CLIENT_SECRET", "TURNSTILE_SECRET_KEY",
|
|
479
|
+
];
|
|
480
|
+
/** A copy of `env` with the operator's secrets stripped — the structural anti-exfil
|
|
481
|
+
* control (the real boundary in Monitor mode, since egress is logged, not blocked).
|
|
482
|
+
* Removes the named keys plus anything matching a secret-shaped suffix. */
|
|
483
|
+
export function scrubEnv(env = process.env) {
|
|
484
|
+
const out = { ...env };
|
|
485
|
+
for (const k of Object.keys(out)) {
|
|
486
|
+
if (SENSITIVE_ENV.includes(k) || /(?:_TOKEN|_SECRET|_API_?KEY|_PASSWORD|_CREDENTIALS?|_PRIVATE_KEY)$/i.test(k))
|
|
487
|
+
delete out[k];
|
|
488
|
+
}
|
|
489
|
+
return out;
|
|
490
|
+
}
|
|
491
|
+
/**
|
|
492
|
+
* Run `fn` with the operator's secrets temporarily removed from `process.env`,
|
|
493
|
+
* then restore it. The OpenCode SDK spawns the agent with a synchronous
|
|
494
|
+
* `{...process.env}` snapshot, so wrapping that spawn in this helper gives the
|
|
495
|
+
* agent (and its shell) a scrubbed env while the runner keeps its own secrets.
|
|
496
|
+
* The scrub window is exactly the synchronous body of `fn` — no async gap.
|
|
497
|
+
*/
|
|
498
|
+
export function withScrubbedEnv(fn) {
|
|
499
|
+
const kept = scrubEnv(process.env);
|
|
500
|
+
const removed = {};
|
|
501
|
+
for (const k of Object.keys(process.env)) {
|
|
502
|
+
const v = process.env[k];
|
|
503
|
+
if (!(k in kept) && v !== undefined) {
|
|
504
|
+
removed[k] = v;
|
|
505
|
+
delete process.env[k];
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
try {
|
|
509
|
+
return fn();
|
|
510
|
+
}
|
|
511
|
+
finally {
|
|
512
|
+
for (const [k, v] of Object.entries(removed))
|
|
513
|
+
process.env[k] = v;
|
|
514
|
+
}
|
|
515
|
+
}
|
|
516
|
+
/* ═══════════════════════ OpenCode subagents ═══════════════════════ */
|
|
517
|
+
/** Read-only tool posture for the reviewer roles — webfetch off too, since they
|
|
518
|
+
* read untrusted target output (don't let them reach back out). */
|
|
519
|
+
const READ_ONLY_TOOLS = { bash: false, edit: false, write: false, task: false, webfetch: false };
|
|
520
|
+
function executorTools() {
|
|
521
|
+
const full = harnessFor("executor").tools === "full";
|
|
522
|
+
return { bash: true, read: true, task: true, edit: full, write: full, webfetch: false };
|
|
523
|
+
}
|
|
524
|
+
function subagent(model, description, prompt, tools) {
|
|
525
|
+
return { model, mode: "subagent", description, prompt, tools };
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* The recon subagents, resolved at import (profile/env at server start);
|
|
529
|
+
* `routeModel` re-resolves live for escalation/shedding. Restart to re-register
|
|
530
|
+
* after a profile change.
|
|
531
|
+
*/
|
|
532
|
+
export const RECON_AGENTS = {
|
|
533
|
+
recon: subagent(modelFor("executor"), "Supervised recon/autopwn executor: enumerate the in-scope target, hypothesise weaknesses, test them with low-impact probes, and hand candidates to recon-verify. Read-only shell; never mutates state without an approved step.", "You are the EXECUTOR in a supervised penetration test of a single, explicitly in-scope target. Work one hypothesis at a time: enumerate -> hypothesise a specific weakness (name the OWASP/API Top 10 or WSTG id) -> test it with the smallest, lowest-impact probe that settles it -> record exactly what you observed. Prefer read-only probes (GET, HEAD, nmap -sV, DNS, reading saved responses). Anything that changes state (POST that writes, PUT, PATCH, DELETE, file writes) is a RED LINE: stop and hand it to the human for approval, with the one request you want to run and why. When you believe you have a finding, call the recon-verify subagent with the evidence — do NOT promote it yourself. Stay strictly inside the declared scope. If you are stuck after a couple of tries, say so plainly rather than widening scope.", executorTools()),
|
|
534
|
+
"recon-triage": subagent(modelFor("triage"), "Fast, cheap triage of tool output: is this response interesting, already seen, or noise? Returns a one-line verdict and the single most promising next direction.", "You triage raw tool output for the executor. In two or three sentences: is there anything security-relevant here, have we effectively seen it already, and what is the single most promising next probe? Do not run tools or speculate beyond the output you were given.", READ_ONLY_TOOLS),
|
|
535
|
+
"recon-verify": subagent(modelFor("verify"), "Adversarially verifies one candidate finding against the declared environment and the standards catalogue, assigns severity, and flags config-dependent findings before they are promoted.", "You VERIFY one candidate finding. Reject it unless there is concrete reproduction evidence (the request/command and the response that proves it). Assign severity with the project's rubric and cite the matching OWASP/API/WSTG id. CRITICAL: compare the finding against the declared environment fidelity — if it depends on a setting that differs from production (an auth flag off, a debug mode on, seed data), mark it config-dependent and say exactly what to re-test against production. Output: {verdict: real|config-dependent|rejected, severity, standard_id, repro, prod_caveat}.", READ_ONLY_TOOLS),
|
|
536
|
+
"recon-escalate": subagent(modelFor("escalate"), "Frontier escalation: called only when the executor is stuck or a High/Critical candidate needs deep adversarial review or multi-step exploit-chain reasoning. Read-only.", "You are the escalation reviewer, called rarely and only for hard cases: a stuck executor, or a High/Critical candidate that must survive adversarial scrutiny before it is reported. Reason carefully about exploitability and chaining, demand evidence, and be willing to downgrade or reject. Do not run tools; reason over what you are given and return a precise recommendation.", READ_ONLY_TOOLS),
|
|
537
|
+
};
|
|
538
|
+
//# sourceMappingURL=recon.js.map
|