cipher-security 2.0.0

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 (76) hide show
  1. package/bin/cipher.js +566 -0
  2. package/lib/api/billing.js +321 -0
  3. package/lib/api/compliance.js +693 -0
  4. package/lib/api/controls.js +1401 -0
  5. package/lib/api/index.js +49 -0
  6. package/lib/api/marketplace.js +467 -0
  7. package/lib/api/openai-proxy.js +383 -0
  8. package/lib/api/server.js +685 -0
  9. package/lib/autonomous/feedback-loop.js +554 -0
  10. package/lib/autonomous/framework.js +512 -0
  11. package/lib/autonomous/index.js +97 -0
  12. package/lib/autonomous/leaderboard.js +594 -0
  13. package/lib/autonomous/modes/architect.js +412 -0
  14. package/lib/autonomous/modes/blue.js +386 -0
  15. package/lib/autonomous/modes/incident.js +684 -0
  16. package/lib/autonomous/modes/privacy.js +369 -0
  17. package/lib/autonomous/modes/purple.js +294 -0
  18. package/lib/autonomous/modes/recon.js +250 -0
  19. package/lib/autonomous/parallel.js +587 -0
  20. package/lib/autonomous/researcher.js +583 -0
  21. package/lib/autonomous/runner.js +955 -0
  22. package/lib/autonomous/scheduler.js +615 -0
  23. package/lib/autonomous/task-parser.js +127 -0
  24. package/lib/autonomous/validators/forensic.js +266 -0
  25. package/lib/autonomous/validators/osint.js +216 -0
  26. package/lib/autonomous/validators/privacy.js +296 -0
  27. package/lib/autonomous/validators/purple.js +298 -0
  28. package/lib/autonomous/validators/sigma.js +248 -0
  29. package/lib/autonomous/validators/threat-model.js +363 -0
  30. package/lib/benchmark/agent.js +119 -0
  31. package/lib/benchmark/baselines.js +43 -0
  32. package/lib/benchmark/builder.js +143 -0
  33. package/lib/benchmark/config.js +35 -0
  34. package/lib/benchmark/coordinator.js +91 -0
  35. package/lib/benchmark/index.js +20 -0
  36. package/lib/benchmark/llm.js +58 -0
  37. package/lib/benchmark/models.js +137 -0
  38. package/lib/benchmark/reporter.js +103 -0
  39. package/lib/benchmark/runner.js +103 -0
  40. package/lib/benchmark/sandbox.js +96 -0
  41. package/lib/benchmark/scorer.js +32 -0
  42. package/lib/benchmark/solver.js +166 -0
  43. package/lib/benchmark/tools.js +62 -0
  44. package/lib/bot/bot.js +238 -0
  45. package/lib/brand.js +105 -0
  46. package/lib/commands.js +100 -0
  47. package/lib/complexity.js +377 -0
  48. package/lib/config.js +213 -0
  49. package/lib/gateway/client.js +309 -0
  50. package/lib/gateway/commands.js +991 -0
  51. package/lib/gateway/config-validate.js +109 -0
  52. package/lib/gateway/gateway.js +367 -0
  53. package/lib/gateway/index.js +62 -0
  54. package/lib/gateway/mode.js +309 -0
  55. package/lib/gateway/plugins.js +222 -0
  56. package/lib/gateway/prompt.js +214 -0
  57. package/lib/mcp/server.js +262 -0
  58. package/lib/memory/compressor.js +425 -0
  59. package/lib/memory/engine.js +763 -0
  60. package/lib/memory/evolution.js +668 -0
  61. package/lib/memory/index.js +58 -0
  62. package/lib/memory/orchestrator.js +506 -0
  63. package/lib/memory/retriever.js +515 -0
  64. package/lib/memory/synthesizer.js +333 -0
  65. package/lib/pipeline/async-scanner.js +510 -0
  66. package/lib/pipeline/binary-analysis.js +1043 -0
  67. package/lib/pipeline/dom-xss-scanner.js +435 -0
  68. package/lib/pipeline/github-actions.js +792 -0
  69. package/lib/pipeline/index.js +124 -0
  70. package/lib/pipeline/osint.js +498 -0
  71. package/lib/pipeline/sarif.js +373 -0
  72. package/lib/pipeline/scanner.js +880 -0
  73. package/lib/pipeline/template-manager.js +525 -0
  74. package/lib/pipeline/xss-scanner.js +353 -0
  75. package/lib/setup-wizard.js +288 -0
  76. package/package.json +31 -0
