windows-exe-decompiler-mcp-server 0.1.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.
- package/CODEX_INSTALLATION.md +69 -0
- package/COPILOT_INSTALLATION.md +77 -0
- package/LICENSE +21 -0
- package/README.md +314 -0
- package/bin/windows-exe-decompiler-mcp-server.js +3 -0
- package/dist/analysis-provenance.d.ts +184 -0
- package/dist/analysis-provenance.js +74 -0
- package/dist/analysis-task-runner.d.ts +31 -0
- package/dist/analysis-task-runner.js +160 -0
- package/dist/artifact-inventory.d.ts +23 -0
- package/dist/artifact-inventory.js +175 -0
- package/dist/cache-manager.d.ts +128 -0
- package/dist/cache-manager.js +454 -0
- package/dist/confidence-semantics.d.ts +66 -0
- package/dist/confidence-semantics.js +122 -0
- package/dist/config.d.ts +335 -0
- package/dist/config.js +193 -0
- package/dist/database.d.ts +227 -0
- package/dist/database.js +601 -0
- package/dist/decompiler-worker.d.ts +441 -0
- package/dist/decompiler-worker.js +1962 -0
- package/dist/dynamic-trace.d.ts +95 -0
- package/dist/dynamic-trace.js +629 -0
- package/dist/env-validator.d.ts +15 -0
- package/dist/env-validator.js +249 -0
- package/dist/error-handler.d.ts +28 -0
- package/dist/error-handler.example.d.ts +22 -0
- package/dist/error-handler.example.js +141 -0
- package/dist/error-handler.js +139 -0
- package/dist/ghidra-analysis-status.d.ts +49 -0
- package/dist/ghidra-analysis-status.js +178 -0
- package/dist/ghidra-config.d.ts +134 -0
- package/dist/ghidra-config.js +464 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +200 -0
- package/dist/job-queue.d.ts +169 -0
- package/dist/job-queue.js +407 -0
- package/dist/logger.d.ts +106 -0
- package/dist/logger.js +176 -0
- package/dist/policy-guard.d.ts +115 -0
- package/dist/policy-guard.js +243 -0
- package/dist/process-output.d.ts +15 -0
- package/dist/process-output.js +90 -0
- package/dist/prompts/function-explanation-review.d.ts +5 -0
- package/dist/prompts/function-explanation-review.js +64 -0
- package/dist/prompts/semantic-name-review.d.ts +5 -0
- package/dist/prompts/semantic-name-review.js +63 -0
- package/dist/runtime-correlation.d.ts +34 -0
- package/dist/runtime-correlation.js +279 -0
- package/dist/runtime-paths.d.ts +3 -0
- package/dist/runtime-paths.js +11 -0
- package/dist/selection-diff.d.ts +667 -0
- package/dist/selection-diff.js +53 -0
- package/dist/semantic-name-suggestion-artifacts.d.ts +116 -0
- package/dist/semantic-name-suggestion-artifacts.js +314 -0
- package/dist/server.d.ts +129 -0
- package/dist/server.js +578 -0
- package/dist/tools/artifact-read.d.ts +235 -0
- package/dist/tools/artifact-read.js +317 -0
- package/dist/tools/artifacts-diff.d.ts +728 -0
- package/dist/tools/artifacts-diff.js +304 -0
- package/dist/tools/artifacts-list.d.ts +515 -0
- package/dist/tools/artifacts-list.js +389 -0
- package/dist/tools/attack-map.d.ts +290 -0
- package/dist/tools/attack-map.js +519 -0
- package/dist/tools/cache-observability.d.ts +4 -0
- package/dist/tools/cache-observability.js +36 -0
- package/dist/tools/code-function-cfg.d.ts +50 -0
- package/dist/tools/code-function-cfg.js +102 -0
- package/dist/tools/code-function-decompile.d.ts +55 -0
- package/dist/tools/code-function-decompile.js +103 -0
- package/dist/tools/code-function-disassemble.d.ts +43 -0
- package/dist/tools/code-function-disassemble.js +185 -0
- package/dist/tools/code-function-explain-apply.d.ts +255 -0
- package/dist/tools/code-function-explain-apply.js +225 -0
- package/dist/tools/code-function-explain-prepare.d.ts +535 -0
- package/dist/tools/code-function-explain-prepare.js +276 -0
- package/dist/tools/code-function-explain-review.d.ts +397 -0
- package/dist/tools/code-function-explain-review.js +589 -0
- package/dist/tools/code-function-rename-apply.d.ts +248 -0
- package/dist/tools/code-function-rename-apply.js +220 -0
- package/dist/tools/code-function-rename-prepare.d.ts +506 -0
- package/dist/tools/code-function-rename-prepare.js +279 -0
- package/dist/tools/code-function-rename-review.d.ts +574 -0
- package/dist/tools/code-function-rename-review.js +761 -0
- package/dist/tools/code-functions-list.d.ts +37 -0
- package/dist/tools/code-functions-list.js +91 -0
- package/dist/tools/code-functions-rank.d.ts +34 -0
- package/dist/tools/code-functions-rank.js +90 -0
- package/dist/tools/code-functions-reconstruct.d.ts +2725 -0
- package/dist/tools/code-functions-reconstruct.js +2807 -0
- package/dist/tools/code-functions-search.d.ts +39 -0
- package/dist/tools/code-functions-search.js +90 -0
- package/dist/tools/code-reconstruct-export.d.ts +1212 -0
- package/dist/tools/code-reconstruct-export.js +4002 -0
- package/dist/tools/code-reconstruct-plan.d.ts +274 -0
- package/dist/tools/code-reconstruct-plan.js +342 -0
- package/dist/tools/dotnet-metadata-extract.d.ts +541 -0
- package/dist/tools/dotnet-metadata-extract.js +355 -0
- package/dist/tools/dotnet-reconstruct-export.d.ts +567 -0
- package/dist/tools/dotnet-reconstruct-export.js +1151 -0
- package/dist/tools/dotnet-types-list.d.ts +325 -0
- package/dist/tools/dotnet-types-list.js +201 -0
- package/dist/tools/dynamic-dependencies.d.ts +115 -0
- package/dist/tools/dynamic-dependencies.js +213 -0
- package/dist/tools/dynamic-memory-import.d.ts +10 -0
- package/dist/tools/dynamic-memory-import.js +567 -0
- package/dist/tools/dynamic-trace-import.d.ts +10 -0
- package/dist/tools/dynamic-trace-import.js +235 -0
- package/dist/tools/entrypoint-fallback-disasm.d.ts +30 -0
- package/dist/tools/entrypoint-fallback-disasm.js +89 -0
- package/dist/tools/ghidra-analyze.d.ts +88 -0
- package/dist/tools/ghidra-analyze.js +208 -0
- package/dist/tools/ghidra-health.d.ts +37 -0
- package/dist/tools/ghidra-health.js +212 -0
- package/dist/tools/ioc-export.d.ts +209 -0
- package/dist/tools/ioc-export.js +542 -0
- package/dist/tools/packer-detect.d.ts +165 -0
- package/dist/tools/packer-detect.js +284 -0
- package/dist/tools/pe-exports-extract.d.ts +175 -0
- package/dist/tools/pe-exports-extract.js +253 -0
- package/dist/tools/pe-fingerprint.d.ts +234 -0
- package/dist/tools/pe-fingerprint.js +269 -0
- package/dist/tools/pe-imports-extract.d.ts +105 -0
- package/dist/tools/pe-imports-extract.js +245 -0
- package/dist/tools/report-generate.d.ts +157 -0
- package/dist/tools/report-generate.js +457 -0
- package/dist/tools/report-summarize.d.ts +2131 -0
- package/dist/tools/report-summarize.js +596 -0
- package/dist/tools/runtime-detect.d.ts +135 -0
- package/dist/tools/runtime-detect.js +247 -0
- package/dist/tools/sample-ingest.d.ts +94 -0
- package/dist/tools/sample-ingest.js +327 -0
- package/dist/tools/sample-profile-get.d.ts +183 -0
- package/dist/tools/sample-profile-get.js +121 -0
- package/dist/tools/sandbox-execute.d.ts +441 -0
- package/dist/tools/sandbox-execute.js +392 -0
- package/dist/tools/strings-extract.d.ts +375 -0
- package/dist/tools/strings-extract.js +314 -0
- package/dist/tools/strings-floss-decode.d.ts +143 -0
- package/dist/tools/strings-floss-decode.js +259 -0
- package/dist/tools/system-health.d.ts +434 -0
- package/dist/tools/system-health.js +446 -0
- package/dist/tools/task-cancel.d.ts +21 -0
- package/dist/tools/task-cancel.js +70 -0
- package/dist/tools/task-status.d.ts +27 -0
- package/dist/tools/task-status.js +106 -0
- package/dist/tools/task-sweep.d.ts +22 -0
- package/dist/tools/task-sweep.js +77 -0
- package/dist/tools/tool-help.d.ts +340 -0
- package/dist/tools/tool-help.js +261 -0
- package/dist/tools/yara-scan.d.ts +554 -0
- package/dist/tools/yara-scan.js +313 -0
- package/dist/types.d.ts +266 -0
- package/dist/types.js +41 -0
- package/dist/worker-pool.d.ts +204 -0
- package/dist/worker-pool.js +650 -0
- package/dist/workflows/deep-static.d.ts +104 -0
- package/dist/workflows/deep-static.js +276 -0
- package/dist/workflows/function-explanation-review.d.ts +655 -0
- package/dist/workflows/function-explanation-review.js +440 -0
- package/dist/workflows/reconstruct.d.ts +2053 -0
- package/dist/workflows/reconstruct.js +666 -0
- package/dist/workflows/semantic-name-review.d.ts +2418 -0
- package/dist/workflows/semantic-name-review.js +521 -0
- package/dist/workflows/triage.d.ts +659 -0
- package/dist/workflows/triage.js +1374 -0
- package/dist/workspace-manager.d.ts +150 -0
- package/dist/workspace-manager.js +411 -0
- package/ghidra_scripts/DecompileFunction.java +487 -0
- package/ghidra_scripts/DecompileFunction.py +150 -0
- package/ghidra_scripts/ExtractCFG.java +256 -0
- package/ghidra_scripts/ExtractCFG.py +233 -0
- package/ghidra_scripts/ExtractFunctions.java +442 -0
- package/ghidra_scripts/ExtractFunctions.py +101 -0
- package/ghidra_scripts/README.md +125 -0
- package/ghidra_scripts/SearchFunctionReferences.java +380 -0
- package/helpers/DotNetMetadataProbe/DotNetMetadataProbe.csproj +9 -0
- package/helpers/DotNetMetadataProbe/Program.cs +566 -0
- package/install-to-codex.ps1 +178 -0
- package/install-to-copilot.ps1 +303 -0
- package/package.json +101 -0
- package/requirements.txt +9 -0
- package/workers/requirements-dynamic.txt +11 -0
- package/workers/requirements.txt +8 -0
- package/workers/speakeasy_compat.py +175 -0
- package/workers/static_worker.py +5183 -0
- package/workers/yara_rules/default.yar +33 -0
- package/workers/yara_rules/malware_families.yar +93 -0
- package/workers/yara_rules/packers.yar +80 -0
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* artifacts.list tool implementation
|
|
3
|
+
* Enumerates artifact inventory for a sample with on-disk observability metadata.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { listArtifactInventory, normalizeRelativeArtifactPath } from '../artifact-inventory.js';
|
|
7
|
+
const TOOL_NAME = 'artifacts.list';
|
|
8
|
+
const TOOL_VERSION = '0.1.2';
|
|
9
|
+
export const ArtifactsListInputSchema = z.object({
|
|
10
|
+
sample_id: z.string().describe('Sample ID (format: sha256:<hex>)'),
|
|
11
|
+
artifact_type: z.string().optional().describe('Optional artifact type filter'),
|
|
12
|
+
artifact_types: z
|
|
13
|
+
.array(z.string())
|
|
14
|
+
.optional()
|
|
15
|
+
.describe('Optional artifact type filter list (union with artifact_type)'),
|
|
16
|
+
include_missing: z
|
|
17
|
+
.boolean()
|
|
18
|
+
.optional()
|
|
19
|
+
.default(true)
|
|
20
|
+
.describe('Include DB artifact records whose files are missing on disk'),
|
|
21
|
+
page: z.number().int().min(1).optional().default(1),
|
|
22
|
+
page_size: z.number().int().min(1).max(500).optional().default(100),
|
|
23
|
+
sort_by: z.enum(['created_at', 'type', 'path', 'size_bytes']).optional().default('created_at'),
|
|
24
|
+
sort_order: z.enum(['asc', 'desc']).optional().default('desc'),
|
|
25
|
+
path_prefix: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe('Optional relative path prefix filter, useful for narrowing to one export/session directory'),
|
|
29
|
+
session_tag: z
|
|
30
|
+
.string()
|
|
31
|
+
.optional()
|
|
32
|
+
.describe('Optional derived session tag filter such as reports/reconstruct/<session>'),
|
|
33
|
+
retention_bucket: z
|
|
34
|
+
.enum(['active', 'recent', 'archive'])
|
|
35
|
+
.optional()
|
|
36
|
+
.describe('Optional lifecycle filter based on artifact age'),
|
|
37
|
+
latest_only: z
|
|
38
|
+
.boolean()
|
|
39
|
+
.optional()
|
|
40
|
+
.default(false)
|
|
41
|
+
.describe('Keep only the latest artifact for each artifact type after filtering'),
|
|
42
|
+
high_value_only: z
|
|
43
|
+
.boolean()
|
|
44
|
+
.optional()
|
|
45
|
+
.default(false)
|
|
46
|
+
.describe('Show only high-value artifact categories (manifest/report/gaps/trace/export)'),
|
|
47
|
+
include_untracked_files: z
|
|
48
|
+
.boolean()
|
|
49
|
+
.optional()
|
|
50
|
+
.default(true)
|
|
51
|
+
.describe('Include files under workspace export roots even if not registered in artifacts table'),
|
|
52
|
+
recursive: z
|
|
53
|
+
.boolean()
|
|
54
|
+
.optional()
|
|
55
|
+
.default(true)
|
|
56
|
+
.describe('Recursively scan export roots for untracked files'),
|
|
57
|
+
scan_roots: z
|
|
58
|
+
.array(z.string())
|
|
59
|
+
.optional()
|
|
60
|
+
.default(['reports', 'ghidra', 'dotnet'])
|
|
61
|
+
.describe('Workspace subdirectories to scan for untracked export files'),
|
|
62
|
+
});
|
|
63
|
+
const ArtifactItemSchema = z.object({
|
|
64
|
+
id: z.string(),
|
|
65
|
+
type: z.string(),
|
|
66
|
+
path: z.string(),
|
|
67
|
+
sha256: z.string(),
|
|
68
|
+
mime: z.string().nullable(),
|
|
69
|
+
created_at: z.string(),
|
|
70
|
+
exists: z.boolean(),
|
|
71
|
+
size_bytes: z.number().nullable(),
|
|
72
|
+
modified_at: z.string().nullable(),
|
|
73
|
+
tracked: z.boolean(),
|
|
74
|
+
session_tag: z.string().nullable(),
|
|
75
|
+
retention_bucket: z.enum(['active', 'recent', 'archive']),
|
|
76
|
+
age_days: z.number().int().nonnegative(),
|
|
77
|
+
});
|
|
78
|
+
const ArtifactsListSummarySchema = z.object({
|
|
79
|
+
total_count: z.number().int().nonnegative(),
|
|
80
|
+
filtered_count: z.number().int().nonnegative(),
|
|
81
|
+
missing_count: z.number().int().nonnegative(),
|
|
82
|
+
untracked_count: z.number().int().nonnegative(),
|
|
83
|
+
by_type: z.record(z.number()),
|
|
84
|
+
latest_by_type: z.record(z.object({
|
|
85
|
+
id: z.string(),
|
|
86
|
+
path: z.string(),
|
|
87
|
+
created_at: z.string(),
|
|
88
|
+
tracked: z.boolean(),
|
|
89
|
+
})),
|
|
90
|
+
latest_by_session: z.record(z.object({
|
|
91
|
+
id: z.string(),
|
|
92
|
+
path: z.string(),
|
|
93
|
+
created_at: z.string(),
|
|
94
|
+
type: z.string(),
|
|
95
|
+
tracked: z.boolean(),
|
|
96
|
+
})),
|
|
97
|
+
session_index: z.record(z.object({
|
|
98
|
+
count: z.number().int().nonnegative(),
|
|
99
|
+
latest_created_at: z.string(),
|
|
100
|
+
tracked_count: z.number().int().nonnegative(),
|
|
101
|
+
untracked_count: z.number().int().nonnegative(),
|
|
102
|
+
types: z.array(z.string()),
|
|
103
|
+
retention_buckets: z.array(z.string()),
|
|
104
|
+
})),
|
|
105
|
+
by_retention_bucket: z.record(z.number()),
|
|
106
|
+
high_value_types: z.array(z.string()),
|
|
107
|
+
});
|
|
108
|
+
export const ArtifactsListOutputSchema = z.object({
|
|
109
|
+
ok: z.boolean(),
|
|
110
|
+
data: z
|
|
111
|
+
.object({
|
|
112
|
+
sample_id: z.string(),
|
|
113
|
+
artifact_type: z.string().nullable(),
|
|
114
|
+
artifact_types: z.array(z.string()).nullable(),
|
|
115
|
+
path_prefix: z.string().nullable(),
|
|
116
|
+
session_tag: z.string().nullable(),
|
|
117
|
+
retention_bucket: z.enum(['active', 'recent', 'archive']).nullable(),
|
|
118
|
+
latest_only: z.boolean(),
|
|
119
|
+
tool_version: z.string(),
|
|
120
|
+
count: z.number().int().nonnegative(),
|
|
121
|
+
total_count: z.number().int().nonnegative(),
|
|
122
|
+
page: z.number().int().positive(),
|
|
123
|
+
page_size: z.number().int().positive(),
|
|
124
|
+
total_pages: z.number().int().nonnegative(),
|
|
125
|
+
artifacts: z.array(ArtifactItemSchema),
|
|
126
|
+
summary: ArtifactsListSummarySchema,
|
|
127
|
+
})
|
|
128
|
+
.optional(),
|
|
129
|
+
warnings: z.array(z.string()).optional(),
|
|
130
|
+
errors: z.array(z.string()).optional(),
|
|
131
|
+
metrics: z
|
|
132
|
+
.object({
|
|
133
|
+
elapsed_ms: z.number(),
|
|
134
|
+
tool: z.string(),
|
|
135
|
+
})
|
|
136
|
+
.optional(),
|
|
137
|
+
});
|
|
138
|
+
export const artifactsListToolDefinition = {
|
|
139
|
+
name: TOOL_NAME,
|
|
140
|
+
description: 'List artifact records for a sample with existence/size timestamps, type filtering, and paginated high-value discovery.',
|
|
141
|
+
inputSchema: ArtifactsListInputSchema,
|
|
142
|
+
outputSchema: ArtifactsListOutputSchema,
|
|
143
|
+
};
|
|
144
|
+
function artifactValueScore(type, artifactPath) {
|
|
145
|
+
const valueSignals = [
|
|
146
|
+
'manifest',
|
|
147
|
+
'gaps',
|
|
148
|
+
'report',
|
|
149
|
+
'triage',
|
|
150
|
+
'reconstruct',
|
|
151
|
+
'trace',
|
|
152
|
+
'ioc_export',
|
|
153
|
+
'attack',
|
|
154
|
+
'sandbox',
|
|
155
|
+
];
|
|
156
|
+
const normalized = `${type} ${artifactPath}`.toLowerCase();
|
|
157
|
+
let score = 0;
|
|
158
|
+
for (const signal of valueSignals) {
|
|
159
|
+
if (normalized.includes(signal)) {
|
|
160
|
+
score += 1;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return score;
|
|
164
|
+
}
|
|
165
|
+
function compareValues(a, b) {
|
|
166
|
+
if (a === null && b === null) {
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
if (a === null) {
|
|
170
|
+
return -1;
|
|
171
|
+
}
|
|
172
|
+
if (b === null) {
|
|
173
|
+
return 1;
|
|
174
|
+
}
|
|
175
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
176
|
+
return a - b;
|
|
177
|
+
}
|
|
178
|
+
return String(a).localeCompare(String(b));
|
|
179
|
+
}
|
|
180
|
+
function toTimestamp(value) {
|
|
181
|
+
if (!value) {
|
|
182
|
+
return 0;
|
|
183
|
+
}
|
|
184
|
+
const parsed = new Date(value).getTime();
|
|
185
|
+
return Number.isFinite(parsed) ? parsed : 0;
|
|
186
|
+
}
|
|
187
|
+
export function createArtifactsListHandler(workspaceManager, database) {
|
|
188
|
+
return async (args) => {
|
|
189
|
+
const startTime = Date.now();
|
|
190
|
+
try {
|
|
191
|
+
const input = ArtifactsListInputSchema.parse(args);
|
|
192
|
+
const sample = database.findSample(input.sample_id);
|
|
193
|
+
if (!sample) {
|
|
194
|
+
return {
|
|
195
|
+
ok: false,
|
|
196
|
+
errors: [`Sample not found: ${input.sample_id}`],
|
|
197
|
+
metrics: {
|
|
198
|
+
elapsed_ms: Date.now() - startTime,
|
|
199
|
+
tool: TOOL_NAME,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
const typeFilter = new Set();
|
|
204
|
+
if (input.artifact_type) {
|
|
205
|
+
typeFilter.add(input.artifact_type);
|
|
206
|
+
}
|
|
207
|
+
for (const item of input.artifact_types || []) {
|
|
208
|
+
typeFilter.add(item);
|
|
209
|
+
}
|
|
210
|
+
const merged = await listArtifactInventory(workspaceManager, database, input.sample_id, {
|
|
211
|
+
artifactTypes: typeFilter,
|
|
212
|
+
includeMissing: input.include_missing,
|
|
213
|
+
includeUntrackedFiles: input.include_untracked_files,
|
|
214
|
+
recursive: input.recursive,
|
|
215
|
+
scanRoots: input.scan_roots,
|
|
216
|
+
});
|
|
217
|
+
let filtered = merged;
|
|
218
|
+
if (input.path_prefix) {
|
|
219
|
+
const normalizedPrefix = normalizeRelativeArtifactPath(input.path_prefix).toLowerCase();
|
|
220
|
+
filtered = filtered.filter((item) => normalizeRelativeArtifactPath(item.path).toLowerCase().startsWith(normalizedPrefix));
|
|
221
|
+
}
|
|
222
|
+
if (input.session_tag) {
|
|
223
|
+
filtered = filtered.filter((item) => item.session_tag === input.session_tag);
|
|
224
|
+
}
|
|
225
|
+
if (input.retention_bucket) {
|
|
226
|
+
filtered = filtered.filter((item) => item.retention_bucket === input.retention_bucket);
|
|
227
|
+
}
|
|
228
|
+
if (input.high_value_only) {
|
|
229
|
+
filtered = filtered.filter((item) => artifactValueScore(item.type, item.path) > 0);
|
|
230
|
+
}
|
|
231
|
+
if (input.latest_only) {
|
|
232
|
+
const latestByType = new Map();
|
|
233
|
+
for (const item of filtered) {
|
|
234
|
+
const existing = latestByType.get(item.type);
|
|
235
|
+
if (!existing || toTimestamp(item.created_at) > toTimestamp(existing.created_at)) {
|
|
236
|
+
latestByType.set(item.type, item);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
filtered = Array.from(latestByType.values());
|
|
240
|
+
}
|
|
241
|
+
filtered.sort((left, right) => {
|
|
242
|
+
const direction = input.sort_order === 'asc' ? 1 : -1;
|
|
243
|
+
if (input.sort_by === 'size_bytes') {
|
|
244
|
+
return direction * compareValues(left.size_bytes, right.size_bytes);
|
|
245
|
+
}
|
|
246
|
+
if (input.sort_by === 'type') {
|
|
247
|
+
return direction * compareValues(left.type, right.type);
|
|
248
|
+
}
|
|
249
|
+
if (input.sort_by === 'path') {
|
|
250
|
+
return direction * compareValues(left.path, right.path);
|
|
251
|
+
}
|
|
252
|
+
return direction * compareValues(left.created_at, right.created_at);
|
|
253
|
+
});
|
|
254
|
+
const totalCount = filtered.length;
|
|
255
|
+
const pageSize = input.page_size;
|
|
256
|
+
const totalPages = totalCount === 0 ? 0 : Math.ceil(totalCount / pageSize);
|
|
257
|
+
const boundedPage = totalPages === 0 ? 1 : Math.min(Math.max(input.page, 1), Math.max(totalPages, 1));
|
|
258
|
+
const startIndex = (boundedPage - 1) * pageSize;
|
|
259
|
+
const pagedArtifacts = filtered.slice(startIndex, startIndex + pageSize);
|
|
260
|
+
const missingCount = merged.filter((item) => item.tracked && !item.exists).length;
|
|
261
|
+
const untrackedCount = merged.filter((item) => !item.tracked).length;
|
|
262
|
+
const byType = {};
|
|
263
|
+
const latestByType = {};
|
|
264
|
+
const latestBySession = {};
|
|
265
|
+
const sessionIndex = {};
|
|
266
|
+
const byRetentionBucket = {};
|
|
267
|
+
const highValueTypes = new Set();
|
|
268
|
+
for (const item of filtered) {
|
|
269
|
+
byType[item.type] = (byType[item.type] || 0) + 1;
|
|
270
|
+
byRetentionBucket[item.retention_bucket] = (byRetentionBucket[item.retention_bucket] || 0) + 1;
|
|
271
|
+
const existing = latestByType[item.type];
|
|
272
|
+
if (!existing || toTimestamp(item.created_at) > toTimestamp(existing.created_at)) {
|
|
273
|
+
latestByType[item.type] = {
|
|
274
|
+
id: item.id,
|
|
275
|
+
path: item.path,
|
|
276
|
+
created_at: item.created_at,
|
|
277
|
+
tracked: item.tracked,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if (item.session_tag) {
|
|
281
|
+
const existingSession = latestBySession[item.session_tag];
|
|
282
|
+
if (!existingSession || toTimestamp(item.created_at) > toTimestamp(existingSession.created_at)) {
|
|
283
|
+
latestBySession[item.session_tag] = {
|
|
284
|
+
id: item.id,
|
|
285
|
+
path: item.path,
|
|
286
|
+
created_at: item.created_at,
|
|
287
|
+
type: item.type,
|
|
288
|
+
tracked: item.tracked,
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
const currentSession = sessionIndex[item.session_tag] || {
|
|
292
|
+
count: 0,
|
|
293
|
+
latest_created_at: item.created_at,
|
|
294
|
+
tracked_count: 0,
|
|
295
|
+
untracked_count: 0,
|
|
296
|
+
types: new Set(),
|
|
297
|
+
retention_buckets: new Set(),
|
|
298
|
+
};
|
|
299
|
+
currentSession.count += 1;
|
|
300
|
+
currentSession.latest_created_at =
|
|
301
|
+
toTimestamp(item.created_at) > toTimestamp(currentSession.latest_created_at)
|
|
302
|
+
? item.created_at
|
|
303
|
+
: currentSession.latest_created_at;
|
|
304
|
+
currentSession.tracked_count += item.tracked ? 1 : 0;
|
|
305
|
+
currentSession.untracked_count += item.tracked ? 0 : 1;
|
|
306
|
+
currentSession.types.add(item.type);
|
|
307
|
+
currentSession.retention_buckets.add(item.retention_bucket);
|
|
308
|
+
sessionIndex[item.session_tag] = currentSession;
|
|
309
|
+
}
|
|
310
|
+
if (artifactValueScore(item.type, item.path) > 0) {
|
|
311
|
+
highValueTypes.add(item.type);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
const warnings = missingCount > 0 || untrackedCount > 0
|
|
315
|
+
? [
|
|
316
|
+
...(missingCount > 0
|
|
317
|
+
? [
|
|
318
|
+
`${missingCount} artifact record(s) are missing on disk${input.include_missing
|
|
319
|
+
? '; keeping them in output for audit visibility.'
|
|
320
|
+
: '; hidden because include_missing=false.'}`,
|
|
321
|
+
]
|
|
322
|
+
: []),
|
|
323
|
+
...(untrackedCount > 0
|
|
324
|
+
? [
|
|
325
|
+
`Discovered ${untrackedCount} untracked file artifact(s) under scan roots: ${input.scan_roots.join(', ')}.`,
|
|
326
|
+
]
|
|
327
|
+
: []),
|
|
328
|
+
]
|
|
329
|
+
: undefined;
|
|
330
|
+
return {
|
|
331
|
+
ok: true,
|
|
332
|
+
data: {
|
|
333
|
+
sample_id: input.sample_id,
|
|
334
|
+
artifact_type: input.artifact_type || null,
|
|
335
|
+
artifact_types: typeFilter.size > 0 ? Array.from(typeFilter) : null,
|
|
336
|
+
path_prefix: input.path_prefix || null,
|
|
337
|
+
session_tag: input.session_tag || null,
|
|
338
|
+
retention_bucket: input.retention_bucket || null,
|
|
339
|
+
latest_only: input.latest_only,
|
|
340
|
+
tool_version: TOOL_VERSION,
|
|
341
|
+
count: pagedArtifacts.length,
|
|
342
|
+
total_count: totalCount,
|
|
343
|
+
page: boundedPage,
|
|
344
|
+
page_size: pageSize,
|
|
345
|
+
total_pages: totalPages,
|
|
346
|
+
artifacts: pagedArtifacts,
|
|
347
|
+
summary: {
|
|
348
|
+
total_count: merged.length,
|
|
349
|
+
filtered_count: totalCount,
|
|
350
|
+
missing_count: missingCount,
|
|
351
|
+
untracked_count: untrackedCount,
|
|
352
|
+
by_type: byType,
|
|
353
|
+
latest_by_type: latestByType,
|
|
354
|
+
latest_by_session: latestBySession,
|
|
355
|
+
session_index: Object.fromEntries(Object.entries(sessionIndex).map(([sessionTag, item]) => [
|
|
356
|
+
sessionTag,
|
|
357
|
+
{
|
|
358
|
+
count: item.count,
|
|
359
|
+
latest_created_at: item.latest_created_at,
|
|
360
|
+
tracked_count: item.tracked_count,
|
|
361
|
+
untracked_count: item.untracked_count,
|
|
362
|
+
types: Array.from(item.types).sort(),
|
|
363
|
+
retention_buckets: Array.from(item.retention_buckets).sort(),
|
|
364
|
+
},
|
|
365
|
+
])),
|
|
366
|
+
by_retention_bucket: byRetentionBucket,
|
|
367
|
+
high_value_types: Array.from(highValueTypes).sort(),
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
warnings,
|
|
371
|
+
metrics: {
|
|
372
|
+
elapsed_ms: Date.now() - startTime,
|
|
373
|
+
tool: TOOL_NAME,
|
|
374
|
+
},
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
catch (error) {
|
|
378
|
+
return {
|
|
379
|
+
ok: false,
|
|
380
|
+
errors: [error.message],
|
|
381
|
+
metrics: {
|
|
382
|
+
elapsed_ms: Date.now() - startTime,
|
|
383
|
+
tool: TOOL_NAME,
|
|
384
|
+
},
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
//# sourceMappingURL=artifacts-list.js.map
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* attack.map tool
|
|
3
|
+
* Map static/simulated indicators to MITRE ATT&CK techniques with evidence links.
|
|
4
|
+
*/
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import type { ToolDefinition, ToolArgs, WorkerResult } from '../types.js';
|
|
7
|
+
import type { WorkspaceManager } from '../workspace-manager.js';
|
|
8
|
+
import type { DatabaseManager } from '../database.js';
|
|
9
|
+
import type { CacheManager } from '../cache-manager.js';
|
|
10
|
+
export declare const AttackMapInputSchema: z.ZodObject<{
|
|
11
|
+
sample_id: z.ZodString;
|
|
12
|
+
include_low_confidence: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
13
|
+
max_techniques: z.ZodDefault<z.ZodOptional<z.ZodNumber>>;
|
|
14
|
+
force_refresh: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
15
|
+
}, "strip", z.ZodTypeAny, {
|
|
16
|
+
sample_id: string;
|
|
17
|
+
force_refresh: boolean;
|
|
18
|
+
include_low_confidence: boolean;
|
|
19
|
+
max_techniques: number;
|
|
20
|
+
}, {
|
|
21
|
+
sample_id: string;
|
|
22
|
+
force_refresh?: boolean | undefined;
|
|
23
|
+
include_low_confidence?: boolean | undefined;
|
|
24
|
+
max_techniques?: number | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
export type AttackMapInput = z.infer<typeof AttackMapInputSchema>;
|
|
27
|
+
export declare const AttackMapOutputSchema: z.ZodObject<{
|
|
28
|
+
ok: z.ZodBoolean;
|
|
29
|
+
data: z.ZodOptional<z.ZodObject<{
|
|
30
|
+
sample_id: z.ZodString;
|
|
31
|
+
techniques: z.ZodArray<z.ZodObject<{
|
|
32
|
+
technique_id: z.ZodString;
|
|
33
|
+
name: z.ZodString;
|
|
34
|
+
tactics: z.ZodArray<z.ZodString, "many">;
|
|
35
|
+
confidence: z.ZodNumber;
|
|
36
|
+
confidence_level: z.ZodEnum<["low", "medium", "high"]>;
|
|
37
|
+
evidence: z.ZodArray<z.ZodString, "many">;
|
|
38
|
+
sources: z.ZodArray<z.ZodString, "many">;
|
|
39
|
+
evidence_weights: z.ZodObject<{
|
|
40
|
+
import: z.ZodNumber;
|
|
41
|
+
string: z.ZodNumber;
|
|
42
|
+
runtime: z.ZodNumber;
|
|
43
|
+
}, "strip", z.ZodTypeAny, {
|
|
44
|
+
string: number;
|
|
45
|
+
runtime: number;
|
|
46
|
+
import: number;
|
|
47
|
+
}, {
|
|
48
|
+
string: number;
|
|
49
|
+
runtime: number;
|
|
50
|
+
import: number;
|
|
51
|
+
}>;
|
|
52
|
+
counter_evidence: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
53
|
+
}, "strip", z.ZodTypeAny, {
|
|
54
|
+
name: string;
|
|
55
|
+
confidence: number;
|
|
56
|
+
sources: string[];
|
|
57
|
+
evidence: string[];
|
|
58
|
+
evidence_weights: {
|
|
59
|
+
string: number;
|
|
60
|
+
runtime: number;
|
|
61
|
+
import: number;
|
|
62
|
+
};
|
|
63
|
+
technique_id: string;
|
|
64
|
+
tactics: string[];
|
|
65
|
+
confidence_level: "high" | "low" | "medium";
|
|
66
|
+
counter_evidence?: string[] | undefined;
|
|
67
|
+
}, {
|
|
68
|
+
name: string;
|
|
69
|
+
confidence: number;
|
|
70
|
+
sources: string[];
|
|
71
|
+
evidence: string[];
|
|
72
|
+
evidence_weights: {
|
|
73
|
+
string: number;
|
|
74
|
+
runtime: number;
|
|
75
|
+
import: number;
|
|
76
|
+
};
|
|
77
|
+
technique_id: string;
|
|
78
|
+
tactics: string[];
|
|
79
|
+
confidence_level: "high" | "low" | "medium";
|
|
80
|
+
counter_evidence?: string[] | undefined;
|
|
81
|
+
}>, "many">;
|
|
82
|
+
capability_clusters: z.ZodArray<z.ZodObject<{
|
|
83
|
+
capability: z.ZodString;
|
|
84
|
+
confidence: z.ZodNumber;
|
|
85
|
+
indicators: z.ZodArray<z.ZodString, "many">;
|
|
86
|
+
}, "strip", z.ZodTypeAny, {
|
|
87
|
+
indicators: string[];
|
|
88
|
+
confidence: number;
|
|
89
|
+
capability: string;
|
|
90
|
+
}, {
|
|
91
|
+
indicators: string[];
|
|
92
|
+
confidence: number;
|
|
93
|
+
capability: string;
|
|
94
|
+
}>, "many">;
|
|
95
|
+
tactic_summary: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
96
|
+
inference: z.ZodObject<{
|
|
97
|
+
classification: z.ZodEnum<["benign", "suspicious", "malicious", "unknown"]>;
|
|
98
|
+
summary: z.ZodString;
|
|
99
|
+
}, "strip", z.ZodTypeAny, {
|
|
100
|
+
summary: string;
|
|
101
|
+
classification: "unknown" | "suspicious" | "malicious" | "benign";
|
|
102
|
+
}, {
|
|
103
|
+
summary: string;
|
|
104
|
+
classification: "unknown" | "suspicious" | "malicious" | "benign";
|
|
105
|
+
}>;
|
|
106
|
+
}, "strip", z.ZodTypeAny, {
|
|
107
|
+
sample_id: string;
|
|
108
|
+
inference: {
|
|
109
|
+
summary: string;
|
|
110
|
+
classification: "unknown" | "suspicious" | "malicious" | "benign";
|
|
111
|
+
};
|
|
112
|
+
techniques: {
|
|
113
|
+
name: string;
|
|
114
|
+
confidence: number;
|
|
115
|
+
sources: string[];
|
|
116
|
+
evidence: string[];
|
|
117
|
+
evidence_weights: {
|
|
118
|
+
string: number;
|
|
119
|
+
runtime: number;
|
|
120
|
+
import: number;
|
|
121
|
+
};
|
|
122
|
+
technique_id: string;
|
|
123
|
+
tactics: string[];
|
|
124
|
+
confidence_level: "high" | "low" | "medium";
|
|
125
|
+
counter_evidence?: string[] | undefined;
|
|
126
|
+
}[];
|
|
127
|
+
capability_clusters: {
|
|
128
|
+
indicators: string[];
|
|
129
|
+
confidence: number;
|
|
130
|
+
capability: string;
|
|
131
|
+
}[];
|
|
132
|
+
tactic_summary: Record<string, number>;
|
|
133
|
+
}, {
|
|
134
|
+
sample_id: string;
|
|
135
|
+
inference: {
|
|
136
|
+
summary: string;
|
|
137
|
+
classification: "unknown" | "suspicious" | "malicious" | "benign";
|
|
138
|
+
};
|
|
139
|
+
techniques: {
|
|
140
|
+
name: string;
|
|
141
|
+
confidence: number;
|
|
142
|
+
sources: string[];
|
|
143
|
+
evidence: string[];
|
|
144
|
+
evidence_weights: {
|
|
145
|
+
string: number;
|
|
146
|
+
runtime: number;
|
|
147
|
+
import: number;
|
|
148
|
+
};
|
|
149
|
+
technique_id: string;
|
|
150
|
+
tactics: string[];
|
|
151
|
+
confidence_level: "high" | "low" | "medium";
|
|
152
|
+
counter_evidence?: string[] | undefined;
|
|
153
|
+
}[];
|
|
154
|
+
capability_clusters: {
|
|
155
|
+
indicators: string[];
|
|
156
|
+
confidence: number;
|
|
157
|
+
capability: string;
|
|
158
|
+
}[];
|
|
159
|
+
tactic_summary: Record<string, number>;
|
|
160
|
+
}>>;
|
|
161
|
+
warnings: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
162
|
+
errors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
163
|
+
metrics: z.ZodOptional<z.ZodObject<{
|
|
164
|
+
elapsed_ms: z.ZodNumber;
|
|
165
|
+
tool: z.ZodString;
|
|
166
|
+
}, "strip", z.ZodTypeAny, {
|
|
167
|
+
elapsed_ms: number;
|
|
168
|
+
tool: string;
|
|
169
|
+
}, {
|
|
170
|
+
elapsed_ms: number;
|
|
171
|
+
tool: string;
|
|
172
|
+
}>>;
|
|
173
|
+
}, "strip", z.ZodTypeAny, {
|
|
174
|
+
ok: boolean;
|
|
175
|
+
metrics?: {
|
|
176
|
+
elapsed_ms: number;
|
|
177
|
+
tool: string;
|
|
178
|
+
} | undefined;
|
|
179
|
+
data?: {
|
|
180
|
+
sample_id: string;
|
|
181
|
+
inference: {
|
|
182
|
+
summary: string;
|
|
183
|
+
classification: "unknown" | "suspicious" | "malicious" | "benign";
|
|
184
|
+
};
|
|
185
|
+
techniques: {
|
|
186
|
+
name: string;
|
|
187
|
+
confidence: number;
|
|
188
|
+
sources: string[];
|
|
189
|
+
evidence: string[];
|
|
190
|
+
evidence_weights: {
|
|
191
|
+
string: number;
|
|
192
|
+
runtime: number;
|
|
193
|
+
import: number;
|
|
194
|
+
};
|
|
195
|
+
technique_id: string;
|
|
196
|
+
tactics: string[];
|
|
197
|
+
confidence_level: "high" | "low" | "medium";
|
|
198
|
+
counter_evidence?: string[] | undefined;
|
|
199
|
+
}[];
|
|
200
|
+
capability_clusters: {
|
|
201
|
+
indicators: string[];
|
|
202
|
+
confidence: number;
|
|
203
|
+
capability: string;
|
|
204
|
+
}[];
|
|
205
|
+
tactic_summary: Record<string, number>;
|
|
206
|
+
} | undefined;
|
|
207
|
+
warnings?: string[] | undefined;
|
|
208
|
+
errors?: string[] | undefined;
|
|
209
|
+
}, {
|
|
210
|
+
ok: boolean;
|
|
211
|
+
metrics?: {
|
|
212
|
+
elapsed_ms: number;
|
|
213
|
+
tool: string;
|
|
214
|
+
} | undefined;
|
|
215
|
+
data?: {
|
|
216
|
+
sample_id: string;
|
|
217
|
+
inference: {
|
|
218
|
+
summary: string;
|
|
219
|
+
classification: "unknown" | "suspicious" | "malicious" | "benign";
|
|
220
|
+
};
|
|
221
|
+
techniques: {
|
|
222
|
+
name: string;
|
|
223
|
+
confidence: number;
|
|
224
|
+
sources: string[];
|
|
225
|
+
evidence: string[];
|
|
226
|
+
evidence_weights: {
|
|
227
|
+
string: number;
|
|
228
|
+
runtime: number;
|
|
229
|
+
import: number;
|
|
230
|
+
};
|
|
231
|
+
technique_id: string;
|
|
232
|
+
tactics: string[];
|
|
233
|
+
confidence_level: "high" | "low" | "medium";
|
|
234
|
+
counter_evidence?: string[] | undefined;
|
|
235
|
+
}[];
|
|
236
|
+
capability_clusters: {
|
|
237
|
+
indicators: string[];
|
|
238
|
+
confidence: number;
|
|
239
|
+
capability: string;
|
|
240
|
+
}[];
|
|
241
|
+
tactic_summary: Record<string, number>;
|
|
242
|
+
} | undefined;
|
|
243
|
+
warnings?: string[] | undefined;
|
|
244
|
+
errors?: string[] | undefined;
|
|
245
|
+
}>;
|
|
246
|
+
export declare const attackMapToolDefinition: ToolDefinition;
|
|
247
|
+
export interface AttackIndicators {
|
|
248
|
+
suspiciousImports: string[];
|
|
249
|
+
suspiciousStrings: string[];
|
|
250
|
+
commands: string[];
|
|
251
|
+
urls: string[];
|
|
252
|
+
ips: string[];
|
|
253
|
+
registryKeys: string[];
|
|
254
|
+
yaraMatches: string[];
|
|
255
|
+
yaraLowConfidence: string[];
|
|
256
|
+
packed: boolean;
|
|
257
|
+
packerConfidence: number;
|
|
258
|
+
runtimeHints?: string[];
|
|
259
|
+
intentLabel?: 'dual_use_tool' | 'operator_utility' | 'malware_like_payload' | 'unknown';
|
|
260
|
+
intentConfidence?: number;
|
|
261
|
+
}
|
|
262
|
+
export interface AttackTechnique {
|
|
263
|
+
technique_id: string;
|
|
264
|
+
name: string;
|
|
265
|
+
tactics: string[];
|
|
266
|
+
confidence: number;
|
|
267
|
+
confidence_level: 'low' | 'medium' | 'high';
|
|
268
|
+
evidence: string[];
|
|
269
|
+
sources: string[];
|
|
270
|
+
evidence_weights: {
|
|
271
|
+
import: number;
|
|
272
|
+
string: number;
|
|
273
|
+
runtime: number;
|
|
274
|
+
};
|
|
275
|
+
counter_evidence?: string[];
|
|
276
|
+
}
|
|
277
|
+
export interface CapabilityCluster {
|
|
278
|
+
capability: string;
|
|
279
|
+
confidence: number;
|
|
280
|
+
indicators: string[];
|
|
281
|
+
}
|
|
282
|
+
export declare function mapIndicatorsToAttack(indicators: AttackIndicators, options: {
|
|
283
|
+
includeLowConfidence: boolean;
|
|
284
|
+
maxTechniques: number;
|
|
285
|
+
}): {
|
|
286
|
+
techniques: AttackTechnique[];
|
|
287
|
+
capabilityClusters: CapabilityCluster[];
|
|
288
|
+
};
|
|
289
|
+
export declare function createAttackMapHandler(workspaceManager: WorkspaceManager, database: DatabaseManager, cacheManager: CacheManager): (args: ToolArgs) => Promise<WorkerResult>;
|
|
290
|
+
//# sourceMappingURL=attack-map.d.ts.map
|