@pensar/apex 1.8.0 → 1.8.2-canary.fb75c486
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/README.md +11 -0
- package/build/agent-6dj1qm50.js +221 -0
- package/build/agent-6xr8vpgm.js +28 -0
- package/build/agent-x1htbpe3.js +22 -0
- package/build/apps-t0gmwc7z.js +446 -0
- package/build/{auth-dxjgy41e.js → auth-p4r1m7xq.js} +50 -13
- package/build/authentication-je2b0c3w.js +22 -0
- package/build/blackboxAgent-a4jnt0y5.js +22 -0
- package/build/{blackboxPentest-8ps4yvbk.js → blackboxPentest-b5741n3h.js} +19 -17
- package/build/{cli-y61d9433.js → cli-0tnv1vkp.js} +138 -38
- package/build/{cli-jg7r7y5n.js → cli-4xb21y6g.js} +30 -2
- package/build/{cli-k0tckznm.js → cli-6p7d2k55.js} +39701 -31695
- package/build/cli-87zakjb2.js +17 -0
- package/build/{authentication-e30mfzbe.js → cli-8frjr68r.js} +11 -18
- package/build/cli-8xknm7d9.js +204 -0
- package/build/cli-9egg9azd.js +22 -0
- package/build/cli-9fsre5pt.js +0 -0
- package/build/cli-abbka8n3.js +501 -0
- package/build/{cli-3y0dgy56.js → cli-c8131c4q.js} +2 -2
- package/build/cli-e08r86zk.js +24 -0
- package/build/{cli-0ghkg3w6.js → cli-e6rgwtpb.js} +19950 -18556
- package/build/cli-g5h24ny8.js +197 -0
- package/build/{cli-nr1cjfr9.js → cli-gtcd5c3f.js} +26 -7
- package/build/cli-k0730f59.js +52 -0
- package/build/{cli-tp1tqn3k.js → cli-mswm4k81.js} +1 -1
- package/build/{cli-m788e4f3.js → cli-q8dfq25x.js} +584 -33
- package/build/cli-rhry8mat.js +7213 -0
- package/build/{cli-g8t710ew.js → cli-ryy39d77.js} +253 -250
- package/build/cli-s1nckt4k.js +20 -0
- package/build/{cli-k4hrygff.js → cli-v9ds4jb8.js} +9 -5
- package/build/{cli-dqt80sw3.js → cli-w5990vr6.js} +199 -68
- package/build/{cli-3w2syxpv.js → cli-wfmdch3r.js} +102695 -104816
- package/build/cli.js +351 -280
- package/build/config-3bvtf3j8.js +188 -0
- package/build/{doctor-8tva8j99.js → doctor-2bkpddws.js} +1 -1
- package/build/{fixes-q5bhgxhc.js → fixes-60k3ts71.js} +23 -4
- package/build/{index-pfee23kv.js → index-0gp3x2r8.js} +19306 -18954
- package/build/index-861hkebg.js +12 -0
- package/build/{index-y5xpp21a.js → index-acc00eq4.js} +77 -108
- package/build/index-acdgrqa0.js +36 -0
- package/build/{index-e898mdyh.js → index-cfberehw.js} +4 -2
- package/build/{index-wfeb2gcc.js → index-hxn4rk8f.js} +9 -11
- package/build/{index-dw1xbhfn.js → index-vc29b21w.js} +161 -26
- package/build/index-vwt27stc.js +184 -0
- package/build/{issues-qbmdneej.js → issues-1bynat5q.js} +33 -9
- package/build/{logs-xm5vbymy.js → logs-e78vx2dy.js} +23 -4
- package/build/{main-3d7dfdvs.js → main-3zneyg7p.js} +93 -17
- package/build/{offesecAgent-re6kt2ff.js → offesecAgent-w9m0svwk.js} +14 -11
- package/build/parse-15kqmy2v.js +207 -0
- package/build/pentest-gpvqpvmd.js +31 -0
- package/build/{pentests-e3rj5845.js → pentests-nq7wa8yb.js} +36 -17
- package/build/{targetedPentest-fs0v570s.js → targetedPentest-fjxqn089.js} +15 -12
- package/build/threatModel-9yqx7d7x.js +29 -0
- package/build/{uninstall-qb2xbh2t.js → uninstall-9zbf4cwc.js} +6 -4
- package/build/{utils-jf52rmrb.js → utils-dh1t2r1e.js} +13 -10
- package/package.json +86 -88
- package/build/agent-4d8j2jsw.js +0 -278
- package/build/agent-z2s6h7n2.js +0 -19
- package/build/blackboxAgent-j9pczwym.js +0 -19
- package/build/cli-03z6pswp.js +0 -1423
- package/build/cli-0fy9j5dw.js +0 -61
- package/build/cli-asyas1xb.js +0 -110
- package/build/cli-dj1dgw2n.js +0 -190
- package/build/cli-q7r2sth7.js +0 -103
- package/build/cli-vkwch0bc.js +0 -1207
- package/build/cli-wr7g9qcr.js +0 -645
- package/build/index-bz6f8jry.js +0 -32
- package/build/pentest-mfm4hake.js +0 -29
- package/build/projects-qk22qcbt.js +0 -35
- package/build/threatModel-xfvc6cch.js +0 -67
|
@@ -1,16 +1,133 @@
|
|
|
1
|
+
import {
|
|
2
|
+
init_ai
|
|
3
|
+
} from "./cli-87zakjb2.js";
|
|
1
4
|
import {
|
|
2
5
|
generateObjectResponse
|
|
3
|
-
} from "./cli-
|
|
6
|
+
} from "./cli-6p7d2k55.js";
|
|
4
7
|
import {
|
|
5
8
|
exports_external1 as exports_external,
|
|
6
9
|
init_zod,
|
|
7
10
|
zod_default
|
|
8
|
-
} from "./cli-
|
|
11
|
+
} from "./cli-e6rgwtpb.js";
|
|
9
12
|
import {
|
|
10
13
|
__callDispose,
|
|
11
14
|
__using
|
|
12
15
|
} from "./cli-8rxa073f.js";
|
|
13
16
|
|
|
17
|
+
// src/util/name.ts
|
|
18
|
+
init_zod();
|
|
19
|
+
init_ai();
|
|
20
|
+
var adjectives = [
|
|
21
|
+
"swift",
|
|
22
|
+
"bright",
|
|
23
|
+
"calm",
|
|
24
|
+
"bold",
|
|
25
|
+
"keen",
|
|
26
|
+
"noble",
|
|
27
|
+
"quick",
|
|
28
|
+
"sharp",
|
|
29
|
+
"vivid",
|
|
30
|
+
"warm",
|
|
31
|
+
"agile",
|
|
32
|
+
"brave",
|
|
33
|
+
"clever",
|
|
34
|
+
"daring",
|
|
35
|
+
"eager",
|
|
36
|
+
"fierce",
|
|
37
|
+
"gentle",
|
|
38
|
+
"humble",
|
|
39
|
+
"jolly",
|
|
40
|
+
"lively",
|
|
41
|
+
"merry",
|
|
42
|
+
"nimble",
|
|
43
|
+
"proud",
|
|
44
|
+
"quiet",
|
|
45
|
+
"rapid",
|
|
46
|
+
"serene",
|
|
47
|
+
"sturdy",
|
|
48
|
+
"tender",
|
|
49
|
+
"valiant",
|
|
50
|
+
"witty",
|
|
51
|
+
"zealous"
|
|
52
|
+
];
|
|
53
|
+
var nouns = [
|
|
54
|
+
"falcon",
|
|
55
|
+
"wolf",
|
|
56
|
+
"hawk",
|
|
57
|
+
"bear",
|
|
58
|
+
"lion",
|
|
59
|
+
"tiger",
|
|
60
|
+
"eagle",
|
|
61
|
+
"raven",
|
|
62
|
+
"phoenix",
|
|
63
|
+
"dragon",
|
|
64
|
+
"panther",
|
|
65
|
+
"cobra",
|
|
66
|
+
"viper",
|
|
67
|
+
"shark",
|
|
68
|
+
"orca",
|
|
69
|
+
"mantis",
|
|
70
|
+
"spider",
|
|
71
|
+
"scorpion",
|
|
72
|
+
"hydra",
|
|
73
|
+
"griffin",
|
|
74
|
+
"sphinx",
|
|
75
|
+
"kraken",
|
|
76
|
+
"cipher",
|
|
77
|
+
"nexus",
|
|
78
|
+
"prism",
|
|
79
|
+
"vector",
|
|
80
|
+
"matrix",
|
|
81
|
+
"pulse",
|
|
82
|
+
"surge",
|
|
83
|
+
"flux"
|
|
84
|
+
];
|
|
85
|
+
function generateRandomName() {
|
|
86
|
+
const adj = adjectives[Math.floor(Math.random() * adjectives.length)] ?? "swift";
|
|
87
|
+
const noun = nouns[Math.floor(Math.random() * nouns.length)] ?? "falcon";
|
|
88
|
+
return `${adj}-${noun}`;
|
|
89
|
+
}
|
|
90
|
+
var sessionNameSchema = exports_external.object({
|
|
91
|
+
name: exports_external.string().describe("A short, descriptive session name (2-4 words, lowercase, hyphenated)")
|
|
92
|
+
});
|
|
93
|
+
async function generateSessionName(opts) {
|
|
94
|
+
const { targets, userMessage, model, authConfig, abortSignal } = opts;
|
|
95
|
+
const contextParts = [];
|
|
96
|
+
if (targets.length > 0) {
|
|
97
|
+
contextParts.push(`Target(s): ${targets.join(", ")}`);
|
|
98
|
+
}
|
|
99
|
+
if (userMessage) {
|
|
100
|
+
contextParts.push(`User objective: ${userMessage}`);
|
|
101
|
+
}
|
|
102
|
+
if (contextParts.length === 0)
|
|
103
|
+
return null;
|
|
104
|
+
const prompt = [
|
|
105
|
+
"Generate a short, descriptive name for a penetration testing session.",
|
|
106
|
+
"The name should be 2-4 lowercase words separated by hyphens.",
|
|
107
|
+
"It should capture the key aspect of the target or task — e.g. 'acme-api-pentest', 'login-auth-bypass', 'ecommerce-checkout-test'.",
|
|
108
|
+
"",
|
|
109
|
+
...contextParts
|
|
110
|
+
].join(`
|
|
111
|
+
`);
|
|
112
|
+
try {
|
|
113
|
+
const result = await generateObjectResponse({
|
|
114
|
+
model,
|
|
115
|
+
schema: sessionNameSchema,
|
|
116
|
+
prompt,
|
|
117
|
+
maxTokens: 50,
|
|
118
|
+
temperature: 0.7,
|
|
119
|
+
authConfig,
|
|
120
|
+
abortSignal
|
|
121
|
+
});
|
|
122
|
+
if (!result?.name)
|
|
123
|
+
return null;
|
|
124
|
+
const name = result.name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
125
|
+
return name || null;
|
|
126
|
+
} catch {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
14
131
|
// src/core/credentials/manager.ts
|
|
15
132
|
import { randomBytes } from "crypto";
|
|
16
133
|
function generateCredentialId() {
|
|
@@ -105,6 +222,16 @@ class CredentialManager {
|
|
|
105
222
|
listReferences() {
|
|
106
223
|
return Array.from(this.store.values()).map(toReference);
|
|
107
224
|
}
|
|
225
|
+
listCredentialsWithHeaders() {
|
|
226
|
+
const out = [];
|
|
227
|
+
for (const stored of this.store.values()) {
|
|
228
|
+
const headers = stored.tokens?.customHeaders;
|
|
229
|
+
if (headers && Object.keys(headers).length > 0) {
|
|
230
|
+
out.push({ tokens: { customHeaders: { ...headers } } });
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
108
235
|
remove(credentialId) {
|
|
109
236
|
return this.store.delete(credentialId);
|
|
110
237
|
}
|
|
@@ -166,25 +293,135 @@ ${lines.join(`
|
|
|
166
293
|
</available_credentials>`;
|
|
167
294
|
}
|
|
168
295
|
}
|
|
296
|
+
// src/core/id/id.ts
|
|
297
|
+
init_zod();
|
|
298
|
+
import { randomBytes as randomBytes2 } from "crypto";
|
|
299
|
+
var prefixes = {
|
|
300
|
+
session: "ses",
|
|
301
|
+
message: "msg",
|
|
302
|
+
permission: "per",
|
|
303
|
+
user: "usr",
|
|
304
|
+
part: "prt"
|
|
305
|
+
};
|
|
306
|
+
function schema(prefix) {
|
|
307
|
+
return zod_default.string().startsWith(prefixes[prefix]);
|
|
308
|
+
}
|
|
309
|
+
var LENGTH = 26;
|
|
310
|
+
var lastTimestamp = 0;
|
|
311
|
+
var counter = 0;
|
|
312
|
+
function descending(prefix, given) {
|
|
313
|
+
return generateID(prefix, true, given);
|
|
314
|
+
}
|
|
315
|
+
function generateID(prefix, descending2, given) {
|
|
316
|
+
if (!given) {
|
|
317
|
+
return create(prefix, descending2);
|
|
318
|
+
}
|
|
319
|
+
if (!given.startsWith(prefixes[prefix])) {
|
|
320
|
+
throw new Error(`ID ${given} does not start with ${prefixes[prefix]}`);
|
|
321
|
+
}
|
|
322
|
+
return given;
|
|
323
|
+
}
|
|
324
|
+
function randomBase62(length) {
|
|
325
|
+
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
326
|
+
let result = "";
|
|
327
|
+
const bytes = randomBytes2(length);
|
|
328
|
+
for (let i = 0;i < length; i++) {
|
|
329
|
+
result += chars[bytes[i] % 62];
|
|
330
|
+
}
|
|
331
|
+
return result;
|
|
332
|
+
}
|
|
333
|
+
function create(prefix, descending2, timestamp) {
|
|
334
|
+
const currentTimestamp = timestamp ?? Date.now();
|
|
335
|
+
if (currentTimestamp !== lastTimestamp) {
|
|
336
|
+
lastTimestamp = currentTimestamp;
|
|
337
|
+
counter = 0;
|
|
338
|
+
}
|
|
339
|
+
counter++;
|
|
340
|
+
let now = BigInt(currentTimestamp) * BigInt(4096) + BigInt(counter);
|
|
341
|
+
now = descending2 ? ~now : now;
|
|
342
|
+
const timeBytes = Buffer.alloc(6);
|
|
343
|
+
for (let i = 0;i < 6; i++) {
|
|
344
|
+
timeBytes[i] = Number(now >> BigInt(40 - 8 * i) & BigInt(255));
|
|
345
|
+
}
|
|
346
|
+
return prefixes[prefix] + "_" + timeBytes.toString("hex") + randomBase62(LENGTH - 12);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
// src/core/services/rateLimiter/index.ts
|
|
350
|
+
function sleep(ms) {
|
|
351
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
class RateLimiter {
|
|
355
|
+
tokens;
|
|
356
|
+
lastRefillTime;
|
|
357
|
+
rps;
|
|
358
|
+
bucketSize;
|
|
359
|
+
msPerToken;
|
|
360
|
+
queue;
|
|
361
|
+
constructor(config) {
|
|
362
|
+
this.rps = config?.requestsPerSecond;
|
|
363
|
+
this.bucketSize = this.rps ? 1 : 0;
|
|
364
|
+
this.tokens = this.bucketSize;
|
|
365
|
+
this.lastRefillTime = performance.now();
|
|
366
|
+
this.msPerToken = this.rps ? 1000 / this.rps : undefined;
|
|
367
|
+
this.queue = Promise.resolve();
|
|
368
|
+
}
|
|
369
|
+
async acquireSlot() {
|
|
370
|
+
if (!this.rps || !this.msPerToken)
|
|
371
|
+
return;
|
|
372
|
+
const previousPromise = this.queue;
|
|
373
|
+
let resolveCurrentRequest;
|
|
374
|
+
this.queue = new Promise((resolve) => {
|
|
375
|
+
resolveCurrentRequest = resolve;
|
|
376
|
+
});
|
|
377
|
+
await previousPromise;
|
|
378
|
+
try {
|
|
379
|
+
const now = performance.now();
|
|
380
|
+
this.refill(now);
|
|
381
|
+
if (this.tokens < 1) {
|
|
382
|
+
const waitTime = (1 - this.tokens) * this.msPerToken;
|
|
383
|
+
await sleep(waitTime);
|
|
384
|
+
const nowAfterSleep = performance.now();
|
|
385
|
+
this.refill(nowAfterSleep);
|
|
386
|
+
}
|
|
387
|
+
this.tokens -= 1;
|
|
388
|
+
} finally {
|
|
389
|
+
resolveCurrentRequest();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
refill(now) {
|
|
393
|
+
if (this.tokens >= this.bucketSize) {
|
|
394
|
+
this.lastRefillTime = now;
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
const elapsed = now - this.lastRefillTime;
|
|
398
|
+
const tokensToAdd = elapsed / this.msPerToken;
|
|
399
|
+
this.tokens = Math.min(this.bucketSize, this.tokens + tokensToAdd);
|
|
400
|
+
this.lastRefillTime = now;
|
|
401
|
+
}
|
|
402
|
+
isEnabled() {
|
|
403
|
+
return this.rps !== undefined;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
169
407
|
// src/core/storage/index.ts
|
|
170
408
|
init_zod();
|
|
409
|
+
import fs, { readdir } from "fs/promises";
|
|
171
410
|
import os from "os";
|
|
172
411
|
import path from "path";
|
|
173
|
-
import fs from "fs/promises";
|
|
174
|
-
import { readdir } from "fs/promises";
|
|
175
412
|
|
|
176
413
|
// src/util/errors.ts
|
|
177
414
|
init_zod();
|
|
178
415
|
|
|
179
416
|
class NamedError extends Error {
|
|
180
417
|
static create(name, data) {
|
|
181
|
-
const
|
|
418
|
+
const schema2 = zod_default.object({
|
|
182
419
|
name: zod_default.literal(name),
|
|
183
420
|
data
|
|
184
421
|
});
|
|
185
422
|
const result = class extends NamedError {
|
|
186
423
|
data;
|
|
187
|
-
static Schema =
|
|
424
|
+
static Schema = schema2;
|
|
188
425
|
name = name;
|
|
189
426
|
constructor(data2, options) {
|
|
190
427
|
super(name, options);
|
|
@@ -195,7 +432,7 @@ class NamedError extends Error {
|
|
|
195
432
|
return typeof input === "object" && input !== null && "name" in input && input.name === name;
|
|
196
433
|
}
|
|
197
434
|
schema() {
|
|
198
|
-
return
|
|
435
|
+
return schema2;
|
|
199
436
|
}
|
|
200
437
|
toObject() {
|
|
201
438
|
return {
|
|
@@ -215,15 +452,17 @@ class NamedError extends Error {
|
|
|
215
452
|
// src/util/lock.ts
|
|
216
453
|
var locks = new Map;
|
|
217
454
|
function getLock(key) {
|
|
218
|
-
|
|
219
|
-
|
|
455
|
+
let lock = locks.get(key);
|
|
456
|
+
if (!lock) {
|
|
457
|
+
lock = {
|
|
220
458
|
readers: 0,
|
|
221
459
|
writer: false,
|
|
222
460
|
waitingReaders: [],
|
|
223
461
|
waitingWriters: []
|
|
224
|
-
}
|
|
462
|
+
};
|
|
463
|
+
locks.set(key, lock);
|
|
225
464
|
}
|
|
226
|
-
return
|
|
465
|
+
return lock;
|
|
227
466
|
}
|
|
228
467
|
function processQueue(key) {
|
|
229
468
|
const lock = locks.get(key);
|
|
@@ -231,12 +470,12 @@ function processQueue(key) {
|
|
|
231
470
|
return;
|
|
232
471
|
if (lock.waitingWriters.length > 0) {
|
|
233
472
|
const nextWriter = lock.waitingWriters.shift();
|
|
234
|
-
nextWriter();
|
|
473
|
+
nextWriter?.();
|
|
235
474
|
return;
|
|
236
475
|
}
|
|
237
476
|
while (lock.waitingReaders.length > 0) {
|
|
238
477
|
const nextReader = lock.waitingReaders.shift();
|
|
239
|
-
nextReader();
|
|
478
|
+
nextReader?.();
|
|
240
479
|
}
|
|
241
480
|
if (lock.readers === 0 && !lock.writer && lock.waitingReaders.length === 0 && lock.waitingWriters.length === 0) {
|
|
242
481
|
locks.delete(key);
|
|
@@ -298,18 +537,6 @@ var NotFoundError = NamedError.create("NotFoundError", zod_default.object({
|
|
|
298
537
|
function getBaseDir() {
|
|
299
538
|
return process.env.PENSAR_DATA_DIR ?? path.join(os.homedir(), ".pensar");
|
|
300
539
|
}
|
|
301
|
-
async function remove(key) {
|
|
302
|
-
const dir = getBaseDir();
|
|
303
|
-
const target = path.join(dir, ...key) + ".json";
|
|
304
|
-
return withErrorHandling(async () => {
|
|
305
|
-
await fs.unlink(target).catch(() => {});
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
async function locate(key, ext) {
|
|
309
|
-
const dir = getBaseDir();
|
|
310
|
-
const target = path.join(dir, ...key) + (ext ? ext : ".json");
|
|
311
|
-
return target;
|
|
312
|
-
}
|
|
313
540
|
async function write2(key, content, ext) {
|
|
314
541
|
const dir = getBaseDir();
|
|
315
542
|
const target = path.join(dir, ...key) + (ext ? ext : ".json");
|
|
@@ -436,228 +663,4 @@ async function list(prefix) {
|
|
|
436
663
|
}
|
|
437
664
|
}
|
|
438
665
|
|
|
439
|
-
|
|
440
|
-
init_zod();
|
|
441
|
-
import { randomBytes as randomBytes2 } from "crypto";
|
|
442
|
-
var prefixes = {
|
|
443
|
-
session: "ses",
|
|
444
|
-
message: "msg",
|
|
445
|
-
permission: "per",
|
|
446
|
-
user: "usr",
|
|
447
|
-
part: "prt"
|
|
448
|
-
};
|
|
449
|
-
function schema(prefix) {
|
|
450
|
-
return zod_default.string().startsWith(prefixes[prefix]);
|
|
451
|
-
}
|
|
452
|
-
var LENGTH = 26;
|
|
453
|
-
var lastTimestamp = 0;
|
|
454
|
-
var counter = 0;
|
|
455
|
-
function descending(prefix, given) {
|
|
456
|
-
return generateID(prefix, true, given);
|
|
457
|
-
}
|
|
458
|
-
function generateID(prefix, descending2, given) {
|
|
459
|
-
if (!given) {
|
|
460
|
-
return create(prefix, descending2);
|
|
461
|
-
}
|
|
462
|
-
if (!given.startsWith(prefixes[prefix])) {
|
|
463
|
-
throw new Error(`ID ${given} does not start with ${prefixes[prefix]}`);
|
|
464
|
-
}
|
|
465
|
-
return given;
|
|
466
|
-
}
|
|
467
|
-
function randomBase62(length) {
|
|
468
|
-
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
469
|
-
let result = "";
|
|
470
|
-
const bytes = randomBytes2(length);
|
|
471
|
-
for (let i = 0;i < length; i++) {
|
|
472
|
-
result += chars[bytes[i] % 62];
|
|
473
|
-
}
|
|
474
|
-
return result;
|
|
475
|
-
}
|
|
476
|
-
function create(prefix, descending2, timestamp) {
|
|
477
|
-
const currentTimestamp = timestamp ?? Date.now();
|
|
478
|
-
if (currentTimestamp !== lastTimestamp) {
|
|
479
|
-
lastTimestamp = currentTimestamp;
|
|
480
|
-
counter = 0;
|
|
481
|
-
}
|
|
482
|
-
counter++;
|
|
483
|
-
let now = BigInt(currentTimestamp) * BigInt(4096) + BigInt(counter);
|
|
484
|
-
now = descending2 ? ~now : now;
|
|
485
|
-
const timeBytes = Buffer.alloc(6);
|
|
486
|
-
for (let i = 0;i < 6; i++) {
|
|
487
|
-
timeBytes[i] = Number(now >> BigInt(40 - 8 * i) & BigInt(255));
|
|
488
|
-
}
|
|
489
|
-
return prefixes[prefix] + "_" + timeBytes.toString("hex") + randomBase62(LENGTH - 12);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
// src/core/services/rateLimiter/index.ts
|
|
493
|
-
function sleep(ms) {
|
|
494
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
class RateLimiter {
|
|
498
|
-
tokens;
|
|
499
|
-
lastRefillTime;
|
|
500
|
-
rps;
|
|
501
|
-
bucketSize;
|
|
502
|
-
msPerToken;
|
|
503
|
-
queue;
|
|
504
|
-
constructor(config) {
|
|
505
|
-
this.rps = config?.requestsPerSecond;
|
|
506
|
-
this.bucketSize = this.rps ? 1 : 0;
|
|
507
|
-
this.tokens = this.bucketSize;
|
|
508
|
-
this.lastRefillTime = performance.now();
|
|
509
|
-
this.msPerToken = this.rps ? 1000 / this.rps : undefined;
|
|
510
|
-
this.queue = Promise.resolve();
|
|
511
|
-
}
|
|
512
|
-
async acquireSlot() {
|
|
513
|
-
if (!this.rps || !this.msPerToken)
|
|
514
|
-
return;
|
|
515
|
-
const previousPromise = this.queue;
|
|
516
|
-
let resolveCurrentRequest;
|
|
517
|
-
this.queue = new Promise((resolve) => {
|
|
518
|
-
resolveCurrentRequest = resolve;
|
|
519
|
-
});
|
|
520
|
-
await previousPromise;
|
|
521
|
-
try {
|
|
522
|
-
const now = performance.now();
|
|
523
|
-
this.refill(now);
|
|
524
|
-
if (this.tokens < 1) {
|
|
525
|
-
const waitTime = (1 - this.tokens) * this.msPerToken;
|
|
526
|
-
await sleep(waitTime);
|
|
527
|
-
const nowAfterSleep = performance.now();
|
|
528
|
-
this.refill(nowAfterSleep);
|
|
529
|
-
}
|
|
530
|
-
this.tokens -= 1;
|
|
531
|
-
} finally {
|
|
532
|
-
resolveCurrentRequest();
|
|
533
|
-
}
|
|
534
|
-
}
|
|
535
|
-
refill(now) {
|
|
536
|
-
if (this.tokens >= this.bucketSize) {
|
|
537
|
-
this.lastRefillTime = now;
|
|
538
|
-
return;
|
|
539
|
-
}
|
|
540
|
-
const elapsed = now - this.lastRefillTime;
|
|
541
|
-
const tokensToAdd = elapsed / this.msPerToken;
|
|
542
|
-
this.tokens = Math.min(this.bucketSize, this.tokens + tokensToAdd);
|
|
543
|
-
this.lastRefillTime = now;
|
|
544
|
-
}
|
|
545
|
-
isEnabled() {
|
|
546
|
-
return this.rps !== undefined;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
// src/util/name.ts
|
|
551
|
-
init_zod();
|
|
552
|
-
var adjectives = [
|
|
553
|
-
"swift",
|
|
554
|
-
"bright",
|
|
555
|
-
"calm",
|
|
556
|
-
"bold",
|
|
557
|
-
"keen",
|
|
558
|
-
"noble",
|
|
559
|
-
"quick",
|
|
560
|
-
"sharp",
|
|
561
|
-
"vivid",
|
|
562
|
-
"warm",
|
|
563
|
-
"agile",
|
|
564
|
-
"brave",
|
|
565
|
-
"clever",
|
|
566
|
-
"daring",
|
|
567
|
-
"eager",
|
|
568
|
-
"fierce",
|
|
569
|
-
"gentle",
|
|
570
|
-
"humble",
|
|
571
|
-
"jolly",
|
|
572
|
-
"lively",
|
|
573
|
-
"merry",
|
|
574
|
-
"nimble",
|
|
575
|
-
"proud",
|
|
576
|
-
"quiet",
|
|
577
|
-
"rapid",
|
|
578
|
-
"serene",
|
|
579
|
-
"sturdy",
|
|
580
|
-
"tender",
|
|
581
|
-
"valiant",
|
|
582
|
-
"witty",
|
|
583
|
-
"zealous"
|
|
584
|
-
];
|
|
585
|
-
var nouns = [
|
|
586
|
-
"falcon",
|
|
587
|
-
"wolf",
|
|
588
|
-
"hawk",
|
|
589
|
-
"bear",
|
|
590
|
-
"lion",
|
|
591
|
-
"tiger",
|
|
592
|
-
"eagle",
|
|
593
|
-
"raven",
|
|
594
|
-
"phoenix",
|
|
595
|
-
"dragon",
|
|
596
|
-
"panther",
|
|
597
|
-
"cobra",
|
|
598
|
-
"viper",
|
|
599
|
-
"shark",
|
|
600
|
-
"orca",
|
|
601
|
-
"mantis",
|
|
602
|
-
"spider",
|
|
603
|
-
"scorpion",
|
|
604
|
-
"hydra",
|
|
605
|
-
"griffin",
|
|
606
|
-
"sphinx",
|
|
607
|
-
"kraken",
|
|
608
|
-
"cipher",
|
|
609
|
-
"nexus",
|
|
610
|
-
"prism",
|
|
611
|
-
"vector",
|
|
612
|
-
"matrix",
|
|
613
|
-
"pulse",
|
|
614
|
-
"surge",
|
|
615
|
-
"flux"
|
|
616
|
-
];
|
|
617
|
-
function generateRandomName() {
|
|
618
|
-
const adj = adjectives[Math.floor(Math.random() * adjectives.length)];
|
|
619
|
-
const noun = nouns[Math.floor(Math.random() * nouns.length)];
|
|
620
|
-
return `${adj}-${noun}`;
|
|
621
|
-
}
|
|
622
|
-
var sessionNameSchema = exports_external.object({
|
|
623
|
-
name: exports_external.string().describe("A short, descriptive session name (2-4 words, lowercase, hyphenated)")
|
|
624
|
-
});
|
|
625
|
-
async function generateSessionName(opts) {
|
|
626
|
-
const { targets, userMessage, model, authConfig, abortSignal } = opts;
|
|
627
|
-
const contextParts = [];
|
|
628
|
-
if (targets.length > 0) {
|
|
629
|
-
contextParts.push(`Target(s): ${targets.join(", ")}`);
|
|
630
|
-
}
|
|
631
|
-
if (userMessage) {
|
|
632
|
-
contextParts.push(`User objective: ${userMessage}`);
|
|
633
|
-
}
|
|
634
|
-
if (contextParts.length === 0)
|
|
635
|
-
return null;
|
|
636
|
-
const prompt = [
|
|
637
|
-
"Generate a short, descriptive name for a penetration testing session.",
|
|
638
|
-
"The name should be 2-4 lowercase words separated by hyphens.",
|
|
639
|
-
"It should capture the key aspect of the target or task — e.g. 'acme-api-pentest', 'login-auth-bypass', 'ecommerce-checkout-test'.",
|
|
640
|
-
"",
|
|
641
|
-
...contextParts
|
|
642
|
-
].join(`
|
|
643
|
-
`);
|
|
644
|
-
try {
|
|
645
|
-
const result = await generateObjectResponse({
|
|
646
|
-
model,
|
|
647
|
-
schema: sessionNameSchema,
|
|
648
|
-
prompt,
|
|
649
|
-
maxTokens: 50,
|
|
650
|
-
temperature: 0.7,
|
|
651
|
-
authConfig,
|
|
652
|
-
abortSignal
|
|
653
|
-
});
|
|
654
|
-
if (!result?.name)
|
|
655
|
-
return null;
|
|
656
|
-
const name = result.name.toLowerCase().replace(/[^a-z0-9-]/g, "-").replace(/-+/g, "-").replace(/^-|-$/g, "").slice(0, 50);
|
|
657
|
-
return name || null;
|
|
658
|
-
} catch {
|
|
659
|
-
return null;
|
|
660
|
-
}
|
|
661
|
-
}
|
|
662
|
-
|
|
663
|
-
export { CredentialManager, NotFoundError, remove, locate, write2 as write, createDir, writeRaw, read2 as read, update, list, schema, descending, RateLimiter, generateRandomName, generateSessionName };
|
|
666
|
+
export { generateRandomName, generateSessionName, CredentialManager, schema, descending, RateLimiter, NotFoundError, write2 as write, createDir, writeRaw, read2 as read, update, list };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
exports_external1 as exports_external,
|
|
3
|
+
init_zod
|
|
4
|
+
} from "./cli-e6rgwtpb.js";
|
|
5
|
+
import {
|
|
6
|
+
__esm
|
|
7
|
+
} from "./cli-8rxa073f.js";
|
|
8
|
+
|
|
9
|
+
// src/core/toolset/index.ts
|
|
10
|
+
var ToolsetStateSchema;
|
|
11
|
+
var init_toolset = __esm(() => {
|
|
12
|
+
init_zod();
|
|
13
|
+
ToolsetStateSchema = exports_external.object({
|
|
14
|
+
baseToolsetId: exports_external.string(),
|
|
15
|
+
enabledTools: exports_external.record(exports_external.string(), exports_external.boolean()),
|
|
16
|
+
lastModified: exports_external.number()
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export { ToolsetStateSchema, init_toolset };
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
OffensiveSecurityAgent
|
|
3
|
-
} from "./cli-
|
|
3
|
+
} from "./cli-wfmdch3r.js";
|
|
4
4
|
import {
|
|
5
5
|
detectOSAndEnhancePrompt
|
|
6
|
-
} from "./cli-
|
|
6
|
+
} from "./cli-mswm4k81.js";
|
|
7
7
|
import {
|
|
8
8
|
hasToolCall,
|
|
9
|
+
init_dist,
|
|
9
10
|
stepCountIs
|
|
10
|
-
} from "./cli-
|
|
11
|
+
} from "./cli-6p7d2k55.js";
|
|
11
12
|
|
|
12
13
|
// src/core/agents/specialized/attackSurface/blackboxAgent.ts
|
|
13
|
-
|
|
14
|
+
init_dist();
|
|
14
15
|
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
|
16
|
+
import { join } from "path";
|
|
15
17
|
|
|
16
18
|
// src/core/agents/specialized/attackSurface/prompts.ts
|
|
17
19
|
var SYSTEM = `You are an autonomous attack surface analysis agent. Your mission is to comprehensively map the attack surface of a target and produce a structured report of all discovered assets and pentest objectives.
|
|
@@ -384,7 +386,8 @@ class BlackboxAttackSurfaceAgent extends OffensiveSecurityAgent {
|
|
|
384
386
|
attackSurfaceRegistry,
|
|
385
387
|
eventBus,
|
|
386
388
|
subagentId,
|
|
387
|
-
enableThinking
|
|
389
|
+
enableThinking,
|
|
390
|
+
openAIReasoningEffort
|
|
388
391
|
} = opts;
|
|
389
392
|
const target = opts.target ?? opts.cwd;
|
|
390
393
|
const resultsPath = join(session.rootPath, "attack-surface-results.json");
|
|
@@ -413,6 +416,7 @@ class BlackboxAttackSurfaceAgent extends OffensiveSecurityAgent {
|
|
|
413
416
|
eventBus,
|
|
414
417
|
subagentId,
|
|
415
418
|
enableThinking,
|
|
419
|
+
openAIReasoningEffort,
|
|
416
420
|
messages: opts.messages,
|
|
417
421
|
activeTools: [
|
|
418
422
|
"execute_command",
|