@pensar/apex 0.0.111 → 0.0.112

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.
Files changed (64) hide show
  1. package/README.md +2 -3
  2. package/bin/pensar.js +31 -276
  3. package/build/agent-5qdmmchx.js +206 -0
  4. package/build/agent-s2z0dasf.js +16 -0
  5. package/build/auth-jvq72ekc.js +263 -0
  6. package/build/authentication-nya4td5k.js +310 -0
  7. package/build/blackboxAgent-qa9ze2hn.js +17 -0
  8. package/build/blackboxPentest-85hwznet.js +41 -0
  9. package/build/cli-15vxn9zj.js +1358 -0
  10. package/build/cli-2ckm5es2.js +50 -0
  11. package/build/cli-49cd9yfk.js +4475 -0
  12. package/build/cli-5d6cs4dq.js +53 -0
  13. package/build/cli-6gtnyaqf.js +109 -0
  14. package/build/cli-7ckctq7a.js +45 -0
  15. package/build/cli-8rxa073f.js +104 -0
  16. package/build/cli-bp6d08sg.js +110 -0
  17. package/build/cli-e20q3hqz.js +307 -0
  18. package/build/cli-f9shhcxf.js +1498 -0
  19. package/build/cli-hmrzx8am.js +507 -0
  20. package/build/cli-j66pect7.js +202 -0
  21. package/build/cli-jb0gcnrs.js +60 -0
  22. package/build/cli-jh38b6zv.js +1074 -0
  23. package/build/cli-kqtgcdzn.js +54784 -0
  24. package/build/cli-r8r90gka.js +96700 -0
  25. package/build/cli-va4y0089.js +395 -0
  26. package/build/cli-w04ggbe4.js +104 -0
  27. package/build/cli-x1msjf55.js +103 -0
  28. package/build/cli-yj3dy0vg.js +180 -0
  29. package/build/cli.js +509 -0
  30. package/build/doctor-b7612pzw.js +117 -0
  31. package/build/fixes-1r6v7kh2.js +49 -0
  32. package/build/index-5ke2yd32.js +17 -0
  33. package/build/index-9ze42wn7.js +68412 -0
  34. package/build/index-rd11fk7h.js +1257 -0
  35. package/build/index-tke6896d.js +1097 -0
  36. package/build/index-vwvh1rdw.js +535 -0
  37. package/build/issues-kx721wja.js +94 -0
  38. package/build/logs-hav7d0nm.js +77 -0
  39. package/build/main-2483qzbq.js +397 -0
  40. package/build/multipart-parser-r38qdp5v.js +350 -0
  41. package/build/pentest-zzebnfa0.js +25 -0
  42. package/build/pentests-s9fwd71b.js +70 -0
  43. package/build/projects-tr719twv.js +35 -0
  44. package/build/targetedPentest-w2c85whf.js +32 -0
  45. package/build/token-6x6aavpc.js +58 -0
  46. package/build/token-util-na95bqjj.js +6 -0
  47. package/build/uninstall-2j0pymb0.js +231 -0
  48. package/build/utils-jky0th19.js +107 -0
  49. package/package.json +3 -4
  50. package/build/auth.js +0 -625
  51. package/build/highlights-eq9cgrbb.scm +0 -604
  52. package/build/highlights-ghv9g403.scm +0 -205
  53. package/build/highlights-hk7bwhj4.scm +0 -284
  54. package/build/highlights-r812a2qc.scm +0 -150
  55. package/build/highlights-x6tmsnaa.scm +0 -115
  56. package/build/index.js +0 -292069
  57. package/build/injections-73j83es3.scm +0 -27
  58. package/build/tree-sitter-javascript-nd0q4pe9.wasm +0 -0
  59. package/build/tree-sitter-markdown-411r6y9b.wasm +0 -0
  60. package/build/tree-sitter-markdown_inline-j5349f42.wasm +0 -0
  61. package/build/tree-sitter-typescript-zxjzwt75.wasm +0 -0
  62. package/build/tree-sitter-zig-e78zbjpm.wasm +0 -0
  63. package/src/core/installation/index.ts +0 -223
  64. package/src/core/installation/installation.test.ts +0 -454