@@ -0,0 +1,386 @@
1
+ // Copyright (c) 2026 defconxt. All rights reserved.
2
+ // Licensed under AGPL-3.0 — see LICENSE file for details.
3
+ // CIPHER is a trademark of defconxt.
4
+
5
+ /**
6
+ * BLUE mode agent — Detection Engineering.
7
+ *
8
+ * Generates Sigma detection rules for given MITRE ATT&CK TTPs.
9
+ * Ported from autonomous/modes/blue.py.
10
+ *
11
+ * @module autonomous/modes/blue
12
+ */
13
+
14
+ import { createRequire } from 'node:module';
15
+ import { ModeAgentConfig, ToolRegistry } from '../framework.js';
16
+ import { SigmaValidator } from '../validators/sigma.js';
17
+
18
+ const require = createRequire(import.meta.url);
19
+ const YAML = require('yaml');
20
+
21
+ // ---------------------------------------------------------------------------
22
+ // ATT&CK technique lookup table
23
+ // ---------------------------------------------------------------------------
24
+
25
+ /** @type {Object<string, Object>} */
26
+ export const ATTACK_TECHNIQUES = {
27
+ 'T1059.001': {
28
+ name: 'PowerShell',
29
+ tactic: 'execution',
30
+ description:
31
+ 'Adversaries may abuse PowerShell commands and scripts for execution. ' +
32
+ 'PowerShell is a powerful interactive command-line interface and scripting ' +
33
+ 'environment included in the Windows operating system.',
34
+ data_sources: [
35
+ 'Command: Command Execution',
36
+ 'Module: Module Load',
37
+ 'Process: Process Creation',
38
+ 'Script: Script Execution',
39
+ ],
40
+ },
41
+ 'T1059.003': {
42
+ name: 'Windows Command Shell',
43
+ tactic: 'execution',
44
+ description:
45
+ 'Adversaries may abuse the Windows command shell (cmd.exe) for execution. ' +
46
+ 'The Windows command shell is the primary command prompt on Windows systems.',
47
+ data_sources: [
48
+ 'Command: Command Execution',
49
+ 'Process: Process Creation',
50
+ ],
51
+ },
52
+ 'T1053.005': {
53
+ name: 'Scheduled Task',
54
+ tactic: 'persistence',
55
+ description:
56
+ 'Adversaries may abuse the Windows Task Scheduler to perform task scheduling ' +
57
+ 'for initial or recurring execution of malicious code.',
58
+ data_sources: [
59
+ 'Command: Command Execution',
60
+ 'Scheduled Job: Scheduled Job Creation',
61
+ 'Process: Process Creation',
62
+ ],
63
+ },
64
+ 'T1003.001': {
65
+ name: 'LSASS Memory',
66
+ tactic: 'credential_access',
67
+ description:
68
+ 'Adversaries may attempt to access credential material stored in the process ' +
69
+ 'memory of the Local Security Authority Subsystem Service (LSASS).',
70
+ data_sources: [
71
+ 'Process: OS API Execution',
72
+ 'Process: Process Access',
73
+ 'Process: Process Creation',
74
+ ],
75
+ },
76
+ 'T1087.001': {
77
+ name: 'Local Account',
78
+ tactic: 'discovery',
79
+ description:
80
+ 'Adversaries may attempt to get a listing of local system accounts. ' +
81
+ 'Information about local accounts can help adversaries determine which ' +
82
+ 'accounts exist on a system.',
83
+ data_sources: [
84
+ 'Command: Command Execution',
85
+ 'Process: Process Creation',
86
+ ],
87
+ },
88
+ 'T1021.001': {
89
+ name: 'Remote Desktop Protocol',
90
+ tactic: 'lateral_movement',
91
+ description:
92
+ 'Adversaries may use Valid Accounts to log into a computer using the Remote ' +
93
+ 'Desktop Protocol (RDP). The adversary may then perform actions as the logged-on user.',
94
+ data_sources: [
95
+ 'Logon Session: Logon Session Creation',
96
+ 'Network Traffic: Network Connection Creation',
97
+ 'Process: Process Creation',
98
+ ],
99
+ },
100
+ 'T1071.001': {
101
+ name: 'Web Protocols',
102
+ tactic: 'command_and_control',
103
+ description:
104
+ 'Adversaries may communicate using application layer protocols associated ' +
105
+ 'with web traffic to avoid detection. Commands to the remote system, and often ' +
106
+ 'the results of those commands, will be embedded within the protocol traffic.',
107
+ data_sources: [
108
+ 'Network Traffic: Network Traffic Content',
109
+ 'Network Traffic: Network Traffic Flow',
110
+ ],
111
+ },
112
+ 'T1055.001': {
113
+ name: 'Dynamic-link Library Injection',
114
+ tactic: 'defense_evasion',
115
+ description:
116
+ 'Adversaries may inject dynamic-link libraries (DLLs) into processes in order ' +
117
+ 'to evade process-based defenses as well as possibly elevate privileges.',
118
+ data_sources: [
119
+ 'Module: Module Load',
120
+ 'Process: OS API Execution',
121
+ 'Process: Process Access',
122
+ ],
123
+ },
124
+ 'T1027': {
125
+ name: 'Obfuscated Files or Information',
126
+ tactic: 'defense_evasion',
127
+ description:
128
+ 'Adversaries may attempt to make an executable or file difficult to discover or ' +
129
+ 'analyze by encrypting, encoding, or otherwise obfuscating its contents.',
130
+ data_sources: [
131
+ 'Command: Command Execution',
132
+ 'File: File Creation',
133
+ 'Process: Process Creation',
134
+ ],
135
+ },
136
+ 'T1070.004': {
137
+ name: 'File Deletion',
138
+ tactic: 'defense_evasion',
139
+ description:
140
+ 'Adversaries may delete files left behind by the actions of their intrusion activity. ' +
141
+ 'Malware, tools, or other non-native files dropped or created on a system may leave ' +
142
+ 'traces to indicate what was done within a network.',
143
+ data_sources: [
144
+ 'Command: Command Execution',
145
+ 'File: File Deletion',
146
+ ],
147
+ },
148
+ 'T1190': {
149
+ name: 'Exploit Public-Facing Application',
150
+ tactic: 'initial_access',
151
+ description:
152
+ 'Adversaries may attempt to exploit a weakness in an Internet-facing host or system ' +
153
+ 'to initially access a network. The weakness in the system can be a software bug, a ' +
154
+ 'temporary glitch, or a misconfiguration.',
155
+ data_sources: [
156
+ 'Application Log: Application Log Content',
157
+ 'Network Traffic: Network Traffic Content',
158
+ ],
159
+ },
160
+ 'T1078': {
161
+ name: 'Valid Accounts',
162
+ tactic: 'defense_evasion',
163
+ description:
164
+ 'Adversaries may obtain and abuse credentials of existing accounts as a means of ' +
165
+ 'gaining Initial Access, Persistence, Privilege Escalation, or Defense Evasion.',
166
+ data_sources: [
167
+ 'Logon Session: Logon Session Creation',
168
+ 'User Account: User Account Authentication',
169
+ ],
170
+ },
171
+ };
172
+
173
+ // ---------------------------------------------------------------------------
174
+ // Tool handlers
175
+ // ---------------------------------------------------------------------------
176
+
177
+ /**
178
+ * Look up a MITRE ATT&CK technique by ID.
179
+ * @param {*} context
180
+ * @param {Object} toolInput
181
+ * @returns {string}
182
+ */
183
+ export function _blueLookupTechnique(context, toolInput) {
184
+ const techniqueId = (toolInput.technique_id || '').toUpperCase();
185
+ const entry = ATTACK_TECHNIQUES[techniqueId];
186
+
187
+ if (!entry) {
188
+ return (
189
+ `Technique ${techniqueId} is not in the local lookup table. ` +
190
+ `Proceed using your own knowledge of this ATT&CK technique. ` +
191
+ `Available techniques: ${Object.keys(ATTACK_TECHNIQUES).sort().join(', ')}`
192
+ );
193
+ }
194
+
195
+ const dataSourcesStr = entry.data_sources.map(ds => ` - ${ds}`).join('\n');
196
+ return (
197
+ `ATT&CK Technique: ${techniqueId} — ${entry.name}\n` +
198
+ `Tactic: ${entry.tactic}\n` +
199
+ `Description: ${entry.description}\n` +
200
+ `Data Sources:\n${dataSourcesStr}`
201
+ );
202
+ }
203
+
204
+ /**
205
+ * Store a Sigma rule YAML string in the shared context.
206
+ * @param {*} context
207
+ * @param {Object} toolInput
208
+ * @returns {string}
209
+ */
210
+ export function _blueWriteSigmaRule(context, toolInput) {
211
+ const content = toolInput.content || '';
212
+ const filename = toolInput.filename || 'rule.yml';
213
+
214
+ if (typeof context !== 'object' || context === null) {
215
+ return "ERROR: Context must be a dict with 'rules' key.";
216
+ }
217
+
218
+ if (!context.rules) {
219
+ context.rules = [];
220
+ }
221
+
222
+ context.rules.push({ filename, content });
223
+
224
+ const ruleNum = context.rules.length;
225
+ return (
226
+ `Sigma rule stored as ${filename} (rule #${ruleNum}). ` +
227
+ `Total rules in context: ${ruleNum}.`
228
+ );
229
+ }
230
+
231
+ // ---------------------------------------------------------------------------
232
+ // Tool schemas (Anthropic format)
233
+ // ---------------------------------------------------------------------------
234
+
235
+ const _BLUE_LOOKUP_TECHNIQUE_SCHEMA = {
236
+ name: 'lookup_technique',
237
+ description:
238
+ 'Look up a MITRE ATT&CK technique by its ID (e.g. T1059.001). ' +
239
+ 'Returns technique name, tactic, description, and relevant data ' +
240
+ 'sources to help write accurate Sigma detection rules.',
241
+ input_schema: {
242
+ type: 'object',
243
+ properties: {
244
+ technique_id: {
245
+ type: 'string',
246
+ description: 'ATT&CK technique ID (e.g. T1059.001, T1190)',
247
+ },
248
+ },
249
+ required: ['technique_id'],
250
+ },
251
+ };
252
+
253
+ const _BLUE_WRITE_SIGMA_RULE_SCHEMA = {
254
+ name: 'write_sigma_rule',
255
+ description:
256
+ 'Write a completed Sigma detection rule. Pass the full YAML content ' +
257
+ 'of the rule. The rule will be stored and validated for structural correctness.',
258
+ input_schema: {
259
+ type: 'object',
260
+ properties: {
261
+ filename: {
262
+ type: 'string',
263
+ description: 'Filename for the rule (e.g. proc_creation_win_powershell.yml)',
264
+ },
265
+ content: {
266
+ type: 'string',
267
+ description: 'Full YAML content of the Sigma rule',
268
+ },
269
+ },
270
+ required: ['content'],
271
+ },
272
+ };
273
+
274
+ // ---------------------------------------------------------------------------
275
+ // System prompt template
276
+ // ---------------------------------------------------------------------------
277
+
278
+ const _BLUE_SYSTEM_PROMPT = `\
279
+ You are an expert detection engineer specializing in Sigma rule development. \
280
+ Your task is to generate high-quality Sigma detection rules for a specific \
281
+ MITRE ATT&CK technique.
282
+
283
+ ## Task
284
+ Generate Sigma detection rules for TTP: {ttp_id} — {ttp_description}
285
+
286
+ ## Sigma Rule Format Reference
287
+
288
+ Every Sigma rule MUST include these required fields:
289
+ - **title**: Descriptive name (verb + noun pattern, e.g. "Suspicious PowerShell Execution")
290
+ - **logsource**: Specifies the log data to query
291
+ - category: process_creation, network_connection, file_change, authentication, etc.
292
+ - product: windows, linux, cloud (match the appropriate platform)
293
+ - **detection**: The detection logic
294
+ - selection: Field/value matching criteria (use Sigma modifiers: |endswith, |contains, |startswith)
295
+ - condition: Boolean logic combining selections (e.g. "selection", "selection and not filter")
296
+
297
+ Recommended fields for production-quality rules:
298
+ - **id**: Random UUID for unique identification
299
+ - **status**: experimental | test | stable
300
+ - **description**: One sentence — what is detected and why it matters
301
+ - **level**: critical | high | medium | low | informational
302
+ - **tags**: ATT&CK mappings in format:
303
+ - attack.<tactic_name> (e.g. attack.execution, attack.persistence)
304
+ - attack.t<id> (e.g. attack.t1059.001) — lowercase 't', dot-separated sub-techniques
305
+ - **falsepositives**: Specific scenarios (not just "legitimate activity")
306
+
307
+ ## Logsource Guidance
308
+ - Windows process creation: category: process_creation, product: windows
309
+ - Windows network connections: category: network_connection, product: windows
310
+ - Linux file changes: category: file_change, product: linux
311
+ - Authentication events: category: authentication, product: windows|linux
312
+
313
+ ## Instructions
314
+ 1. Use the \`lookup_technique\` tool to retrieve metadata about the target TTP
315
+ 2. Based on the technique details, design one or more Sigma detection rules
316
+ 3. Use the \`write_sigma_rule\` tool to submit each completed rule
317
+ 4. Aim for detection rules that balance true positive rate with manageable false positives
318
+ 5. Include appropriate ATT&CK tags with both tactic and technique ID
319
+ `;
320
+
321
+ // ---------------------------------------------------------------------------
322
+ // Output parser (fallback for text-based output)
323
+ // ---------------------------------------------------------------------------
324
+
325
+ /**
326
+ * Extract Sigma YAML from LLM text output.
327
+ * @param {string} text
328
+ * @returns {Object}
329
+ */
330
+ export function _blueOutputParser(text) {
331
+ if (!text || !text.trim()) {
332
+ return { rules: [], raw_yaml: text };
333
+ }
334
+
335
+ // Strip code fences — findall+join pattern
336
+ const matches = [...text.matchAll(/```(?:ya?ml)?\s*\n(.*?)```/gs)].map(m => m[1]);
337
+ const yamlText = matches.length > 0 ? matches.join('\n---\n') : text;
338
+
339
+ try {
340
+ const docs = YAML.parseAllDocuments(yamlText);
341
+ const rules = docs
342
+ .map(d => d.toJSON())
343
+ .filter(d => d !== null && typeof d === 'object');
344
+ return { rules, raw_yaml: yamlText };
345
+ } catch (e) {
346
+ return { raw_text: text, parse_error: e.message };
347
+ }
348
+ }
349
+
350
+ // ---------------------------------------------------------------------------
351
+ // Factory function
352
+ // ---------------------------------------------------------------------------
353
+
354
+ /**
355
+ * Build a BLUE-mode ModeAgentConfig for detection engineering.
356
+ * @returns {ModeAgentConfig}
357
+ */
358
+ function _makeBlueConfig() {
359
+ const reg = new ToolRegistry();
360
+ reg.register('lookup_technique', _BLUE_LOOKUP_TECHNIQUE_SCHEMA, _blueLookupTechnique);
361
+ reg.register('write_sigma_rule', _BLUE_WRITE_SIGMA_RULE_SCHEMA, _blueWriteSigmaRule);
362
+
363
+ return new ModeAgentConfig({
364
+ mode: 'BLUE',
365
+ toolRegistry: reg,
366
+ systemPromptTemplate: _BLUE_SYSTEM_PROMPT,
367
+ validator: new SigmaValidator(),
368
+ maxTurns: 15,
369
+ requiresSandbox: false,
370
+ completionCheck: null,
371
+ outputParser: _blueOutputParser,
372
+ outputFormat: 'yaml',
373
+ });
374
+ }
375
+
376
+ // ---------------------------------------------------------------------------
377
+ // Registration function — called by runner.initModes()
378
+ // ---------------------------------------------------------------------------
379
+
380
+ /**
381
+ * Register BLUE mode with the given registerMode function.
382
+ * @param {Function} registerMode
383
+ */
384
+ export function register(registerMode) {
385
+ registerMode('BLUE', _makeBlueConfig);
386
+ }