misp-mcp 1.3.6 → 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.
- package/LICENSE +1 -0
- package/README.md +125 -20
- package/dist/chunk-FLXCWDXW.js +6865 -0
- package/dist/chunk-FLXCWDXW.js.map +1 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +12 -7
- package/dist/cli.js.map +1 -1
- package/dist/{client-D1YKT07H.d.ts → client-KcKJOyu8.d.ts} +81 -1
- package/dist/index.d.ts +22 -4
- package/dist/index.js +9 -6
- package/dist/index.js.map +1 -1
- package/dist/mcp-bin.js +3 -5
- package/dist/mcp-bin.js.map +1 -1
- package/package.json +7 -6
- package/dist/chunk-GTLBUJZI.js +0 -2491
- package/dist/chunk-GTLBUJZI.js.map +0 -1
- package/dist/chunk-ZKNV5JUW.js +0 -26
- package/dist/chunk-ZKNV5JUW.js.map +0 -1
package/dist/chunk-GTLBUJZI.js
DELETED
|
@@ -1,2491 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
// src/config.ts
|
|
4
|
-
function getConfig() {
|
|
5
|
-
const url = process.env.MISP_URL;
|
|
6
|
-
if (!url) {
|
|
7
|
-
throw new Error("MISP_URL environment variable is required");
|
|
8
|
-
}
|
|
9
|
-
const apiKey = process.env.MISP_API_KEY;
|
|
10
|
-
if (!apiKey) {
|
|
11
|
-
throw new Error("MISP_API_KEY environment variable is required");
|
|
12
|
-
}
|
|
13
|
-
const verifySsl = process.env.MISP_VERIFY_SSL !== "false";
|
|
14
|
-
const timeout = parseInt(process.env.MISP_TIMEOUT ?? "30", 10) * 1e3;
|
|
15
|
-
return {
|
|
16
|
-
url: url.replace(/\/+$/, ""),
|
|
17
|
-
apiKey,
|
|
18
|
-
verifySsl,
|
|
19
|
-
timeout
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
// src/client.ts
|
|
24
|
-
import { Agent, fetch } from "undici";
|
|
25
|
-
var ID_PATTERN = /^[A-Za-z0-9_-]+$/;
|
|
26
|
-
function encodeId(id, kind = "id") {
|
|
27
|
-
if (!ID_PATTERN.test(id)) {
|
|
28
|
-
throw new Error(`Invalid ${kind}: ${JSON.stringify(id)}`);
|
|
29
|
-
}
|
|
30
|
-
return encodeURIComponent(id);
|
|
31
|
-
}
|
|
32
|
-
function describeFetchError(err) {
|
|
33
|
-
const parts = [];
|
|
34
|
-
const codes = [];
|
|
35
|
-
let current = err;
|
|
36
|
-
while (current instanceof Error) {
|
|
37
|
-
parts.push(current.message);
|
|
38
|
-
const code = current.code;
|
|
39
|
-
if (code) codes.push(code);
|
|
40
|
-
current = current.cause;
|
|
41
|
-
}
|
|
42
|
-
if (parts.length === 0) parts.push(String(err));
|
|
43
|
-
const detail = [...new Set(parts)].join(" -> ");
|
|
44
|
-
const allCodes = codes.join(",");
|
|
45
|
-
const lowerDetail = detail.toLowerCase();
|
|
46
|
-
if (/CERT|SELF_SIGNED|UNABLE_TO_VERIFY|DEPTH_ZERO/.test(allCodes) || lowerDetail.includes("certificate")) {
|
|
47
|
-
return `${detail} (TLS certificate rejected; set MISP_VERIFY_SSL=false if your MISP instance uses a self-signed certificate)`;
|
|
48
|
-
}
|
|
49
|
-
if (/ENOTFOUND|EAI_AGAIN/.test(allCodes)) {
|
|
50
|
-
return `${detail} (could not resolve the MISP_URL hostname from this machine)`;
|
|
51
|
-
}
|
|
52
|
-
if (/ECONNREFUSED|EHOSTUNREACH|ENETUNREACH|ETIMEDOUT|ECONNRESET/.test(allCodes)) {
|
|
53
|
-
return `${detail} (MISP_URL is not reachable from this machine; check the URL, port, and any firewall or proxy in between)`;
|
|
54
|
-
}
|
|
55
|
-
return detail;
|
|
56
|
-
}
|
|
57
|
-
var MispClient = class {
|
|
58
|
-
baseUrl;
|
|
59
|
-
apiKey;
|
|
60
|
-
timeout;
|
|
61
|
-
dispatcher;
|
|
62
|
-
constructor(config) {
|
|
63
|
-
this.baseUrl = config.url;
|
|
64
|
-
this.apiKey = config.apiKey;
|
|
65
|
-
this.timeout = config.timeout;
|
|
66
|
-
this.dispatcher = new Agent({
|
|
67
|
-
connect: { rejectUnauthorized: config.verifySsl }
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
async request(method, path, body, rawResponse = false) {
|
|
71
|
-
const url = `${this.baseUrl}${path}`;
|
|
72
|
-
const headers = {
|
|
73
|
-
Authorization: this.apiKey,
|
|
74
|
-
Accept: "application/json",
|
|
75
|
-
"Content-Type": "application/json"
|
|
76
|
-
};
|
|
77
|
-
const controller = new AbortController();
|
|
78
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
79
|
-
let response;
|
|
80
|
-
try {
|
|
81
|
-
response = await fetch(url, {
|
|
82
|
-
method,
|
|
83
|
-
headers,
|
|
84
|
-
body: body ? JSON.stringify(body) : void 0,
|
|
85
|
-
signal: controller.signal,
|
|
86
|
-
dispatcher: this.dispatcher
|
|
87
|
-
});
|
|
88
|
-
} catch (err) {
|
|
89
|
-
if (err instanceof Error && err.name === "AbortError") {
|
|
90
|
-
throw new Error(`MISP API timeout after ${this.timeout}ms`);
|
|
91
|
-
}
|
|
92
|
-
throw new Error(`MISP API request failed: ${describeFetchError(err)}`);
|
|
93
|
-
} finally {
|
|
94
|
-
clearTimeout(timeoutId);
|
|
95
|
-
}
|
|
96
|
-
const text = await response.text();
|
|
97
|
-
if (!response.ok) {
|
|
98
|
-
const statusMessages = {
|
|
99
|
-
401: "Invalid API key or unauthorized",
|
|
100
|
-
403: "Insufficient permissions",
|
|
101
|
-
404: "Resource not found",
|
|
102
|
-
405: "Method not allowed"
|
|
103
|
-
};
|
|
104
|
-
const prefix = statusMessages[response.status] || `HTTP ${response.status}`;
|
|
105
|
-
let detail = "";
|
|
106
|
-
try {
|
|
107
|
-
const parsed = JSON.parse(text);
|
|
108
|
-
detail = parsed.message || parsed.errors || text;
|
|
109
|
-
} catch {
|
|
110
|
-
detail = text;
|
|
111
|
-
}
|
|
112
|
-
throw new Error(`${prefix}: ${detail}`);
|
|
113
|
-
}
|
|
114
|
-
if (rawResponse) {
|
|
115
|
-
return text;
|
|
116
|
-
}
|
|
117
|
-
try {
|
|
118
|
-
return JSON.parse(text);
|
|
119
|
-
} catch {
|
|
120
|
-
throw new Error(`Failed to parse MISP response as JSON: ${text.slice(0, 200)}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
// --- Event methods ---
|
|
124
|
-
async searchEvents(params) {
|
|
125
|
-
const body = {
|
|
126
|
-
returnFormat: "json",
|
|
127
|
-
limit: params.limit ?? 50
|
|
128
|
-
};
|
|
129
|
-
if (params.value) body.value = params.value;
|
|
130
|
-
if (params.type) body.type = params.type;
|
|
131
|
-
if (params.category) body.category = params.category;
|
|
132
|
-
if (params.tags) body.tags = params.tags;
|
|
133
|
-
if (params.eventid) body.eventid = params.eventid;
|
|
134
|
-
if (params.org) body.org = params.org;
|
|
135
|
-
if (params.dateFrom) body.from = params.dateFrom;
|
|
136
|
-
if (params.dateTo) body.to = params.dateTo;
|
|
137
|
-
if (params.last) body.last = params.last;
|
|
138
|
-
if (params.published !== void 0) body.published = params.published ? 1 : 0;
|
|
139
|
-
if (params.page) body.page = params.page;
|
|
140
|
-
const data = await this.request(
|
|
141
|
-
"POST",
|
|
142
|
-
"/events/restSearch",
|
|
143
|
-
body
|
|
144
|
-
);
|
|
145
|
-
return (data.response || []).map((r) => r.Event);
|
|
146
|
-
}
|
|
147
|
-
async getEvent(eventId) {
|
|
148
|
-
const data = await this.request(
|
|
149
|
-
"GET",
|
|
150
|
-
`/events/view/${encodeId(eventId, "eventId")}`
|
|
151
|
-
);
|
|
152
|
-
return data.Event;
|
|
153
|
-
}
|
|
154
|
-
async createEvent(params) {
|
|
155
|
-
const eventData = {
|
|
156
|
-
info: params.info,
|
|
157
|
-
distribution: params.distribution,
|
|
158
|
-
threat_level_id: params.threat_level_id,
|
|
159
|
-
analysis: params.analysis
|
|
160
|
-
};
|
|
161
|
-
if (params.date) eventData.date = params.date;
|
|
162
|
-
const data = await this.request("POST", "/events/add", {
|
|
163
|
-
Event: eventData
|
|
164
|
-
});
|
|
165
|
-
if (params.tags && params.tags.length > 0 && data.Event.id) {
|
|
166
|
-
for (const tag of params.tags) {
|
|
167
|
-
await this.tagEvent(data.Event.id, tag);
|
|
168
|
-
}
|
|
169
|
-
return this.getEvent(data.Event.id);
|
|
170
|
-
}
|
|
171
|
-
return data.Event;
|
|
172
|
-
}
|
|
173
|
-
async updateEvent(eventId, params) {
|
|
174
|
-
const eventData = {};
|
|
175
|
-
if (params.info !== void 0) eventData.info = params.info;
|
|
176
|
-
if (params.threat_level_id !== void 0)
|
|
177
|
-
eventData.threat_level_id = params.threat_level_id;
|
|
178
|
-
if (params.analysis !== void 0) eventData.analysis = params.analysis;
|
|
179
|
-
const data = await this.request(
|
|
180
|
-
"POST",
|
|
181
|
-
`/events/edit/${encodeId(eventId, "eventId")}`,
|
|
182
|
-
{ Event: eventData }
|
|
183
|
-
);
|
|
184
|
-
return data.Event;
|
|
185
|
-
}
|
|
186
|
-
async publishEvent(eventId) {
|
|
187
|
-
return this.request(
|
|
188
|
-
"POST",
|
|
189
|
-
`/events/publish/${encodeId(eventId, "eventId")}`
|
|
190
|
-
);
|
|
191
|
-
}
|
|
192
|
-
async tagEvent(eventId, tag) {
|
|
193
|
-
return this.request("POST", "/events/addTag", {
|
|
194
|
-
event: eventId,
|
|
195
|
-
tag
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
async untagEvent(eventId, tag) {
|
|
199
|
-
return this.request("POST", "/events/removeTag", {
|
|
200
|
-
event: eventId,
|
|
201
|
-
tag
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
// --- Attribute methods ---
|
|
205
|
-
async searchAttributes(params) {
|
|
206
|
-
const body = {
|
|
207
|
-
returnFormat: "json",
|
|
208
|
-
limit: params.limit ?? 50
|
|
209
|
-
};
|
|
210
|
-
if (params.value) body.value = params.value;
|
|
211
|
-
if (params.type) body.type = params.type;
|
|
212
|
-
if (params.category) body.category = params.category;
|
|
213
|
-
if (params.tags) body.tags = params.tags;
|
|
214
|
-
if (params.to_ids !== void 0) body.to_ids = params.to_ids ? 1 : 0;
|
|
215
|
-
if (params.includeCorrelations)
|
|
216
|
-
body.includeCorrelations = 1;
|
|
217
|
-
if (params.last) body.last = params.last;
|
|
218
|
-
const data = await this.request(
|
|
219
|
-
"POST",
|
|
220
|
-
"/attributes/restSearch",
|
|
221
|
-
body
|
|
222
|
-
);
|
|
223
|
-
return data.response?.Attribute || [];
|
|
224
|
-
}
|
|
225
|
-
async addAttribute(eventId, params) {
|
|
226
|
-
const attrData = {
|
|
227
|
-
type: params.type,
|
|
228
|
-
value: params.value
|
|
229
|
-
};
|
|
230
|
-
if (params.category) attrData.category = params.category;
|
|
231
|
-
if (params.to_ids !== void 0) attrData.to_ids = params.to_ids;
|
|
232
|
-
if (params.comment) attrData.comment = params.comment;
|
|
233
|
-
if (params.distribution !== void 0)
|
|
234
|
-
attrData.distribution = params.distribution;
|
|
235
|
-
const data = await this.request(
|
|
236
|
-
"POST",
|
|
237
|
-
`/attributes/add/${encodeId(eventId, "eventId")}`,
|
|
238
|
-
attrData
|
|
239
|
-
);
|
|
240
|
-
if (params.tags && params.tags.length > 0 && data.Attribute?.id) {
|
|
241
|
-
for (const tag of params.tags) {
|
|
242
|
-
await this.request("POST", "/attributes/addTag", {
|
|
243
|
-
attribute: data.Attribute.id,
|
|
244
|
-
tag
|
|
245
|
-
});
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return data.Attribute;
|
|
249
|
-
}
|
|
250
|
-
async deleteAttribute(attributeId, hard = false) {
|
|
251
|
-
const body = hard ? { hard: 1 } : {};
|
|
252
|
-
return this.request(
|
|
253
|
-
"POST",
|
|
254
|
-
`/attributes/delete/${encodeId(attributeId, "attributeId")}`,
|
|
255
|
-
body
|
|
256
|
-
);
|
|
257
|
-
}
|
|
258
|
-
// --- Describe types ---
|
|
259
|
-
async describeTypes() {
|
|
260
|
-
const data = await this.request(
|
|
261
|
-
"GET",
|
|
262
|
-
"/attributes/describeTypes"
|
|
263
|
-
);
|
|
264
|
-
return data.result;
|
|
265
|
-
}
|
|
266
|
-
// --- Tags ---
|
|
267
|
-
async listTags(search) {
|
|
268
|
-
const path = search ? `/tags/search/${encodeURIComponent(search)}` : "/tags";
|
|
269
|
-
const data = await this.request("GET", path);
|
|
270
|
-
return data.Tag || [];
|
|
271
|
-
}
|
|
272
|
-
// --- Sightings ---
|
|
273
|
-
async addSighting(params) {
|
|
274
|
-
const body = {
|
|
275
|
-
type: params.type
|
|
276
|
-
};
|
|
277
|
-
if (params.value) body.value = params.value;
|
|
278
|
-
if (params.source) body.source = params.source;
|
|
279
|
-
if (params.timestamp) body.timestamp = params.timestamp;
|
|
280
|
-
const path = params.attributeId ? `/sightings/add/${encodeId(params.attributeId, "attributeId")}` : "/sightings/add";
|
|
281
|
-
const data = await this.request("POST", path, body);
|
|
282
|
-
return data.Sighting;
|
|
283
|
-
}
|
|
284
|
-
// --- Warninglists ---
|
|
285
|
-
async checkWarninglists(value) {
|
|
286
|
-
return this.request(
|
|
287
|
-
"POST",
|
|
288
|
-
"/warninglists/checkValue",
|
|
289
|
-
[value]
|
|
290
|
-
);
|
|
291
|
-
}
|
|
292
|
-
// --- Statistics ---
|
|
293
|
-
async getStatistics() {
|
|
294
|
-
return this.request("GET", "/events/index");
|
|
295
|
-
}
|
|
296
|
-
// --- Taxonomies ---
|
|
297
|
-
async listTaxonomies() {
|
|
298
|
-
const data = await this.request("GET", "/taxonomies");
|
|
299
|
-
return (data || []).map((t) => t.Taxonomy);
|
|
300
|
-
}
|
|
301
|
-
// --- Exports ---
|
|
302
|
-
async exportEvents(params) {
|
|
303
|
-
const formatEndpoints = {
|
|
304
|
-
csv: "/events/csv/download",
|
|
305
|
-
stix: "/events/stix/download",
|
|
306
|
-
suricata: "/events/nids/suricata/download",
|
|
307
|
-
snort: "/events/nids/snort/download",
|
|
308
|
-
text: "/attributes/text/download",
|
|
309
|
-
rpz: "/attributes/rpz/download"
|
|
310
|
-
};
|
|
311
|
-
const endpoint = formatEndpoints[params.format];
|
|
312
|
-
if (!endpoint) {
|
|
313
|
-
throw new Error(
|
|
314
|
-
`Unsupported export format: ${params.format}. Supported: ${Object.keys(formatEndpoints).join(", ")}`
|
|
315
|
-
);
|
|
316
|
-
}
|
|
317
|
-
const body = {};
|
|
318
|
-
if (params.eventId) body.eventid = params.eventId;
|
|
319
|
-
if (params.type) body.type = params.type;
|
|
320
|
-
if (params.tags) body.tags = params.tags;
|
|
321
|
-
if (params.last) body.last = params.last;
|
|
322
|
-
return this.request("POST", endpoint, body, true);
|
|
323
|
-
}
|
|
324
|
-
async exportHashes(params) {
|
|
325
|
-
const validFormats = ["md5", "sha1", "sha256"];
|
|
326
|
-
if (!validFormats.includes(params.format)) {
|
|
327
|
-
throw new Error(
|
|
328
|
-
`Unsupported hash format: ${params.format}. Supported: ${validFormats.join(", ")}`
|
|
329
|
-
);
|
|
330
|
-
}
|
|
331
|
-
let path = `/events/hids/${params.format}/download`;
|
|
332
|
-
const queryParts = [];
|
|
333
|
-
if (params.last) queryParts.push(`last=${encodeURIComponent(params.last)}`);
|
|
334
|
-
if (params.tags) queryParts.push(`tags=${encodeURIComponent(params.tags.join(","))}`);
|
|
335
|
-
if (queryParts.length > 0) path += `?${queryParts.join("&")}`;
|
|
336
|
-
return this.request("GET", path, void 0, true);
|
|
337
|
-
}
|
|
338
|
-
// --- Objects ---
|
|
339
|
-
async listObjectTemplates() {
|
|
340
|
-
const data = await this.request("GET", "/objectTemplates");
|
|
341
|
-
return (data || []).map((t) => t.ObjectTemplate);
|
|
342
|
-
}
|
|
343
|
-
async getObjectTemplate(templateId) {
|
|
344
|
-
const data = await this.request(
|
|
345
|
-
"GET",
|
|
346
|
-
`/objectTemplates/view/${encodeId(templateId, "templateId")}`
|
|
347
|
-
);
|
|
348
|
-
return data.ObjectTemplate;
|
|
349
|
-
}
|
|
350
|
-
async addObject(eventId, params) {
|
|
351
|
-
const body = {
|
|
352
|
-
name: params.name,
|
|
353
|
-
Attribute: params.attributes.map((a) => ({
|
|
354
|
-
object_relation: a.object_relation,
|
|
355
|
-
type: a.type,
|
|
356
|
-
value: a.value,
|
|
357
|
-
to_ids: a.to_ids ?? false,
|
|
358
|
-
comment: a.comment
|
|
359
|
-
}))
|
|
360
|
-
};
|
|
361
|
-
if (params.comment) body.comment = params.comment;
|
|
362
|
-
if (params.distribution !== void 0)
|
|
363
|
-
body.distribution = params.distribution;
|
|
364
|
-
const data = await this.request(
|
|
365
|
-
"POST",
|
|
366
|
-
`/objects/add/${encodeId(eventId, "eventId")}`,
|
|
367
|
-
body
|
|
368
|
-
);
|
|
369
|
-
return data.Object;
|
|
370
|
-
}
|
|
371
|
-
async deleteObject(objectId, hard = false) {
|
|
372
|
-
const body = hard ? { hard: 1 } : {};
|
|
373
|
-
return this.request(
|
|
374
|
-
"POST",
|
|
375
|
-
`/objects/delete/${encodeId(objectId, "objectId")}`,
|
|
376
|
-
body
|
|
377
|
-
);
|
|
378
|
-
}
|
|
379
|
-
// --- Galaxies ---
|
|
380
|
-
async listGalaxies() {
|
|
381
|
-
const data = await this.request("GET", "/galaxies");
|
|
382
|
-
return (data || []).map((g) => g.Galaxy);
|
|
383
|
-
}
|
|
384
|
-
async getGalaxy(galaxyId) {
|
|
385
|
-
const data = await this.request("GET", `/galaxies/view/${encodeId(galaxyId, "galaxyId")}`);
|
|
386
|
-
return {
|
|
387
|
-
...data.Galaxy,
|
|
388
|
-
GalaxyCluster: data.GalaxyCluster
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
async searchGalaxyClusters(search, galaxyType) {
|
|
392
|
-
const body = {
|
|
393
|
-
searchall: search
|
|
394
|
-
};
|
|
395
|
-
if (galaxyType) body.context = galaxyType;
|
|
396
|
-
const data = await this.request("POST", "/galaxy_clusters/restSearch", body);
|
|
397
|
-
return (data || []).map((c) => c.GalaxyCluster);
|
|
398
|
-
}
|
|
399
|
-
async attachGalaxyCluster(targetType, targetId, galaxyClusterId) {
|
|
400
|
-
if (!ID_PATTERN.test(galaxyClusterId)) {
|
|
401
|
-
throw new Error(`Invalid galaxyClusterId: ${JSON.stringify(galaxyClusterId)}`);
|
|
402
|
-
}
|
|
403
|
-
return this.request(
|
|
404
|
-
"POST",
|
|
405
|
-
`/galaxies/attachCluster/${encodeId(targetId, "targetId")}/${targetType}`,
|
|
406
|
-
{ Galaxy: { target_id: galaxyClusterId } }
|
|
407
|
-
);
|
|
408
|
-
}
|
|
409
|
-
// --- Feeds ---
|
|
410
|
-
async listFeeds() {
|
|
411
|
-
const data = await this.request(
|
|
412
|
-
"GET",
|
|
413
|
-
"/feeds"
|
|
414
|
-
);
|
|
415
|
-
return (data || []).map((f) => f.Feed);
|
|
416
|
-
}
|
|
417
|
-
async toggleFeed(feedId, enable) {
|
|
418
|
-
return this.request(
|
|
419
|
-
"POST",
|
|
420
|
-
`/feeds/${enable ? "enable" : "disable"}/${encodeId(feedId, "feedId")}`
|
|
421
|
-
);
|
|
422
|
-
}
|
|
423
|
-
async fetchFeed(feedId) {
|
|
424
|
-
return this.request(
|
|
425
|
-
"GET",
|
|
426
|
-
`/feeds/fetchFromFeed/${encodeId(feedId, "feedId")}`
|
|
427
|
-
);
|
|
428
|
-
}
|
|
429
|
-
async cacheFeed(feedId) {
|
|
430
|
-
return this.request(
|
|
431
|
-
"GET",
|
|
432
|
-
`/feeds/cacheFeeds/${encodeId(feedId, "feedId")}`
|
|
433
|
-
);
|
|
434
|
-
}
|
|
435
|
-
// --- Organisations ---
|
|
436
|
-
async listOrganisations(scope = "all") {
|
|
437
|
-
const data = await this.request("GET", `/organisations/index/scope:${scope}`);
|
|
438
|
-
return (data || []).map((o) => o.Organisation);
|
|
439
|
-
}
|
|
440
|
-
async getOrganisation(orgId) {
|
|
441
|
-
const data = await this.request(
|
|
442
|
-
"GET",
|
|
443
|
-
`/organisations/view/${encodeId(orgId, "orgId")}`
|
|
444
|
-
);
|
|
445
|
-
return data.Organisation;
|
|
446
|
-
}
|
|
447
|
-
// --- Server ---
|
|
448
|
-
async getVersion() {
|
|
449
|
-
return this.request("GET", "/servers/getVersion");
|
|
450
|
-
}
|
|
451
|
-
async getServerSettings() {
|
|
452
|
-
try {
|
|
453
|
-
return await this.request(
|
|
454
|
-
"GET",
|
|
455
|
-
"/servers/serverSettings"
|
|
456
|
-
);
|
|
457
|
-
} catch (err) {
|
|
458
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
459
|
-
if (msg.startsWith("Insufficient permissions") || msg.startsWith("HTTP 403")) {
|
|
460
|
-
return {};
|
|
461
|
-
}
|
|
462
|
-
throw err;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
async listSharingGroups() {
|
|
466
|
-
const data = await this.request("GET", "/sharing_groups");
|
|
467
|
-
return (data.response || []).map((g) => g.SharingGroup);
|
|
468
|
-
}
|
|
469
|
-
async deleteEvent(eventId) {
|
|
470
|
-
return this.request(
|
|
471
|
-
"POST",
|
|
472
|
-
`/events/delete/${encodeId(eventId, "eventId")}`
|
|
473
|
-
);
|
|
474
|
-
}
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
// src/mcp-server.ts
|
|
478
|
-
import { readFileSync } from "fs";
|
|
479
|
-
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
480
|
-
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
481
|
-
|
|
482
|
-
// src/tools/events.ts
|
|
483
|
-
import { z } from "zod";
|
|
484
|
-
|
|
485
|
-
// src/guards.ts
|
|
486
|
-
function destructiveEnvOptIn() {
|
|
487
|
-
return process.env.MISP_ALLOW_DESTRUCTIVE === "true";
|
|
488
|
-
}
|
|
489
|
-
function blocked(text) {
|
|
490
|
-
return {
|
|
491
|
-
content: [{ type: "text", text }],
|
|
492
|
-
isError: true
|
|
493
|
-
};
|
|
494
|
-
}
|
|
495
|
-
function requireConfirmation(confirm, action) {
|
|
496
|
-
if (confirm === true || destructiveEnvOptIn()) {
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
return blocked(
|
|
500
|
-
`Refused: ${action} is a destructive action. Pass "confirm": true to proceed, or set MISP_ALLOW_DESTRUCTIVE=true to pre-authorize destructive operations.`
|
|
501
|
-
);
|
|
502
|
-
}
|
|
503
|
-
function requireHardConfirmation(confirmHard, action) {
|
|
504
|
-
if (confirmHard === true) {
|
|
505
|
-
return null;
|
|
506
|
-
}
|
|
507
|
-
return blocked(
|
|
508
|
-
`Refused: ${action} is a PERMANENT, irreversible delete. Pass "confirmHard": true (in addition to "confirm": true) to proceed.`
|
|
509
|
-
);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// src/tools/events.ts
|
|
513
|
-
function registerEventTools(server, client) {
|
|
514
|
-
server.tool(
|
|
515
|
-
"misp_search_events",
|
|
516
|
-
"Search MISP events by IOC value, type, tags, date range, or organization",
|
|
517
|
-
{
|
|
518
|
-
value: z.string().optional().describe("IOC value to search across all attributes"),
|
|
519
|
-
type: z.string().optional().describe("Attribute type filter (ip-src, ip-dst, domain, md5, sha256, url, email-src, etc.)"),
|
|
520
|
-
category: z.string().optional().describe("Category filter (Network activity, Payload delivery, External analysis, etc.)"),
|
|
521
|
-
tags: z.array(z.string()).optional().describe("Tag filters (e.g., tlp:white, misp-galaxy:mitre-attack-pattern)"),
|
|
522
|
-
eventId: z.string().optional().describe("Specific event ID"),
|
|
523
|
-
org: z.string().optional().describe("Organization filter"),
|
|
524
|
-
dateFrom: z.string().optional().describe("Start date (YYYY-MM-DD)"),
|
|
525
|
-
dateTo: z.string().optional().describe("End date (YYYY-MM-DD)"),
|
|
526
|
-
last: z.string().optional().describe("Relative time (e.g., 1d, 7d, 30d, 6m)"),
|
|
527
|
-
published: z.boolean().optional().describe("Only published events"),
|
|
528
|
-
limit: z.number().optional().describe("Max results (default 50)"),
|
|
529
|
-
page: z.number().optional().describe("Page number for pagination")
|
|
530
|
-
},
|
|
531
|
-
async (params) => {
|
|
532
|
-
try {
|
|
533
|
-
const events = await client.searchEvents({
|
|
534
|
-
value: params.value,
|
|
535
|
-
type: params.type,
|
|
536
|
-
category: params.category,
|
|
537
|
-
tags: params.tags,
|
|
538
|
-
eventid: params.eventId,
|
|
539
|
-
org: params.org,
|
|
540
|
-
dateFrom: params.dateFrom,
|
|
541
|
-
dateTo: params.dateTo,
|
|
542
|
-
last: params.last,
|
|
543
|
-
published: params.published,
|
|
544
|
-
limit: params.limit,
|
|
545
|
-
page: params.page
|
|
546
|
-
});
|
|
547
|
-
if (events.length === 0) {
|
|
548
|
-
return {
|
|
549
|
-
content: [{ type: "text", text: "No events found matching the search criteria." }]
|
|
550
|
-
};
|
|
551
|
-
}
|
|
552
|
-
const summary = events.map((e) => ({
|
|
553
|
-
id: e.id,
|
|
554
|
-
info: e.info,
|
|
555
|
-
date: e.date,
|
|
556
|
-
threat_level: ["", "High", "Medium", "Low", "Undefined"][parseInt(e.threat_level_id) || 0],
|
|
557
|
-
analysis: ["Initial", "Ongoing", "Complete"][parseInt(e.analysis) || 0],
|
|
558
|
-
published: e.published,
|
|
559
|
-
org: e.Orgc?.name || "Unknown",
|
|
560
|
-
attribute_count: e.attribute_count,
|
|
561
|
-
tags: (e.Tag || []).map((t) => t.name)
|
|
562
|
-
}));
|
|
563
|
-
return {
|
|
564
|
-
content: [
|
|
565
|
-
{
|
|
566
|
-
type: "text",
|
|
567
|
-
text: JSON.stringify(summary, null, 2)
|
|
568
|
-
}
|
|
569
|
-
]
|
|
570
|
-
};
|
|
571
|
-
} catch (err) {
|
|
572
|
-
return {
|
|
573
|
-
content: [
|
|
574
|
-
{ type: "text", text: `Error searching events: ${err instanceof Error ? err.message : String(err)}` }
|
|
575
|
-
],
|
|
576
|
-
isError: true
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
);
|
|
581
|
-
server.tool(
|
|
582
|
-
"misp_get_event",
|
|
583
|
-
"Get full details of a specific MISP event including all attributes, objects, tags, and related events",
|
|
584
|
-
{
|
|
585
|
-
eventId: z.string().describe("Event ID to retrieve")
|
|
586
|
-
},
|
|
587
|
-
async ({ eventId }) => {
|
|
588
|
-
try {
|
|
589
|
-
const event = await client.getEvent(eventId);
|
|
590
|
-
const result = {
|
|
591
|
-
id: event.id,
|
|
592
|
-
uuid: event.uuid,
|
|
593
|
-
info: event.info,
|
|
594
|
-
date: event.date,
|
|
595
|
-
threat_level: ["", "High", "Medium", "Low", "Undefined"][parseInt(event.threat_level_id) || 0],
|
|
596
|
-
analysis: ["Initial", "Ongoing", "Complete"][parseInt(event.analysis) || 0],
|
|
597
|
-
distribution: ["Organization", "Community", "Connected communities", "All communities", "Sharing group"][parseInt(event.distribution) || 0],
|
|
598
|
-
published: event.published,
|
|
599
|
-
org: event.Orgc?.name || "Unknown",
|
|
600
|
-
tags: (event.Tag || []).map((t) => t.name),
|
|
601
|
-
attribute_count: event.attribute_count,
|
|
602
|
-
attributes: (event.Attribute || []).map((a) => ({
|
|
603
|
-
id: a.id,
|
|
604
|
-
type: a.type,
|
|
605
|
-
category: a.category,
|
|
606
|
-
value: a.value,
|
|
607
|
-
to_ids: a.to_ids,
|
|
608
|
-
comment: a.comment
|
|
609
|
-
})),
|
|
610
|
-
objects: (event.Object || []).map((o) => ({
|
|
611
|
-
id: o.id,
|
|
612
|
-
name: o.name,
|
|
613
|
-
meta_category: o.meta_category,
|
|
614
|
-
attributes: (o.Attribute || []).map((a) => ({
|
|
615
|
-
type: a.type,
|
|
616
|
-
value: a.value
|
|
617
|
-
}))
|
|
618
|
-
})),
|
|
619
|
-
galaxies: (event.Galaxy || []).map((g) => ({
|
|
620
|
-
name: g.name,
|
|
621
|
-
type: g.type,
|
|
622
|
-
clusters: (g.GalaxyCluster || []).map((c) => c.value)
|
|
623
|
-
})),
|
|
624
|
-
related_events: (event.RelatedEvent || []).map((r) => ({
|
|
625
|
-
id: r.Event.id,
|
|
626
|
-
info: r.Event.info,
|
|
627
|
-
date: r.Event.date
|
|
628
|
-
}))
|
|
629
|
-
};
|
|
630
|
-
return {
|
|
631
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
632
|
-
};
|
|
633
|
-
} catch (err) {
|
|
634
|
-
return {
|
|
635
|
-
content: [
|
|
636
|
-
{ type: "text", text: `Error getting event: ${err instanceof Error ? err.message : String(err)}` }
|
|
637
|
-
],
|
|
638
|
-
isError: true
|
|
639
|
-
};
|
|
640
|
-
}
|
|
641
|
-
}
|
|
642
|
-
);
|
|
643
|
-
server.tool(
|
|
644
|
-
"misp_create_event",
|
|
645
|
-
"Create a new MISP event for documenting incidents or threat intelligence. Does not publish - use misp_publish_event separately.",
|
|
646
|
-
{
|
|
647
|
-
info: z.string().describe("Event description/title"),
|
|
648
|
-
distribution: z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).describe("0=Organization only, 1=Community, 2=Connected communities, 3=All communities, 4=Sharing group"),
|
|
649
|
-
threatLevel: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).describe("1=High, 2=Medium, 3=Low, 4=Undefined"),
|
|
650
|
-
analysis: z.union([z.literal(0), z.literal(1), z.literal(2)]).describe("0=Initial, 1=Ongoing, 2=Complete"),
|
|
651
|
-
date: z.string().optional().describe("Event date (YYYY-MM-DD)"),
|
|
652
|
-
tags: z.array(z.string()).optional().describe("Tags to apply")
|
|
653
|
-
},
|
|
654
|
-
async (params) => {
|
|
655
|
-
try {
|
|
656
|
-
const event = await client.createEvent({
|
|
657
|
-
info: params.info,
|
|
658
|
-
distribution: params.distribution,
|
|
659
|
-
threat_level_id: params.threatLevel,
|
|
660
|
-
analysis: params.analysis,
|
|
661
|
-
date: params.date,
|
|
662
|
-
tags: params.tags
|
|
663
|
-
});
|
|
664
|
-
return {
|
|
665
|
-
content: [
|
|
666
|
-
{
|
|
667
|
-
type: "text",
|
|
668
|
-
text: JSON.stringify(
|
|
669
|
-
{
|
|
670
|
-
id: event.id,
|
|
671
|
-
uuid: event.uuid,
|
|
672
|
-
info: event.info,
|
|
673
|
-
date: event.date,
|
|
674
|
-
published: event.published,
|
|
675
|
-
tags: (event.Tag || []).map((t) => t.name)
|
|
676
|
-
},
|
|
677
|
-
null,
|
|
678
|
-
2
|
|
679
|
-
)
|
|
680
|
-
}
|
|
681
|
-
]
|
|
682
|
-
};
|
|
683
|
-
} catch (err) {
|
|
684
|
-
return {
|
|
685
|
-
content: [
|
|
686
|
-
{ type: "text", text: `Error creating event: ${err instanceof Error ? err.message : String(err)}` }
|
|
687
|
-
],
|
|
688
|
-
isError: true
|
|
689
|
-
};
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
);
|
|
693
|
-
server.tool(
|
|
694
|
-
"misp_update_event",
|
|
695
|
-
"Update an existing MISP event's metadata (info, threat level, analysis status). Publishing is separate - use misp_publish_event.",
|
|
696
|
-
{
|
|
697
|
-
eventId: z.string().describe("Event ID to update"),
|
|
698
|
-
info: z.string().optional().describe("New event description"),
|
|
699
|
-
threatLevel: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional().describe("1=High, 2=Medium, 3=Low, 4=Undefined"),
|
|
700
|
-
analysis: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional().describe("0=Initial, 1=Ongoing, 2=Complete")
|
|
701
|
-
},
|
|
702
|
-
async ({ eventId, info, threatLevel, analysis }) => {
|
|
703
|
-
try {
|
|
704
|
-
const event = await client.updateEvent(eventId, {
|
|
705
|
-
info,
|
|
706
|
-
threat_level_id: threatLevel,
|
|
707
|
-
analysis
|
|
708
|
-
});
|
|
709
|
-
return {
|
|
710
|
-
content: [
|
|
711
|
-
{
|
|
712
|
-
type: "text",
|
|
713
|
-
text: JSON.stringify(
|
|
714
|
-
{
|
|
715
|
-
id: event.id,
|
|
716
|
-
info: event.info,
|
|
717
|
-
threat_level_id: event.threat_level_id,
|
|
718
|
-
analysis: event.analysis,
|
|
719
|
-
published: event.published
|
|
720
|
-
},
|
|
721
|
-
null,
|
|
722
|
-
2
|
|
723
|
-
)
|
|
724
|
-
}
|
|
725
|
-
]
|
|
726
|
-
};
|
|
727
|
-
} catch (err) {
|
|
728
|
-
return {
|
|
729
|
-
content: [
|
|
730
|
-
{ type: "text", text: `Error updating event: ${err instanceof Error ? err.message : String(err)}` }
|
|
731
|
-
],
|
|
732
|
-
isError: true
|
|
733
|
-
};
|
|
734
|
-
}
|
|
735
|
-
}
|
|
736
|
-
);
|
|
737
|
-
server.tool(
|
|
738
|
-
"misp_publish_event",
|
|
739
|
-
"Publish a MISP event, triggering alerts and notifications to sharing partners. State-changing: requires confirm:true (or MISP_ALLOW_DESTRUCTIVE=true).",
|
|
740
|
-
{
|
|
741
|
-
eventId: z.string().describe("Event ID to publish"),
|
|
742
|
-
confirm: z.boolean().optional().describe("Must be true to publish (triggers alerts to sharing partners) unless MISP_ALLOW_DESTRUCTIVE=true")
|
|
743
|
-
},
|
|
744
|
-
async ({ eventId, confirm }) => {
|
|
745
|
-
try {
|
|
746
|
-
const guard = requireConfirmation(confirm, `publishing event ${eventId}`);
|
|
747
|
-
if (guard) return guard;
|
|
748
|
-
const result = await client.publishEvent(eventId);
|
|
749
|
-
return {
|
|
750
|
-
content: [
|
|
751
|
-
{ type: "text", text: result.message || `Event ${eventId} published successfully.` }
|
|
752
|
-
]
|
|
753
|
-
};
|
|
754
|
-
} catch (err) {
|
|
755
|
-
return {
|
|
756
|
-
content: [
|
|
757
|
-
{ type: "text", text: `Error publishing event: ${err instanceof Error ? err.message : String(err)}` }
|
|
758
|
-
],
|
|
759
|
-
isError: true
|
|
760
|
-
};
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
);
|
|
764
|
-
server.tool(
|
|
765
|
-
"misp_tag_event",
|
|
766
|
-
"Add or remove a tag from a MISP event (TLP, MITRE ATT&CK, custom tags). Removing a tag is destructive and requires confirm:true (or MISP_ALLOW_DESTRUCTIVE=true).",
|
|
767
|
-
{
|
|
768
|
-
eventId: z.string().describe("Event ID to tag"),
|
|
769
|
-
tag: z.string().describe("Tag name (e.g., tlp:white, misp-galaxy:mitre-attack-pattern)"),
|
|
770
|
-
remove: z.boolean().optional().describe("Set to true to remove the tag instead of adding"),
|
|
771
|
-
confirm: z.boolean().optional().describe("Required (true) when remove is true, unless MISP_ALLOW_DESTRUCTIVE=true. Ignored when adding a tag.")
|
|
772
|
-
},
|
|
773
|
-
async ({ eventId, tag, remove, confirm }) => {
|
|
774
|
-
try {
|
|
775
|
-
if (remove) {
|
|
776
|
-
const guard = requireConfirmation(confirm, `removing tag "${tag}" from event ${eventId}`);
|
|
777
|
-
if (guard) return guard;
|
|
778
|
-
await client.untagEvent(eventId, tag);
|
|
779
|
-
return {
|
|
780
|
-
content: [
|
|
781
|
-
{ type: "text", text: `Tag "${tag}" removed from event ${eventId}.` }
|
|
782
|
-
]
|
|
783
|
-
};
|
|
784
|
-
} else {
|
|
785
|
-
await client.tagEvent(eventId, tag);
|
|
786
|
-
return {
|
|
787
|
-
content: [
|
|
788
|
-
{ type: "text", text: `Tag "${tag}" added to event ${eventId}.` }
|
|
789
|
-
]
|
|
790
|
-
};
|
|
791
|
-
}
|
|
792
|
-
} catch (err) {
|
|
793
|
-
return {
|
|
794
|
-
content: [
|
|
795
|
-
{ type: "text", text: `Error tagging event: ${err instanceof Error ? err.message : String(err)}` }
|
|
796
|
-
],
|
|
797
|
-
isError: true
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
);
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
// src/tools/attributes.ts
|
|
805
|
-
import { z as z2 } from "zod";
|
|
806
|
-
function registerAttributeTools(server, client) {
|
|
807
|
-
server.tool(
|
|
808
|
-
"misp_search_attributes",
|
|
809
|
-
"Search for specific attributes (IOCs) across all MISP events",
|
|
810
|
-
{
|
|
811
|
-
value: z2.string().optional().describe("IOC value to search"),
|
|
812
|
-
type: z2.string().optional().describe("Attribute type (ip-src, ip-dst, domain, md5, sha256, url, email-src, hostname, etc.)"),
|
|
813
|
-
category: z2.string().optional().describe("Category filter"),
|
|
814
|
-
tags: z2.array(z2.string()).optional().describe("Tag filters"),
|
|
815
|
-
toIds: z2.boolean().optional().describe("Only IDS-flagged attributes"),
|
|
816
|
-
includeCorrelations: z2.boolean().optional().describe("Include correlation data"),
|
|
817
|
-
last: z2.string().optional().describe("Relative time filter (e.g., 1d, 7d, 30d)"),
|
|
818
|
-
limit: z2.number().optional().describe("Max results (default 50)")
|
|
819
|
-
},
|
|
820
|
-
async (params) => {
|
|
821
|
-
try {
|
|
822
|
-
const attributes = await client.searchAttributes({
|
|
823
|
-
value: params.value,
|
|
824
|
-
type: params.type,
|
|
825
|
-
category: params.category,
|
|
826
|
-
tags: params.tags,
|
|
827
|
-
to_ids: params.toIds,
|
|
828
|
-
includeCorrelations: params.includeCorrelations,
|
|
829
|
-
last: params.last,
|
|
830
|
-
limit: params.limit
|
|
831
|
-
});
|
|
832
|
-
if (attributes.length === 0) {
|
|
833
|
-
return {
|
|
834
|
-
content: [{ type: "text", text: "No attributes found matching the search criteria." }]
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
const summary = attributes.map((a) => ({
|
|
838
|
-
id: a.id,
|
|
839
|
-
event_id: a.event_id,
|
|
840
|
-
type: a.type,
|
|
841
|
-
category: a.category,
|
|
842
|
-
value: a.value,
|
|
843
|
-
to_ids: a.to_ids,
|
|
844
|
-
comment: a.comment || void 0,
|
|
845
|
-
tags: (a.Tag || []).map((t) => t.name),
|
|
846
|
-
event_info: a.Event?.info,
|
|
847
|
-
correlations: a.RelatedAttribute ? a.RelatedAttribute.map((r) => ({
|
|
848
|
-
value: r.value,
|
|
849
|
-
type: r.type,
|
|
850
|
-
event_id: r.event_id
|
|
851
|
-
})) : void 0
|
|
852
|
-
}));
|
|
853
|
-
return {
|
|
854
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
855
|
-
};
|
|
856
|
-
} catch (err) {
|
|
857
|
-
return {
|
|
858
|
-
content: [
|
|
859
|
-
{ type: "text", text: `Error searching attributes: ${err instanceof Error ? err.message : String(err)}` }
|
|
860
|
-
],
|
|
861
|
-
isError: true
|
|
862
|
-
};
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
);
|
|
866
|
-
server.tool(
|
|
867
|
-
"misp_add_attribute",
|
|
868
|
-
"Add an IOC/attribute to a MISP event",
|
|
869
|
-
{
|
|
870
|
-
eventId: z2.string().describe("Event ID to add the attribute to"),
|
|
871
|
-
type: z2.string().describe("Attribute type (ip-src, ip-dst, domain, md5, sha256, sha1, url, email-src, hostname, filename, etc.)"),
|
|
872
|
-
value: z2.string().describe("The IOC value"),
|
|
873
|
-
category: z2.string().optional().describe("Category (auto-determined from type if omitted)"),
|
|
874
|
-
toIds: z2.boolean().optional().describe("Flag for IDS export (default true for applicable types)"),
|
|
875
|
-
comment: z2.string().optional().describe("Context/notes about this IOC"),
|
|
876
|
-
distribution: z2.number().optional().describe("Distribution level (0-4)"),
|
|
877
|
-
tags: z2.array(z2.string()).optional().describe("Tags to apply to the attribute")
|
|
878
|
-
},
|
|
879
|
-
async (params) => {
|
|
880
|
-
try {
|
|
881
|
-
const attribute = await client.addAttribute(params.eventId, {
|
|
882
|
-
type: params.type,
|
|
883
|
-
value: params.value,
|
|
884
|
-
category: params.category,
|
|
885
|
-
to_ids: params.toIds,
|
|
886
|
-
comment: params.comment,
|
|
887
|
-
distribution: params.distribution,
|
|
888
|
-
tags: params.tags
|
|
889
|
-
});
|
|
890
|
-
return {
|
|
891
|
-
content: [
|
|
892
|
-
{
|
|
893
|
-
type: "text",
|
|
894
|
-
text: JSON.stringify(
|
|
895
|
-
{
|
|
896
|
-
id: attribute.id,
|
|
897
|
-
event_id: attribute.event_id,
|
|
898
|
-
type: attribute.type,
|
|
899
|
-
category: attribute.category,
|
|
900
|
-
value: attribute.value,
|
|
901
|
-
to_ids: attribute.to_ids
|
|
902
|
-
},
|
|
903
|
-
null,
|
|
904
|
-
2
|
|
905
|
-
)
|
|
906
|
-
}
|
|
907
|
-
]
|
|
908
|
-
};
|
|
909
|
-
} catch (err) {
|
|
910
|
-
return {
|
|
911
|
-
content: [
|
|
912
|
-
{ type: "text", text: `Error adding attribute: ${err instanceof Error ? err.message : String(err)}` }
|
|
913
|
-
],
|
|
914
|
-
isError: true
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
}
|
|
918
|
-
);
|
|
919
|
-
server.tool(
|
|
920
|
-
"misp_add_attributes_bulk",
|
|
921
|
-
"Add multiple attributes (IOCs) to a MISP event at once",
|
|
922
|
-
{
|
|
923
|
-
eventId: z2.string().describe("Event ID to add attributes to"),
|
|
924
|
-
attributes: z2.array(
|
|
925
|
-
z2.object({
|
|
926
|
-
type: z2.string().describe("Attribute type"),
|
|
927
|
-
value: z2.string().describe("IOC value"),
|
|
928
|
-
category: z2.string().optional().describe("Category"),
|
|
929
|
-
toIds: z2.boolean().optional().describe("IDS flag"),
|
|
930
|
-
comment: z2.string().optional().describe("Comment")
|
|
931
|
-
})
|
|
932
|
-
).describe("Array of attributes to add")
|
|
933
|
-
},
|
|
934
|
-
async ({ eventId, attributes }) => {
|
|
935
|
-
try {
|
|
936
|
-
const results = [];
|
|
937
|
-
for (const attr of attributes) {
|
|
938
|
-
try {
|
|
939
|
-
const created = await client.addAttribute(eventId, {
|
|
940
|
-
type: attr.type,
|
|
941
|
-
value: attr.value,
|
|
942
|
-
category: attr.category,
|
|
943
|
-
to_ids: attr.toIds,
|
|
944
|
-
comment: attr.comment
|
|
945
|
-
});
|
|
946
|
-
results.push({
|
|
947
|
-
value: attr.value,
|
|
948
|
-
type: attr.type,
|
|
949
|
-
id: created.id
|
|
950
|
-
});
|
|
951
|
-
} catch (err) {
|
|
952
|
-
results.push({
|
|
953
|
-
value: attr.value,
|
|
954
|
-
type: attr.type,
|
|
955
|
-
error: err instanceof Error ? err.message : String(err)
|
|
956
|
-
});
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
const succeeded = results.filter((r) => r.id);
|
|
960
|
-
const failed = results.filter((r) => r.error);
|
|
961
|
-
return {
|
|
962
|
-
content: [
|
|
963
|
-
{
|
|
964
|
-
type: "text",
|
|
965
|
-
text: JSON.stringify(
|
|
966
|
-
{
|
|
967
|
-
total: attributes.length,
|
|
968
|
-
succeeded: succeeded.length,
|
|
969
|
-
failed: failed.length,
|
|
970
|
-
results
|
|
971
|
-
},
|
|
972
|
-
null,
|
|
973
|
-
2
|
|
974
|
-
)
|
|
975
|
-
}
|
|
976
|
-
]
|
|
977
|
-
};
|
|
978
|
-
} catch (err) {
|
|
979
|
-
return {
|
|
980
|
-
content: [
|
|
981
|
-
{ type: "text", text: `Error adding attributes: ${err instanceof Error ? err.message : String(err)}` }
|
|
982
|
-
],
|
|
983
|
-
isError: true
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
}
|
|
987
|
-
);
|
|
988
|
-
server.tool(
|
|
989
|
-
"misp_delete_attribute",
|
|
990
|
-
"Delete (soft or hard) an attribute from MISP. Destructive: requires confirm:true (or MISP_ALLOW_DESTRUCTIVE=true); hard delete also requires confirmHard:true.",
|
|
991
|
-
{
|
|
992
|
-
attributeId: z2.string().describe("Attribute ID to delete"),
|
|
993
|
-
hard: z2.boolean().optional().describe("Hard delete (permanent) instead of soft delete"),
|
|
994
|
-
confirm: z2.boolean().optional().describe("Must be true to perform this destructive deletion (unless MISP_ALLOW_DESTRUCTIVE=true)"),
|
|
995
|
-
confirmHard: z2.boolean().optional().describe("Must be true (in addition to confirm) to perform a permanent hard delete")
|
|
996
|
-
},
|
|
997
|
-
async ({ attributeId, hard, confirm, confirmHard }) => {
|
|
998
|
-
try {
|
|
999
|
-
const guard = requireConfirmation(confirm, `deleting attribute ${attributeId}`);
|
|
1000
|
-
if (guard) return guard;
|
|
1001
|
-
if (hard) {
|
|
1002
|
-
const hardGuard = requireHardConfirmation(
|
|
1003
|
-
confirmHard,
|
|
1004
|
-
`hard-deleting attribute ${attributeId}`
|
|
1005
|
-
);
|
|
1006
|
-
if (hardGuard) return hardGuard;
|
|
1007
|
-
}
|
|
1008
|
-
const result = await client.deleteAttribute(attributeId, hard);
|
|
1009
|
-
return {
|
|
1010
|
-
content: [
|
|
1011
|
-
{ type: "text", text: result.message || `Attribute ${attributeId} deleted successfully.` }
|
|
1012
|
-
]
|
|
1013
|
-
};
|
|
1014
|
-
} catch (err) {
|
|
1015
|
-
return {
|
|
1016
|
-
content: [
|
|
1017
|
-
{ type: "text", text: `Error deleting attribute: ${err instanceof Error ? err.message : String(err)}` }
|
|
1018
|
-
],
|
|
1019
|
-
isError: true
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
}
|
|
1023
|
-
);
|
|
1024
|
-
}
|
|
1025
|
-
|
|
1026
|
-
// src/tools/correlation.ts
|
|
1027
|
-
import { z as z3 } from "zod";
|
|
1028
|
-
function registerCorrelationTools(server, client) {
|
|
1029
|
-
server.tool(
|
|
1030
|
-
"misp_correlate",
|
|
1031
|
-
"Find correlations for a specific observable value across all MISP events",
|
|
1032
|
-
{
|
|
1033
|
-
value: z3.string().describe("Observable value to correlate (IP, domain, hash, etc.)")
|
|
1034
|
-
},
|
|
1035
|
-
async ({ value }) => {
|
|
1036
|
-
try {
|
|
1037
|
-
const attributes = await client.searchAttributes({
|
|
1038
|
-
value,
|
|
1039
|
-
includeCorrelations: true
|
|
1040
|
-
});
|
|
1041
|
-
if (attributes.length === 0) {
|
|
1042
|
-
return {
|
|
1043
|
-
content: [{ type: "text", text: `No results found for "${value}" in MISP.` }]
|
|
1044
|
-
};
|
|
1045
|
-
}
|
|
1046
|
-
const eventMap = /* @__PURE__ */ new Map();
|
|
1047
|
-
for (const attr of attributes) {
|
|
1048
|
-
const eid = attr.event_id;
|
|
1049
|
-
if (!eventMap.has(eid)) {
|
|
1050
|
-
eventMap.set(eid, {
|
|
1051
|
-
event_id: eid,
|
|
1052
|
-
event_info: attr.Event?.info || "Unknown",
|
|
1053
|
-
attributes: []
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
eventMap.get(eid).attributes.push({
|
|
1057
|
-
id: attr.id,
|
|
1058
|
-
type: attr.type,
|
|
1059
|
-
category: attr.category,
|
|
1060
|
-
value: attr.value
|
|
1061
|
-
});
|
|
1062
|
-
}
|
|
1063
|
-
const correlations = [];
|
|
1064
|
-
for (const attr of attributes) {
|
|
1065
|
-
if (attr.RelatedAttribute) {
|
|
1066
|
-
for (const rel of attr.RelatedAttribute) {
|
|
1067
|
-
correlations.push({
|
|
1068
|
-
value: rel.value,
|
|
1069
|
-
type: rel.type,
|
|
1070
|
-
event_id: rel.event_id
|
|
1071
|
-
});
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
const result = {
|
|
1076
|
-
searched_value: value,
|
|
1077
|
-
found_in_events: Array.from(eventMap.values()),
|
|
1078
|
-
total_events: eventMap.size,
|
|
1079
|
-
total_attributes: attributes.length,
|
|
1080
|
-
correlations: correlations.length > 0 ? correlations : void 0
|
|
1081
|
-
};
|
|
1082
|
-
return {
|
|
1083
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
1084
|
-
};
|
|
1085
|
-
} catch (err) {
|
|
1086
|
-
return {
|
|
1087
|
-
content: [
|
|
1088
|
-
{ type: "text", text: `Error correlating value: ${err instanceof Error ? err.message : String(err)}` }
|
|
1089
|
-
],
|
|
1090
|
-
isError: true
|
|
1091
|
-
};
|
|
1092
|
-
}
|
|
1093
|
-
}
|
|
1094
|
-
);
|
|
1095
|
-
server.tool(
|
|
1096
|
-
"misp_get_related_events",
|
|
1097
|
-
"Get events related to a specific event through shared attributes and correlations",
|
|
1098
|
-
{
|
|
1099
|
-
eventId: z3.string().describe("Event ID to find related events for"),
|
|
1100
|
-
maxAttributes: z3.number().int().positive().optional().describe("Max number of to_ids attributes to correlate across (default 20). Higher values hit the MISP API more."),
|
|
1101
|
-
perAttributeLimit: z3.number().int().positive().optional().describe("Max matches to fetch per attribute value (default 100).")
|
|
1102
|
-
},
|
|
1103
|
-
async ({ eventId, maxAttributes, perAttributeLimit }) => {
|
|
1104
|
-
try {
|
|
1105
|
-
const attrCap = maxAttributes ?? 20;
|
|
1106
|
-
const matchLimit = perAttributeLimit ?? 100;
|
|
1107
|
-
const event = await client.getEvent(eventId);
|
|
1108
|
-
const eventAttributes = event.Attribute || [];
|
|
1109
|
-
if (eventAttributes.length === 0) {
|
|
1110
|
-
return {
|
|
1111
|
-
content: [{ type: "text", text: `Event ${eventId} has no attributes to correlate.` }]
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
const relatedMap = /* @__PURE__ */ new Map();
|
|
1115
|
-
if (event.RelatedEvent && event.RelatedEvent.length > 0) {
|
|
1116
|
-
for (const rel of event.RelatedEvent) {
|
|
1117
|
-
relatedMap.set(rel.Event.id, {
|
|
1118
|
-
event_id: rel.Event.id,
|
|
1119
|
-
event_info: rel.Event.info,
|
|
1120
|
-
overlapping_iocs: [],
|
|
1121
|
-
correlation_count: 0
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
const toIdsAttrs = eventAttributes.filter((a) => a.to_ids);
|
|
1126
|
-
const truncatedAttributes = toIdsAttrs.length > attrCap;
|
|
1127
|
-
const valuesToSearch = toIdsAttrs.slice(0, attrCap).map((a) => a.value);
|
|
1128
|
-
let truncatedMatches = false;
|
|
1129
|
-
for (const value of valuesToSearch) {
|
|
1130
|
-
const matches = await client.searchAttributes({
|
|
1131
|
-
value,
|
|
1132
|
-
includeCorrelations: true,
|
|
1133
|
-
limit: matchLimit
|
|
1134
|
-
});
|
|
1135
|
-
if (matches.length >= matchLimit) {
|
|
1136
|
-
truncatedMatches = true;
|
|
1137
|
-
}
|
|
1138
|
-
for (const match of matches) {
|
|
1139
|
-
if (match.event_id !== eventId) {
|
|
1140
|
-
if (!relatedMap.has(match.event_id)) {
|
|
1141
|
-
relatedMap.set(match.event_id, {
|
|
1142
|
-
event_id: match.event_id,
|
|
1143
|
-
event_info: match.Event?.info || "Unknown",
|
|
1144
|
-
overlapping_iocs: [],
|
|
1145
|
-
correlation_count: 0
|
|
1146
|
-
});
|
|
1147
|
-
}
|
|
1148
|
-
const entry = relatedMap.get(match.event_id);
|
|
1149
|
-
if (!entry.overlapping_iocs.includes(value)) {
|
|
1150
|
-
entry.overlapping_iocs.push(value);
|
|
1151
|
-
}
|
|
1152
|
-
entry.correlation_count++;
|
|
1153
|
-
}
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
const related = Array.from(relatedMap.values()).sort(
|
|
1157
|
-
(a, b) => b.correlation_count - a.correlation_count
|
|
1158
|
-
);
|
|
1159
|
-
return {
|
|
1160
|
-
content: [
|
|
1161
|
-
{
|
|
1162
|
-
type: "text",
|
|
1163
|
-
text: JSON.stringify(
|
|
1164
|
-
{
|
|
1165
|
-
event_id: eventId,
|
|
1166
|
-
event_info: event.info,
|
|
1167
|
-
related_events: related,
|
|
1168
|
-
total_related: related.length,
|
|
1169
|
-
truncated: truncatedAttributes || truncatedMatches,
|
|
1170
|
-
truncation_reason: truncatedAttributes ? `Only the first ${attrCap} of ${toIdsAttrs.length} to_ids attributes were correlated. Raise maxAttributes to scan more.` : truncatedMatches ? `At least one attribute hit the per-attribute match limit of ${matchLimit}. Raise perAttributeLimit to see more correlations.` : void 0
|
|
1171
|
-
},
|
|
1172
|
-
null,
|
|
1173
|
-
2
|
|
1174
|
-
)
|
|
1175
|
-
}
|
|
1176
|
-
]
|
|
1177
|
-
};
|
|
1178
|
-
} catch (err) {
|
|
1179
|
-
return {
|
|
1180
|
-
content: [
|
|
1181
|
-
{ type: "text", text: `Error finding related events: ${err instanceof Error ? err.message : String(err)}` }
|
|
1182
|
-
],
|
|
1183
|
-
isError: true
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
);
|
|
1188
|
-
server.tool(
|
|
1189
|
-
"misp_describe_types",
|
|
1190
|
-
"Get all available MISP attribute types and categories with their mappings",
|
|
1191
|
-
{},
|
|
1192
|
-
async () => {
|
|
1193
|
-
try {
|
|
1194
|
-
const types = await client.describeTypes();
|
|
1195
|
-
return {
|
|
1196
|
-
content: [{ type: "text", text: JSON.stringify(types, null, 2) }]
|
|
1197
|
-
};
|
|
1198
|
-
} catch (err) {
|
|
1199
|
-
return {
|
|
1200
|
-
content: [
|
|
1201
|
-
{ type: "text", text: `Error getting types: ${err instanceof Error ? err.message : String(err)}` }
|
|
1202
|
-
],
|
|
1203
|
-
isError: true
|
|
1204
|
-
};
|
|
1205
|
-
}
|
|
1206
|
-
}
|
|
1207
|
-
);
|
|
1208
|
-
}
|
|
1209
|
-
|
|
1210
|
-
// src/tools/tags.ts
|
|
1211
|
-
import { z as z4 } from "zod";
|
|
1212
|
-
function registerTagTools(server, client) {
|
|
1213
|
-
server.tool(
|
|
1214
|
-
"misp_list_tags",
|
|
1215
|
-
"List available MISP tags with usage statistics",
|
|
1216
|
-
{
|
|
1217
|
-
search: z4.string().optional().describe("Search filter for tag names"),
|
|
1218
|
-
limit: z4.number().optional().describe("Max results to return")
|
|
1219
|
-
},
|
|
1220
|
-
async ({ search, limit }) => {
|
|
1221
|
-
try {
|
|
1222
|
-
let tags = await client.listTags(search);
|
|
1223
|
-
if (limit && limit > 0) {
|
|
1224
|
-
tags = tags.slice(0, limit);
|
|
1225
|
-
}
|
|
1226
|
-
if (tags.length === 0) {
|
|
1227
|
-
return {
|
|
1228
|
-
content: [{ type: "text", text: "No tags found." }]
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
const summary = tags.map((t) => ({
|
|
1232
|
-
id: t.id,
|
|
1233
|
-
name: t.name,
|
|
1234
|
-
colour: t.colour,
|
|
1235
|
-
event_count: t.event_count,
|
|
1236
|
-
attribute_count: t.attribute_count
|
|
1237
|
-
}));
|
|
1238
|
-
return {
|
|
1239
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
1240
|
-
};
|
|
1241
|
-
} catch (err) {
|
|
1242
|
-
return {
|
|
1243
|
-
content: [
|
|
1244
|
-
{ type: "text", text: `Error listing tags: ${err instanceof Error ? err.message : String(err)}` }
|
|
1245
|
-
],
|
|
1246
|
-
isError: true
|
|
1247
|
-
};
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
);
|
|
1251
|
-
server.tool(
|
|
1252
|
-
"misp_search_by_tag",
|
|
1253
|
-
"Search MISP events or attributes by tag (MITRE ATT&CK, TLP, custom tags)",
|
|
1254
|
-
{
|
|
1255
|
-
tag: z4.string().describe("Tag name to search for (e.g., tlp:white, mitre-attack:T1059)"),
|
|
1256
|
-
type: z4.enum(["event", "attribute"]).optional().describe("Search events or attributes (default: event)")
|
|
1257
|
-
},
|
|
1258
|
-
async ({ tag, type: searchType }) => {
|
|
1259
|
-
try {
|
|
1260
|
-
if (searchType === "attribute") {
|
|
1261
|
-
const attributes = await client.searchAttributes({ tags: [tag] });
|
|
1262
|
-
if (attributes.length === 0) {
|
|
1263
|
-
return {
|
|
1264
|
-
content: [{ type: "text", text: `No attributes found with tag "${tag}".` }]
|
|
1265
|
-
};
|
|
1266
|
-
}
|
|
1267
|
-
const summary2 = attributes.map((a) => ({
|
|
1268
|
-
id: a.id,
|
|
1269
|
-
event_id: a.event_id,
|
|
1270
|
-
type: a.type,
|
|
1271
|
-
value: a.value,
|
|
1272
|
-
category: a.category,
|
|
1273
|
-
event_info: a.Event?.info
|
|
1274
|
-
}));
|
|
1275
|
-
return {
|
|
1276
|
-
content: [{ type: "text", text: JSON.stringify(summary2, null, 2) }]
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
const events = await client.searchEvents({ tags: [tag] });
|
|
1280
|
-
if (events.length === 0) {
|
|
1281
|
-
return {
|
|
1282
|
-
content: [{ type: "text", text: `No events found with tag "${tag}".` }]
|
|
1283
|
-
};
|
|
1284
|
-
}
|
|
1285
|
-
const summary = events.map((e) => ({
|
|
1286
|
-
id: e.id,
|
|
1287
|
-
info: e.info,
|
|
1288
|
-
date: e.date,
|
|
1289
|
-
threat_level: ["", "High", "Medium", "Low", "Undefined"][parseInt(e.threat_level_id) || 0],
|
|
1290
|
-
org: e.Orgc?.name || "Unknown",
|
|
1291
|
-
tags: (e.Tag || []).map((t) => t.name)
|
|
1292
|
-
}));
|
|
1293
|
-
return {
|
|
1294
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
1295
|
-
};
|
|
1296
|
-
} catch (err) {
|
|
1297
|
-
return {
|
|
1298
|
-
content: [
|
|
1299
|
-
{ type: "text", text: `Error searching by tag: ${err instanceof Error ? err.message : String(err)}` }
|
|
1300
|
-
],
|
|
1301
|
-
isError: true
|
|
1302
|
-
};
|
|
1303
|
-
}
|
|
1304
|
-
}
|
|
1305
|
-
);
|
|
1306
|
-
}
|
|
1307
|
-
|
|
1308
|
-
// src/tools/exports.ts
|
|
1309
|
-
import { z as z5 } from "zod";
|
|
1310
|
-
function registerExportTools(server, client) {
|
|
1311
|
-
server.tool(
|
|
1312
|
-
"misp_export_iocs",
|
|
1313
|
-
"Export IOCs from MISP in various formats (CSV, STIX, Suricata, Snort, text, RPZ)",
|
|
1314
|
-
{
|
|
1315
|
-
format: z5.enum(["csv", "stix", "suricata", "snort", "text", "rpz"]).describe("Export format"),
|
|
1316
|
-
eventId: z5.string().optional().describe("Specific event ID (or all events if omitted)"),
|
|
1317
|
-
type: z5.string().optional().describe("Filter by attribute type"),
|
|
1318
|
-
tags: z5.array(z5.string()).optional().describe("Filter by tags"),
|
|
1319
|
-
last: z5.string().optional().describe("Relative time filter (e.g., 1d, 7d)")
|
|
1320
|
-
},
|
|
1321
|
-
async (params) => {
|
|
1322
|
-
try {
|
|
1323
|
-
const output = await client.exportEvents({
|
|
1324
|
-
format: params.format,
|
|
1325
|
-
eventId: params.eventId,
|
|
1326
|
-
type: params.type,
|
|
1327
|
-
tags: params.tags,
|
|
1328
|
-
last: params.last
|
|
1329
|
-
});
|
|
1330
|
-
if (!output || output.trim().length === 0) {
|
|
1331
|
-
return {
|
|
1332
|
-
content: [
|
|
1333
|
-
{ type: "text", text: `No IOCs found for the specified criteria in ${params.format} format.` }
|
|
1334
|
-
]
|
|
1335
|
-
};
|
|
1336
|
-
}
|
|
1337
|
-
return {
|
|
1338
|
-
content: [{ type: "text", text: output }]
|
|
1339
|
-
};
|
|
1340
|
-
} catch (err) {
|
|
1341
|
-
return {
|
|
1342
|
-
content: [
|
|
1343
|
-
{ type: "text", text: `Error exporting IOCs: ${err instanceof Error ? err.message : String(err)}` }
|
|
1344
|
-
],
|
|
1345
|
-
isError: true
|
|
1346
|
-
};
|
|
1347
|
-
}
|
|
1348
|
-
}
|
|
1349
|
-
);
|
|
1350
|
-
server.tool(
|
|
1351
|
-
"misp_export_hashes",
|
|
1352
|
-
"Export file hashes from MISP for HIDS integration",
|
|
1353
|
-
{
|
|
1354
|
-
format: z5.enum(["md5", "sha1", "sha256"]).describe("Hash format to export"),
|
|
1355
|
-
last: z5.string().optional().describe("Relative time filter (e.g., 1d, 7d)"),
|
|
1356
|
-
tags: z5.array(z5.string()).optional().describe("Filter by tags")
|
|
1357
|
-
},
|
|
1358
|
-
async (params) => {
|
|
1359
|
-
try {
|
|
1360
|
-
const output = await client.exportHashes({
|
|
1361
|
-
format: params.format,
|
|
1362
|
-
last: params.last,
|
|
1363
|
-
tags: params.tags
|
|
1364
|
-
});
|
|
1365
|
-
if (!output || output.trim().length === 0) {
|
|
1366
|
-
return {
|
|
1367
|
-
content: [
|
|
1368
|
-
{ type: "text", text: `No ${params.format} hashes found for the specified criteria.` }
|
|
1369
|
-
]
|
|
1370
|
-
};
|
|
1371
|
-
}
|
|
1372
|
-
return {
|
|
1373
|
-
content: [{ type: "text", text: output }]
|
|
1374
|
-
};
|
|
1375
|
-
} catch (err) {
|
|
1376
|
-
return {
|
|
1377
|
-
content: [
|
|
1378
|
-
{ type: "text", text: `Error exporting hashes: ${err instanceof Error ? err.message : String(err)}` }
|
|
1379
|
-
],
|
|
1380
|
-
isError: true
|
|
1381
|
-
};
|
|
1382
|
-
}
|
|
1383
|
-
}
|
|
1384
|
-
);
|
|
1385
|
-
}
|
|
1386
|
-
|
|
1387
|
-
// src/tools/sightings.ts
|
|
1388
|
-
import { z as z6 } from "zod";
|
|
1389
|
-
function registerSightingTools(server, client) {
|
|
1390
|
-
server.tool(
|
|
1391
|
-
"misp_add_sighting",
|
|
1392
|
-
"Report a sighting of an IOC (confirms it was observed in the wild, marks as false positive, or sets expiration)",
|
|
1393
|
-
{
|
|
1394
|
-
attributeId: z6.string().optional().describe("Attribute ID to sight (use this or value)"),
|
|
1395
|
-
value: z6.string().optional().describe("Attribute value to sight (use this or attributeId)"),
|
|
1396
|
-
type: z6.union([z6.literal(0), z6.literal(1), z6.literal(2)]).describe("0=Sighting (seen in the wild), 1=False positive, 2=Expiration"),
|
|
1397
|
-
source: z6.string().optional().describe("Source of the sighting (e.g., organization name, sensor ID)"),
|
|
1398
|
-
timestamp: z6.string().optional().describe("Timestamp of the sighting (Unix timestamp)")
|
|
1399
|
-
},
|
|
1400
|
-
async (params) => {
|
|
1401
|
-
try {
|
|
1402
|
-
if (!params.attributeId && !params.value) {
|
|
1403
|
-
return {
|
|
1404
|
-
content: [
|
|
1405
|
-
{ type: "text", text: "Either attributeId or value must be provided." }
|
|
1406
|
-
],
|
|
1407
|
-
isError: true
|
|
1408
|
-
};
|
|
1409
|
-
}
|
|
1410
|
-
const sighting = await client.addSighting({
|
|
1411
|
-
attributeId: params.attributeId,
|
|
1412
|
-
value: params.value,
|
|
1413
|
-
type: params.type,
|
|
1414
|
-
source: params.source,
|
|
1415
|
-
timestamp: params.timestamp
|
|
1416
|
-
});
|
|
1417
|
-
const typeLabels = ["Sighting", "False positive", "Expiration"];
|
|
1418
|
-
return {
|
|
1419
|
-
content: [
|
|
1420
|
-
{
|
|
1421
|
-
type: "text",
|
|
1422
|
-
text: JSON.stringify(
|
|
1423
|
-
{
|
|
1424
|
-
id: sighting.id,
|
|
1425
|
-
type: typeLabels[params.type],
|
|
1426
|
-
attribute_id: sighting.attribute_id,
|
|
1427
|
-
event_id: sighting.event_id,
|
|
1428
|
-
source: sighting.source,
|
|
1429
|
-
date_sighting: sighting.date_sighting
|
|
1430
|
-
},
|
|
1431
|
-
null,
|
|
1432
|
-
2
|
|
1433
|
-
)
|
|
1434
|
-
}
|
|
1435
|
-
]
|
|
1436
|
-
};
|
|
1437
|
-
} catch (err) {
|
|
1438
|
-
return {
|
|
1439
|
-
content: [
|
|
1440
|
-
{ type: "text", text: `Error adding sighting: ${err instanceof Error ? err.message : String(err)}` }
|
|
1441
|
-
],
|
|
1442
|
-
isError: true
|
|
1443
|
-
};
|
|
1444
|
-
}
|
|
1445
|
-
}
|
|
1446
|
-
);
|
|
1447
|
-
}
|
|
1448
|
-
|
|
1449
|
-
// src/tools/warninglists.ts
|
|
1450
|
-
import { z as z7 } from "zod";
|
|
1451
|
-
function registerWarninglistTools(server, client) {
|
|
1452
|
-
server.tool(
|
|
1453
|
-
"misp_check_warninglists",
|
|
1454
|
-
"Check if an observable value appears on any MISP warninglists (known benign/false positive lists)",
|
|
1455
|
-
{
|
|
1456
|
-
value: z7.string().describe("Value to check against warninglists (IP, domain, hash, etc.)")
|
|
1457
|
-
},
|
|
1458
|
-
async ({ value }) => {
|
|
1459
|
-
try {
|
|
1460
|
-
const results = await client.checkWarninglists(value);
|
|
1461
|
-
const matches = results[value] || [];
|
|
1462
|
-
if (matches.length === 0) {
|
|
1463
|
-
return {
|
|
1464
|
-
content: [
|
|
1465
|
-
{
|
|
1466
|
-
type: "text",
|
|
1467
|
-
text: `"${value}" does not appear on any warninglists. This does not confirm it is malicious, but it is not a known benign indicator.`
|
|
1468
|
-
}
|
|
1469
|
-
]
|
|
1470
|
-
};
|
|
1471
|
-
}
|
|
1472
|
-
const summary = matches.map((w) => ({
|
|
1473
|
-
name: w.name,
|
|
1474
|
-
category: w.category,
|
|
1475
|
-
description: w.description,
|
|
1476
|
-
type: w.type
|
|
1477
|
-
}));
|
|
1478
|
-
return {
|
|
1479
|
-
content: [
|
|
1480
|
-
{
|
|
1481
|
-
type: "text",
|
|
1482
|
-
text: JSON.stringify(
|
|
1483
|
-
{
|
|
1484
|
-
value,
|
|
1485
|
-
on_warninglists: true,
|
|
1486
|
-
match_count: matches.length,
|
|
1487
|
-
warninglists: summary,
|
|
1488
|
-
note: "This value appears on known benign/false positive lists. Exercise caution before treating it as malicious."
|
|
1489
|
-
},
|
|
1490
|
-
null,
|
|
1491
|
-
2
|
|
1492
|
-
)
|
|
1493
|
-
}
|
|
1494
|
-
]
|
|
1495
|
-
};
|
|
1496
|
-
} catch (err) {
|
|
1497
|
-
return {
|
|
1498
|
-
content: [
|
|
1499
|
-
{ type: "text", text: `Error checking warninglists: ${err instanceof Error ? err.message : String(err)}` }
|
|
1500
|
-
],
|
|
1501
|
-
isError: true
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
}
|
|
1505
|
-
);
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
// src/tools/objects.ts
|
|
1509
|
-
import { z as z8 } from "zod";
|
|
1510
|
-
function registerObjectTools(server, client) {
|
|
1511
|
-
server.tool(
|
|
1512
|
-
"misp_list_object_templates",
|
|
1513
|
-
"List available MISP object templates (file, domain-ip, email, network-connection, etc.)",
|
|
1514
|
-
{
|
|
1515
|
-
search: z8.string().optional().describe("Filter templates by name"),
|
|
1516
|
-
limit: z8.number().optional().describe("Max results (default 50)")
|
|
1517
|
-
},
|
|
1518
|
-
async ({ search, limit }) => {
|
|
1519
|
-
try {
|
|
1520
|
-
const templates = await client.listObjectTemplates();
|
|
1521
|
-
let filtered = templates;
|
|
1522
|
-
if (search) {
|
|
1523
|
-
const q = search.toLowerCase();
|
|
1524
|
-
filtered = templates.filter(
|
|
1525
|
-
(t) => t.name.toLowerCase().includes(q) || t.description.toLowerCase().includes(q)
|
|
1526
|
-
);
|
|
1527
|
-
}
|
|
1528
|
-
if (limit && limit > 0) {
|
|
1529
|
-
filtered = filtered.slice(0, limit);
|
|
1530
|
-
}
|
|
1531
|
-
if (filtered.length === 0) {
|
|
1532
|
-
return {
|
|
1533
|
-
content: [{ type: "text", text: "No object templates found." }]
|
|
1534
|
-
};
|
|
1535
|
-
}
|
|
1536
|
-
const summary = filtered.map((t) => ({
|
|
1537
|
-
id: t.id,
|
|
1538
|
-
uuid: t.uuid,
|
|
1539
|
-
name: t.name,
|
|
1540
|
-
description: t.description,
|
|
1541
|
-
version: t.version,
|
|
1542
|
-
meta_category: t.meta_category
|
|
1543
|
-
}));
|
|
1544
|
-
return {
|
|
1545
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
1546
|
-
};
|
|
1547
|
-
} catch (err) {
|
|
1548
|
-
return {
|
|
1549
|
-
content: [
|
|
1550
|
-
{
|
|
1551
|
-
type: "text",
|
|
1552
|
-
text: `Error listing object templates: ${err instanceof Error ? err.message : String(err)}`
|
|
1553
|
-
}
|
|
1554
|
-
],
|
|
1555
|
-
isError: true
|
|
1556
|
-
};
|
|
1557
|
-
}
|
|
1558
|
-
}
|
|
1559
|
-
);
|
|
1560
|
-
server.tool(
|
|
1561
|
-
"misp_get_object_template",
|
|
1562
|
-
"Get details of a specific MISP object template including required and optional attributes",
|
|
1563
|
-
{
|
|
1564
|
-
templateId: z8.string().describe("Object template ID or UUID")
|
|
1565
|
-
},
|
|
1566
|
-
async ({ templateId }) => {
|
|
1567
|
-
try {
|
|
1568
|
-
const template = await client.getObjectTemplate(templateId);
|
|
1569
|
-
return {
|
|
1570
|
-
content: [{ type: "text", text: JSON.stringify(template, null, 2) }]
|
|
1571
|
-
};
|
|
1572
|
-
} catch (err) {
|
|
1573
|
-
return {
|
|
1574
|
-
content: [
|
|
1575
|
-
{
|
|
1576
|
-
type: "text",
|
|
1577
|
-
text: `Error getting object template: ${err instanceof Error ? err.message : String(err)}`
|
|
1578
|
-
}
|
|
1579
|
-
],
|
|
1580
|
-
isError: true
|
|
1581
|
-
};
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
);
|
|
1585
|
-
server.tool(
|
|
1586
|
-
"misp_add_object",
|
|
1587
|
-
"Add a MISP object (structured group of attributes) to an event",
|
|
1588
|
-
{
|
|
1589
|
-
eventId: z8.string().describe("Event ID to add the object to"),
|
|
1590
|
-
templateName: z8.string().describe(
|
|
1591
|
-
"Object template name (e.g., file, domain-ip, email, network-connection, url)"
|
|
1592
|
-
),
|
|
1593
|
-
attributes: z8.array(
|
|
1594
|
-
z8.object({
|
|
1595
|
-
object_relation: z8.string().describe(
|
|
1596
|
-
"Attribute relation within the object (e.g., filename, md5, ip, domain)"
|
|
1597
|
-
),
|
|
1598
|
-
type: z8.string().describe("Attribute type (ip-dst, domain, md5, filename, etc.)"),
|
|
1599
|
-
value: z8.string().describe("Attribute value"),
|
|
1600
|
-
to_ids: z8.boolean().optional().describe("Flag for IDS export"),
|
|
1601
|
-
comment: z8.string().optional().describe("Comment")
|
|
1602
|
-
})
|
|
1603
|
-
).describe("Attributes to include in the object"),
|
|
1604
|
-
comment: z8.string().optional().describe("Object-level comment"),
|
|
1605
|
-
distribution: z8.number().optional().describe("Distribution level (0-4)")
|
|
1606
|
-
},
|
|
1607
|
-
async ({ eventId, templateName, attributes, comment, distribution }) => {
|
|
1608
|
-
try {
|
|
1609
|
-
const result = await client.addObject(eventId, {
|
|
1610
|
-
name: templateName,
|
|
1611
|
-
attributes,
|
|
1612
|
-
comment,
|
|
1613
|
-
distribution
|
|
1614
|
-
});
|
|
1615
|
-
return {
|
|
1616
|
-
content: [
|
|
1617
|
-
{
|
|
1618
|
-
type: "text",
|
|
1619
|
-
text: JSON.stringify(
|
|
1620
|
-
{
|
|
1621
|
-
id: result.id,
|
|
1622
|
-
name: result.name,
|
|
1623
|
-
event_id: result.event_id,
|
|
1624
|
-
meta_category: result.meta_category,
|
|
1625
|
-
description: result.description,
|
|
1626
|
-
attributes: (result.Attribute || []).map((a) => ({
|
|
1627
|
-
type: a.type,
|
|
1628
|
-
object_relation: a.object_relation,
|
|
1629
|
-
value: a.value
|
|
1630
|
-
}))
|
|
1631
|
-
},
|
|
1632
|
-
null,
|
|
1633
|
-
2
|
|
1634
|
-
)
|
|
1635
|
-
}
|
|
1636
|
-
]
|
|
1637
|
-
};
|
|
1638
|
-
} catch (err) {
|
|
1639
|
-
return {
|
|
1640
|
-
content: [
|
|
1641
|
-
{
|
|
1642
|
-
type: "text",
|
|
1643
|
-
text: `Error adding object: ${err instanceof Error ? err.message : String(err)}`
|
|
1644
|
-
}
|
|
1645
|
-
],
|
|
1646
|
-
isError: true
|
|
1647
|
-
};
|
|
1648
|
-
}
|
|
1649
|
-
}
|
|
1650
|
-
);
|
|
1651
|
-
server.tool(
|
|
1652
|
-
"misp_delete_object",
|
|
1653
|
-
"Delete a MISP object from an event. Destructive: requires confirm:true (or MISP_ALLOW_DESTRUCTIVE=true); hard delete also requires confirmHard:true.",
|
|
1654
|
-
{
|
|
1655
|
-
objectId: z8.string().describe("Object ID to delete"),
|
|
1656
|
-
hard: z8.boolean().optional().describe("Hard delete (permanent) instead of soft delete"),
|
|
1657
|
-
confirm: z8.boolean().optional().describe("Must be true to perform this destructive deletion (unless MISP_ALLOW_DESTRUCTIVE=true)"),
|
|
1658
|
-
confirmHard: z8.boolean().optional().describe("Must be true (in addition to confirm) to perform a permanent hard delete")
|
|
1659
|
-
},
|
|
1660
|
-
async ({ objectId, hard, confirm, confirmHard }) => {
|
|
1661
|
-
try {
|
|
1662
|
-
const guard = requireConfirmation(confirm, `deleting object ${objectId}`);
|
|
1663
|
-
if (guard) return guard;
|
|
1664
|
-
if (hard) {
|
|
1665
|
-
const hardGuard = requireHardConfirmation(
|
|
1666
|
-
confirmHard,
|
|
1667
|
-
`hard-deleting object ${objectId}`
|
|
1668
|
-
);
|
|
1669
|
-
if (hardGuard) return hardGuard;
|
|
1670
|
-
}
|
|
1671
|
-
const result = await client.deleteObject(objectId, hard);
|
|
1672
|
-
return {
|
|
1673
|
-
content: [
|
|
1674
|
-
{
|
|
1675
|
-
type: "text",
|
|
1676
|
-
text: result.message || `Object ${objectId} deleted successfully.`
|
|
1677
|
-
}
|
|
1678
|
-
]
|
|
1679
|
-
};
|
|
1680
|
-
} catch (err) {
|
|
1681
|
-
return {
|
|
1682
|
-
content: [
|
|
1683
|
-
{
|
|
1684
|
-
type: "text",
|
|
1685
|
-
text: `Error deleting object: ${err instanceof Error ? err.message : String(err)}`
|
|
1686
|
-
}
|
|
1687
|
-
],
|
|
1688
|
-
isError: true
|
|
1689
|
-
};
|
|
1690
|
-
}
|
|
1691
|
-
}
|
|
1692
|
-
);
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
// src/tools/galaxies.ts
|
|
1696
|
-
import { z as z9 } from "zod";
|
|
1697
|
-
function registerGalaxyTools(server, client) {
|
|
1698
|
-
server.tool(
|
|
1699
|
-
"misp_list_galaxies",
|
|
1700
|
-
"List available MISP galaxies (MITRE ATT&CK, threat actors, malware families, tools, etc.)",
|
|
1701
|
-
{
|
|
1702
|
-
search: z9.string().optional().describe("Filter galaxies by name or type"),
|
|
1703
|
-
namespace: z9.string().optional().describe(
|
|
1704
|
-
"Filter by namespace (e.g., mitre-attack-pattern, mitre-intrusion-set, mitre-malware)"
|
|
1705
|
-
)
|
|
1706
|
-
},
|
|
1707
|
-
async ({ search, namespace }) => {
|
|
1708
|
-
try {
|
|
1709
|
-
const galaxies = await client.listGalaxies();
|
|
1710
|
-
let filtered = galaxies;
|
|
1711
|
-
if (search) {
|
|
1712
|
-
const q = search.toLowerCase();
|
|
1713
|
-
filtered = filtered.filter(
|
|
1714
|
-
(g) => g.name.toLowerCase().includes(q) || g.type.toLowerCase().includes(q) || g.description.toLowerCase().includes(q)
|
|
1715
|
-
);
|
|
1716
|
-
}
|
|
1717
|
-
if (namespace) {
|
|
1718
|
-
const ns = namespace.toLowerCase();
|
|
1719
|
-
filtered = filtered.filter(
|
|
1720
|
-
(g) => g.type.toLowerCase().includes(ns)
|
|
1721
|
-
);
|
|
1722
|
-
}
|
|
1723
|
-
if (filtered.length === 0) {
|
|
1724
|
-
return {
|
|
1725
|
-
content: [{ type: "text", text: "No galaxies found matching the criteria." }]
|
|
1726
|
-
};
|
|
1727
|
-
}
|
|
1728
|
-
const summary = filtered.map((g) => ({
|
|
1729
|
-
id: g.id,
|
|
1730
|
-
name: g.name,
|
|
1731
|
-
type: g.type,
|
|
1732
|
-
description: g.description.length > 150 ? g.description.slice(0, 150) + "..." : g.description
|
|
1733
|
-
}));
|
|
1734
|
-
return {
|
|
1735
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
1736
|
-
};
|
|
1737
|
-
} catch (err) {
|
|
1738
|
-
return {
|
|
1739
|
-
content: [
|
|
1740
|
-
{
|
|
1741
|
-
type: "text",
|
|
1742
|
-
text: `Error listing galaxies: ${err instanceof Error ? err.message : String(err)}`
|
|
1743
|
-
}
|
|
1744
|
-
],
|
|
1745
|
-
isError: true
|
|
1746
|
-
};
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
);
|
|
1750
|
-
server.tool(
|
|
1751
|
-
"misp_get_galaxy",
|
|
1752
|
-
"Get a specific galaxy with its clusters (e.g., MITRE ATT&CK techniques, threat actor profiles)",
|
|
1753
|
-
{
|
|
1754
|
-
galaxyId: z9.string().describe("Galaxy ID to retrieve")
|
|
1755
|
-
},
|
|
1756
|
-
async ({ galaxyId }) => {
|
|
1757
|
-
try {
|
|
1758
|
-
const galaxy = await client.getGalaxy(galaxyId);
|
|
1759
|
-
const result = {
|
|
1760
|
-
id: galaxy.id,
|
|
1761
|
-
uuid: galaxy.uuid,
|
|
1762
|
-
name: galaxy.name,
|
|
1763
|
-
type: galaxy.type,
|
|
1764
|
-
description: galaxy.description,
|
|
1765
|
-
clusters: (galaxy.GalaxyCluster || []).map((c) => ({
|
|
1766
|
-
id: c.id,
|
|
1767
|
-
value: c.value,
|
|
1768
|
-
description: c.description && c.description.length > 200 ? c.description.slice(0, 200) + "..." : c.description,
|
|
1769
|
-
tag_name: c.tag_name
|
|
1770
|
-
})),
|
|
1771
|
-
cluster_count: (galaxy.GalaxyCluster || []).length
|
|
1772
|
-
};
|
|
1773
|
-
return {
|
|
1774
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
1775
|
-
};
|
|
1776
|
-
} catch (err) {
|
|
1777
|
-
return {
|
|
1778
|
-
content: [
|
|
1779
|
-
{
|
|
1780
|
-
type: "text",
|
|
1781
|
-
text: `Error getting galaxy: ${err instanceof Error ? err.message : String(err)}`
|
|
1782
|
-
}
|
|
1783
|
-
],
|
|
1784
|
-
isError: true
|
|
1785
|
-
};
|
|
1786
|
-
}
|
|
1787
|
-
}
|
|
1788
|
-
);
|
|
1789
|
-
server.tool(
|
|
1790
|
-
"misp_search_galaxy_clusters",
|
|
1791
|
-
"Search galaxy clusters by keyword (find specific MITRE ATT&CK techniques, threat actors, malware, etc.)",
|
|
1792
|
-
{
|
|
1793
|
-
search: z9.string().describe(
|
|
1794
|
-
"Search term (e.g., 'phishing', 'APT28', 'ransomware', 'T1566')"
|
|
1795
|
-
),
|
|
1796
|
-
galaxyType: z9.string().optional().describe(
|
|
1797
|
-
"Limit to a specific galaxy type (e.g., mitre-attack-pattern, mitre-intrusion-set)"
|
|
1798
|
-
)
|
|
1799
|
-
},
|
|
1800
|
-
async ({ search, galaxyType }) => {
|
|
1801
|
-
try {
|
|
1802
|
-
const results = await client.searchGalaxyClusters(search, galaxyType);
|
|
1803
|
-
if (results.length === 0) {
|
|
1804
|
-
return {
|
|
1805
|
-
content: [
|
|
1806
|
-
{
|
|
1807
|
-
type: "text",
|
|
1808
|
-
text: `No galaxy clusters found matching "${search}".`
|
|
1809
|
-
}
|
|
1810
|
-
]
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1813
|
-
const summary = results.map((c) => ({
|
|
1814
|
-
id: c.id,
|
|
1815
|
-
galaxy_id: c.galaxy_id,
|
|
1816
|
-
value: c.value,
|
|
1817
|
-
description: c.description && c.description.length > 200 ? c.description.slice(0, 200) + "..." : c.description,
|
|
1818
|
-
tag_name: c.tag_name,
|
|
1819
|
-
type: c.type
|
|
1820
|
-
}));
|
|
1821
|
-
return {
|
|
1822
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
1823
|
-
};
|
|
1824
|
-
} catch (err) {
|
|
1825
|
-
return {
|
|
1826
|
-
content: [
|
|
1827
|
-
{
|
|
1828
|
-
type: "text",
|
|
1829
|
-
text: `Error searching galaxy clusters: ${err instanceof Error ? err.message : String(err)}`
|
|
1830
|
-
}
|
|
1831
|
-
],
|
|
1832
|
-
isError: true
|
|
1833
|
-
};
|
|
1834
|
-
}
|
|
1835
|
-
}
|
|
1836
|
-
);
|
|
1837
|
-
server.tool(
|
|
1838
|
-
"misp_attach_galaxy_cluster",
|
|
1839
|
-
"Attach a galaxy cluster (MITRE ATT&CK technique, threat actor, etc.) to an event or attribute",
|
|
1840
|
-
{
|
|
1841
|
-
targetType: z9.enum(["event", "attribute"]).describe("Attach to an event or attribute"),
|
|
1842
|
-
targetId: z9.string().describe("Event ID or attribute ID"),
|
|
1843
|
-
galaxyClusterId: z9.string().describe("Galaxy cluster ID to attach")
|
|
1844
|
-
},
|
|
1845
|
-
async ({ targetType, targetId, galaxyClusterId }) => {
|
|
1846
|
-
try {
|
|
1847
|
-
await client.attachGalaxyCluster(targetType, targetId, galaxyClusterId);
|
|
1848
|
-
return {
|
|
1849
|
-
content: [
|
|
1850
|
-
{
|
|
1851
|
-
type: "text",
|
|
1852
|
-
text: `Galaxy cluster ${galaxyClusterId} attached to ${targetType} ${targetId}.`
|
|
1853
|
-
}
|
|
1854
|
-
]
|
|
1855
|
-
};
|
|
1856
|
-
} catch (err) {
|
|
1857
|
-
return {
|
|
1858
|
-
content: [
|
|
1859
|
-
{
|
|
1860
|
-
type: "text",
|
|
1861
|
-
text: `Error attaching galaxy cluster: ${err instanceof Error ? err.message : String(err)}`
|
|
1862
|
-
}
|
|
1863
|
-
],
|
|
1864
|
-
isError: true
|
|
1865
|
-
};
|
|
1866
|
-
}
|
|
1867
|
-
}
|
|
1868
|
-
);
|
|
1869
|
-
}
|
|
1870
|
-
|
|
1871
|
-
// src/tools/feeds.ts
|
|
1872
|
-
import { z as z10 } from "zod";
|
|
1873
|
-
function registerFeedTools(server, client) {
|
|
1874
|
-
server.tool(
|
|
1875
|
-
"misp_list_feeds",
|
|
1876
|
-
"List configured MISP feeds (threat intel sources, IOC feeds, etc.)",
|
|
1877
|
-
{
|
|
1878
|
-
enabled: z10.boolean().optional().describe("Filter by enabled/disabled status")
|
|
1879
|
-
},
|
|
1880
|
-
async ({ enabled }) => {
|
|
1881
|
-
try {
|
|
1882
|
-
let feeds = await client.listFeeds();
|
|
1883
|
-
if (enabled !== void 0) {
|
|
1884
|
-
feeds = feeds.filter((f) => f.enabled === enabled);
|
|
1885
|
-
}
|
|
1886
|
-
if (feeds.length === 0) {
|
|
1887
|
-
return {
|
|
1888
|
-
content: [{ type: "text", text: "No feeds found." }]
|
|
1889
|
-
};
|
|
1890
|
-
}
|
|
1891
|
-
const summary = feeds.map((f) => ({
|
|
1892
|
-
id: f.id,
|
|
1893
|
-
name: f.name,
|
|
1894
|
-
provider: f.provider,
|
|
1895
|
-
url: f.url,
|
|
1896
|
-
enabled: f.enabled,
|
|
1897
|
-
source_format: f.source_format,
|
|
1898
|
-
distribution: f.distribution,
|
|
1899
|
-
event_id: f.event_id,
|
|
1900
|
-
caching_enabled: f.caching_enabled
|
|
1901
|
-
}));
|
|
1902
|
-
return {
|
|
1903
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
1904
|
-
};
|
|
1905
|
-
} catch (err) {
|
|
1906
|
-
return {
|
|
1907
|
-
content: [
|
|
1908
|
-
{
|
|
1909
|
-
type: "text",
|
|
1910
|
-
text: `Error listing feeds: ${err instanceof Error ? err.message : String(err)}`
|
|
1911
|
-
}
|
|
1912
|
-
],
|
|
1913
|
-
isError: true
|
|
1914
|
-
};
|
|
1915
|
-
}
|
|
1916
|
-
}
|
|
1917
|
-
);
|
|
1918
|
-
server.tool(
|
|
1919
|
-
"misp_toggle_feed",
|
|
1920
|
-
"Enable or disable a MISP feed",
|
|
1921
|
-
{
|
|
1922
|
-
feedId: z10.string().describe("Feed ID"),
|
|
1923
|
-
enable: z10.boolean().describe("true to enable, false to disable")
|
|
1924
|
-
},
|
|
1925
|
-
async ({ feedId, enable }) => {
|
|
1926
|
-
try {
|
|
1927
|
-
await client.toggleFeed(feedId, enable);
|
|
1928
|
-
return {
|
|
1929
|
-
content: [
|
|
1930
|
-
{
|
|
1931
|
-
type: "text",
|
|
1932
|
-
text: `Feed ${feedId} ${enable ? "enabled" : "disabled"} successfully.`
|
|
1933
|
-
}
|
|
1934
|
-
]
|
|
1935
|
-
};
|
|
1936
|
-
} catch (err) {
|
|
1937
|
-
return {
|
|
1938
|
-
content: [
|
|
1939
|
-
{
|
|
1940
|
-
type: "text",
|
|
1941
|
-
text: `Error toggling feed: ${err instanceof Error ? err.message : String(err)}`
|
|
1942
|
-
}
|
|
1943
|
-
],
|
|
1944
|
-
isError: true
|
|
1945
|
-
};
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1948
|
-
);
|
|
1949
|
-
server.tool(
|
|
1950
|
-
"misp_fetch_feed",
|
|
1951
|
-
"Trigger a fetch/pull of data from a specific MISP feed",
|
|
1952
|
-
{
|
|
1953
|
-
feedId: z10.string().describe("Feed ID to fetch")
|
|
1954
|
-
},
|
|
1955
|
-
async ({ feedId }) => {
|
|
1956
|
-
try {
|
|
1957
|
-
const result = await client.fetchFeed(feedId);
|
|
1958
|
-
return {
|
|
1959
|
-
content: [
|
|
1960
|
-
{
|
|
1961
|
-
type: "text",
|
|
1962
|
-
text: result.message || `Feed ${feedId} fetch initiated.`
|
|
1963
|
-
}
|
|
1964
|
-
]
|
|
1965
|
-
};
|
|
1966
|
-
} catch (err) {
|
|
1967
|
-
return {
|
|
1968
|
-
content: [
|
|
1969
|
-
{
|
|
1970
|
-
type: "text",
|
|
1971
|
-
text: `Error fetching feed: ${err instanceof Error ? err.message : String(err)}`
|
|
1972
|
-
}
|
|
1973
|
-
],
|
|
1974
|
-
isError: true
|
|
1975
|
-
};
|
|
1976
|
-
}
|
|
1977
|
-
}
|
|
1978
|
-
);
|
|
1979
|
-
server.tool(
|
|
1980
|
-
"misp_cache_feed",
|
|
1981
|
-
"Cache feed data locally for correlation without creating events",
|
|
1982
|
-
{
|
|
1983
|
-
feedId: z10.string().describe("Feed ID to cache")
|
|
1984
|
-
},
|
|
1985
|
-
async ({ feedId }) => {
|
|
1986
|
-
try {
|
|
1987
|
-
const result = await client.cacheFeed(feedId);
|
|
1988
|
-
return {
|
|
1989
|
-
content: [
|
|
1990
|
-
{
|
|
1991
|
-
type: "text",
|
|
1992
|
-
text: result.message || `Feed ${feedId} cache initiated.`
|
|
1993
|
-
}
|
|
1994
|
-
]
|
|
1995
|
-
};
|
|
1996
|
-
} catch (err) {
|
|
1997
|
-
return {
|
|
1998
|
-
content: [
|
|
1999
|
-
{
|
|
2000
|
-
type: "text",
|
|
2001
|
-
text: `Error caching feed: ${err instanceof Error ? err.message : String(err)}`
|
|
2002
|
-
}
|
|
2003
|
-
],
|
|
2004
|
-
isError: true
|
|
2005
|
-
};
|
|
2006
|
-
}
|
|
2007
|
-
}
|
|
2008
|
-
);
|
|
2009
|
-
}
|
|
2010
|
-
|
|
2011
|
-
// src/tools/organisations.ts
|
|
2012
|
-
import { z as z11 } from "zod";
|
|
2013
|
-
function registerOrganisationTools(server, client) {
|
|
2014
|
-
server.tool(
|
|
2015
|
-
"misp_list_organisations",
|
|
2016
|
-
"List MISP organisations (local and remote sharing partners)",
|
|
2017
|
-
{
|
|
2018
|
-
scope: z11.enum(["local", "external", "all"]).optional().describe("Filter by local, external, or all organisations")
|
|
2019
|
-
},
|
|
2020
|
-
async ({ scope }) => {
|
|
2021
|
-
try {
|
|
2022
|
-
const orgs = await client.listOrganisations(scope || "all");
|
|
2023
|
-
if (orgs.length === 0) {
|
|
2024
|
-
return {
|
|
2025
|
-
content: [{ type: "text", text: "No organisations found." }]
|
|
2026
|
-
};
|
|
2027
|
-
}
|
|
2028
|
-
const summary = orgs.map((o) => ({
|
|
2029
|
-
id: o.id,
|
|
2030
|
-
name: o.name,
|
|
2031
|
-
uuid: o.uuid,
|
|
2032
|
-
description: o.description,
|
|
2033
|
-
nationality: o.nationality,
|
|
2034
|
-
sector: o.sector,
|
|
2035
|
-
type: o.type,
|
|
2036
|
-
local: o.local
|
|
2037
|
-
}));
|
|
2038
|
-
return {
|
|
2039
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
2040
|
-
};
|
|
2041
|
-
} catch (err) {
|
|
2042
|
-
return {
|
|
2043
|
-
content: [
|
|
2044
|
-
{
|
|
2045
|
-
type: "text",
|
|
2046
|
-
text: `Error listing organisations: ${err instanceof Error ? err.message : String(err)}`
|
|
2047
|
-
}
|
|
2048
|
-
],
|
|
2049
|
-
isError: true
|
|
2050
|
-
};
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
);
|
|
2054
|
-
server.tool(
|
|
2055
|
-
"misp_get_organisation",
|
|
2056
|
-
"Get details of a specific MISP organisation",
|
|
2057
|
-
{
|
|
2058
|
-
orgId: z11.string().describe("Organisation ID")
|
|
2059
|
-
},
|
|
2060
|
-
async ({ orgId }) => {
|
|
2061
|
-
try {
|
|
2062
|
-
const org = await client.getOrganisation(orgId);
|
|
2063
|
-
return {
|
|
2064
|
-
content: [{ type: "text", text: JSON.stringify(org, null, 2) }]
|
|
2065
|
-
};
|
|
2066
|
-
} catch (err) {
|
|
2067
|
-
return {
|
|
2068
|
-
content: [
|
|
2069
|
-
{
|
|
2070
|
-
type: "text",
|
|
2071
|
-
text: `Error getting organisation: ${err instanceof Error ? err.message : String(err)}`
|
|
2072
|
-
}
|
|
2073
|
-
],
|
|
2074
|
-
isError: true
|
|
2075
|
-
};
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
);
|
|
2079
|
-
}
|
|
2080
|
-
|
|
2081
|
-
// src/tools/servers.ts
|
|
2082
|
-
import { z as z12 } from "zod";
|
|
2083
|
-
function registerServerTools(server, client) {
|
|
2084
|
-
server.tool(
|
|
2085
|
-
"misp_server_status",
|
|
2086
|
-
"Get MISP server version, status, and diagnostic information",
|
|
2087
|
-
{},
|
|
2088
|
-
async () => {
|
|
2089
|
-
try {
|
|
2090
|
-
const version = await client.getVersion();
|
|
2091
|
-
const settings = await client.getServerSettings();
|
|
2092
|
-
return {
|
|
2093
|
-
content: [
|
|
2094
|
-
{
|
|
2095
|
-
type: "text",
|
|
2096
|
-
text: JSON.stringify(
|
|
2097
|
-
{
|
|
2098
|
-
version: version.version,
|
|
2099
|
-
pymisp_recommended: version.pymisp_recommended_version,
|
|
2100
|
-
permissions: {
|
|
2101
|
-
sync: version.perm_sync,
|
|
2102
|
-
sighting: version.perm_sighting,
|
|
2103
|
-
galaxy_editor: version.perm_galaxy_editor,
|
|
2104
|
-
analyst_data: version.perm_analyst_data
|
|
2105
|
-
},
|
|
2106
|
-
diagnostics: settings.diagnostics
|
|
2107
|
-
},
|
|
2108
|
-
null,
|
|
2109
|
-
2
|
|
2110
|
-
)
|
|
2111
|
-
}
|
|
2112
|
-
]
|
|
2113
|
-
};
|
|
2114
|
-
} catch (err) {
|
|
2115
|
-
return {
|
|
2116
|
-
content: [
|
|
2117
|
-
{
|
|
2118
|
-
type: "text",
|
|
2119
|
-
text: `Error getting server status: ${err instanceof Error ? err.message : String(err)}`
|
|
2120
|
-
}
|
|
2121
|
-
],
|
|
2122
|
-
isError: true
|
|
2123
|
-
};
|
|
2124
|
-
}
|
|
2125
|
-
}
|
|
2126
|
-
);
|
|
2127
|
-
server.tool(
|
|
2128
|
-
"misp_list_sharing_groups",
|
|
2129
|
-
"List MISP sharing groups for controlled event distribution",
|
|
2130
|
-
{},
|
|
2131
|
-
async () => {
|
|
2132
|
-
try {
|
|
2133
|
-
const groups = await client.listSharingGroups();
|
|
2134
|
-
if (groups.length === 0) {
|
|
2135
|
-
return {
|
|
2136
|
-
content: [
|
|
2137
|
-
{
|
|
2138
|
-
type: "text",
|
|
2139
|
-
text: "No sharing groups configured."
|
|
2140
|
-
}
|
|
2141
|
-
]
|
|
2142
|
-
};
|
|
2143
|
-
}
|
|
2144
|
-
const summary = groups.map((g) => ({
|
|
2145
|
-
id: g.id,
|
|
2146
|
-
name: g.name,
|
|
2147
|
-
description: g.description,
|
|
2148
|
-
uuid: g.uuid,
|
|
2149
|
-
releasability: g.releasability,
|
|
2150
|
-
active: g.active,
|
|
2151
|
-
org_count: g.org_count
|
|
2152
|
-
}));
|
|
2153
|
-
return {
|
|
2154
|
-
content: [{ type: "text", text: JSON.stringify(summary, null, 2) }]
|
|
2155
|
-
};
|
|
2156
|
-
} catch (err) {
|
|
2157
|
-
return {
|
|
2158
|
-
content: [
|
|
2159
|
-
{
|
|
2160
|
-
type: "text",
|
|
2161
|
-
text: `Error listing sharing groups: ${err instanceof Error ? err.message : String(err)}`
|
|
2162
|
-
}
|
|
2163
|
-
],
|
|
2164
|
-
isError: true
|
|
2165
|
-
};
|
|
2166
|
-
}
|
|
2167
|
-
}
|
|
2168
|
-
);
|
|
2169
|
-
server.tool(
|
|
2170
|
-
"misp_delete_event",
|
|
2171
|
-
"Delete a MISP event (requires appropriate permissions). Destructive: requires confirm:true (or MISP_ALLOW_DESTRUCTIVE=true).",
|
|
2172
|
-
{
|
|
2173
|
-
eventId: z12.string().describe("Event ID to delete"),
|
|
2174
|
-
confirm: z12.boolean().optional().describe("Must be true to perform this destructive deletion (unless MISP_ALLOW_DESTRUCTIVE=true)")
|
|
2175
|
-
},
|
|
2176
|
-
async ({ eventId, confirm }) => {
|
|
2177
|
-
try {
|
|
2178
|
-
const guard = requireConfirmation(confirm, `deleting event ${eventId}`);
|
|
2179
|
-
if (guard) return guard;
|
|
2180
|
-
const result = await client.deleteEvent(eventId);
|
|
2181
|
-
return {
|
|
2182
|
-
content: [
|
|
2183
|
-
{
|
|
2184
|
-
type: "text",
|
|
2185
|
-
text: result.message || `Event ${eventId} deleted.`
|
|
2186
|
-
}
|
|
2187
|
-
]
|
|
2188
|
-
};
|
|
2189
|
-
} catch (err) {
|
|
2190
|
-
return {
|
|
2191
|
-
content: [
|
|
2192
|
-
{
|
|
2193
|
-
type: "text",
|
|
2194
|
-
text: `Error deleting event: ${err instanceof Error ? err.message : String(err)}`
|
|
2195
|
-
}
|
|
2196
|
-
],
|
|
2197
|
-
isError: true
|
|
2198
|
-
};
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
);
|
|
2202
|
-
}
|
|
2203
|
-
|
|
2204
|
-
// src/resources.ts
|
|
2205
|
-
function registerResources(server, client) {
|
|
2206
|
-
server.resource(
|
|
2207
|
-
"types",
|
|
2208
|
-
"misp://types",
|
|
2209
|
-
{
|
|
2210
|
-
description: "All supported MISP attribute types and categories with their mappings",
|
|
2211
|
-
mimeType: "application/json"
|
|
2212
|
-
},
|
|
2213
|
-
async () => {
|
|
2214
|
-
const types = await client.describeTypes();
|
|
2215
|
-
const summary = {
|
|
2216
|
-
types: types.types,
|
|
2217
|
-
categories: types.categories,
|
|
2218
|
-
category_type_mappings: types.category_type_mappings,
|
|
2219
|
-
type_defaults: Object.entries(types.sane_defaults).map(([type, info]) => ({
|
|
2220
|
-
type,
|
|
2221
|
-
default_category: info.default_category,
|
|
2222
|
-
to_ids: info.to_ids === 1
|
|
2223
|
-
}))
|
|
2224
|
-
};
|
|
2225
|
-
return {
|
|
2226
|
-
contents: [
|
|
2227
|
-
{
|
|
2228
|
-
uri: "misp://types",
|
|
2229
|
-
mimeType: "application/json",
|
|
2230
|
-
text: JSON.stringify(summary, null, 2)
|
|
2231
|
-
}
|
|
2232
|
-
]
|
|
2233
|
-
};
|
|
2234
|
-
}
|
|
2235
|
-
);
|
|
2236
|
-
server.resource(
|
|
2237
|
-
"statistics",
|
|
2238
|
-
"misp://statistics",
|
|
2239
|
-
{
|
|
2240
|
-
description: "MISP instance capability summary (supported attribute types and categories). Use misp_search_events for actual counts.",
|
|
2241
|
-
mimeType: "application/json"
|
|
2242
|
-
},
|
|
2243
|
-
async () => {
|
|
2244
|
-
const types = await client.describeTypes();
|
|
2245
|
-
const stats = {
|
|
2246
|
-
available_types: types.types.length,
|
|
2247
|
-
available_categories: types.categories.length,
|
|
2248
|
-
note: "This resource reports capability metadata, not event totals. Use misp_search_events with date/tag filters to count events."
|
|
2249
|
-
};
|
|
2250
|
-
return {
|
|
2251
|
-
contents: [
|
|
2252
|
-
{
|
|
2253
|
-
uri: "misp://statistics",
|
|
2254
|
-
mimeType: "application/json",
|
|
2255
|
-
text: JSON.stringify(stats, null, 2)
|
|
2256
|
-
}
|
|
2257
|
-
]
|
|
2258
|
-
};
|
|
2259
|
-
}
|
|
2260
|
-
);
|
|
2261
|
-
server.resource(
|
|
2262
|
-
"taxonomies",
|
|
2263
|
-
"misp://taxonomies",
|
|
2264
|
-
{
|
|
2265
|
-
description: "Available MISP taxonomies (TLP, MITRE ATT&CK, etc.)",
|
|
2266
|
-
mimeType: "application/json"
|
|
2267
|
-
},
|
|
2268
|
-
async () => {
|
|
2269
|
-
const taxonomies = await client.listTaxonomies();
|
|
2270
|
-
const summary = taxonomies.map((t) => ({
|
|
2271
|
-
namespace: t.namespace,
|
|
2272
|
-
description: t.description,
|
|
2273
|
-
version: t.version,
|
|
2274
|
-
enabled: t.enabled
|
|
2275
|
-
}));
|
|
2276
|
-
return {
|
|
2277
|
-
contents: [
|
|
2278
|
-
{
|
|
2279
|
-
uri: "misp://taxonomies",
|
|
2280
|
-
mimeType: "application/json",
|
|
2281
|
-
text: JSON.stringify(summary, null, 2)
|
|
2282
|
-
}
|
|
2283
|
-
]
|
|
2284
|
-
};
|
|
2285
|
-
}
|
|
2286
|
-
);
|
|
2287
|
-
}
|
|
2288
|
-
|
|
2289
|
-
// src/prompts.ts
|
|
2290
|
-
import { z as z13 } from "zod";
|
|
2291
|
-
function registerPrompts(server) {
|
|
2292
|
-
server.prompt(
|
|
2293
|
-
"investigate-ioc",
|
|
2294
|
-
"Deep investigation of an IOC across MISP - searches for the indicator, finds correlations, checks warninglists, and summarizes threat context",
|
|
2295
|
-
{
|
|
2296
|
-
ioc: z13.string().describe("The IOC value to investigate (IP, domain, hash, URL, email, etc.)"),
|
|
2297
|
-
iocType: z13.string().optional().describe("IOC type hint (ip-src, domain, md5, sha256, url, etc.)")
|
|
2298
|
-
},
|
|
2299
|
-
({ ioc, iocType }) => {
|
|
2300
|
-
const typeHint = iocType ? `The IOC type is "${iocType}".` : "Determine the IOC type from the value format.";
|
|
2301
|
-
return {
|
|
2302
|
-
messages: [
|
|
2303
|
-
{
|
|
2304
|
-
role: "user",
|
|
2305
|
-
content: {
|
|
2306
|
-
type: "text",
|
|
2307
|
-
text: `Investigate the following IOC in MISP: "${ioc}"
|
|
2308
|
-
|
|
2309
|
-
${typeHint}
|
|
2310
|
-
|
|
2311
|
-
Follow these steps:
|
|
2312
|
-
1. Use misp_search_attributes to search for this IOC value across all events. If you know the type, filter by it.
|
|
2313
|
-
2. Use misp_correlate to find all correlations for this value across events.
|
|
2314
|
-
3. Use misp_check_warninglists to check if this value appears on any known benign/false positive lists.
|
|
2315
|
-
4. For each event found, note the threat level, tags (especially TLP and MITRE ATT&CK), and related IOCs.
|
|
2316
|
-
5. If the IOC appears in multiple events, use misp_get_related_events on the most relevant event to discover additional related intelligence.
|
|
2317
|
-
|
|
2318
|
-
Provide a structured summary including:
|
|
2319
|
-
- Whether the IOC was found in MISP and in how many events
|
|
2320
|
-
- Threat level assessment based on event metadata
|
|
2321
|
-
- Related IOCs and correlations discovered
|
|
2322
|
-
- Whether it appears on any warninglists (potential false positive)
|
|
2323
|
-
- MITRE ATT&CK techniques associated with this IOC
|
|
2324
|
-
- Recommended next steps for the analyst`
|
|
2325
|
-
}
|
|
2326
|
-
}
|
|
2327
|
-
]
|
|
2328
|
-
};
|
|
2329
|
-
}
|
|
2330
|
-
);
|
|
2331
|
-
server.prompt(
|
|
2332
|
-
"create-incident-event",
|
|
2333
|
-
"Guided workflow for creating a MISP event from an incident, including adding attributes, tagging, and publishing",
|
|
2334
|
-
{
|
|
2335
|
-
description: z13.string().describe("Description of the incident"),
|
|
2336
|
-
iocs: z13.string().optional().describe("Comma-separated list of IOCs to add (e.g., '192.168.1.1,evil.com,abc123hash')")
|
|
2337
|
-
},
|
|
2338
|
-
({ description, iocs }) => {
|
|
2339
|
-
const iocList = iocs ? `
|
|
2340
|
-
The following IOCs should be added: ${iocs}` : "\nAsk the analyst for any IOCs (IP addresses, domains, file hashes, URLs) associated with this incident.";
|
|
2341
|
-
return {
|
|
2342
|
-
messages: [
|
|
2343
|
-
{
|
|
2344
|
-
role: "user",
|
|
2345
|
-
content: {
|
|
2346
|
-
type: "text",
|
|
2347
|
-
text: `Create a MISP event for the following incident:
|
|
2348
|
-
|
|
2349
|
-
"${description}"
|
|
2350
|
-
${iocList}
|
|
2351
|
-
|
|
2352
|
-
Follow these steps:
|
|
2353
|
-
1. Use misp_create_event with:
|
|
2354
|
-
- An informative title based on the incident description
|
|
2355
|
-
- Appropriate threat level (1=High for active compromise, 2=Medium for suspicious activity, 3=Low for informational)
|
|
2356
|
-
- Analysis status: 0 (Initial)
|
|
2357
|
-
- Distribution: 0 (Organization only) to start - can be broadened later
|
|
2358
|
-
|
|
2359
|
-
2. For each IOC:
|
|
2360
|
-
- Determine the correct attribute type (ip-src, ip-dst, domain, md5, sha256, url, etc.)
|
|
2361
|
-
- Use misp_add_attribute (or misp_add_attributes_bulk for multiple) to add them
|
|
2362
|
-
- Use misp_check_warninglists to verify none are known false positives
|
|
2363
|
-
|
|
2364
|
-
3. Add appropriate tags using misp_tag_event:
|
|
2365
|
-
- TLP tag (tlp:white, tlp:green, tlp:amber, tlp:red)
|
|
2366
|
-
- Relevant MITRE ATT&CK technique tags if applicable
|
|
2367
|
-
- Any organization-specific tags
|
|
2368
|
-
|
|
2369
|
-
4. Summarize what was created:
|
|
2370
|
-
- Event ID and title
|
|
2371
|
-
- Number of attributes added
|
|
2372
|
-
- Tags applied
|
|
2373
|
-
- Ask if the analyst wants to publish (misp_publish_event) or keep as draft`
|
|
2374
|
-
}
|
|
2375
|
-
}
|
|
2376
|
-
]
|
|
2377
|
-
};
|
|
2378
|
-
}
|
|
2379
|
-
);
|
|
2380
|
-
server.prompt(
|
|
2381
|
-
"threat-report",
|
|
2382
|
-
"Generate a threat intelligence report from MISP data by aggregating events, extracting IOC patterns, and summarizing the threat landscape",
|
|
2383
|
-
{
|
|
2384
|
-
eventId: z13.string().optional().describe("Specific event ID to report on"),
|
|
2385
|
-
tag: z13.string().optional().describe("Filter by tag (e.g., mitre-attack:T1059, tlp:amber)"),
|
|
2386
|
-
dateRange: z13.string().optional().describe("Date range or relative time (e.g., '7d', '30d', '2024-01-01 to 2024-01-31')")
|
|
2387
|
-
},
|
|
2388
|
-
({ eventId, tag, dateRange }) => {
|
|
2389
|
-
let scopeInstructions;
|
|
2390
|
-
if (eventId) {
|
|
2391
|
-
scopeInstructions = `Focus on event ID ${eventId}. Use misp_get_event to get full details, then misp_get_related_events for context.`;
|
|
2392
|
-
} else if (tag) {
|
|
2393
|
-
scopeInstructions = `Focus on events tagged with "${tag}". Use misp_search_by_tag to find matching events.`;
|
|
2394
|
-
} else if (dateRange) {
|
|
2395
|
-
const isRelative = /^\d+[dmhwy]$/.test(dateRange);
|
|
2396
|
-
if (isRelative) {
|
|
2397
|
-
scopeInstructions = `Focus on events from the last ${dateRange}. Use misp_search_events with last="${dateRange}".`;
|
|
2398
|
-
} else {
|
|
2399
|
-
scopeInstructions = `Focus on events in the date range: ${dateRange}. Use misp_search_events with appropriate dateFrom/dateTo.`;
|
|
2400
|
-
}
|
|
2401
|
-
} else {
|
|
2402
|
-
scopeInstructions = `Generate a report on recent threat activity. Use misp_search_events with last="7d" to get the latest events.`;
|
|
2403
|
-
}
|
|
2404
|
-
return {
|
|
2405
|
-
messages: [
|
|
2406
|
-
{
|
|
2407
|
-
role: "user",
|
|
2408
|
-
content: {
|
|
2409
|
-
type: "text",
|
|
2410
|
-
text: `Generate a threat intelligence report from MISP data.
|
|
2411
|
-
|
|
2412
|
-
${scopeInstructions}
|
|
2413
|
-
|
|
2414
|
-
Report structure:
|
|
2415
|
-
1. **Executive Summary**: Brief overview of the threat landscape for the specified scope
|
|
2416
|
-
2. **Key Events**: List the most significant events with threat levels and descriptions
|
|
2417
|
-
3. **IOC Summary**:
|
|
2418
|
-
- Use misp_search_attributes to aggregate IOC types and counts
|
|
2419
|
-
- List the most significant indicators by type (IPs, domains, hashes, URLs)
|
|
2420
|
-
4. **MITRE ATT&CK Coverage**: List any ATT&CK techniques observed across the events
|
|
2421
|
-
5. **Correlations**: Use misp_correlate on high-value IOCs to discover cross-event links
|
|
2422
|
-
6. **Recommendations**:
|
|
2423
|
-
- Immediate blocking actions (IPs, domains to block)
|
|
2424
|
-
- Detection rules needed
|
|
2425
|
-
- Areas requiring further investigation
|
|
2426
|
-
|
|
2427
|
-
Format the report in clear markdown with headers and tables where appropriate.`
|
|
2428
|
-
}
|
|
2429
|
-
}
|
|
2430
|
-
]
|
|
2431
|
-
};
|
|
2432
|
-
}
|
|
2433
|
-
);
|
|
2434
|
-
}
|
|
2435
|
-
|
|
2436
|
-
// src/mcp-server.ts
|
|
2437
|
-
var packageJson = JSON.parse(
|
|
2438
|
-
readFileSync(new URL("../package.json", import.meta.url), "utf8")
|
|
2439
|
-
);
|
|
2440
|
-
function createMispMcpServer(deps = {}) {
|
|
2441
|
-
const config = deps.config ?? getConfig();
|
|
2442
|
-
const client = deps.client ?? new MispClient(config);
|
|
2443
|
-
const server = new McpServer({
|
|
2444
|
-
name: "misp-mcp",
|
|
2445
|
-
version: packageJson.version ?? "0.0.0",
|
|
2446
|
-
description: "MCP server for MISP threat intelligence platform - IOC lookups, event management, correlation discovery, and intelligence enrichment"
|
|
2447
|
-
});
|
|
2448
|
-
registerEventTools(server, client);
|
|
2449
|
-
registerAttributeTools(server, client);
|
|
2450
|
-
registerCorrelationTools(server, client);
|
|
2451
|
-
registerTagTools(server, client);
|
|
2452
|
-
registerExportTools(server, client);
|
|
2453
|
-
registerSightingTools(server, client);
|
|
2454
|
-
registerWarninglistTools(server, client);
|
|
2455
|
-
registerObjectTools(server, client);
|
|
2456
|
-
registerGalaxyTools(server, client);
|
|
2457
|
-
registerFeedTools(server, client);
|
|
2458
|
-
registerOrganisationTools(server, client);
|
|
2459
|
-
registerServerTools(server, client);
|
|
2460
|
-
registerResources(server, client);
|
|
2461
|
-
registerPrompts(server);
|
|
2462
|
-
return server;
|
|
2463
|
-
}
|
|
2464
|
-
function stripSchemaFromToolList(transport) {
|
|
2465
|
-
const send = transport.send.bind(transport);
|
|
2466
|
-
transport.send = (message) => {
|
|
2467
|
-
const tools = message?.result?.tools;
|
|
2468
|
-
if (Array.isArray(tools)) {
|
|
2469
|
-
for (const tool of tools) {
|
|
2470
|
-
if (tool?.inputSchema) delete tool.inputSchema.$schema;
|
|
2471
|
-
if (tool?.outputSchema) delete tool.outputSchema.$schema;
|
|
2472
|
-
}
|
|
2473
|
-
}
|
|
2474
|
-
return send(message);
|
|
2475
|
-
};
|
|
2476
|
-
}
|
|
2477
|
-
async function serveMcp() {
|
|
2478
|
-
const config = getConfig();
|
|
2479
|
-
const server = createMispMcpServer({ config });
|
|
2480
|
-
const transport = new StdioServerTransport();
|
|
2481
|
-
stripSchemaFromToolList(transport);
|
|
2482
|
-
await server.connect(transport);
|
|
2483
|
-
}
|
|
2484
|
-
|
|
2485
|
-
export {
|
|
2486
|
-
getConfig,
|
|
2487
|
-
MispClient,
|
|
2488
|
-
createMispMcpServer,
|
|
2489
|
-
serveMcp
|
|
2490
|
-
};
|
|
2491
|
-
//# sourceMappingURL=chunk-GTLBUJZI.js.map
|