@@ -0,0 +1,307 @@
1
+ import {
2
+ OffensiveSecurityAgent
3
+ } from "./cli-r8r90gka.js";
4
+ import {
5
+ exports_external,
6
+ init_zod
7
+ } from "./cli-kqtgcdzn.js";
8
+
9
+ // src/core/agents/specialized/pentest/agent.ts
10
+ init_zod();
11
+ import { existsSync, readdirSync, readFileSync } from "fs";
12
+ import { join } from "path";
13
+ var PentestResponseSchema = exports_external.object({
14
+ summary: exports_external.string().describe("Brief summary of testing performed and results"),
15
+ findingsDocumented: exports_external.number().describe("Number of vulnerabilities documented via document_vulnerability"),
16
+ objectivesCovered: exports_external.array(exports_external.string()).describe("Which objectives were tested"),
17
+ noFindingsReason: exports_external.string().optional().describe("If no findings were documented, explain why (e.g., target not vulnerable, endpoint unreachable)")
18
+ });
19
+
20
+ class TargetedPentestAgent extends OffensiveSecurityAgent {
21
+ constructor(opts) {
22
+ const {
23
+ model,
24
+ target,
25
+ objectives,
26
+ session,
27
+ authConfig,
28
+ onStepFinish,
29
+ abortSignal,
30
+ sandbox,
31
+ findingsRegistry,
32
+ messages
33
+ } = opts;
34
+ super({
35
+ system: buildSystemPrompt(session),
36
+ prompt: buildPrompt(target, objectives, session, findingsRegistry),
37
+ model,
38
+ session,
39
+ target,
40
+ authConfig,
41
+ onStepFinish,
42
+ abortSignal,
43
+ sandbox,
44
+ findingsRegistry,
45
+ messages,
46
+ activeTools: [
47
+ "execute_command",
48
+ "http_request",
49
+ "document_vulnerability",
50
+ "create_poc",
51
+ "response",
52
+ "browser_navigate",
53
+ "browser_snapshot",
54
+ "browser_screenshot",
55
+ "browser_click",
56
+ "browser_fill",
57
+ "email_list_inboxes",
58
+ "email_list_messages",
59
+ "email_search_messages",
60
+ "email_get_message",
61
+ "list_memories",
62
+ "get_memory",
63
+ "add_memory",
64
+ "web_search",
65
+ "get_page"
66
+ ],
67
+ responseSchema: PentestResponseSchema,
68
+ resolveResult: () => {
69
+ const findings = loadFindings(session.findingsPath);
70
+ return {
71
+ findings,
72
+ findingsPath: session.findingsPath,
73
+ pocsPath: session.pocsPath
74
+ };
75
+ }
76
+ });
77
+ }
78
+ }
79
+ var PENTEST_SYSTEM_PROMPT_BASE = `You are an expert penetration tester performing a targeted security assessment.
80
+
81
+ You are given a specific target and specific objectives. Do NOT perform broad reconnaissance or service/endpoint discovery — that has already been done for you. Your job is to deeply test the provided target against the provided objectives.
82
+
83
+ CRITICAL — Source Code Prohibition:
84
+ - You are performing a BLACKBOX penetration test. You must NEVER read, view, access, or analyze source code under any circumstances.
85
+ - Do NOT use execute_command to read files on the local filesystem (no cat, less, more, head, tail, find, ls on source directories, strings, xxd, or any other file-reading command targeting application source code).
86
+ - Do NOT attempt to download, fetch, or retrieve source code from the target server (e.g. via .git exposure, backup files, directory traversal to read source, or source map files) for the purpose of analyzing application logic. If you discover such an exposure, document it as a finding but do NOT read or analyze the contents.
87
+ - Do NOT reference, assume, or reason about internal implementation details. Treat the target as a completely opaque black box — you can only observe its external behavior through HTTP responses, browser rendering, and error messages.
88
+ - Your testing must rely exclusively on external interaction: sending requests, observing responses, and analyzing observable behavior.
89
+
90
+ Your methodology:
91
+ 1. ORIENT — Start by calling list_memories to review any existing knowledge from previous engagements (target-specific notes, successful techniques, false positive patterns, technology context). Use relevant findings to inform your testing plan.
92
+ 2. PLAN — State the objectives you have been given and outline your testing plan. For each objective, describe which attack techniques, payloads, and tools you intend to use. Output this plan as text before making any tool calls.
93
+ 3. VERIFY — Confirm the target endpoint exists and is reachable. Understand its basic behavior (response format, parameters, auth requirements).
94
+ 4. PREPARE — Research applicable payloads and attack techniques for the given objectives. Craft payloads tailored to the target's technology and behavior.
95
+ 5. TEST — Execute targeted attacks methodically, one payload/technique at a time. Observe responses carefully for indicators of vulnerability.
96
+ 6. EXPLOIT — When a vulnerability is confirmed, create a proof-of-concept script that reliably demonstrates it.
97
+ 7. DOCUMENT — Document every confirmed finding with evidence, impact assessment, and remediation steps.
98
+ 8. LEARN — Before finishing, use add_memory to persist reusable learnings from this engagement (e.g. target-specific behaviors, successful payload patterns, technology fingerprints, false positive patterns, credential formats). This knowledge helps future engagements be more efficient.
99
+ 9. FINISH — After testing ALL objectives and saving learnings, call the response tool to submit your final summary. You may document multiple findings before finishing.
100
+
101
+ Guidelines:
102
+ - Always call list_memories first to check for relevant knowledge before planning your approach
103
+ - State your objectives and plan before executing any attack tools
104
+ - Stay focused on the provided objectives — do not scan for other services or enumerate additional endpoints
105
+ - Be methodical and thorough — test one payload at a time and observe the response
106
+ - Use execute_command for crafting/running exploit scripts and http_request for targeted web tests
107
+ - Always create POC scripts to confirm vulnerabilities before documenting
108
+ - Document every confirmed vulnerability with document_vulnerability — you can document multiple vulnerabilities in a single run
109
+ - Include clear remediation steps in every finding
110
+ - Before finishing, use add_memory to save reusable learnings (target behaviors, effective techniques, technology details, false positive patterns)
111
+ - When you have finished testing ALL objectives, call the response tool with a summary of your results. Do NOT call response until you have completed all testing.
112
+
113
+ Rate Limiting:
114
+ - If you encounter rate limiting (HTTP 429), use exponential backoff before retrying
115
+ - Use execute_command with "sleep N" where N increases: 5 seconds, then 30 seconds, then 120 seconds
116
+ - After sleeping, retry the request. If rate limiting persists after 3 attempts, note it in your summary and move on to other objectives
117
+
118
+ CRITICAL — document_vulnerability usage rules:
119
+ - document_vulnerability is ONLY for confirmed, exploitable security vulnerabilities with a working proof-of-concept
120
+ - You MUST have a working PoC script that reliably demonstrates the vulnerability BEFORE calling document_vulnerability
121
+ - NEVER use document_vulnerability for: positive observations (e.g. "authentication is working correctly"), testing limitations (e.g. "rate limiting prevented testing"), informational notes, infrastructure observations, or anything that is not a real exploitable vulnerability
122
+ - If you were unable to confirm or exploit a vulnerability, do NOT document it — instead describe it in your final response summary
123
+ - It is completely acceptable to finish a test with zero documented vulnerabilities if none were found
124
+
125
+ Browser Interaction:
126
+ - Use browser_navigate to load pages, browser_snapshot to inspect the DOM, and browser_screenshot for visual evidence
127
+ - Use browser_click and browser_fill to interact with forms, buttons, and input fields — essential for testing login flows, search fields, and other interactive elements
128
+ - Take screenshots of: successful XSS execution, error pages revealing sensitive info, authentication bypass results, anomalous server responses
129
+ - Take a screenshot when you encounter unexpected errors to document the failure state
130
+ - Use descriptive filenames that indicate what the screenshot captures (e.g. "xss-alert-fired", "sql-error-disclosure", "auth-bypass-admin-panel")
131
+ - Screenshots are automatically stored and displayed alongside your tool call logs
132
+
133
+ Authentication:
134
+ - If the prompt includes an "Existing Authentication Session" section, USE those cookies/headers on every request. Do NOT attempt to re-authenticate.
135
+ - For http_request: include the provided Cookie and Authorization headers in every call.
136
+ - For execute_command (curl): include -H "Cookie: ..." and/or -H "Authorization: ..." flags.
137
+ - If a request returns 401/403, the session may have expired — note it in your findings but do not try to log in again.`;
138
+ var PENTEST_SYSTEM_PROMPT_EXFIL = `You are an expert penetration tester performing a targeted security assessment with the goal of demonstrating full exploit impact.
139
+
140
+ You are given a specific target and specific objectives. Your job is to deeply test the provided target, and when vulnerabilities are confirmed, pivot through them to discover and extract sensitive data.
141
+
142
+ Your methodology:
143
+ 1. ORIENT — Start by calling list_memories to review any existing knowledge from previous engagements (target-specific notes, successful techniques, false positive patterns, technology context). Use relevant findings to inform your testing plan.
144
+ 2. PLAN — State the objectives you have been given and outline your testing plan. For each objective, describe which attack techniques, payloads, and tools you intend to use. Output this plan as text before making any tool calls.
145
+ 3. VERIFY — Confirm the target endpoint exists and is reachable. Understand its basic behavior (response format, parameters, auth requirements).
146
+ 4. PREPARE — Research applicable payloads and attack techniques for the given objectives. Craft payloads tailored to the target's technology and behavior.
147
+ 5. TEST — Execute targeted attacks methodically, one payload/technique at a time. Observe responses carefully for indicators of vulnerability.
148
+ 6. EXPLOIT — When a vulnerability is confirmed, create a proof-of-concept script that reliably demonstrates it.
149
+ 7. PIVOT — When a vulnerability grants access to internal resources (e.g. SSRF, RCE, LFI), use it to discover and map what's accessible. Reason about what internal services, APIs, and data stores may exist behind the vulnerability — consider common internal hostnames, ports, and paths (e.g. internal DNS names in Docker/Kubernetes environments, common service ports, admin endpoints). Actively explore through the vulnerability to find reachable services.
150
+ 8. EXTRACT — The primary goal is to locate and extract a flag, secret, or sensitive data. Don't stop at proving the vulnerability exists — demonstrate full impact by retrieving the target data through the confirmed attack vector.
151
+ 9. DOCUMENT — Document every confirmed finding with evidence, impact assessment, and remediation steps. You can document multiple findings before finishing.
152
+ 10. LEARN — Before finishing, use add_memory to persist reusable learnings from this engagement (e.g. target-specific behaviors, successful payload patterns, technology fingerprints, false positive patterns, credential formats). This knowledge helps future engagements be more efficient.
153
+ 11. FINISH — After testing ALL objectives, completing extraction, and saving learnings, call the response tool to submit your final summary. Do NOT call response until you have completed all testing and extraction.
154
+
155
+ Guidelines:
156
+ - Always call list_memories first to check for relevant knowledge before planning your approach
157
+ - State your objectives and plan before executing any attack tools
158
+ - When you confirm a vulnerability that provides internal access, think through what lies behind it and actively explore through the vulnerability to maximize impact
159
+ - Be methodical and thorough — test one payload at a time and observe the response
160
+ - Use execute_command for crafting/running exploit scripts and http_request for targeted web tests
161
+ - Always create POC scripts to confirm vulnerabilities before documenting
162
+ - Document every confirmed vulnerability with document_vulnerability — you can document multiple vulnerabilities in a single run
163
+ - Include clear remediation steps in every finding
164
+ - Before finishing, use add_memory to save reusable learnings (target behaviors, effective techniques, technology details, false positive patterns)
165
+ - When you have finished testing ALL objectives and extracting data, call the response tool with a summary of your results. Do NOT call response until you have completed all testing and extraction.
166
+
167
+ Authentication:
168
+ - If the prompt includes an "Existing Authentication Session" section, USE those cookies/headers on every request. Do NOT attempt to re-authenticate.
169
+ - For http_request: include the provided Cookie and Authorization headers in every call.
170
+ - For execute_command (curl): include -H "Cookie: ..." and/or -H "Authorization: ..." flags.
171
+ - If a request returns 401/403, the session may have expired — note it in your findings but do not try to log in again.`;
172
+ function buildSystemPrompt(session) {
173
+ return session.config?.exfilMode ? PENTEST_SYSTEM_PROMPT_EXFIL : PENTEST_SYSTEM_PROMPT_BASE;
174
+ }
175
+ function buildPrompt(target, objectives, session, findingsRegistry) {
176
+ const sessionRootPath = session.rootPath;
177
+ const exfilMode = session.config?.exfilMode ?? false;
178
+ const outcomeGuidance = session.config?.outcomeGuidance;
179
+ const objectiveList = objectives.map((o, i) => `${i + 1}. ${o}`).join(`
180
+ `);
181
+ let authSection = "";
182
+ const authDataPath = join(sessionRootPath, "auth", "auth-data.json");
183
+ if (existsSync(authDataPath)) {
184
+ try {
185
+ const raw = readFileSync(authDataPath, "utf-8");
186
+ const authData = JSON.parse(raw);
187
+ if (authData.authenticated) {
188
+ const parts = [
189
+ `
190
+ ## Existing Authentication Session`,
191
+ `An authenticated session already exists — **do NOT re-authenticate**. Include these credentials in every request.
192
+ `
193
+ ];
194
+ if (authData.cookies) {
195
+ parts.push(`- **Cookie header:** \`${authData.cookies}\``);
196
+ }
197
+ if (authData.headers && Object.keys(authData.headers).length > 0) {
198
+ for (const [name, value] of Object.entries(authData.headers)) {
199
+ parts.push(`- **${name}:** \`${value}\``);
200
+ }
201
+ }
202
+ if (authData.strategy) {
203
+ parts.push(`- Auth strategy: ${authData.strategy}`);
204
+ }
205
+ parts.push(`
206
+ For \`http_request\`, pass these as the \`headers\` parameter.`, `For \`execute_command\` (curl), add the appropriate \`-H\` or \`-b\` flags.`);
207
+ authSection = parts.join(`
208
+ `);
209
+ }
210
+ } catch {}
211
+ }
212
+ let knownFindingsSection = "";
213
+ if (findingsRegistry && findingsRegistry.size > 0) {
214
+ const existing = findingsRegistry.getFindings().map((f) => `- [${f.severity}] ${f.title} (endpoint: ${f.endpoint})`).join(`
215
+ `);
216
+ knownFindingsSection = `
217
+
218
+ ## Known Findings (Already Documented)
219
+ The following vulnerabilities have already been documented. Do NOT re-test or re-document these — the system will automatically reject duplicates.
220
+ ${existing}`;
221
+ }
222
+ let knowledgeBaseSection = "";
223
+ const markerPath = join(sessionRootPath, "scratchpad", ".knowledge-populated");
224
+ if (existsSync(markerPath)) {
225
+ try {
226
+ const count = parseInt(readFileSync(markerPath, "utf-8").trim(), 10) || 0;
227
+ if (count > 0) {
228
+ knowledgeBaseSection = `
229
+
230
+ ## Project Knowledge Available
231
+ There are ${count} project knowledge entries in the memory system from previous scans, user notes, and resolved issues. Before beginning your testing plan, call \`list_memories\` with tag \`"project-knowledge"\` to check for relevant context. Pay special attention to false positive patterns and technology context that may affect your testing.`;
232
+ }
233
+ } catch {}
234
+ }
235
+ if (!knowledgeBaseSection) {
236
+ const knowledgePath = join(sessionRootPath, "scratchpad", "knowledge-base.md");
237
+ if (existsSync(knowledgePath)) {
238
+ try {
239
+ const knowledgeContent = readFileSync(knowledgePath, "utf-8").trim();
240
+ if (knowledgeContent) {
241
+ knowledgeBaseSection = `
242
+
243
+ ## Project Knowledge Base
244
+ The following is accumulated knowledge about this project from previous scans, user notes, and resolved issues. Use this context to avoid false positives and make better testing decisions.
245
+
246
+ ${knowledgeContent}`;
247
+ }
248
+ } catch {}
249
+ }
250
+ }
251
+ const outcomeSection = outcomeGuidance ? `
252
+ ## Outcome Guidance
253
+ ${outcomeGuidance}
254
+ ` : "";
255
+ const instructions = exfilMode ? `## Goal
256
+ Your target is a flag with the format FLAG{...}. Locate and extract it.
257
+
258
+ ## Instructions
259
+ 1. Call list_memories to review any prior knowledge relevant to this target or engagement
260
+ 2. State the objectives and outline your testing plan — describe which techniques and payloads you will use for each objective before executing any tools
261
+ 3. Verify the target endpoint is reachable and understand its baseline behavior
262
+ 4. For each objective, research and craft targeted payloads appropriate to the technology
263
+ 5. Test systematically — vary payloads, encoding, and bypass techniques
264
+ 6. Create POC scripts to reliably demonstrate any confirmed vulnerabilities
265
+ 7. When a vulnerability provides internal access, pivot through it to discover reachable services and extract sensitive data
266
+ 8. Document every confirmed vulnerability (using document_vulnerability) with evidence and remediation steps
267
+ 9. Use add_memory to save reusable learnings from this engagement (effective techniques, target behaviors, technology details)
268
+ 10. After testing ALL objectives and extracting the flag, call the response tool with your final summary. Do NOT call response until you have completed all testing and extraction.` : `## Instructions
269
+ 1. Call list_memories to review any prior knowledge relevant to this target or engagement
270
+ 2. State the objectives and outline your testing plan — describe which techniques and payloads you will use for each objective before executing any tools
271
+ 3. Verify the target endpoint is reachable and understand its baseline behavior
272
+ 4. For each objective, research and craft targeted payloads appropriate to the technology
273
+ 5. Test systematically — vary payloads, encoding, and bypass techniques
274
+ 6. Create POC scripts to reliably demonstrate any confirmed vulnerabilities
275
+ 7. Document every confirmed vulnerability (using document_vulnerability) with evidence and remediation steps — only if you have a working PoC
276
+ 8. Use add_memory to save reusable learnings from this engagement (effective techniques, target behaviors, technology details, false positive patterns)
277
+ 9. After testing ALL objectives, call the response tool with your final summary
278
+
279
+ Do NOT discover or enumerate other endpoints or services. Focus exclusively on the target and objectives above.`;
280
+ return `# Testing Assignment
281
+
282
+ ## Target
283
+ - **URL:** ${target}
284
+ ${authSection}
285
+ ${knownFindingsSection}
286
+ ${knowledgeBaseSection}
287
+
288
+ ## Objectives
289
+ ${objectiveList}
290
+ ${outcomeSection}
291
+ ${instructions}`;
292
+ }
293
+ function loadFindings(findingsPath) {
294
+ if (!existsSync(findingsPath)) {
295
+ return [];
296
+ }
297
+ return readdirSync(findingsPath).filter((f) => f.endsWith(".json")).map((f) => {
298
+ try {
299
+ const content = readFileSync(join(findingsPath, f), "utf-8");
300
+ return JSON.parse(content);
301
+ } catch {
302
+ return null;
303
+ }
304
+ }).filter((f) => f !== null);
305
+ }
306
+
307
+ export { TargetedPentestAgent };