hackmyagent 0.11.12 → 0.11.14
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 +16 -15
- package/dist/arp/engine/correlation.d.ts +27 -0
- package/dist/arp/engine/correlation.d.ts.map +1 -0
- package/dist/arp/engine/correlation.js +95 -0
- package/dist/arp/engine/correlation.js.map +1 -0
- package/dist/arp/engine/event-engine.d.ts +1 -0
- package/dist/arp/engine/event-engine.d.ts.map +1 -1
- package/dist/arp/engine/event-engine.js +16 -0
- package/dist/arp/engine/event-engine.js.map +1 -1
- package/dist/arp/index.d.ts +2 -0
- package/dist/arp/index.d.ts.map +1 -1
- package/dist/arp/index.js +5 -1
- package/dist/arp/index.js.map +1 -1
- package/dist/arp/intelligence/anomaly.d.ts +4 -0
- package/dist/arp/intelligence/anomaly.d.ts.map +1 -1
- package/dist/arp/intelligence/anomaly.js +71 -0
- package/dist/arp/intelligence/anomaly.js.map +1 -1
- package/dist/arp/intelligence/nanomind-l1.d.ts +72 -0
- package/dist/arp/intelligence/nanomind-l1.d.ts.map +1 -0
- package/dist/arp/intelligence/nanomind-l1.js +268 -0
- package/dist/arp/intelligence/nanomind-l1.js.map +1 -0
- package/dist/arp/monitors/network.d.ts +16 -1
- package/dist/arp/monitors/network.d.ts.map +1 -1
- package/dist/arp/monitors/network.js +55 -1
- package/dist/arp/monitors/network.js.map +1 -1
- package/dist/arp/proxy/server.d.ts +7 -0
- package/dist/arp/proxy/server.d.ts.map +1 -1
- package/dist/arp/proxy/server.js +24 -0
- package/dist/arp/proxy/server.js.map +1 -1
- package/dist/attack-engine/feedback-loop.d.ts +36 -0
- package/dist/attack-engine/feedback-loop.d.ts.map +1 -0
- package/dist/attack-engine/feedback-loop.js +261 -0
- package/dist/attack-engine/feedback-loop.js.map +1 -0
- package/dist/attack-engine/index.d.ts +13 -0
- package/dist/attack-engine/index.d.ts.map +1 -0
- package/dist/attack-engine/index.js +21 -0
- package/dist/attack-engine/index.js.map +1 -0
- package/dist/attack-engine/payload-generator.d.ts +21 -0
- package/dist/attack-engine/payload-generator.d.ts.map +1 -0
- package/dist/attack-engine/payload-generator.js +210 -0
- package/dist/attack-engine/payload-generator.js.map +1 -0
- package/dist/attack-engine/target-reader.d.ts +15 -0
- package/dist/attack-engine/target-reader.d.ts.map +1 -0
- package/dist/attack-engine/target-reader.js +152 -0
- package/dist/attack-engine/target-reader.js.map +1 -0
- package/dist/attack-engine/training-pipeline.d.ts +57 -0
- package/dist/attack-engine/training-pipeline.d.ts.map +1 -0
- package/dist/attack-engine/training-pipeline.js +146 -0
- package/dist/attack-engine/training-pipeline.js.map +1 -0
- package/dist/attack-engine/types.d.ts +133 -0
- package/dist/attack-engine/types.d.ts.map +1 -0
- package/dist/attack-engine/types.js +22 -0
- package/dist/attack-engine/types.js.map +1 -0
- package/dist/cli.js +210 -12
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/output/asff.d.ts +37 -0
- package/dist/output/asff.d.ts.map +1 -0
- package/dist/output/asff.js +112 -0
- package/dist/output/asff.js.map +1 -0
- package/dist/semantic/index.d.ts +2 -0
- package/dist/semantic/index.d.ts.map +1 -1
- package/dist/semantic/index.js +9 -1
- package/dist/semantic/index.js.map +1 -1
- package/dist/semantic/nanomind-analyzer.d.ts +77 -0
- package/dist/semantic/nanomind-analyzer.d.ts.map +1 -0
- package/dist/semantic/nanomind-analyzer.js +165 -0
- package/dist/semantic/nanomind-analyzer.js.map +1 -0
- package/dist/simulation/engine.d.ts +69 -0
- package/dist/simulation/engine.d.ts.map +1 -0
- package/dist/simulation/engine.js +297 -0
- package/dist/simulation/engine.js.map +1 -0
- package/dist/simulation/index.d.ts +15 -0
- package/dist/simulation/index.d.ts.map +1 -0
- package/dist/simulation/index.js +31 -0
- package/dist/simulation/index.js.map +1 -0
- package/dist/simulation/llm-executor.d.ts +58 -0
- package/dist/simulation/llm-executor.d.ts.map +1 -0
- package/dist/simulation/llm-executor.js +297 -0
- package/dist/simulation/llm-executor.js.map +1 -0
- package/dist/simulation/mock-tools.d.ts +35 -0
- package/dist/simulation/mock-tools.d.ts.map +1 -0
- package/dist/simulation/mock-tools.js +181 -0
- package/dist/simulation/mock-tools.js.map +1 -0
- package/dist/simulation/probes.d.ts +17 -0
- package/dist/simulation/probes.d.ts.map +1 -0
- package/dist/simulation/probes.js +295 -0
- package/dist/simulation/probes.js.map +1 -0
- package/dist/simulation/types.d.ts +79 -0
- package/dist/simulation/types.d.ts.map +1 -0
- package/dist/simulation/types.js +25 -0
- package/dist/simulation/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Target Reader -- Semantic Vulnerability Surface Extraction
|
|
4
|
+
*
|
|
5
|
+
* NanoMind reads the target artifact semantically and extracts:
|
|
6
|
+
* declared purpose, constraints, capabilities, data access patterns,
|
|
7
|
+
* governance mechanisms, and a vulnerability surface map.
|
|
8
|
+
*
|
|
9
|
+
* The attack surface is derived from the target's own declarations.
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.readTarget = readTarget;
|
|
13
|
+
/**
|
|
14
|
+
* Read a target artifact and extract its semantic vulnerability surface.
|
|
15
|
+
*/
|
|
16
|
+
function readTarget(content, artifactType, name = 'unknown') {
|
|
17
|
+
const text = content.toLowerCase();
|
|
18
|
+
// Extract declared purpose (first meaningful paragraph or description)
|
|
19
|
+
const declaredPurpose = extractPurpose(content);
|
|
20
|
+
// Extract capabilities from manifests, tool declarations, etc.
|
|
21
|
+
const capabilities = extractCapabilities(content);
|
|
22
|
+
// Extract constraints (must/should/never/always patterns)
|
|
23
|
+
const constraints = extractConstraints(content);
|
|
24
|
+
// Determine governance mechanism
|
|
25
|
+
const governanceMechanism = detectGovernance(content);
|
|
26
|
+
// Extract data access patterns
|
|
27
|
+
const dataAccessPatterns = extractDataAccess(content, capabilities);
|
|
28
|
+
// Build vulnerability surface from all extracted signals
|
|
29
|
+
const vulnerabilitySurface = buildVulnerabilitySurface(declaredPurpose, capabilities, constraints, governanceMechanism, dataAccessPatterns, text);
|
|
30
|
+
return {
|
|
31
|
+
artifactType,
|
|
32
|
+
declaredPurpose,
|
|
33
|
+
capabilities,
|
|
34
|
+
constraints,
|
|
35
|
+
governanceMechanism,
|
|
36
|
+
dataAccessPatterns,
|
|
37
|
+
vulnerabilitySurface,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function extractPurpose(content) {
|
|
41
|
+
// Check YAML frontmatter
|
|
42
|
+
const descMatch = content.match(/description:\s*(.+)/);
|
|
43
|
+
if (descMatch)
|
|
44
|
+
return descMatch[1].trim();
|
|
45
|
+
// Check first heading + paragraph
|
|
46
|
+
const lines = content.split('\n').filter(l => l.trim().length > 0);
|
|
47
|
+
for (const line of lines) {
|
|
48
|
+
if (!line.startsWith('#') && !line.startsWith('-') && !line.startsWith('---') && line.trim().length > 20) {
|
|
49
|
+
return line.trim().slice(0, 200);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return 'Unknown purpose';
|
|
53
|
+
}
|
|
54
|
+
function extractCapabilities(content) {
|
|
55
|
+
const caps = [];
|
|
56
|
+
// YAML capabilities list
|
|
57
|
+
const yamlCaps = content.match(/capabilities:\s*\n((?:\s+-\s+.+\n?)*)/);
|
|
58
|
+
if (yamlCaps) {
|
|
59
|
+
const items = yamlCaps[1].split('\n')
|
|
60
|
+
.filter(l => l.trim().startsWith('-'))
|
|
61
|
+
.map(l => l.replace(/^\s*-\s*/, '').trim());
|
|
62
|
+
caps.push(...items);
|
|
63
|
+
}
|
|
64
|
+
// Tool-use patterns in content
|
|
65
|
+
const toolPatterns = [
|
|
66
|
+
/(?:can|will|may)\s+(read|write|delete|update|send|fetch|call|access|query|execute)\s+([a-z_.\s]+)/gi,
|
|
67
|
+
];
|
|
68
|
+
for (const pattern of toolPatterns) {
|
|
69
|
+
let match;
|
|
70
|
+
while ((match = pattern.exec(content)) !== null) {
|
|
71
|
+
caps.push(`${match[1]}.${match[2].trim().split(/\s+/)[0]}`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return [...new Set(caps)];
|
|
75
|
+
}
|
|
76
|
+
function extractConstraints(content) {
|
|
77
|
+
const patterns = /(?:must|should|never|always|cannot|will not|forbidden|shall not|restricted)[^.]+\./gi;
|
|
78
|
+
const matches = content.match(patterns);
|
|
79
|
+
return matches ? [...new Set(matches.map(m => m.trim()))] : [];
|
|
80
|
+
}
|
|
81
|
+
function detectGovernance(content) {
|
|
82
|
+
if (/soul\.md/i.test(content))
|
|
83
|
+
return 'soul';
|
|
84
|
+
if (/system.?prompt/i.test(content))
|
|
85
|
+
return 'system_prompt';
|
|
86
|
+
if (/runtime.?check|enforcement/i.test(content))
|
|
87
|
+
return 'runtime_check';
|
|
88
|
+
return 'none';
|
|
89
|
+
}
|
|
90
|
+
function extractDataAccess(content, capabilities) {
|
|
91
|
+
const patterns = [];
|
|
92
|
+
const dataTypes = ['user', 'customer', 'payment', 'session', 'credential', 'email', 'profile', 'ticket', 'order', 'transaction'];
|
|
93
|
+
for (const dt of dataTypes) {
|
|
94
|
+
if (content.toLowerCase().includes(dt)) {
|
|
95
|
+
patterns.push(dt);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return patterns;
|
|
99
|
+
}
|
|
100
|
+
function buildVulnerabilitySurface(purpose, capabilities, constraints, governance, dataAccess, text) {
|
|
101
|
+
const surface = [];
|
|
102
|
+
// Each capability is a potential attack surface
|
|
103
|
+
for (const cap of capabilities) {
|
|
104
|
+
if (/write|send|call|execute|delete/i.test(cap)) {
|
|
105
|
+
surface.push({
|
|
106
|
+
surface: `Capability: ${cap}`,
|
|
107
|
+
exploitApproach: `Exploit ${cap} to perform actions outside declared scope`,
|
|
108
|
+
attackCategory: 'capability_abuse',
|
|
109
|
+
estimatedSuccess: 0.3,
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Each constraint is a potential bypass surface
|
|
114
|
+
for (const constraint of constraints) {
|
|
115
|
+
if (/never|must not|forbidden/i.test(constraint)) {
|
|
116
|
+
surface.push({
|
|
117
|
+
surface: `Constraint: ${constraint.slice(0, 80)}`,
|
|
118
|
+
exploitApproach: 'Craft input that satisfies constraint wording while violating intent',
|
|
119
|
+
attackCategory: 'soul_bypass',
|
|
120
|
+
estimatedSuccess: 0.4,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// Data access creates exfiltration surface
|
|
125
|
+
if (dataAccess.length > 0) {
|
|
126
|
+
surface.push({
|
|
127
|
+
surface: `Data access: ${dataAccess.join(', ')}`,
|
|
128
|
+
exploitApproach: 'Social engineering using the target\'s own data domain',
|
|
129
|
+
attackCategory: 'social_engineering',
|
|
130
|
+
estimatedSuccess: 0.5,
|
|
131
|
+
});
|
|
132
|
+
if (dataAccess.some(d => ['credential', 'session', 'payment'].includes(d))) {
|
|
133
|
+
surface.push({
|
|
134
|
+
surface: `Sensitive data: ${dataAccess.filter(d => ['credential', 'session', 'payment'].includes(d)).join(', ')}`,
|
|
135
|
+
exploitApproach: 'Exfiltrate sensitive data via compliance framing',
|
|
136
|
+
attackCategory: 'data_exfiltration',
|
|
137
|
+
estimatedSuccess: 0.4,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
// Weak governance
|
|
142
|
+
if (governance === 'none') {
|
|
143
|
+
surface.push({
|
|
144
|
+
surface: 'No governance mechanism detected',
|
|
145
|
+
exploitApproach: 'Direct instruction override without governance resistance',
|
|
146
|
+
attackCategory: 'instruction_override',
|
|
147
|
+
estimatedSuccess: 0.7,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return surface;
|
|
151
|
+
}
|
|
152
|
+
//# sourceMappingURL=target-reader.js.map
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ACtB,CAAC,CAAC;QAEH,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC3E,OAAO,CAAC,IAAI,CAAC;gBACX,OAAO,EAAE,mBAAmB,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,YAAY,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;gBACjH,eAAe,EAAE,kDAAkD;gBACnE,cAAc,EAAE,mBAAmB;gBACnC,gBAAgB,EAAE,GAAG;aACtB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;IAED,kBAAkB;IAClB,IAAI,UAAU,KAAK,MAAM,EAAE,CAAC;QAC1B,OAAO,CAAC,IAAI,CAAC;YACX,OAAO,EAAE,kCAAkC;YAC3C,eAAe,EAAE,2DAA2D;YAC5E,cAAc,EAAE,sBAAsB;YACtC,gBAAgB,EAAE,GAAG;SACtB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automated Training Data Pipeline
|
|
3
|
+
*
|
|
4
|
+
* Every HMA scan with --semantic or --simulate flags automatically
|
|
5
|
+
* generates labeled training data for NanoMind. This closes the
|
|
6
|
+
* improvement loop: scan -> observe -> label -> train -> improve.
|
|
7
|
+
*
|
|
8
|
+
* Training data is written to ~/.opena2a/training-data/ as JSONL files.
|
|
9
|
+
* The NanoMind training pipeline reads from this directory during
|
|
10
|
+
* SFT (supervised fine-tuning) stages.
|
|
11
|
+
*/
|
|
12
|
+
import type { AttackSessionResult } from './types.js';
|
|
13
|
+
import type { SimulationResult } from '../simulation/types.js';
|
|
14
|
+
export interface TrainingPair {
|
|
15
|
+
/** The artifact content that was scanned/attacked */
|
|
16
|
+
input: string;
|
|
17
|
+
/** Ground truth label */
|
|
18
|
+
label: 'malicious' | 'benign' | 'edge_case' | 'defense';
|
|
19
|
+
/** Attack class (for malicious) or defense mechanism (for defense) */
|
|
20
|
+
attackClass: string;
|
|
21
|
+
/** Behavioral evidence from simulation or attack */
|
|
22
|
+
evidence: string;
|
|
23
|
+
/** Confidence in the label (0-1) */
|
|
24
|
+
confidence: number;
|
|
25
|
+
/** Source of this training pair */
|
|
26
|
+
source: 'simulation' | 'attack_session' | 'scan';
|
|
27
|
+
/** When this pair was generated */
|
|
28
|
+
timestamp: string;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Initialize the training data directory.
|
|
32
|
+
*/
|
|
33
|
+
export declare function initTrainingPipeline(): void;
|
|
34
|
+
/**
|
|
35
|
+
* Export simulation results as training data.
|
|
36
|
+
* CLEAN simulations -> benign labels. MALICIOUS -> malicious labels.
|
|
37
|
+
*/
|
|
38
|
+
export declare function exportSimulationTraining(artifactContent: string, result: SimulationResult): number;
|
|
39
|
+
/**
|
|
40
|
+
* Export attack session results as training data.
|
|
41
|
+
* Successful attacks -> malicious behavior. Failed attacks -> defense patterns.
|
|
42
|
+
*/
|
|
43
|
+
export declare function exportAttackTraining(session: AttackSessionResult): number;
|
|
44
|
+
/**
|
|
45
|
+
* Export a single scan result as training data.
|
|
46
|
+
* Used by the --semantic flag when NanoMind classifies a finding.
|
|
47
|
+
*/
|
|
48
|
+
export declare function exportScanTraining(artifactContent: string, label: 'malicious' | 'benign', attackClass: string, confidence: number): void;
|
|
49
|
+
/**
|
|
50
|
+
* Get training data statistics.
|
|
51
|
+
*/
|
|
52
|
+
export declare function getTrainingStats(): {
|
|
53
|
+
totalPairs: number;
|
|
54
|
+
corpusPath: string;
|
|
55
|
+
exists: boolean;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=training-pipeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"training-pipeline.d.ts","sourceRoot":"","sources":["../../src/attack-engine/training-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAKH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAM/D,MAAM,WAAW,YAAY;IAC3B,qDAAqD;IACrD,KAAK,EAAE,MAAM,CAAC;IACd,yBAAyB;IACzB,KAAK,EAAE,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,SAAS,CAAC;IACxD,sEAAsE;IACtE,WAAW,EAAE,MAAM,CAAC;IACpB,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,oCAAoC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,mCAAmC;IACnC,MAAM,EAAE,YAAY,GAAG,gBAAgB,GAAG,MAAM,CAAC;IACjD,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAW3C;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CACtC,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,gBAAgB,GACvB,MAAM,CA+BR;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,mBAAmB,GAAG,MAAM,CA+BzE;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,eAAe,EAAE,MAAM,EACvB,KAAK,EAAE,WAAW,GAAG,QAAQ,EAC7B,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,GACjB,IAAI,CAYN;AASD;;GAEG;AACH,wBAAgB,gBAAgB,IAAI;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,OAAO,CAAC;CACjB,CAYA"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Automated Training Data Pipeline
|
|
4
|
+
*
|
|
5
|
+
* Every HMA scan with --semantic or --simulate flags automatically
|
|
6
|
+
* generates labeled training data for NanoMind. This closes the
|
|
7
|
+
* improvement loop: scan -> observe -> label -> train -> improve.
|
|
8
|
+
*
|
|
9
|
+
* Training data is written to ~/.opena2a/training-data/ as JSONL files.
|
|
10
|
+
* The NanoMind training pipeline reads from this directory during
|
|
11
|
+
* SFT (supervised fine-tuning) stages.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.initTrainingPipeline = initTrainingPipeline;
|
|
15
|
+
exports.exportSimulationTraining = exportSimulationTraining;
|
|
16
|
+
exports.exportAttackTraining = exportAttackTraining;
|
|
17
|
+
exports.exportScanTraining = exportScanTraining;
|
|
18
|
+
exports.getTrainingStats = getTrainingStats;
|
|
19
|
+
const node_fs_1 = require("node:fs");
|
|
20
|
+
const node_path_1 = require("node:path");
|
|
21
|
+
const node_os_1 = require("node:os");
|
|
22
|
+
const TRAINING_DIR = (0, node_path_1.join)((0, node_os_1.homedir)(), '.opena2a', 'training-data');
|
|
23
|
+
const CORPUS_FILE = (0, node_path_1.join)(TRAINING_DIR, 'labeled-pairs.jsonl');
|
|
24
|
+
const MANIFEST_FILE = (0, node_path_1.join)(TRAINING_DIR, 'manifest.json');
|
|
25
|
+
/**
|
|
26
|
+
* Initialize the training data directory.
|
|
27
|
+
*/
|
|
28
|
+
function initTrainingPipeline() {
|
|
29
|
+
(0, node_fs_1.mkdirSync)(TRAINING_DIR, { recursive: true });
|
|
30
|
+
if (!(0, node_fs_1.existsSync)(MANIFEST_FILE)) {
|
|
31
|
+
(0, node_fs_1.writeFileSync)(MANIFEST_FILE, JSON.stringify({
|
|
32
|
+
version: '1.0',
|
|
33
|
+
createdAt: new Date().toISOString(),
|
|
34
|
+
totalPairs: 0,
|
|
35
|
+
pairsByLabel: { malicious: 0, benign: 0, edge_case: 0, defense: 0 },
|
|
36
|
+
pairsBySource: { simulation: 0, attack_session: 0, scan: 0 },
|
|
37
|
+
}, null, 2));
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Export simulation results as training data.
|
|
42
|
+
* CLEAN simulations -> benign labels. MALICIOUS -> malicious labels.
|
|
43
|
+
*/
|
|
44
|
+
function exportSimulationTraining(artifactContent, result) {
|
|
45
|
+
initTrainingPipeline();
|
|
46
|
+
let count = 0;
|
|
47
|
+
if (result.verdict === 'CLEAN') {
|
|
48
|
+
appendPair({
|
|
49
|
+
input: artifactContent.slice(0, 4096),
|
|
50
|
+
label: 'benign',
|
|
51
|
+
attackClass: 'none',
|
|
52
|
+
evidence: `All ${result.probeCount} probes passed. Semantic delta: ${result.semanticDelta.toFixed(2)}.`,
|
|
53
|
+
confidence: result.confidence,
|
|
54
|
+
source: 'simulation',
|
|
55
|
+
timestamp: new Date().toISOString(),
|
|
56
|
+
});
|
|
57
|
+
count++;
|
|
58
|
+
}
|
|
59
|
+
else if (result.verdict === 'MALICIOUS') {
|
|
60
|
+
for (const probe of result.failedProbes) {
|
|
61
|
+
appendPair({
|
|
62
|
+
input: artifactContent.slice(0, 4096),
|
|
63
|
+
label: 'malicious',
|
|
64
|
+
attackClass: probe.attackClass,
|
|
65
|
+
evidence: probe.observedBehavior,
|
|
66
|
+
confidence: probe.confidence,
|
|
67
|
+
source: 'simulation',
|
|
68
|
+
timestamp: new Date().toISOString(),
|
|
69
|
+
});
|
|
70
|
+
count++;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return count;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Export attack session results as training data.
|
|
77
|
+
* Successful attacks -> malicious behavior. Failed attacks -> defense patterns.
|
|
78
|
+
*/
|
|
79
|
+
function exportAttackTraining(session) {
|
|
80
|
+
initTrainingPipeline();
|
|
81
|
+
let count = 0;
|
|
82
|
+
for (const result of session.results) {
|
|
83
|
+
if (result.outcome === 'SUCCESS') {
|
|
84
|
+
appendPair({
|
|
85
|
+
input: result.observedBehavior,
|
|
86
|
+
label: 'malicious',
|
|
87
|
+
attackClass: result.category,
|
|
88
|
+
evidence: `Attack succeeded: ${result.payloadId}`,
|
|
89
|
+
confidence: result.confidence,
|
|
90
|
+
source: 'attack_session',
|
|
91
|
+
timestamp: new Date().toISOString(),
|
|
92
|
+
});
|
|
93
|
+
count++;
|
|
94
|
+
}
|
|
95
|
+
else if (result.outcome === 'FAIL' && result.defenseMechanism) {
|
|
96
|
+
appendPair({
|
|
97
|
+
input: result.observedBehavior,
|
|
98
|
+
label: 'defense',
|
|
99
|
+
attackClass: result.category,
|
|
100
|
+
evidence: `Defense held: ${result.defenseMechanism}`,
|
|
101
|
+
confidence: result.confidence,
|
|
102
|
+
source: 'attack_session',
|
|
103
|
+
timestamp: new Date().toISOString(),
|
|
104
|
+
});
|
|
105
|
+
count++;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return count;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Export a single scan result as training data.
|
|
112
|
+
* Used by the --semantic flag when NanoMind classifies a finding.
|
|
113
|
+
*/
|
|
114
|
+
function exportScanTraining(artifactContent, label, attackClass, confidence) {
|
|
115
|
+
initTrainingPipeline();
|
|
116
|
+
appendPair({
|
|
117
|
+
input: artifactContent.slice(0, 4096),
|
|
118
|
+
label,
|
|
119
|
+
attackClass,
|
|
120
|
+
evidence: `NanoMind semantic classification`,
|
|
121
|
+
confidence,
|
|
122
|
+
source: 'scan',
|
|
123
|
+
timestamp: new Date().toISOString(),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Append a training pair to the JSONL corpus file.
|
|
128
|
+
*/
|
|
129
|
+
function appendPair(pair) {
|
|
130
|
+
(0, node_fs_1.appendFileSync)(CORPUS_FILE, JSON.stringify(pair) + '\n');
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Get training data statistics.
|
|
134
|
+
*/
|
|
135
|
+
function getTrainingStats() {
|
|
136
|
+
const exists = (0, node_fs_1.existsSync)(CORPUS_FILE);
|
|
137
|
+
if (!exists) {
|
|
138
|
+
return { totalPairs: 0, corpusPath: CORPUS_FILE, exists: false };
|
|
139
|
+
}
|
|
140
|
+
// Count lines (each line = one training pair)
|
|
141
|
+
const { readFileSync } = require('node:fs');
|
|
142
|
+
const content = readFileSync(CORPUS_FILE, 'utf-8');
|
|
143
|
+
const lines = content.split('\n').filter((l) => l.trim().length > 0);
|
|
144
|
+
return { totalPairs: lines.length, corpusPath: CORPUS_FILE, exists: true };
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=training-pipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"training-pipeline.js","sourceRoot":"","sources":["../../src/attack-engine/training-pipeline.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;GAUG;;AAgCH,oDAWC;AAMD,4DAkCC;AAMD,oDA+BC;AAMD,gDAiBC;AAYD,4CAgBC;AAzKD,qCAA+E;AAC/E,yCAAiC;AACjC,qCAAkC;AAIlC,MAAM,YAAY,GAAG,IAAA,gBAAI,EAAC,IAAA,iBAAO,GAAE,EAAE,UAAU,EAAE,eAAe,CAAC,CAAC;AAClE,MAAM,WAAW,GAAG,IAAA,gBAAI,EAAC,YAAY,EAAE,qBAAqB,CAAC,CAAC;AAC9D,MAAM,aAAa,GAAG,IAAA,gBAAI,EAAC,YAAY,EAAE,eAAe,CAAC,CAAC;AAmB1D;;GAEG;AACH,SAAgB,oBAAoB;IAClC,IAAA,mBAAS,EAAC,YAAY,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,IAAI,CAAC,IAAA,oBAAU,EAAC,aAAa,CAAC,EAAE,CAAC;QAC/B,IAAA,uBAAa,EAAC,aAAa,EAAE,IAAI,CAAC,SAAS,CAAC;YAC1C,OAAO,EAAE,KAAK;YACd,SAAS,EAAE,IAAI,IA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@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HMA Adaptive Attack Engine Types
|
|
3
|
+
*
|
|
4
|
+
* NanoMind-powered red team agent that generates target-specific
|
|
5
|
+
* attack payloads, observes responses, adapts, and iterates.
|
|
6
|
+
*/
|
|
7
|
+
export interface SemanticTargetProfile {
|
|
8
|
+
/** Artifact type being targeted */
|
|
9
|
+
artifactType: 'skill' | 'soul' | 'mcp_tool' | 'mcp_server' | 'system_prompt' | 'a2a_card';
|
|
10
|
+
/** What the target claims to do */
|
|
11
|
+
declaredPurpose: string;
|
|
12
|
+
/** Tools and resources the target can access */
|
|
13
|
+
capabilities: string[];
|
|
14
|
+
/** How the target phrases its limitations */
|
|
15
|
+
constraints: string[];
|
|
16
|
+
/** How governance is enforced */
|
|
17
|
+
governanceMechanism: string;
|
|
18
|
+
/** Data types the target regularly touches */
|
|
19
|
+
dataAccessPatterns: string[];
|
|
20
|
+
/** Specific vulnerability surface identified by NanoMind */
|
|
21
|
+
vulnerabilitySurface: VulnerabilitySurfaceEntry[];
|
|
22
|
+
}
|
|
23
|
+
export interface VulnerabilitySurfaceEntry {
|
|
24
|
+
/** Which aspect of the target is vulnerable */
|
|
25
|
+
surface: string;
|
|
26
|
+
/** How the vulnerability could be exploited */
|
|
27
|
+
exploitApproach: string;
|
|
28
|
+
/** Which attack category this maps to */
|
|
29
|
+
attackCategory: AttackCategory;
|
|
30
|
+
/** Estimated likelihood of success (0-1) */
|
|
31
|
+
estimatedSuccess: number;
|
|
32
|
+
}
|
|
33
|
+
export type AttackCategory = 'prompt_injection' | 'data_exfiltration' | 'privilege_escalation' | 'social_engineering' | 'instruction_override' | 'memory_poisoning' | 'soul_bypass' | 'indirect_injection' | 'capability_abuse' | 'persistence' | 'semantic_mismatch';
|
|
34
|
+
export interface AdaptivePayload {
|
|
35
|
+
id: string;
|
|
36
|
+
category: AttackCategory;
|
|
37
|
+
/** The actual attack input to inject */
|
|
38
|
+
input: string;
|
|
39
|
+
/** Why this payload was generated for this specific target */
|
|
40
|
+
rationale: string;
|
|
41
|
+
/** Which vulnerability surface entry this targets */
|
|
42
|
+
targetsSurface: string;
|
|
43
|
+
/** Iteration number (1 = first attempt) */
|
|
44
|
+
iteration: number;
|
|
45
|
+
/** If iteration > 1, what defense was detected and how this variant adapts */
|
|
46
|
+
adaptsTo?: string;
|
|
47
|
+
}
|
|
48
|
+
export type AttackOutcome = 'SUCCESS' | 'PARTIAL' | 'FAIL';
|
|
49
|
+
export interface AttackResult {
|
|
50
|
+
payloadId: string;
|
|
51
|
+
category: AttackCategory;
|
|
52
|
+
outcome: AttackOutcome;
|
|
53
|
+
/** What the target actually did in response */
|
|
54
|
+
observedBehavior: string;
|
|
55
|
+
/** Defense mechanism detected (if FAIL) */
|
|
56
|
+
defenseMechanism?: string;
|
|
57
|
+
/** How strong the defense is (0-1) */
|
|
58
|
+
defenseStrength?: number;
|
|
59
|
+
/** Tool calls observed during the attack */
|
|
60
|
+
toolCalls: Array<{
|
|
61
|
+
tool: string;
|
|
62
|
+
args: Record<string, unknown>;
|
|
63
|
+
}>;
|
|
64
|
+
/** Confidence in the outcome classification */
|
|
65
|
+
confidence: number;
|
|
66
|
+
}
|
|
67
|
+
export interface DefenseMap {
|
|
68
|
+
/** All defenses discovered during the attack session */
|
|
69
|
+
defenses: DefenseEntry[];
|
|
70
|
+
/** Overall resilience score (0-1, 1 = all attacks blocked) */
|
|
71
|
+
resilienceScore: number;
|
|
72
|
+
/** Categories where defenses held */
|
|
73
|
+
strongCategories: AttackCategory[];
|
|
74
|
+
/** Categories where defenses failed */
|
|
75
|
+
weakCategories: AttackCategory[];
|
|
76
|
+
}
|
|
77
|
+
export interface DefenseEntry {
|
|
78
|
+
mechanism: string;
|
|
79
|
+
category: AttackCategory;
|
|
80
|
+
strength: number;
|
|
81
|
+
bypassAttempts: number;
|
|
82
|
+
bypassSuccesses: number;
|
|
83
|
+
/** What the target did to enforce this defense */
|
|
84
|
+
enforcement: string;
|
|
85
|
+
}
|
|
86
|
+
export interface AttackSessionResult {
|
|
87
|
+
/** Target profile that was attacked */
|
|
88
|
+
target: SemanticTargetProfile;
|
|
89
|
+
/** All attack results across all iterations */
|
|
90
|
+
results: AttackResult[];
|
|
91
|
+
/** Total payloads generated */
|
|
92
|
+
totalPayloads: number;
|
|
93
|
+
/** Total successful attacks */
|
|
94
|
+
successCount: number;
|
|
95
|
+
/** Total partial successes */
|
|
96
|
+
partialCount: number;
|
|
97
|
+
/** Defense map discovered */
|
|
98
|
+
defenseMap: DefenseMap;
|
|
99
|
+
/** Duration of the full attack session */
|
|
100
|
+
durationMs: number;
|
|
101
|
+
/** Vulnerabilities found with specific remediation */
|
|
102
|
+
vulnerabilities: VulnerabilityFinding[];
|
|
103
|
+
}
|
|
104
|
+
export interface VulnerabilityFinding {
|
|
105
|
+
category: AttackCategory;
|
|
106
|
+
severity: 'critical' | 'high' | 'medium' | 'low';
|
|
107
|
+
title: string;
|
|
108
|
+
description: string;
|
|
109
|
+
/** The exact attack input that triggered it */
|
|
110
|
+
triggerInput: string;
|
|
111
|
+
/** What defense was bypassed */
|
|
112
|
+
defenseBypass: string;
|
|
113
|
+
/** Specific fix (not generic) */
|
|
114
|
+
remediation: string;
|
|
115
|
+
/** Confidence based on reproduction count */
|
|
116
|
+
confidence: number;
|
|
117
|
+
/** How many attack iterations confirmed this */
|
|
118
|
+
reproductions: number;
|
|
119
|
+
}
|
|
120
|
+
export interface AttackEngineConfig {
|
|
121
|
+
/** Max iterations per attack category (default: 5) */
|
|
122
|
+
maxIterations: number;
|
|
123
|
+
/** Max total payloads per session (default: 50) */
|
|
124
|
+
maxPayloads: number;
|
|
125
|
+
/** Timeout per individual attack in ms (default: 5000) */
|
|
126
|
+
attackTimeoutMs: number;
|
|
127
|
+
/** Which attack categories to run (default: all 11) */
|
|
128
|
+
categories: AttackCategory[];
|
|
129
|
+
/** LLM provider for payload generation */
|
|
130
|
+
llmProvider: 'nanomind-daemon' | 'anthropic' | 'ollama';
|
|
131
|
+
}
|
|
132
|
+
export declare const DEFAULT_ATTACK_CONFIG: AttackEngineConfig;
|
|
133
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/attack-engine/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,MAAM,WAAW,qBAAqB;IACpC,mCAAmC;IACnC,YAAY,EAAE,OAAO,GAAG,MAAM,GAAG,UAAU,GAAG,YAAY,GAAG,eAAe,GAAG,UAAU,CAAC;IAC1F,mCAAmC;IACnC,eAAe,EAAE,MAAM,CAAC;IACxB,gDAAgD;IAChD,YAAY,EAAE,MAAM,EAAE,CAAC;IACvB,6CAA6C;IAC7C,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,iCAAiC;IACjC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,8CAA8C;IAC9C,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,4DAA4D;IAC5D,oBAAoB,EAAE,yBAAyB,EAAE,CAAC;CACnD;AAED,MAAM,WAAW,yBAAyB;IACxC,+CAA+C;IAC/C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,eAAe,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,cAAc,EAAE,cAAc,CAAC;IAC/B,4CAA4C;IAC5C,gBAAgB,EAAE,MAAM,CAAC;CAC1B;AAMD,MAAM,MAAM,cAAc,GACtB,kBAAkB,GAClB,mBAAmB,GACnB,sBAAsB,GACtB,oBAAoB,GACpB,sBAAsB,GACtB,kBAAkB,GAClB,aAAa,GACb,oBAAoB,GACpB,kBAAkB,GAClB,aAAa,GACb,mBAAmB,CAAC;AAMxB,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,cAAc,CAAC;IACzB,wCAAwC;IACxC,KAAK,EAAE,MAAM,CAAC;IACd,8DAA8D;IAC9D,SAAS,EAAE,MA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team agent that generates target-specific
|
|
6
|
+
* attack payloads, observes responses, adapts, and iterates.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.DEFAULT_ATTACK_CONFIG = void 0;
|
|
10
|
+
exports.DEFAULT_ATTACK_CONFIG = {
|
|
11
|
+
maxIterations: 5,
|
|
12
|
+
maxPayloads: 50,
|
|
13
|
+
attackTimeoutMs: 5000,
|
|
14
|
+
categories: [
|
|
15
|
+
'prompt_injection', 'data_exfiltration', 'privilege_escalation',
|
|
16
|
+
'social_engineering', 'instruction_override', 'memory_poisoning',
|
|
17
|
+
'soul_bypass', 'indirect_injection', 'capability_abuse',
|
|
18
|
+
'persistence', 'semantic_mismatch',
|
|
19
|
+
],
|
|
20
|
+
llmProvider: 'nanomind-daemon',
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/attack-engine/types.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AA8KU,QAAA,qBAAqB,GAAuB;IACvD,aAAa,EAAE,CAAC;IAChB,WAAW,EAAE,EAAE;IACf,eAAe,EAAE,IAAI;IACrB,UAAU,EAAE;QACV,kBAAkB,EAAE,mBAAmB,EAAE,sBAAsB;QAC/D,oBAAoB,EAAE,sBAAsB,EAAE,kBAAkB;QAChE,aAAa,EAAE,oBAAoB,EAAE,kBAAkB;QACvD,aAAa,EAAE,mBAAmB;KACnC;IACD,WAAW,EAAE,iBAAiB;CAC/B,CAAC"}
|